GEOSX
MeshObjectPath.hpp
Go to the documentation of this file.
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 
19 #ifndef GEOS_MESH_MESHOBJECTPATH_HPP_
20 #define GEOS_MESH_MESHOBJECTPATH_HPP_
21 
22 
23 #include "codingUtilities/EnumStrings.hpp"
24 #include "MeshLevel.hpp"
25 
26 namespace geos
27 {
28 class MeshBody;
29 class MeshLevel;
30 
36 {
37 public:
38 
46  using permutationMapType = std::map< string, std::map< string, std::map< string, std::vector< string > > > >;
47 
51  enum class ObjectTypes : int
52  {
53  nodes,
54  edges,
55  faces,
56  elems,
57  invalid
58  };
59 
67  MeshObjectPath( string const path,
68  dataRepository::Group const & meshBodies );
69 
76  void processPath( string const path,
77  dataRepository::Group const & meshBodies );
78 
83  ObjectTypes const & getObjectType() const
84  {
85  return m_objectType;
86  }
87 
94  {
95  return m_pathPermutations;
96  }
97 
104  bool containsMeshLevel( MeshLevel const & meshLevel ) const;
105 
116  template< typename OBJECT_TYPE = dataRepository::Group,
117  typename FUNC >
118  void forObjectsInPath( dataRepository::Group & meshBodies,
119  FUNC && func ) const;
120 
131  template< typename OBJECT_TYPE = dataRepository::Group,
132  typename FUNC >
133  void forObjectsInPath( dataRepository::Group const & meshBodies,
134  FUNC && func ) const;
135 
146  template< typename OBJECT_TYPE = dataRepository::Group,
147  typename FUNC >
148  void forObjectsInPath( MeshLevel & level, FUNC && func ) const;
149 
150 #if defined(MESH_OBJECT_PATH_PRIVATE_FUNCTION_UNIT_TESTING)
151  template< typename OBJECT_TYPE >
152  bool testCheckObjectTypeConsistency()
153  {
154  return checkObjectTypeConsistency< OBJECT_TYPE >();
155  }
156 
157  std::vector< string > testFillPathTokens( string const & path,
158  dataRepository::Group const & meshBodies )
159  {
160  return fillPathTokens( path, meshBodies );
161  }
162 
163 #endif
164 
165 private:
166 
177  template< typename OBJECT_TYPE,
178  typename FUNC >
179  void forObjectsInPath( std::pair< string const, std::map< string, std::vector< string > > > const & levelPair,
180  MeshLevel & meshLevel,
181  FUNC && func ) const;
182 
183  template< typename OBJECT_TYPE,
184  typename FUNC >
185  void forObjectsInPath( std::pair< string const, std::map< string, std::vector< string > > > const & levelPair,
186  MeshLevel const & meshLevel,
187  FUNC && func ) const;
188 
196  template< typename OBJECT_TYPE >
197  bool checkObjectTypeConsistency() const;
198 
202  void printPermutations() const;
203 
210  std::vector< string > fillPathTokens( string const & path,
211  dataRepository::Group const & meshBodies ) const;
212 
219  void processPathTokens( std::vector< string > const & pathTokens,
220  dataRepository::Group const & meshBodies );
221 
222 
223 
225  ObjectTypes const m_objectType;
226 
228  permutationMapType m_pathPermutations;
229 
230 };
231 
232 } /* namespace geos */
233 
234 #include "MeshBody.hpp"
235 
236 namespace geos
237 {
238 
243  MeshLevel::groupStructKeys::nodeManagerString(),
244  MeshLevel::groupStructKeys::edgeManagerString(),
245  MeshLevel::groupStructKeys::faceManagerString(),
246  MeshLevel::groupStructKeys::elemManagerString(),
247  "invalid" );
248 
249 template< typename OBJECT_TYPE >
250 bool MeshObjectPath::checkObjectTypeConsistency() const
251 {
252  bool consistent = false;
253  if( m_objectType == ObjectTypes::nodes )
254  {
255  consistent = std::is_same< NodeManager, OBJECT_TYPE >::value;
256  }
257  else if( m_objectType == ObjectTypes::edges )
258  {
259  consistent = std::is_same< EdgeManager, OBJECT_TYPE >::value;
260  }
261  else if( m_objectType == ObjectTypes::faces )
262  {
263  consistent = std::is_same< FaceManager, OBJECT_TYPE >::value;
264  }
265  else if( m_objectType == ObjectTypes::elems )
266  {
267  consistent = std::is_base_of< ElementRegionBase, OBJECT_TYPE >::value ||
268  std::is_base_of< ElementSubRegionBase, OBJECT_TYPE >::value;
269  }
270  return consistent;
271 }
272 
273 template< typename OBJECT_TYPE,
274  typename FUNC >
275 void MeshObjectPath::forObjectsInPath( std::pair< string const, std::map< string, std::vector< string > > > const & levelPair,
276  MeshLevel & meshLevel,
277  FUNC && func ) const
278 {
279  forObjectsInPath< OBJECT_TYPE >( levelPair, const_cast< MeshLevel const & >( meshLevel ), [&]( OBJECT_TYPE const & object )
280  {
281  func( const_cast< OBJECT_TYPE & >(object) );
282  } );
283 }
284 
285 template< typename OBJECT_TYPE,
286  typename FUNC >
287 void MeshObjectPath::forObjectsInPath( std::pair< string const, std::map< string, std::vector< string > > > const & levelPair,
288  MeshLevel const & meshLevel,
289  FUNC && func ) const
290 {
291  if( m_objectType == ObjectTypes::nodes )
292  {
293  func( dynamic_cast< OBJECT_TYPE const & >(meshLevel.getNodeManager() ) );
294  }
295  else if( m_objectType == ObjectTypes::edges )
296  {
297  func( dynamic_cast< OBJECT_TYPE const & >(meshLevel.getEdgeManager()) );
298  }
299  else if( m_objectType == ObjectTypes::faces )
300  {
301  func( dynamic_cast< OBJECT_TYPE const & >(meshLevel.getFaceManager()) );
302  }
303  else if( m_objectType == ObjectTypes::elems )
304  {
305  ElementRegionManager const & elemRegionMan = meshLevel.getElemManager();
306  for( auto & elemRegionPair : levelPair.second )
307  {
308  ElementRegionBase const & elemRegion = elemRegionMan.getRegion( elemRegionPair.first );
309  if( std::is_base_of< ElementRegionBase, OBJECT_TYPE >::value )
310  {
311  func( dynamic_cast< OBJECT_TYPE const & >(elemRegion) );
312  }
313  else
314  {
315  for( auto & elemSubRegionName : elemRegionPair.second )
316  {
317  ElementSubRegionBase const & subRegion = elemRegion.getSubRegion( elemSubRegionName );
318  if( std::is_base_of< ElementSubRegionBase, OBJECT_TYPE >::value ||
319  std::is_same< dataRepository::Group, OBJECT_TYPE >::value )
320  {
321  func( dynamic_cast< OBJECT_TYPE const & >(subRegion) );
322  }
323  else
324  {
325  GEOS_ERROR( "You shouldn't be here" );
326  }
327  }
328  }
329  }
330  }
331 }
332 
333 template< typename OBJECT_TYPE,
334  typename FUNC >
336  FUNC && func ) const
337 {
338  forObjectsInPath< OBJECT_TYPE >( const_cast< dataRepository::Group const & >(meshBodies),
339  [&]( auto const & object )
340  {
341  func( const_cast< OBJECT_TYPE & >(object) );
342  } );
343 }
344 
345 template< typename OBJECT_TYPE, typename FUNC >
347  FUNC && func ) const
348 {
349  checkObjectTypeConsistency< OBJECT_TYPE >();
350  for( auto const & meshBodyPair : m_pathPermutations )
351  {
352  MeshBody const & meshBody = meshBodies.getGroup< MeshBody >( meshBodyPair.first );
353  for( auto const & meshLevelPair : meshBodyPair.second )
354  {
355  MeshLevel const & meshLevel = meshBody.getMeshLevel( meshLevelPair.first );
356  forObjectsInPath< OBJECT_TYPE, FUNC >( meshLevelPair, meshLevel, std::forward< FUNC >( func ));
357  }
358  }
359 }
360 
361 template< typename OBJECT_TYPE,
362  typename FUNC >
364  FUNC && func ) const
365 {
366  string const bodyName = meshLevel.getParent().getParent().getName();
367  string const levelName = meshLevel.getName();
368 
369  auto bodyIter = m_pathPermutations.find( bodyName );
370  if( bodyIter != m_pathPermutations.end() )
371  {
372  auto const levelIter = bodyIter->second.find( levelName );
373  if( levelIter != bodyIter->second.end() )
374  {
375  // string const objectTypeName = stringutilities::toLower( OBJECT_TYPE::catalogName());
376  // if( objectTypeName == stringutilities::toLower( EnumStrings< ObjectTypes >::toString( m_objectType ) ) ||
377  // ( objectTypeName.find( "elem" )!=string::npos && m_objectType==ObjectTypes::elems ) ||
378  // ( objectTypeName == "group") )
379  if( checkObjectTypeConsistency< OBJECT_TYPE >() ||
380  std::is_same< OBJECT_TYPE, dataRepository::Group >::value )
381  {
382  forObjectsInPath< OBJECT_TYPE, FUNC >( *levelIter, meshLevel, std::forward< FUNC >( func ) );
383  }
384  }
385  }
386 }
387 
388 
389 
390 } /* namespace geos */
391 
392 #endif /* GEOS_MESH_MESHOBJECTPATH_HPP_ */
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:122
The class is used to manage mesh body.
Definition: MeshBody.hpp:35
MeshLevel & getMeshLevel(T const &level) const
Get a reference to a MeshLevel.
Definition: MeshBody.hpp:100
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:41
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:1308
T & getGroup(KEY const &key)
Return a reference to a sub-group of the current Group.
Definition: Group.hpp:333
Group & getParent()
Access the group's parent.
Definition: Group.hpp:1341
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:409