GEOSX
FluxStencil.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
20 #ifndef GEOSX_FINITEVOLUME_FLUXSTENCIL_HPP_
21 #define GEOSX_FINITEVOLUME_FLUXSTENCIL_HPP_
22 
23 #include <common/DataTypes.hpp>
24 #include "codingUtilities/Utilities.hpp"
25 
26 namespace geosx
27 {
28 
34 template< typename INDEX, typename WEIGHT >
36 {
37 public:
38 
42  static localIndex constexpr NUM_POINT_IN_FLUX = 2;
43 
47  static localIndex constexpr MAX_STENCIL_SIZE = 18;
48 
50  using index_type = INDEX;
52  using weight_type = WEIGHT;
53 
54  explicit FluxStencil();
55 
61  explicit FluxStencil( localIndex const numConn,
62  localIndex const avgStencilSize );
63 
68  localIndex numConnections() const;
69 
75  void reserve( localIndex const numConn,
76  localIndex const avgStencilSize );
77 
85  void add( localIndex const numPts,
86  INDEX const * const indices,
87  WEIGHT const * const weights,
88  localIndex const connectorIndex );
89 
95  bool zero( localIndex const connectorIndex );
96 
100  void compress();
101 
106  struct Entry
107  {
108  INDEX index;
109  WEIGHT weight;
110  };
111 
116  ArrayOfArraysView< Entry const, true > getConnections() const { return m_connections.toViewConst(); }
117 
118 private:
119 
120  ArrayOfArrays< Entry > m_connections;
121  map< localIndex, localIndex > m_connectorIndices;
122 
123 };
124 
125 template< typename INDEX, typename WEIGHT >
127  : FluxStencil( 0, 0 )
128 {}
129 
130 template< typename INDEX, typename WEIGHT >
132  localIndex const avgStencilSize )
133  : m_connections()
134 {
135  reserve( numConn, avgStencilSize );
136 }
137 
138 template< typename INDEX, typename WEIGHT >
140 {
141  return m_connections.size();
142 }
143 
144 template< typename INDEX, typename WEIGHT >
146  localIndex const avgStencilSize )
147 {
148  m_connections.reserve( numConn );
149  m_connections.reserveValues( numConn * avgStencilSize );
150 }
151 
152 template< typename INDEX, typename WEIGHT >
154  INDEX const * const indices,
155  WEIGHT const * const weights,
156  localIndex const connectorIndex )
157 {
158  GEOSX_ERROR_IF( numPts >= MAX_STENCIL_SIZE, "Maximum stencil size exceeded" );
159 
160  stackArray1d< Entry, MAX_STENCIL_SIZE > entries( numPts );
161  for( localIndex i = 0; i < numPts; ++i )
162  {
163  entries[i] = { indices[i], weights[i] };
164  }
165 
166  m_connections.appendArray( entries.begin(), entries.end() );
167  m_connectorIndices[connectorIndex] = m_connections.size() - 1;
168 }
169 
170 template< typename INDEX, typename WEIGHT >
171 bool FluxStencil< INDEX, WEIGHT >::zero( localIndex const connectorIndex )
172 {
173  return
174  executeOnMapValue( m_connectorIndices, connectorIndex, [&]( localIndex const connectionListIndex )
175  {
176  Entry * const entries = m_connections[connectionListIndex];
177  for( localIndex i = 0; i < m_connections.sizeOfArray( connectionListIndex ); ++i )
178  {
179  entries[i].weight = 0; // TODO remove entries altogether?
180  }
181 // m_connections.resizeArray( connectionListIndex, 0 );
182  } );
183 }
184 
185 
186 template< typename INDEX, typename WEIGHT >
188 {
189  // nothing for the moment
190 }
191 
192 }
193 
194 
195 #endif //GEOSX_FINITEVOLUME_FLUXSTENCIL_HPP_
StackArray< T, 1, MAXSIZE > stackArray1d
Alias for 1D stack array.
Definition: DataTypes.hpp:209
WEIGHT weight_type
Alias for WEIGHT.
Definition: FluxStencil.hpp:52
Structure containing the index and the weight of the single edge in the stencil graph.
INDEX index_type
Alias for INDEX.
Definition: FluxStencil.hpp:50
static localIndex constexpr MAX_STENCIL_SIZE
Maximum number of points in a stencil (required to use static arrays in kernels). ...
Definition: FluxStencil.hpp:47
Base template for ordered and unordered maps.
Definition: DataTypes.hpp:349
This class implements an array of arrays like object with contiguous storage.
localIndex numConnections() const
Return the size of the stencil collection (i.e. number of connections).
void add(localIndex const numPts, INDEX const *const indices, WEIGHT const *const weights, localIndex const connectorIndex)
Add data for one connection.
This class provides a view into an array of arrays like object.
static localIndex constexpr NUM_POINT_IN_FLUX
Number of points the flux is between (normally 2).
Definition: FluxStencil.hpp:42
bool zero(localIndex const connectorIndex)
Zero out connections.
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
WEIGHT weight
edge weight
INDEX index
edge index
void compress()
Called after adding connections is done to compress the data.
#define GEOSX_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:103
ArrayOfArraysView< Entry const, true > getConnections() const
Return the connections.
void reserve(localIndex const numConn, localIndex const avgStencilSize)
Resize the collection.