GEOS
ParticleRegionBase.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_PARTICLEREGIONBASE_HPP
17 #define GEOS_MESH_PARTICLEREGIONBASE_HPP
18 
19 #include "ParticleSubRegion.hpp"
21 
22 namespace geos
23 {
24 
33 {
34 public:
35 
40 
44  ParticleRegionBase() = delete;
45 
51  ParticleRegionBase( string const & name, Group * const parent );
52 
53 
59 
63  virtual ~ParticleRegionBase() override;
64 
66 
67 
77  static string verifyMeshBodyName( Group const & meshBodies,
78  string const & meshBodyBlockName );
79 
84 
89  virtual void generateMesh( Group & particleBlocks )
90  {
91  GEOS_UNUSED_VAR( particleBlocks );
92  GEOS_ERROR( "ParticleRegionBase::GenerateMesh() should be overriden if called." );
93  }
94 
96 
101 
106  {
107  return getGroup( viewKeyStruct::particleSubRegions() ).getSubGroups();
108  }
109 
114  subGroupMap const & getSubRegions() const
115  {
116  return getGroup( viewKeyStruct::particleSubRegions() ).getSubGroups();
117  }
118 
119 
127  template< typename SUBREGIONTYPE=ParticleSubRegionBase, typename KEY_TYPE=void >
128  SUBREGIONTYPE const & getSubRegion( KEY_TYPE const & key ) const
129  {
130  return this->getGroup( viewKeyStruct::particleSubRegions() ).getGroup< SUBREGIONTYPE >( key );
131  }
132 
136  template< typename SUBREGIONTYPE=ParticleSubRegionBase, typename KEY_TYPE=void >
137  SUBREGIONTYPE & getSubRegion( KEY_TYPE const & key )
138  {
139  return this->getGroup( viewKeyStruct::particleSubRegions() ).getGroup< SUBREGIONTYPE >( key );
140  }
141 
147  {
148  return this->getGroup( viewKeyStruct::particleSubRegions() ).getSubGroups().size();
149  }
150 
160  template< typename SUBREGIONTYPE = ParticleSubRegionBase, typename ... SUBREGIONTYPES >
162  {
163  localIndex numParticle = 0;
164  this->forParticleSubRegions< SUBREGIONTYPE, SUBREGIONTYPES... >( [&]( Group const & group ) -> void
165  {
166  numParticle += group.size();
167  } );
168  return numParticle;
169  }
170 
174  string_array & getMaterialList() {return m_materialList;}
175 
180  string_array const & getMaterialList() const {return m_materialList;}
181 
187  template< typename CONSTITUTIVE_TYPE >
189 
190 
192 
193 
198 
199 
204  template< typename LAMBDA >
205  void forParticleSubRegions( LAMBDA && lambda ) const
206  {
207  forParticleSubRegions< ParticleSubRegion >( std::forward< LAMBDA >( lambda ) );
208  }
209 
213  template< typename LAMBDA >
214  void forParticleSubRegions( LAMBDA && lambda )
215  {
216  forParticleSubRegions< ParticleSubRegion >( std::forward< LAMBDA >( lambda ) );
217  }
218 
224  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
225  void forParticleSubRegions( LAMBDA && lambda ) const
226  {
227  this->getGroup( viewKeyStruct::particleSubRegions() ).forSubGroups< SUBREGIONTYPE, SUBREGIONTYPES... >( std::forward< LAMBDA >( lambda ) );
228  }
229 
233  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
234  void forParticleSubRegions( LAMBDA && lambda )
235  {
236  this->getGroup( viewKeyStruct::particleSubRegions() ).forSubGroups< SUBREGIONTYPE, SUBREGIONTYPES... >( std::forward< LAMBDA >( lambda ) );
237  }
238 
244  template< typename LAMBDA >
245  void forParticleSubRegionsIndex( LAMBDA && lambda ) const
246  {
247  forParticleSubRegionsIndex< ParticleSubRegion >( std::forward< LAMBDA >( lambda ) );
248  }
249 
253  template< typename LAMBDA >
254  void forParticleSubRegionsIndex( LAMBDA && lambda )
255  {
256  forParticleSubRegionsIndex< ParticleSubRegion >( std::forward< LAMBDA >( lambda ) );
257  }
258 
267  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
268  void forParticleSubRegionsIndex( LAMBDA && lambda ) const
269  {
270  for( localIndex esr=0; esr<this->numSubRegions(); ++esr )
271  {
272  ParticleSubRegionBase const & subRegion = this->getSubRegion( esr );
273  applyLambdaToContainer< SUBREGIONTYPE, SUBREGIONTYPES... >( subRegion, [&]( auto const & castedSubRegion )
274  {
275  lambda( esr, castedSubRegion );
276  } );
277  }
278  }
279 
283  template< typename SUBREGIONTYPE, typename ... SUBREGIONTYPES, typename LAMBDA >
284  void forParticleSubRegionsIndex( LAMBDA && lambda )
285  {
286  for( localIndex esr=0; esr<this->numSubRegions(); ++esr )
287  {
288  ParticleSubRegionBase & subRegion = this->getSubRegion( esr );
289  applyLambdaToContainer< SUBREGIONTYPE, SUBREGIONTYPES... >( subRegion, [&]( auto & castedSubRegion )
290  {
291  lambda( esr, castedSubRegion );
292  } );
293  }
294  }
295 
297 
303  {
305  static constexpr char const * materialListString() { return "materialList"; }
307  static constexpr char const * meshBodyString() { return "meshBody"; }
309  static constexpr char const * particleSubRegions() { return "particleSubRegions"; }
310  };
311 
312 private:
313 
314  ParticleRegionBase & operator=( const ParticleRegionBase & rhs );
315 
317  string_array m_materialList;
318 
320  string m_meshBody;
321 
322 };
323 
324 
325 
328 
329 
336 template< typename CONSTITUTIVE_TYPE >
338 {
339  string_array rval;
340  for( string const & matName : m_materialList )
341  {
342  if( this->getSubRegion( 0 ).getConstitutiveModels().hasGroup< CONSTITUTIVE_TYPE >( matName ) )
343  {
344  rval.emplace_back( matName );
345  }
346  }
347  return rval;
348 }
349 
350 }
351 
352 
353 
354 #endif /* GEOS_MESH_PARTICLEREGIONBASE_HPP */
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:84
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:157
The ObjectManagerBase is the base object of all object managers in the mesh data hierachy.
The ParticleRegionBase is the base class to manage the data stored at the particle level.
virtual void generateMesh(Group &particleBlocks)
Generate mesh.
string_array & getMaterialList()
Get the material list in the particle region.
string_array const & getMaterialList() const
Get the material list in the particle region.
subGroupMap const & getSubRegions() const
Get a collection of the subregions.
void forParticleSubRegions(LAMBDA &&lambda) const
Apply a lambda to all particle subregions.
ParticleRegionBase(string const &name, Group *const parent)
Main constructor.
void forParticleSubRegionsIndex(LAMBDA &&lambda) const
Apply LAMBDA to the subregions with the specific subregion types listed in the template,...
void forParticleSubRegions(LAMBDA &&lambda)
Apply a lambda to all particle subregions.
localIndex getNumberOfParticles() const
Get the number of particles in the region for specific subregion types provided as template arguments...
void forParticleSubRegionsIndex(LAMBDA &&lambda)
Apply LAMBDA to the subregions, loop using subregion indices.
SUBREGIONTYPE & getSubRegion(KEY_TYPE const &key)
Get a reference to a subregion.
ParticleRegionBase()=delete
Deleted default constructor.
ParticleRegionBase(const ParticleRegionBase &init)
Copy constructor.
virtual ~ParticleRegionBase() override
Default destructor.
void forParticleSubRegions(LAMBDA &&lambda)
Apply a lambda to all particle subregions.
subGroupMap & getSubRegions()
Get a collection of the subregions.
string_array getConstitutiveNames() const
Get the name of the constitutive in the particle region.
void forParticleSubRegionsIndex(LAMBDA &&lambda)
Apply LAMBDA to the subregions, loop using subregion indices.
localIndex numSubRegions() const
Get the number of subregions in the region.
void forParticleSubRegions(LAMBDA &&lambda) const
Apply LAMBDA to the subregions with the specific subregion types listed in the template.
SUBREGIONTYPE const & getSubRegion(KEY_TYPE const &key) const
Get a reference to a subregion.
void forParticleSubRegionsIndex(LAMBDA &&lambda) const
Apply LAMBDA to the subregions, loop using subregion indices.
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...
T & getGroup(KEY const &key)
Return a reference to a sub-group of the current Group.
Definition: Group.hpp:336
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
Struct to serve as a container for variable strings and keys.
static constexpr char const * particleSubRegions()
static constexpr char const * materialListString()
static constexpr char const * meshBodyString()