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 Total, S.A
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, std::vector< string > > > >;
48 
52  enum class ObjectTypes : int
53  {
54  nodes,
55  edges,
56  faces,
57  elems,
58  invalid
59  };
60 
68  MeshObjectPath( string const path,
69  dataRepository::Group const & meshBodies );
70 
77  void processPath( string const path,
78  dataRepository::Group const & meshBodies );
79 
84  ObjectTypes const & getObjectType() const
85  {
86  return m_objectType;
87  }
88 
95  {
96  return m_pathPermutations;
97  }
98 
105  bool containsMeshLevel( MeshLevel const & meshLevel ) const;
106 
117  template< typename OBJECT_TYPE = dataRepository::Group,
118  typename FUNC >
119  void forObjectsInPath( dataRepository::Group & meshBodies,
120  FUNC && func ) const;
121 
132  template< typename OBJECT_TYPE = dataRepository::Group,
133  typename FUNC >
134  void forObjectsInPath( dataRepository::Group const & meshBodies,
135  FUNC && func ) const;
136 
147  template< typename OBJECT_TYPE = dataRepository::Group,
148  typename FUNC >
149  void forObjectsInPath( MeshLevel & level, FUNC && func ) const;
150 
151 #if defined(MESH_OBJECT_PATH_PRIVATE_FUNCTION_UNIT_TESTING)
152  template< typename OBJECT_TYPE >
153  bool testCheckObjectTypeConsistency()
154  {
155  return checkObjectTypeConsistency< OBJECT_TYPE >();
156  }
157 
158  std::vector< string > testFillPathTokens( string const & path,
159  dataRepository::Group const & meshBodies )
160  {
161  return fillPathTokens( path, meshBodies );
162  }
163 
164 #endif
165 
166 private:
167 
178  template< typename OBJECT_TYPE,
179  typename FUNC >
180  void forObjectsInPath( std::pair< string const, std::map< string, std::vector< string > > > const & levelPair,
181  MeshLevel & meshLevel,
182  FUNC && func ) const;
183 
184  template< typename OBJECT_TYPE,
185  typename FUNC >
186  void forObjectsInPath( std::pair< string const, std::map< string, std::vector< string > > > const & levelPair,
187  MeshLevel const & meshLevel,
188  FUNC && func ) const;
189 
197  template< typename OBJECT_TYPE >
198  bool checkObjectTypeConsistency() const;
199 
203  void printPermutations() const;
204 
211  std::vector< string > fillPathTokens( string const & path,
212  dataRepository::Group const & meshBodies ) const;
213 
220  void processPathTokens( std::vector< string > const & pathTokens,
221  dataRepository::Group const & meshBodies );
222 
223 
224 
226  ObjectTypes const m_objectType;
227 
229  permutationMapType m_pathPermutations;
230 
231 };
232 
233 } /* namespace geos */
234 
235 #include "MeshBody.hpp"
236 
237 namespace geos
238 {
239 
244  MeshLevel::groupStructKeys::nodeManagerString(),
245  MeshLevel::groupStructKeys::edgeManagerString(),
246  MeshLevel::groupStructKeys::faceManagerString(),
247  MeshLevel::groupStructKeys::elemManagerString(),
248  "invalid" );
249 
250 template< typename OBJECT_TYPE >
251 bool MeshObjectPath::checkObjectTypeConsistency() const
252 {
253  bool consistent = false;
254  if( m_objectType == ObjectTypes::nodes )
255  {
256  consistent = std::is_same< NodeManager, OBJECT_TYPE >::value;
257  }
258  else if( m_objectType == ObjectTypes::edges )
259  {
260  consistent = std::is_same< EdgeManager, OBJECT_TYPE >::value;
261  }
262  else if( m_objectType == ObjectTypes::faces )
263  {
264  consistent = std::is_same< FaceManager, OBJECT_TYPE >::value;
265  }
266  else if( m_objectType == ObjectTypes::elems )
267  {
268  consistent = std::is_base_of< ElementRegionBase, OBJECT_TYPE >::value ||
269  std::is_base_of< ElementSubRegionBase, OBJECT_TYPE >::value;
270  }
271  return consistent;
272 }
273 
274 template< typename OBJECT_TYPE,
275  typename FUNC >
276 void MeshObjectPath::forObjectsInPath( std::pair< string const, std::map< string, std::vector< string > > > const & levelPair,
277  MeshLevel & meshLevel,
278  FUNC && func ) const
279 {
280  forObjectsInPath< OBJECT_TYPE >( levelPair, const_cast< MeshLevel const & >( meshLevel ), [&]( OBJECT_TYPE const & object )
281  {
282  func( const_cast< OBJECT_TYPE & >(object) );
283  } );
284 }
285 
286 template< typename OBJECT_TYPE,
287  typename FUNC >
288 void MeshObjectPath::forObjectsInPath( std::pair< string const, std::map< string, std::vector< string > > > const & levelPair,
289  MeshLevel const & meshLevel,
290  FUNC && func ) const
291 {
292  if( m_objectType == ObjectTypes::nodes )
293  {
294  func( dynamic_cast< OBJECT_TYPE const & >(meshLevel.getNodeManager() ) );
295  }
296  else if( m_objectType == ObjectTypes::edges )
297  {
298  func( dynamic_cast< OBJECT_TYPE const & >(meshLevel.getEdgeManager()) );
299  }
300  else if( m_objectType == ObjectTypes::faces )
301  {
302  func( dynamic_cast< OBJECT_TYPE const & >(meshLevel.getFaceManager()) );
303  }
304  else if( m_objectType == ObjectTypes::elems )
305  {
306  ElementRegionManager const & elemRegionMan = meshLevel.getElemManager();
307  for( auto & elemRegionPair : levelPair.second )
308  {
309  ElementRegionBase const & elemRegion = elemRegionMan.getRegion( elemRegionPair.first );
310  if( std::is_base_of< ElementRegionBase, OBJECT_TYPE >::value )
311  {
312  func( dynamic_cast< OBJECT_TYPE const & >(elemRegion) );
313  }
314  else
315  {
316  for( auto & elemSubRegionName : elemRegionPair.second )
317  {
318  ElementSubRegionBase const & subRegion = elemRegion.getSubRegion( elemSubRegionName );
319  if( std::is_base_of< ElementSubRegionBase, OBJECT_TYPE >::value ||
320  std::is_same< dataRepository::Group, OBJECT_TYPE >::value )
321  {
322  func( dynamic_cast< OBJECT_TYPE const & >(subRegion) );
323  }
324  else
325  {
326  GEOS_ERROR( "You shouldn't be here" );
327  }
328  }
329  }
330  }
331  }
332 }
333 
334 template< typename OBJECT_TYPE,
335  typename FUNC >
337  FUNC && func ) const
338 {
339  forObjectsInPath< OBJECT_TYPE >( const_cast< dataRepository::Group const & >(meshBodies),
340  [&]( auto const & object )
341  {
342  func( const_cast< OBJECT_TYPE & >(object) );
343  } );
344 }
345 
346 template< typename OBJECT_TYPE, typename FUNC >
348  FUNC && func ) const
349 {
350  checkObjectTypeConsistency< OBJECT_TYPE >();
351  for( auto const & meshBodyPair : m_pathPermutations )
352  {
353  MeshBody const & meshBody = meshBodies.getGroup< MeshBody >( meshBodyPair.first );
354  for( auto const & meshLevelPair : meshBodyPair.second )
355  {
356  MeshLevel const & meshLevel = meshBody.getMeshLevel( meshLevelPair.first );
357  forObjectsInPath< OBJECT_TYPE, FUNC >( meshLevelPair, meshLevel, std::forward< FUNC >( func ));
358  }
359  }
360 }
361 
362 template< typename OBJECT_TYPE,
363  typename FUNC >
365  FUNC && func ) const
366 {
367  string const bodyName = meshLevel.getParent().getParent().getName();
368  string const levelName = meshLevel.getName();
369 
370  auto bodyIter = m_pathPermutations.find( bodyName );
371  if( bodyIter != m_pathPermutations.end() )
372  {
373  auto const levelIter = bodyIter->second.find( levelName );
374  if( levelIter != bodyIter->second.end() )
375  {
376  // string const objectTypeName = stringutilities::toLower( OBJECT_TYPE::catalogName());
377  // if( objectTypeName == stringutilities::toLower( EnumStrings< ObjectTypes >::toString( m_objectType ) ) ||
378  // ( objectTypeName.find( "elem" )!=string::npos && m_objectType==ObjectTypes::elems ) ||
379  // ( objectTypeName == "group") )
380  if( checkObjectTypeConsistency< OBJECT_TYPE >() ||
381  std::is_same< OBJECT_TYPE, dataRepository::Group >::value )
382  {
383  forObjectsInPath< OBJECT_TYPE, FUNC >( *levelIter, meshLevel, std::forward< FUNC >( func ) );
384  }
385  }
386  }
387 }
388 
389 
390 
391 } /* namespace geos */
392 
393 #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.
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.
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.
std::map< string, std::map< string, std::map< string, std::vector< string > > > > permutationMapType
The container type that holds the path information The first key is the name of a MeshBody The second...
ObjectTypes const & getObjectType() const
Get the Object Type object.
string const & getName() const
Get group name.
Definition: Group.hpp:1329
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
ENUM_STRINGS(LinearSolverParameters::SolverType, "direct", "cg", "gmres", "fgmres", "bicgstab", "preconditioner")
Declare strings associated with enumeration values.
mapBase< TKEY, TVAL, std::integral_constant< bool, true > > map
Ordered map type.
Definition: DataTypes.hpp:369