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 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 
19 #ifndef GEOSX_FINITEVOLUME_STENCILBASE_HPP_
20 #define GEOSX_FINITEVOLUME_STENCILBASE_HPP_
21 
22 #include "common/DataTypes.hpp"
23 #include "codingUtilities/Utilities.hpp"
24 
25 namespace geosx
26 {
27 
33 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
35 {
36 public:
37 
38  StencilBase():
42  m_weights(),
44  {}
45 
49  virtual ~StencilBase() = default;
50 
54  StencilBase( StencilBase const & ) = default;
55 
59  StencilBase( StencilBase && ) = default;
60 
65  virtual void reserve( localIndex const size );
66 
75  virtual void move( LvArray::MemorySpace const space );
76 
77 
87  virtual void add( localIndex const numPts,
88  localIndex const * const elementRegionIndices,
89  localIndex const * const elementSubRegionIndices,
90  localIndex const * const elementIndices,
91  real64 const * const weights,
92  localIndex const connectorIndex ) = 0;
93 
100  virtual bool zero( localIndex const connectorIndex );
101 
106  virtual localIndex size() const = 0;
107 
112  void setName( string const & name );
113 
118  typename LEAFCLASSTRAITS::IndexContainerViewConstType getElementRegionIndices() const { return m_elementRegionIndices.toViewConst(); }
119 
124  typename LEAFCLASSTRAITS::IndexContainerViewConstType getElementSubRegionIndices() const { return m_elementSubRegionIndices.toViewConst(); }
125 
130  typename LEAFCLASSTRAITS::IndexContainerViewConstType getElementIndices() const { return m_elementIndices.toViewConst(); }
131 
136  typename LEAFCLASSTRAITS::WeightContainerViewConstType getWeights() const { return m_weights.toViewConst(); }
137 
138 protected:
140  typename LEAFCLASSTRAITS::IndexContainerType m_elementRegionIndices;
141 
143  typename LEAFCLASSTRAITS::IndexContainerType m_elementSubRegionIndices;
144 
146  typename LEAFCLASSTRAITS::IndexContainerType m_elementIndices;
147 
149  typename LEAFCLASSTRAITS::WeightContainerType m_weights;
150 
153 
154 };
155 
156 
157 
158 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
160 {
161  m_elementRegionIndices.reserve( size * 2 );
162  m_elementSubRegionIndices.reserve( size * 2 );
163  m_elementIndices.reserve( size * 2 );
164  m_weights.reserve( size * 2 );
165 }
166 
167 
168 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
170 {
171  return
172  executeOnMapValue( m_connectorIndices, connectorIndex, [&]( localIndex const connectionListIndex )
173  {
174  for( localIndex i = 0; i < static_cast< LEAFCLASS * >(this)->stencilSize( connectorIndex ); ++i )
175  {
176  m_weights[connectionListIndex][i] = 0;
177  }
178  } );
179 }
180 
181 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
183 {
184  m_elementRegionIndices.setName( name + "/elementRegionIndices" );
185  m_elementSubRegionIndices.setName( name + "/elementSubRegionIndices" );
186  m_elementIndices.setName( name + "/elementIndices" );
187  m_weights.setName( name + "/weights" );
188 }
189 
190 template< typename LEAFCLASSTRAITS, typename LEAFCLASS >
192 {
193  m_elementRegionIndices.move( space, true );
194  m_elementSubRegionIndices.move( space, true );
195  m_elementIndices.move( space, true );
196  m_weights.move( space, true );
197 }
198 
199 
200 } /* namespace geosx */
201 
202 #endif /* GEOSX_FINITEVOLUME_STENCILBASE_HPP_ */
virtual bool zero(localIndex const connectorIndex)
Zero weights for a stencil entry.
virtual void reserve(localIndex const size)
Reserve the size of the stencil.
LEAFCLASSTRAITS::WeightContainerType m_weights
The container for the weights for each point in each stencil.
map< localIndex, localIndex > m_connectorIndices
The map that provides the stencil index given the index of the underlying connector object...
LEAFCLASSTRAITS::IndexContainerType m_elementIndices
The container for the element indices for each point in each stencil.
virtual ~StencilBase()=default
Destructor.
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.
Base template for ordered and unordered maps.
Definition: DataTypes.hpp:349
void setName(string const &name)
Set the name used in data movement logging callbacks.
virtual localIndex size() const =0
Give the number of stencil entries.
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
LEAFCLASSTRAITS::IndexContainerType m_elementSubRegionIndices
The container for the element sub region indices for each point in each stencil.
LEAFCLASSTRAITS::IndexContainerViewConstType getElementIndices() const
Const access to the element indices.
MemorySpace
An enum containing the available memory spaces.
virtual void move(LvArray::MemorySpace const space)
Move the data arrays associated with the stencil to a specified memory space.
LEAFCLASSTRAITS::WeightContainerViewConstType getWeights() const
Const access to the stencil weights.
LEAFCLASSTRAITS::IndexContainerViewConstType getElementSubRegionIndices() const
Const access to the element subregions indices.
LEAFCLASSTRAITS::IndexContainerType m_elementRegionIndices
The container for the element region indices for each point in each stencil.
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
LEAFCLASSTRAITS::IndexContainerViewConstType getElementRegionIndices() const
Const access to the element regions indices.