GEOSX
StencilBase.hpp
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 TotalEnergies
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 
19 #ifndef GEOS_FINITEVOLUME_STENCILBASE_HPP_
20 #define GEOS_FINITEVOLUME_STENCILBASE_HPP_
21 
22 #include "common/DataTypes.hpp"
23 #include "codingUtilities/Utilities.hpp"
25 
26 namespace geos
27 {
28 
36 template< template< typename ... > class CONTAINER,
37  localIndex MAX_NUM_POINTS_IN_FLUX,
38  localIndex MAX_STENCIL_SIZE,
39  localIndex MAX_NUM_CONNECTIONS >
41 {
43  using IndexContainerType = CONTAINER< localIndex >;
44 
46  using IndexContainerViewConstType = LvArray::typeManipulation::NestedViewTypeConst< IndexContainerType >;
47 
49  using WeightContainerType = CONTAINER< real64 >;
50 
52  using WeightContainerViewConstType = LvArray::typeManipulation::NestedViewTypeConst< WeightContainerType >;
53 
55  using WeightContainerViewType = LvArray::typeManipulation::NestedViewType< WeightContainerType >;
56 
58  static constexpr localIndex maxNumPointsInFlux = MAX_NUM_POINTS_IN_FLUX;
59 
61  static constexpr localIndex maxStencilSize = MAX_STENCIL_SIZE;
62 
64  static constexpr localIndex maxNumConnections = MAX_NUM_CONNECTIONS;
65 };
66 
71 
78 template< typename TRAITS >
79 class StencilWrapperBase : public TRAITS
80 {
81 public:
82 
90  StencilWrapperBase( typename TRAITS::IndexContainerType const & elementRegionIndices,
91  typename TRAITS::IndexContainerType const & elementSubRegionIndices,
92  typename TRAITS::IndexContainerType const & elementIndices,
93  typename TRAITS::WeightContainerType const & weights ):
94  m_elementRegionIndices( elementRegionIndices.toViewConst() ),
95  m_elementSubRegionIndices( elementSubRegionIndices.toViewConst() ),
96  m_elementIndices( elementIndices.toViewConst() ),
97  m_weights( weights.toView() )
98  {};
99 
104  typename TRAITS::IndexContainerViewConstType
106 
111  typename TRAITS::IndexContainerViewConstType
113 
118  typename TRAITS::IndexContainerViewConstType
120 
125  typename TRAITS::WeightContainerViewConstType
126  getWeights() const { return m_weights; }
127 
128 protected:
129 
131  typename TRAITS::IndexContainerViewConstType m_elementRegionIndices;
132 
134  typename TRAITS::IndexContainerViewConstType m_elementSubRegionIndices;
135 
137  typename TRAITS::IndexContainerViewConstType m_elementIndices;
138 
140  typename TRAITS::WeightContainerViewType m_weights;
141 };
142 
143 
149 template< typename TRAITS, typename LEAFCLASS >
150 class StencilBase : public TRAITS
151 {
152 public:
153 
157  virtual ~StencilBase() = default;
158 
163  virtual void reserve( localIndex const size );
164 
173  virtual void move( LvArray::MemorySpace const space );
174 
175 
185  virtual void add( localIndex const numPts,
186  localIndex const * const elementRegionIndices,
187  localIndex const * const elementSubRegionIndices,
188  localIndex const * const elementIndices,
189  real64 const * const weights,
190  localIndex const connectorIndex ) = 0;
191 
198  virtual bool zero( localIndex const connectorIndex );
199 
204  virtual localIndex size() const = 0;
205 
210  void setName( string const & name );
211 
216  typename TRAITS::IndexContainerViewConstType
217  getElementRegionIndices() const { return m_elementRegionIndices.toViewConst(); }
218 
223  typename TRAITS::IndexContainerViewConstType
224  getElementSubRegionIndices() const { return m_elementSubRegionIndices.toViewConst(); }
225 
230  typename TRAITS::IndexContainerViewConstType
231  getElementIndices() const { return m_elementIndices.toViewConst(); }
232 
237  typename TRAITS::WeightContainerViewConstType
238  getWeights() const { return m_weights.toViewConst(); }
239 
240 protected:
241 
243  typename TRAITS::IndexContainerType m_elementRegionIndices;
244 
246  typename TRAITS::IndexContainerType m_elementSubRegionIndices;
247 
249  typename TRAITS::IndexContainerType m_elementIndices;
250 
252  typename TRAITS::WeightContainerType m_weights;
253 
256 };
257 
258 
259 
260 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
262 {
263  m_elementRegionIndices.reserve( size * 2 );
264  m_elementSubRegionIndices.reserve( size * 2 );
265  m_elementIndices.reserve( size * 2 );
266  m_weights.reserve( size * 2 );
267 }
268 
269 
270 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
272 {
273  return
274  executeOnMapValue( m_connectorIndices, connectorIndex, [&]( localIndex const connectionListIndex )
275  {
276  for( localIndex i = 0; i < static_cast< LEAFCLASS * >(this)->stencilSize( connectorIndex ); ++i )
277  {
278  m_weights[connectionListIndex][i] = 0;
279  }
280  } );
281 }
282 
283 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
285 {
286  m_elementRegionIndices.setName( name + "/elementRegionIndices" );
287  m_elementSubRegionIndices.setName( name + "/elementSubRegionIndices" );
288  m_elementIndices.setName( name + "/elementIndices" );
289  m_weights.setName( name + "/weights" );
290 }
291 
292 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
293 void StencilBase< LEAFCLASSTRAITS, LEAFCLASS >::move( LvArray::MemorySpace const space )
294 {
295  m_elementRegionIndices.move( space, true );
296  m_elementSubRegionIndices.move( space, true );
297  m_elementIndices.move( space, true );
298  m_weights.move( space, true );
299 }
300 
301 } /* namespace geos */
302 
303 #endif /* GEOS_FINITEVOLUME_STENCILBASE_HPP_ */
Provides management of the interior stencil points when using Two-Point flux approximation.
TRAITS::IndexContainerViewConstType getElementSubRegionIndices() const
Const access to the element subregions indices.
TRAITS::IndexContainerType m_elementRegionIndices
The container for the element region indices for each point in each stencil.
virtual ~StencilBase()=default
Destructor.
TRAITS::IndexContainerType m_elementSubRegionIndices
The container for the element sub region indices for each point in each stencil.
TRAITS::WeightContainerType m_weights
The container for the weights for each point in each stencil.
TRAITS::IndexContainerViewConstType getElementIndices() const
Const access to the element indices.
virtual localIndex size() const =0
Give the number of stencil entries.
virtual void add(localIndex const numPts, localIndex const *const elementRegionIndices, localIndex const *const elementSubRegionIndices, localIndex const *const elementIndices, real64 const *const weights, localIndex const connectorIndex)=0
Add an entry to the stencil.
unordered_map< localIndex, localIndex > m_connectorIndices
The map that provides the stencil index given the index of the underlying connector object.
TRAITS::WeightContainerViewConstType getWeights() const
Const access to the stencil weights.
void setName(string const &name)
Set the name used in data movement logging callbacks.
TRAITS::IndexContainerViewConstType getElementRegionIndices() const
Const access to the element regions indices.
virtual bool zero(localIndex const connectorIndex)
Zero weights for a stencil entry.
TRAITS::IndexContainerType m_elementIndices
The container for the element indices for each point in each stencil.
virtual void move(LvArray::MemorySpace const space)
Move the data arrays associated with the stencil to a specified memory space.
virtual void reserve(localIndex const size)
Reserve the size of the stencil.
TRAITS::IndexContainerViewConstType getElementIndices() const
Const access to the element indices.
TRAITS::IndexContainerViewConstType m_elementRegionIndices
The container for the element region indices for each point in each stencil.
TRAITS::WeightContainerViewConstType getWeights() const
Const access to the stencil weights.
TRAITS::IndexContainerViewConstType getElementSubRegionIndices() const
Const access to the element subregions indices.
StencilWrapperBase(typename TRAITS::IndexContainerType const &elementRegionIndices, typename TRAITS::IndexContainerType const &elementSubRegionIndices, typename TRAITS::IndexContainerType const &elementIndices, typename TRAITS::WeightContainerType const &weights)
Constructor.
Definition: StencilBase.hpp:90
TRAITS::IndexContainerViewConstType getElementRegionIndices() const
Const access to the element regions indices.
TRAITS::IndexContainerViewConstType m_elementSubRegionIndices
The container for the element sub region indices for each point in each stencil.
TRAITS::WeightContainerViewType m_weights
The container for the weights for each point in each stencil.
TRAITS::IndexContainerViewConstType m_elementIndices
The container for the element indices for each point in each stencil.
Base template for ordered and unordered maps.
Definition: DataTypes.hpp:369
double real64
64-bit floating point type.
Definition: DataTypes.hpp:139
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
A collection of properties of a stencil type.
Definition: StencilBase.hpp:41
LvArray::typeManipulation::NestedViewType< WeightContainerType > WeightContainerViewType
The array view to type for the stencil weights.
Definition: StencilBase.hpp:55
CONTAINER< localIndex > IndexContainerType
The array type that will be used to store the indices of the stencil contributors.
Definition: StencilBase.hpp:43
LvArray::typeManipulation::NestedViewTypeConst< IndexContainerType > IndexContainerViewConstType
The array view to const type for the stencil indices.
Definition: StencilBase.hpp:46
CONTAINER< real64 > WeightContainerType
The array type that is used to store the weights of the stencil contributors.
Definition: StencilBase.hpp:49
LvArray::typeManipulation::NestedViewTypeConst< WeightContainerType > WeightContainerViewConstType
The array view to const type for the stencil weights.
Definition: StencilBase.hpp:52