GEOSX
ElementRegionBase.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 
15 #ifndef GEOSX_MESH_ELEMENTREGIONBASE_HPP
16 #define GEOSX_MESH_ELEMENTREGIONBASE_HPP
17 
18 #include "CellElementSubRegion.hpp"
19 #include "FaceElementSubRegion.hpp"
20 #include "WellElementSubRegion.hpp"
23 
24 namespace geosx
25 {
26 
27 class StableTimeStep;
28 
29 class FaceManager;
30 
39 {
40 public:
41 
45 
50  ElementRegionBase() = delete;
51 
57  ElementRegionBase( string const & name, Group * const parent );
58 
59 
64  ElementRegionBase( const ElementRegionBase & init );
65 
69  virtual ~ElementRegionBase() override;
70 
72 
76 
82  virtual void GenerateMesh( Group * const cellBlocks )
83  {
84  GEOSX_UNUSED_VAR( cellBlocks );
85  GEOSX_ERROR( "ElementRegionBase::GenerateMesh() should be overriden if called." );
86  }
87 
89 
93 
99  {
100  return GetGroup( viewKeyStruct::elementSubRegions )->GetSubGroups();
101  }
102 
107  subGroupMap const & GetSubRegions() const
108  {
109  return GetGroup( viewKeyStruct::elementSubRegions )->GetSubGroups();
110  }
111 
112 
120  template< typename SUBREGIONTYPE=ElementSubRegionBase >
121  SUBREGIONTYPE const * GetSubRegion( string const & regionName ) const
122  {
123  return this->GetGroup( viewKeyStruct::elementSubRegions )->GetGroup< SUBREGIONTYPE >( regionName );
124  }
125 
129  template< typename SUBREGIONTYPE=ElementSubRegionBase >
130  SUBREGIONTYPE * GetSubRegion( string const & regionName )
131  {
132  return this->GetGroup( viewKeyStruct::elementSubRegions )->GetGroup< SUBREGIONTYPE >( regionName );
133  }
134 
141  template< typename SUBREGIONTYPE=ElementSubRegionBase >
142  SUBREGIONTYPE const * GetSubRegion( localIndex const & index ) const
143  {
144  return this->GetGroup( viewKeyStruct::elementSubRegions )->GetGroup< SUBREGIONTYPE >( index );
145  }
146 
150  template< typename SUBREGIONTYPE=ElementSubRegionBase >
151  SUBREGIONTYPE * GetSubRegion( localIndex const & index )
152  {
153  return this->GetGroup( viewKeyStruct::elementSubRegions )->GetGroup< SUBREGIONTYPE >( index );
154  }
155 
161  {
162  return this->GetGroup( viewKeyStruct::elementSubRegions )->GetSubGroups().size();
163  }
164 
174  template< typename SUBREGIONTYPE = ElementSubRegionBase, typename ... SUBREGIONTYPES >
176  {
177  localIndex numElem = 0;
178  this->forElementSubRegions< SUBREGIONTYPE, SUBREGIONTYPES... >( [&]( Group const & cellBlock ) -> void
179  {
180  numElem += cellBlock.size();
181  } );
182  return numElem;
183  }
184 
188  string_array & getMaterialList() {return m_materialList;}
189 
194  string_array const & getMaterialList() const {return m_materialList;}
195 
201  template< typename CONSTITUTIVE_TYPE >
203 
204 
206 
210 
212 
217  template< typename LAMBDA >
218  void forElementSubRegions( LAMBDA && lambda ) const
219  {
220  forElementSubRegions< CellElementSubRegion, FaceElementSubRegion, WellElementSubRegion, EmbeddedSurfaceSubRegion >( std::forward< LAMBDA >( lambda ) );
221  }
222 
226  template< typename LAMBDA >
227  void forElementSubRegions( LAMBDA && lambda )
228  {
229  forElementSubRegions< CellElementSubRegion, FaceElementSubRegion, WellElementSubRegion, EmbeddedSurfaceSubRegion >( std::forward< LAMBDA >( lambda ) );
230  }
231 
237  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
238  void forElementSubRegions( LAMBDA && lambda ) const
239  {
240  Group const * const elementSubRegions = this->GetGroup( viewKeyStruct::elementSubRegions );
241  elementSubRegions->forSubGroups< SUBREGIONTYPE, SUBREGIONTYPES... >( std::forward< LAMBDA >( lambda ) );
242  }
243 
247  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
248  void forElementSubRegions( LAMBDA && lambda )
249  {
250  Group * const elementSubRegions = this->GetGroup( viewKeyStruct::elementSubRegions );
251  elementSubRegions->forSubGroups< SUBREGIONTYPE, SUBREGIONTYPES... >( std::forward< LAMBDA >( lambda ) );
252  }
253 
259  template< typename LAMBDA >
260  void forElementSubRegionsIndex( LAMBDA && lambda ) const
261  {
262  forElementSubRegionsIndex< CellElementSubRegion, FaceElementSubRegion, WellElementSubRegion, EmbeddedSurfaceSubRegion >( std::forward< LAMBDA >( lambda ) );
263  }
264 
268  template< typename LAMBDA >
269  void forElementSubRegionsIndex( LAMBDA && lambda )
270  {
271  forElementSubRegionsIndex< CellElementSubRegion, FaceElementSubRegion, WellElementSubRegion, EmbeddedSurfaceSubRegion >( std::forward< LAMBDA >( lambda ) );
272  }
273 
282  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
283  void forElementSubRegionsIndex( LAMBDA && lambda ) const
284  {
285  for( localIndex esr=0; esr<this->numSubRegions(); ++esr )
286  {
287  ElementSubRegionBase const & subRegion = *this->GetSubRegion( esr );
288  applyLambdaToContainer< SUBREGIONTYPE, SUBREGIONTYPES... >( subRegion, [&]( auto const & castedSubRegion )
289  {
290  lambda( esr, castedSubRegion );
291  } );
292  }
293  }
294 
298  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
299  void forElementSubRegionsIndex( LAMBDA && lambda )
300  {
301  for( localIndex esr=0; esr<this->numSubRegions(); ++esr )
302  {
303  ElementSubRegionBase & subRegion = *this->GetSubRegion( esr );
304  applyLambdaToContainer< SUBREGIONTYPE, SUBREGIONTYPES... >( subRegion, [&]( auto & castedSubRegion )
305  {
306  lambda( esr, castedSubRegion );
307  } );
308  }
309  }
310 
312 
318  {
320  static constexpr auto materialListString = "materialList";
322  static constexpr auto elementSubRegions = "elementSubRegions";
323  };
324 
325 
326 protected:
327 
328 private:
329 
330  ElementRegionBase & operator=( const ElementRegionBase & rhs );
331 
333  string_array m_materialList;
334 
336  string m_numericalMethod;
337 
338 };
339 
340 
341 
344 
345 
352 template< typename CONSTITUTIVE_TYPE >
354 {
355  string_array rval;
356  for( string const & matName : m_materialList )
357  {
358  Group const * const matModel = this->GetSubRegion( 0 )->GetConstitutiveModels()->GetGroup( matName );
359  if( dynamic_cast< CONSTITUTIVE_TYPE const * >( matModel ) != nullptr )
360  {
361  rval.emplace_back( matName );
362  }
363  }
364  return rval;
365 }
366 
367 }
368 
369 
370 
371 #endif /* GEOSX_MESH_ELEMENTREGIONBASE_HPP */
void forElementSubRegions(LAMBDA &&lambda) const
Apply LAMBDA to the subregions with the specific subregion types listed in the template.
SUBREGIONTYPE * GetSubRegion(localIndex const &index)
Get a pointer to a subregion by specifying its index.
void forElementSubRegions(LAMBDA &&lambda) const
Apply a lambda to all subregions.
subGroupMap & GetSubRegions()
Get a collection of the subregions.
ElementRegionBase()=delete
Deleted default constructor.
string_array getConstitutiveNames() const
Get the name of the constiutive in the element region.
string_array & getMaterialList()
Get the material list in the element region.
localIndex numSubRegions() const
Get the number of subregions in the region.
subGroupMap const & GetSubRegions() const
Get a collection of the subregions.
localIndex getNumberOfElements() const
Get the number of elements in the region for specific subregion types provided as template arguments...
SUBREGIONTYPE const * GetSubRegion(localIndex const &index) const
Get a pointer to a subregion by specifying its index.
virtual void GenerateMesh(Group *const cellBlocks)
Generate mesh.
void forElementSubRegionsIndex(LAMBDA &&lambda) const
Apply LAMBDA to the subregions with the specific subregion types listed in the template, loop using subregion indices.
std::enable_if_t< _NDIM==1 > emplace_back(ARGS &&... args)
Construct a value in place at the end of the array.
Definition: Array.hpp:461
static constexpr auto materialListString
String key for the material list.
string_array const & getMaterialList() const
Get the material list in the element region.
The ObjectManagerBase is the base object of all object managers in the mesh data hierachy.
void forElementSubRegionsIndex(LAMBDA &&lambda) const
Apply LAMBDA to the subregions, loop using subregion indices.
SUBREGIONTYPE const * GetSubRegion(string const &regionName) const
Get a pointer to a subregion by specifying its name.
void forElementSubRegionsIndex(LAMBDA &&lambda)
Apply LAMBDA to the subregions, loop using subregion indices.
static bool applyLambdaToContainer(CONTAINERTYPE &container, LAMBDA &&lambda)
Apply a given functor to a container if the container can be cast to one of the specified types...
Definition: Group.hpp:557
static constexpr auto elementSubRegions
String key for the element subregions.
void forElementSubRegions(LAMBDA &&lambda)
Apply a lambda to all subregions.
virtual ~ElementRegionBase() override
Default destructor.
#define GEOSX_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:110
void forElementSubRegions(LAMBDA &&lambda)
Apply a lambda to all subregions.
The ElementRegionBase is the base class to manage the data stored at the element level.
#define GEOSX_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:78
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
void forElementSubRegionsIndex(LAMBDA &&lambda)
Apply LAMBDA to the subregions, loop using subregion indices.
void forSubGroups(LAMBDA lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:593
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
Definition: Array.hpp:55
struct to serve as a container for variable strings and keys
T * GetGroup(localIndex index)
Retrieve a sub-group from the current Group using an index.
Definition: Group.hpp:374
SUBREGIONTYPE * GetSubRegion(string const &regionName)
Get a pointer to a subregion by specifying its name.
Struct to serve as a container for variable strings and keys.