GEOS
StencilBase.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 Total, S.A
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_FINITEVOLUME_STENCILBASE_HPP_
21 #define GEOS_FINITEVOLUME_STENCILBASE_HPP_
22 
23 #include "common/DataTypes.hpp"
24 #include "codingUtilities/Utilities.hpp"
26 
27 namespace geos
28 {
29 
37 template< template< typename ... > class CONTAINER,
38  localIndex MAX_NUM_POINTS_IN_FLUX,
39  localIndex MAX_STENCIL_SIZE,
40  localIndex MAX_NUM_CONNECTIONS >
42 {
44  using IndexContainerType = CONTAINER< localIndex >;
45 
47  using IndexContainerViewConstType = LvArray::typeManipulation::NestedViewTypeConst< IndexContainerType >;
48 
50  using WeightContainerType = CONTAINER< real64 >;
51 
53  using WeightContainerViewConstType = LvArray::typeManipulation::NestedViewTypeConst< WeightContainerType >;
54 
56  using WeightContainerViewType = LvArray::typeManipulation::NestedViewType< WeightContainerType >;
57 
59  static constexpr localIndex maxNumPointsInFlux = MAX_NUM_POINTS_IN_FLUX;
60 
62  static constexpr localIndex maxStencilSize = MAX_STENCIL_SIZE;
63 
65  static constexpr localIndex maxNumConnections = MAX_NUM_CONNECTIONS;
66 };
67 
72 
79 template< typename TRAITS >
80 class StencilWrapperBase : public TRAITS
81 {
82 public:
83 
91  StencilWrapperBase( typename TRAITS::IndexContainerType const & elementRegionIndices,
92  typename TRAITS::IndexContainerType const & elementSubRegionIndices,
93  typename TRAITS::IndexContainerType const & elementIndices,
94  typename TRAITS::WeightContainerType const & weights ):
95  m_elementRegionIndices( elementRegionIndices.toViewConst() ),
96  m_elementSubRegionIndices( elementSubRegionIndices.toViewConst() ),
97  m_elementIndices( elementIndices.toViewConst() ),
98  m_weights( weights.toView() )
99  {};
100 
105  typename TRAITS::IndexContainerViewConstType
107 
112  typename TRAITS::IndexContainerViewConstType
114 
119  typename TRAITS::IndexContainerViewConstType
121 
126  typename TRAITS::WeightContainerViewConstType
127  getWeights() const { return m_weights; }
128 
129 protected:
130 
132  typename TRAITS::IndexContainerViewConstType m_elementRegionIndices;
133 
135  typename TRAITS::IndexContainerViewConstType m_elementSubRegionIndices;
136 
138  typename TRAITS::IndexContainerViewConstType m_elementIndices;
139 
141  typename TRAITS::WeightContainerViewType m_weights;
142 };
143 
144 
150 template< typename TRAITS, typename LEAFCLASS >
151 class StencilBase : public TRAITS
152 {
153 public:
154 
158  virtual ~StencilBase() = default;
159 
164  virtual void reserve( localIndex const size );
165 
174  virtual void move( LvArray::MemorySpace const space );
175 
176 
186  virtual void add( localIndex const numPts,
187  localIndex const * const elementRegionIndices,
188  localIndex const * const elementSubRegionIndices,
189  localIndex const * const elementIndices,
190  real64 const * const weights,
191  localIndex const connectorIndex ) = 0;
192 
199  virtual bool zero( localIndex const connectorIndex );
200 
205  virtual localIndex size() const = 0;
206 
211  void setName( string const & name );
212 
217  typename TRAITS::IndexContainerViewConstType
218  getElementRegionIndices() const { return m_elementRegionIndices.toViewConst(); }
219 
224  typename TRAITS::IndexContainerViewConstType
225  getElementSubRegionIndices() const { return m_elementSubRegionIndices.toViewConst(); }
226 
231  typename TRAITS::IndexContainerViewConstType
232  getElementIndices() const { return m_elementIndices.toViewConst(); }
233 
238  typename TRAITS::WeightContainerViewConstType
239  getWeights() const { return m_weights.toViewConst(); }
240 
241 protected:
242 
244  typename TRAITS::IndexContainerType m_elementRegionIndices;
245 
247  typename TRAITS::IndexContainerType m_elementSubRegionIndices;
248 
250  typename TRAITS::IndexContainerType m_elementIndices;
251 
253  typename TRAITS::WeightContainerType m_weights;
254 
257 };
258 
259 
260 
261 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
263 {
264  m_elementRegionIndices.reserve( size * 2 );
265  m_elementSubRegionIndices.reserve( size * 2 );
266  m_elementIndices.reserve( size * 2 );
267  m_weights.reserve( size * 2 );
268 }
269 
270 
271 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
273 {
274  return
275  executeOnMapValue( m_connectorIndices, connectorIndex, [&]( localIndex const connectionListIndex )
276  {
277  for( localIndex i = 0; i < static_cast< LEAFCLASS * >(this)->stencilSize( connectorIndex ); ++i )
278  {
279  m_weights[connectionListIndex][i] = 0;
280  }
281  } );
282 }
283 
284 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
286 {
287  m_elementRegionIndices.setName( name + "/elementRegionIndices" );
288  m_elementSubRegionIndices.setName( name + "/elementSubRegionIndices" );
289  m_elementIndices.setName( name + "/elementIndices" );
290  m_weights.setName( name + "/weights" );
291 }
292 
293 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
294 void StencilBase< LEAFCLASSTRAITS, LEAFCLASS >::move( LvArray::MemorySpace const space )
295 {
296  m_elementRegionIndices.move( space, true );
297  m_elementSubRegionIndices.move( space, true );
298  m_elementIndices.move( space, true );
299  m_weights.move( space, true );
300 }
301 
302 } /* namespace geos */
303 
304 #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:91
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:329
double real64
64-bit floating point type.
Definition: DataTypes.hpp:99
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
A collection of properties of a stencil type.
Definition: StencilBase.hpp:42
LvArray::typeManipulation::NestedViewType< WeightContainerType > WeightContainerViewType
The array view to type for the stencil weights.
Definition: StencilBase.hpp:56
CONTAINER< localIndex > IndexContainerType
The array type that will be used to store the indices of the stencil contributors.
Definition: StencilBase.hpp:44
LvArray::typeManipulation::NestedViewTypeConst< IndexContainerType > IndexContainerViewConstType
The array view to const type for the stencil indices.
Definition: StencilBase.hpp:47
CONTAINER< real64 > WeightContainerType
The array type that is used to store the weights of the stencil contributors.
Definition: StencilBase.hpp:50
LvArray::typeManipulation::NestedViewTypeConst< WeightContainerType > WeightContainerViewConstType
The array view to const type for the stencil weights.
Definition: StencilBase.hpp:53