GEOS
ElementRegionBase.hpp
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 TotalEnergies
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 
16 #ifndef GEOS_MESH_ELEMENTREGIONBASE_HPP
17 #define GEOS_MESH_ELEMENTREGIONBASE_HPP
18 
19 #include "CellElementSubRegion.hpp"
20 #include "FaceElementSubRegion.hpp"
21 #include "WellElementSubRegion.hpp"
24 
25 namespace geos
26 {
27 
28 class FaceManager;
29 
38 {
39 public:
40 
45 
49  ElementRegionBase() = delete;
50 
56  ElementRegionBase( string const & name, Group * const parent );
57 
58 
64 
68  virtual ~ElementRegionBase() override;
69 
71 
72 
82  static string verifyMeshBodyName( Group const & meshBodies,
83  string const & meshBodyBlockName );
84 
89 
90 
98  template< typename SUBREGION_TYPE >
99  SUBREGION_TYPE & createElementSubRegion( string const & name );
100 
101 
106  virtual void generateMesh( Group const & blocks ) = 0;
107 
109 
114 
119  {
121  }
122 
127  Group const & getSubRegions() const
128  {
130  }
131 
132 
141  template< typename SUBREGIONTYPE=ElementSubRegionBase, typename KEY_TYPE=void >
142  SUBREGIONTYPE const & getSubRegion( KEY_TYPE const & key ) const
143  {
144  return this->getGroup( viewKeyStruct::elementSubRegions() ).getGroup< SUBREGIONTYPE >( key );
145  }
146 
150  template< typename SUBREGIONTYPE=ElementSubRegionBase, typename KEY_TYPE=void >
151  SUBREGIONTYPE & getSubRegion( KEY_TYPE const & key )
152  {
153  return this->getGroup( viewKeyStruct::elementSubRegions() ).getGroup< SUBREGIONTYPE >( key );
154  }
155 
163  template< typename T=ElementSubRegionBase >
164  bool hasSubRegion( string const & name ) const
165  {
166  return this->getGroup( viewKeyStruct::elementSubRegions() ).hasGroup< T >( name );
167  }
168 
169 
175  {
176  return this->getSubRegions().numSubGroups();
177  }
178 
188  template< typename SUBREGIONTYPE = ElementSubRegionBase, typename ... SUBREGIONTYPES >
190  {
191  localIndex numElem = 0;
192  this->forElementSubRegions< SUBREGIONTYPE, SUBREGIONTYPES... >( [&]( Group const & group ) -> void
193  {
194  numElem += group.size();
195  } );
196  return numElem;
197  }
198 
202  string_array & getMaterialList() {return m_materialList;}
203 
208  string_array const & getMaterialList() const {return m_materialList;}
209 
215  template< typename CONSTITUTIVE_TYPE >
217 
223  { return dynamicCast< ElementRegionBase & >( subRegion.getParent().getParent() ); }
224 
229  static ElementRegionBase const & getParentRegion( ElementSubRegionBase const & subRegion )
230  { return dynamicCast< ElementRegionBase const & >( subRegion.getParent().getParent() ); }
231 
232 
234 
239 
240 
245  template< typename LAMBDA >
246  void forElementSubRegions( LAMBDA && lambda ) const
247  {
248  forElementSubRegions< CellElementSubRegion, FaceElementSubRegion, WellElementSubRegion, EmbeddedSurfaceSubRegion >( std::forward< LAMBDA >( lambda ) );
249  }
250 
254  template< typename LAMBDA >
255  void forElementSubRegions( LAMBDA && lambda )
256  {
257  forElementSubRegions< CellElementSubRegion, FaceElementSubRegion, WellElementSubRegion, EmbeddedSurfaceSubRegion >( std::forward< LAMBDA >( lambda ) );
258  }
259 
265  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
266  void forElementSubRegions( LAMBDA && lambda ) const
267  {
268  this->getGroup( viewKeyStruct::elementSubRegions() ).forSubGroups< SUBREGIONTYPE, SUBREGIONTYPES... >( std::forward< LAMBDA >( lambda ) );
269  }
270 
274  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
275  void forElementSubRegions( LAMBDA && lambda )
276  {
277  this->getGroup( viewKeyStruct::elementSubRegions() ).forSubGroups< SUBREGIONTYPE, SUBREGIONTYPES... >( std::forward< LAMBDA >( lambda ) );
278  }
279 
285  template< typename LAMBDA >
286  void forElementSubRegionsIndex( LAMBDA && lambda ) const
287  {
288  forElementSubRegionsIndex< CellElementSubRegion, FaceElementSubRegion, WellElementSubRegion, EmbeddedSurfaceSubRegion >( std::forward< LAMBDA >( lambda ) );
289  }
290 
294  template< typename LAMBDA >
295  void forElementSubRegionsIndex( LAMBDA && lambda )
296  {
297  forElementSubRegionsIndex< CellElementSubRegion, FaceElementSubRegion, WellElementSubRegion, EmbeddedSurfaceSubRegion >( std::forward< LAMBDA >( lambda ) );
298  }
299 
308  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
309  void forElementSubRegionsIndex( LAMBDA && lambda ) const
310  {
311  for( localIndex esr=0; esr<this->numSubRegions(); ++esr )
312  {
313  ElementSubRegionBase const & subRegion = this->getSubRegion( esr );
314  applyLambdaToContainer< SUBREGIONTYPE, SUBREGIONTYPES... >( subRegion, [&]( auto const & castedSubRegion )
315  {
316  lambda( esr, castedSubRegion );
317  } );
318  }
319  }
320 
324  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
325  void forElementSubRegionsIndex( LAMBDA && lambda )
326  {
327  for( localIndex esr=0; esr<this->numSubRegions(); ++esr )
328  {
329  ElementSubRegionBase & subRegion = this->getSubRegion( esr );
330  applyLambdaToContainer< SUBREGIONTYPE, SUBREGIONTYPES... >( subRegion, [&]( auto & castedSubRegion )
331  {
332  lambda( esr, castedSubRegion );
333  } );
334  }
335  }
336 
338 
344  {
346  static constexpr char const * materialListString() { return "materialList"; }
348  static constexpr char const * meshBodyString() { return "meshBody"; }
350  static constexpr char const * elementSubRegions() { return "elementSubRegions"; }
351  };
352 
353 private:
354 
355  ElementRegionBase & operator=( const ElementRegionBase & rhs );
356 
358  string_array m_materialList;
359 
361  string m_meshBody;
362 
363 };
364 
365 
366 
369 
370 
377 template< typename CONSTITUTIVE_TYPE >
379 {
380  string_array rval;
381  for( string const & matName : m_materialList )
382  {
383  if( this->getSubRegion( 0 ).getConstitutiveModels().hasGroup< CONSTITUTIVE_TYPE >( matName ) )
384  {
385  rval.emplace_back( matName );
386  }
387  }
388  return rval;
389 }
390 
391 
392 template< typename SUBREGION_TYPE >
393 SUBREGION_TYPE & ElementRegionBase::createElementSubRegion( string const & name )
394 {
395  return getGroup( viewKeyStruct::elementSubRegions() ).registerGroup< SUBREGION_TYPE >( name );
396 }
397 
398 
399 }
400 
401 
402 
403 #endif /* GEOS_MESH_ELEMENTREGIONBASE_HPP */
The ElementRegionBase is the base class to manage the data stored at the element level.
SUBREGION_TYPE & createElementSubRegion(string const &name)
Create a Element Sub Region object.
ElementRegionBase(string const &name, Group *const parent)
Main constructor.
bool hasSubRegion(string const &name) const
Check to see if this region has a subregion.
virtual void generateMesh(Group const &blocks)=0
Generate mesh.
virtual ~ElementRegionBase() override
Default destructor.
void forElementSubRegions(LAMBDA &&lambda)
Apply a lambda to all subregions.
void forElementSubRegionsIndex(LAMBDA &&lambda)
Apply LAMBDA to the subregions, loop using subregion indices.
Group 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.
static ElementRegionBase & getParentRegion(ElementSubRegionBase &subRegion)
void forElementSubRegions(LAMBDA &&lambda) const
Apply LAMBDA to the subregions with the specific subregion types listed in the template.
void forElementSubRegions(LAMBDA &&lambda) const
Apply a lambda to all subregions.
string_array const & getMaterialList() const
Get the material list in the element region.
void forElementSubRegionsIndex(LAMBDA &&lambda) const
Apply LAMBDA to the subregions, loop using subregion indices.
Group & getSubRegions()
Get a collection of the subregions.
void forElementSubRegions(LAMBDA &&lambda)
Apply a lambda to all subregions.
SUBREGIONTYPE & getSubRegion(KEY_TYPE const &key)
Get a reference to a subregion.
static string verifyMeshBodyName(Group const &meshBodies, string const &meshBodyBlockName)
verify that the meshBody name specified exists in the meshBodies group. If there is only one meshBody...
ElementRegionBase(const ElementRegionBase &init)
Copy constructor.
string_array getConstitutiveNames() const
Get the name of the constiutive in the element region.
void forElementSubRegionsIndex(LAMBDA &&lambda) const
Apply LAMBDA to the subregions with the specific subregion types listed in the template,...
string_array & getMaterialList()
Get the material list in the element region.
localIndex numSubRegions() const
Get the number of subregions in the region.
SUBREGIONTYPE const & getSubRegion(KEY_TYPE const &key) const
Get a reference to a subregion.
static ElementRegionBase const & getParentRegion(ElementSubRegionBase const &subRegion)
void forElementSubRegionsIndex(LAMBDA &&lambda)
Apply LAMBDA to the subregions, loop using subregion indices.
ElementRegionBase()=delete
Deleted default constructor.
The ObjectManagerBase is the base object of all object managers in the mesh data hierachy.
localIndex numSubGroups() const
return the number of sub groups in this Group
Definition: Group.hpp:410
T & getGroup(KEY const &key)
Return a reference to a sub-group of the current Group.
Definition: Group.hpp:336
Group & getParent()
Access the group's parent.
Definition: Group.hpp:1362
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:482
array1d< string > string_array
A 1-dimensional array of geos::string types.
Definition: DataTypes.hpp:392
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
Struct to serve as a container for variable strings and keys.
static constexpr char const * elementSubRegions()
static constexpr char const * materialListString()
static constexpr char const * meshBodyString()
struct to serve as a container for variable strings and keys