GEOS
MeshObjectPath.hpp
Go to the documentation of this file.
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 
20 #ifndef GEOS_MESH_MESHOBJECTPATH_HPP_
21 #define GEOS_MESH_MESHOBJECTPATH_HPP_
22 
23 
25 #include "MeshLevel.hpp"
26 
27 namespace geos
28 {
29 class MeshBody;
30 class MeshLevel;
31 
37 {
38 public:
39 
47  using permutationMapType = std::map< string, std::map< string, std::map< string, stdVector< string > > > >;
48 
52  enum class ObjectTypes : int
53  {
54  nodes,
55  edges,
56  faces,
57  elems,
58  invalid
59  };
60 
63  using SetNameToTypesMap = std::map< std::string, std::map< MeshObjectPath::ObjectTypes, localIndex > >;
64 
72  MeshObjectPath( string const path,
73  dataRepository::Group const & meshBodies );
74 
81  void processPath( string const path,
82  dataRepository::Group const & meshBodies );
83 
88  ObjectTypes const & getObjectType() const
89  {
90  return m_objectType;
91  }
92 
99  {
100  return m_pathPermutations;
101  }
102 
109  bool containsMeshLevel( MeshLevel const & meshLevel ) const;
110 
121  template< typename OBJECT_TYPE = dataRepository::Group,
122  typename FUNC >
123  void forObjectsInPath( dataRepository::Group & meshBodies,
124  FUNC && func ) const;
125 
136  template< typename OBJECT_TYPE = dataRepository::Group,
137  typename FUNC >
138  void forObjectsInPath( dataRepository::Group const & meshBodies,
139  FUNC && func ) const;
140 
151  template< typename OBJECT_TYPE = dataRepository::Group,
152  typename FUNC >
153  void forObjectsInPath( MeshLevel & level, FUNC && func ) const;
154 
165  template< typename TYPE, typename ... NEXT_TYPES,
166  typename FUNC >
167  void forManagersForSetName( MeshLevel const & mesh, string const & setName,
168  FUNC && func ) const;
169 
170 #if defined(MESH_OBJECT_PATH_PRIVATE_FUNCTION_UNIT_TESTING)
171  template< typename OBJECT_TYPE >
172  bool testCheckObjectTypeConsistency()
173  {
174  return checkObjectTypeConsistency< OBJECT_TYPE >();
175  }
176 
177  stdVector< string > testFillPathTokens( string const & path,
178  dataRepository::Group const & meshBodies )
179  {
180  return fillPathTokens( path, meshBodies );
181  }
182 
183 #endif
184 
185 private:
186 
197  template< typename OBJECT_TYPE,
198  typename FUNC >
199  void forObjectsInPath( std::pair< string const, std::map< string, stdVector< string > > > const & levelPair,
200  MeshLevel & meshLevel,
201  FUNC && func ) const;
202 
203  template< typename OBJECT_TYPE,
204  typename FUNC >
205  void forObjectsInPath( std::pair< string const, std::map< string, stdVector< string > > > const & levelPair,
206  MeshLevel const & meshLevel,
207  FUNC && func ) const;
208 
216  template< typename OBJECT_TYPE >
217  bool checkObjectTypeConsistency() const;
218 
222  void printPermutations() const;
223 
230  stdVector< string > fillPathTokens( string const & path,
231  dataRepository::Group const & meshBodies ) const;
232 
239  void processPathTokens( stdVector< string > const & pathTokens,
240  dataRepository::Group const & meshBodies );
241 
242 
243 
245  ObjectTypes const m_objectType;
246 
248  permutationMapType m_pathPermutations;
249 
250 };
251 
252 } /* namespace geos */
253 
254 #include "MeshBody.hpp"
255 
256 namespace geos
257 {
258 
263  MeshLevel::groupStructKeys::nodeManagerString(),
264  MeshLevel::groupStructKeys::edgeManagerString(),
265  MeshLevel::groupStructKeys::faceManagerString(),
266  MeshLevel::groupStructKeys::elemManagerString(),
267  "invalid" );
268 
269 template< typename OBJECT_TYPE >
270 bool MeshObjectPath::checkObjectTypeConsistency() const
271 {
272  bool consistent = false;
273  if( m_objectType == ObjectTypes::nodes )
274  {
275  consistent = std::is_same< NodeManager, OBJECT_TYPE >::value;
276  }
277  else if( m_objectType == ObjectTypes::edges )
278  {
279  consistent = std::is_same< EdgeManager, OBJECT_TYPE >::value;
280  }
281  else if( m_objectType == ObjectTypes::faces )
282  {
283  consistent = std::is_same< FaceManager, OBJECT_TYPE >::value;
284  }
285  else if( m_objectType == ObjectTypes::elems )
286  {
287  consistent = std::is_base_of< ElementRegionBase, OBJECT_TYPE >::value ||
288  std::is_base_of< ElementSubRegionBase, OBJECT_TYPE >::value;
289  }
290  return consistent;
291 }
292 
293 template< typename OBJECT_TYPE,
294  typename FUNC >
295 void MeshObjectPath::forObjectsInPath( std::pair< string const, std::map< string, stdVector< string > > > const & levelPair,
296  MeshLevel & meshLevel,
297  FUNC && func ) const
298 {
299  forObjectsInPath< OBJECT_TYPE >( levelPair, const_cast< MeshLevel const & >( meshLevel ), [&]( OBJECT_TYPE const & object )
300  {
301  func( const_cast< OBJECT_TYPE & >(object) );
302  } );
303 }
304 
305 template< typename OBJECT_TYPE,
306  typename FUNC >
307 void MeshObjectPath::forObjectsInPath( std::pair< string const, std::map< string, stdVector< string > > > const & levelPair,
308  MeshLevel const & meshLevel,
309  FUNC && func ) const
310 {
311  if( m_objectType == ObjectTypes::nodes )
312  {
313  func( dynamic_cast< OBJECT_TYPE const & >(meshLevel.getNodeManager() ) );
314  }
315  else if( m_objectType == ObjectTypes::edges )
316  {
317  func( dynamic_cast< OBJECT_TYPE const & >(meshLevel.getEdgeManager()) );
318  }
319  else if( m_objectType == ObjectTypes::faces )
320  {
321  func( dynamic_cast< OBJECT_TYPE const & >(meshLevel.getFaceManager()) );
322  }
323  else if( m_objectType == ObjectTypes::elems )
324  {
325  ElementRegionManager const & elemRegionMan = meshLevel.getElemManager();
326  for( auto & elemRegionPair : levelPair.second )
327  {
328  ElementRegionBase const & elemRegion = elemRegionMan.getRegion( elemRegionPair.first );
329  if( std::is_base_of< ElementRegionBase, OBJECT_TYPE >::value )
330  {
331  func( dynamic_cast< OBJECT_TYPE const & >(elemRegion) );
332  }
333  else
334  {
335  for( auto & elemSubRegionName : elemRegionPair.second )
336  {
337  ElementSubRegionBase const & subRegion = elemRegion.getSubRegion( elemSubRegionName );
338  if( std::is_base_of< ElementSubRegionBase, OBJECT_TYPE >::value ||
339  std::is_same< dataRepository::Group, OBJECT_TYPE >::value )
340  {
341  func( dynamic_cast< OBJECT_TYPE const & >(subRegion) );
342  }
343  else
344  {
345  GEOS_ERROR( "You shouldn't be here" );
346  }
347  }
348  }
349  }
350  }
351 }
352 
353 template< typename OBJECT_TYPE,
354  typename FUNC >
356  FUNC && func ) const
357 {
358  forObjectsInPath< OBJECT_TYPE >( const_cast< dataRepository::Group const & >(meshBodies),
359  [&]( auto const & object )
360  {
361  func( const_cast< OBJECT_TYPE & >(object) );
362  } );
363 }
364 
365 template< typename OBJECT_TYPE, typename FUNC >
367  FUNC && func ) const
368 {
369  checkObjectTypeConsistency< OBJECT_TYPE >();
370  for( auto const & meshBodyPair : m_pathPermutations )
371  {
372  MeshBody const & meshBody = meshBodies.getGroup< MeshBody >( meshBodyPair.first );
373  for( auto const & meshLevelPair : meshBodyPair.second )
374  {
375  MeshLevel const & meshLevel = meshBody.getMeshLevel( meshLevelPair.first );
376  forObjectsInPath< OBJECT_TYPE, FUNC >( meshLevelPair, meshLevel, std::forward< FUNC >( func ));
377  }
378  }
379 }
380 
381 template< typename OBJECT_TYPE,
382  typename FUNC >
384  FUNC && func ) const
385 {
386  string const bodyName = meshLevel.getParent().getParent().getName();
387  string const levelName = meshLevel.getName();
388 
389  auto bodyIter = m_pathPermutations.find( bodyName );
390  if( bodyIter != m_pathPermutations.end() )
391  {
392  auto const levelIter = bodyIter->second.find( levelName );
393  if( levelIter != bodyIter->second.end() )
394  {
395  // string const objectTypeName = stringutilities::toLower( OBJECT_TYPE::catalogName());
396  // if( objectTypeName == stringutilities::toLower( EnumStrings< ObjectTypes >::toString( m_objectType ) ) ||
397  // ( objectTypeName.find( "elem" )!=string::npos && m_objectType==ObjectTypes::elems ) ||
398  // ( objectTypeName == "group") )
399  if( checkObjectTypeConsistency< OBJECT_TYPE >() ||
400  std::is_same< OBJECT_TYPE, dataRepository::Group >::value )
401  {
402  forObjectsInPath< OBJECT_TYPE, FUNC >( *levelIter, meshLevel, std::forward< FUNC >( func ) );
403  }
404  }
405  }
406 }
407 
408 template< typename TYPE, typename ... NEXT_TYPES,
409  typename FUNC >
410 void MeshObjectPath::forManagersForSetName( MeshLevel const & mesh, string const & setName,
411  FUNC && func ) const
412 {
413  mesh.forSubGroups< TYPE >( [&]( dataRepository::Group const & targetManager )
414  {
415  TYPE const * manager = dynamic_cast< TYPE const * >( &targetManager );
416 
417  if( manager != nullptr )
418  {
419  if( manager->sets().hasWrapper( setName ))
420  {
421  auto const & targetSet = manager->getSet( setName );
422  if( std::is_same_v< TYPE, NodeManager > &&
424  targetSet.size() > 0 )
425  {
426  func( MeshObjectPath::ObjectTypes::nodes, setName );
427  }
428  else if( std::is_same_v< TYPE, EdgeManager > &&
430  targetSet.size() > 0 )
431  {
432  func( MeshObjectPath::ObjectTypes::edges, setName );
433  }
434  else if( std::is_same_v< TYPE, FaceManager > &&
436  targetSet.size() > 0 )
437  {
438  func( MeshObjectPath::ObjectTypes::faces, setName );
439  }
440  }
441  }
442  } );
443 
444  if constexpr ( sizeof...(NEXT_TYPES) > 0 )
445  forManagersForSetName< NEXT_TYPES... >( mesh, setName, func );
446 }
447 
448 
449 
450 } /* namespace geos */
451 
452 #endif /* GEOS_MESH_MESHOBJECTPATH_HPP_ */
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:157
The class is used to manage mesh body.
Definition: MeshBody.hpp:36
MeshLevel & getMeshLevel(T const &level) const
Get a reference to a MeshLevel.
Definition: MeshBody.hpp:101
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:42
Class to hold the path to a collection of mesh objects.
std::map< string, std::map< string, std::map< string, stdVector< string > > > > permutationMapType
The container type that holds the path information The first key is the name of a MeshBody The second...
void forManagersForSetName(MeshLevel const &mesh, string const &setName, FUNC &&func) const
Given an objectType and a setName from the current fieldSpecification, iterate over all managers; if ...
void processPath(string const path, dataRepository::Group const &meshBodies)
Processes the path string into the permutation container.
void forObjectsInPath(dataRepository::Group &meshBodies, FUNC &&func) const
LLoop over objects in the path and execute a callback function.
bool containsMeshLevel(MeshLevel const &meshLevel) const
Helper function to decide whether a given meshLevel is in the objectPath.
std::map< std::string, std::map< MeshObjectPath::ObjectTypes, localIndex > > SetNameToTypesMap
alias for the map allowing to know the existance of given element types (node, edge,...
permutationMapType const & pathPermutations() const
Get the m_pathPermutations object.
MeshObjectPath(string const path, dataRepository::Group const &meshBodies)
Construct a new Mesh Object Path object.
ObjectTypes
Contains enums for the types of objects.
ObjectTypes const & getObjectType() const
Get the Object Type object.
string const & getName() const
Get group name.
Definition: Group.hpp:1331
T & getGroup(KEY const &key)
Return a reference to a sub-group of the current Group.
Definition: Group.hpp:318
Group & getParent()
Access the group's parent.
Definition: Group.hpp:1364
void forSubGroups(LAMBDA &&lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:500
mapBase< TKEY, TVAL, std::integral_constant< bool, true > > map
Ordered map type.
Definition: DataTypes.hpp:339
ENUM_STRINGS(LinearSolverParameters::SolverType, "direct", "cg", "gmres", "fgmres", "bicgstab", "richardson", "preconditioner")
Declare strings associated with enumeration values.
internal::StdVectorWrapper< T, Allocator, USE_STD_CONTAINER_BOUNDS_CHECKING > stdVector