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 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 
15 #ifndef GEOS_MESH_ELEMENTREGIONBASE_HPP
16 #define GEOS_MESH_ELEMENTREGIONBASE_HPP
17 
18 #include "CellElementSubRegion.hpp"
19 #include "FaceElementSubRegion.hpp"
20 #include "WellElementSubRegion.hpp"
23 
24 namespace geos
25 {
26 
27 class FaceManager;
28 
37 {
38 public:
39 
44 
48  ElementRegionBase() = delete;
49 
55  ElementRegionBase( string const & name, Group * const parent );
56 
57 
63 
67  virtual ~ElementRegionBase() override;
68 
70 
71 
81  static string verifyMeshBodyName( Group const & meshBodies,
82  string const & meshBodyBlockName );
83 
88 
89 
97  template< typename SUBREGION_TYPE >
98  SUBREGION_TYPE & createElementSubRegion( string const & name );
99 
100 
105  virtual void generateMesh( Group const & blocks ) = 0;
106 
108 
113 
118  {
120  }
121 
126  Group const & getSubRegions() const
127  {
129  }
130 
131 
140  template< typename SUBREGIONTYPE=ElementSubRegionBase, typename KEY_TYPE=void >
141  SUBREGIONTYPE const & getSubRegion( KEY_TYPE const & key ) const
142  {
143  return this->getGroup( viewKeyStruct::elementSubRegions() ).getGroup< SUBREGIONTYPE >( key );
144  }
145 
149  template< typename SUBREGIONTYPE=ElementSubRegionBase, typename KEY_TYPE=void >
150  SUBREGIONTYPE & getSubRegion( KEY_TYPE const & key )
151  {
152  return this->getGroup( viewKeyStruct::elementSubRegions() ).getGroup< SUBREGIONTYPE >( key );
153  }
154 
162  template< typename T=ElementSubRegionBase >
163  bool hasSubRegion( string const & name ) const
164  {
165  return this->getGroup( viewKeyStruct::elementSubRegions() ).hasGroup< T >( name );
166  }
167 
168 
174  {
175  return this->getSubRegions().numSubGroups();
176  }
177 
187  template< typename SUBREGIONTYPE = ElementSubRegionBase, typename ... SUBREGIONTYPES >
189  {
190  localIndex numElem = 0;
191  this->forElementSubRegions< SUBREGIONTYPE, SUBREGIONTYPES... >( [&]( Group const & group ) -> void
192  {
193  numElem += group.size();
194  } );
195  return numElem;
196  }
197 
201  string_array & getMaterialList() {return m_materialList;}
202 
207  string_array const & getMaterialList() const {return m_materialList;}
208 
214  template< typename CONSTITUTIVE_TYPE >
216 
217 
219 
224 
225 
230  template< typename LAMBDA >
231  void forElementSubRegions( LAMBDA && lambda ) const
232  {
233  forElementSubRegions< CellElementSubRegion, FaceElementSubRegion, WellElementSubRegion, EmbeddedSurfaceSubRegion >( std::forward< LAMBDA >( lambda ) );
234  }
235 
239  template< typename LAMBDA >
240  void forElementSubRegions( LAMBDA && lambda )
241  {
242  forElementSubRegions< CellElementSubRegion, FaceElementSubRegion, WellElementSubRegion, EmbeddedSurfaceSubRegion >( std::forward< LAMBDA >( lambda ) );
243  }
244 
250  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
251  void forElementSubRegions( LAMBDA && lambda ) const
252  {
253  this->getGroup( viewKeyStruct::elementSubRegions() ).forSubGroups< SUBREGIONTYPE, SUBREGIONTYPES... >( std::forward< LAMBDA >( lambda ) );
254  }
255 
259  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
260  void forElementSubRegions( LAMBDA && lambda )
261  {
262  this->getGroup( viewKeyStruct::elementSubRegions() ).forSubGroups< SUBREGIONTYPE, SUBREGIONTYPES... >( std::forward< LAMBDA >( lambda ) );
263  }
264 
270  template< typename LAMBDA >
271  void forElementSubRegionsIndex( LAMBDA && lambda ) const
272  {
273  forElementSubRegionsIndex< CellElementSubRegion, FaceElementSubRegion, WellElementSubRegion, EmbeddedSurfaceSubRegion >( std::forward< LAMBDA >( lambda ) );
274  }
275 
279  template< typename LAMBDA >
280  void forElementSubRegionsIndex( LAMBDA && lambda )
281  {
282  forElementSubRegionsIndex< CellElementSubRegion, FaceElementSubRegion, WellElementSubRegion, EmbeddedSurfaceSubRegion >( std::forward< LAMBDA >( lambda ) );
283  }
284 
293  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
294  void forElementSubRegionsIndex( LAMBDA && lambda ) const
295  {
296  for( localIndex esr=0; esr<this->numSubRegions(); ++esr )
297  {
298  ElementSubRegionBase const & subRegion = this->getSubRegion( esr );
299  applyLambdaToContainer< SUBREGIONTYPE, SUBREGIONTYPES... >( subRegion, [&]( auto const & castedSubRegion )
300  {
301  lambda( esr, castedSubRegion );
302  } );
303  }
304  }
305 
309  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
310  void forElementSubRegionsIndex( LAMBDA && lambda )
311  {
312  for( localIndex esr=0; esr<this->numSubRegions(); ++esr )
313  {
314  ElementSubRegionBase & subRegion = this->getSubRegion( esr );
315  applyLambdaToContainer< SUBREGIONTYPE, SUBREGIONTYPES... >( subRegion, [&]( auto & castedSubRegion )
316  {
317  lambda( esr, castedSubRegion );
318  } );
319  }
320  }
321 
323 
329  {
331  static constexpr char const * materialListString() { return "materialList"; }
333  static constexpr char const * meshBodyString() { return "meshBody"; }
335  static constexpr char const * elementSubRegions() { return "elementSubRegions"; }
336  };
337 
338 private:
339 
340  ElementRegionBase & operator=( const ElementRegionBase & rhs );
341 
343  string_array m_materialList;
344 
346  string m_meshBody;
347 
348 };
349 
350 
351 
354 
355 
362 template< typename CONSTITUTIVE_TYPE >
364 {
365  string_array rval;
366  for( string const & matName : m_materialList )
367  {
368  if( this->getSubRegion( 0 ).getConstitutiveModels().hasGroup< CONSTITUTIVE_TYPE >( matName ) )
369  {
370  rval.emplace_back( matName );
371  }
372  }
373  return rval;
374 }
375 
376 
377 template< typename SUBREGION_TYPE >
378 SUBREGION_TYPE & ElementRegionBase::createElementSubRegion( string const & name )
379 {
380  return getGroup( viewKeyStruct::elementSubRegions() ).registerGroup< SUBREGION_TYPE >( name );
381 }
382 
383 
384 }
385 
386 
387 
388 #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.
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.
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:399
T & getGroup(KEY const &key)
Return a reference to a sub-group of the current Group.
Definition: Group.hpp:333
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:472
array1d< string > string_array
A 1-dimensional array of geos::string types.
Definition: DataTypes.hpp:432
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
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