GEOSX
Group.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 Total, S.A
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 
20 #ifndef GEOSX_DATAREPOSITORY_GROUP_HPP_
21 #define GEOSX_DATAREPOSITORY_GROUP_HPP_
22 
23 #include "InputFlags.hpp"
25 #include "MappedVector.hpp"
26 #include "RestartFlags.hpp"
27 #include "Wrapper.hpp"
28 #include "xmlWrapper.hpp"
29 
30 #include <iostream>
31 
32 #ifndef NOCHARTOSTRING_KEYLOOKUP
33 #define NOCHARTOSTRING_KEYLOOKUP 0
35 #endif
36 
37 // Forward declaration of conduit::Node
38 namespace conduit
39 {
40 class Node;
41 }
42 
43 
47 namespace geosx
48 {
49 
53 namespace dataRepository
54 {
55 
56 //START_SPHINX_INCLUDE_00
58 using keyType = string;
59 
62 //END_SPHINX_INCLUDE_00
63 
70 class Group
71 {
72 public:
73  //START_SPHINX_INCLUDE_01
76 
79  //END_SPHINX_INCLUDE_01
80 
84 
92  explicit Group( std::string const & name,
93  Group * const parent );
94 
95 
100  Group( Group && source );
101 
105  virtual ~Group();
106 
110  Group() = delete;
111 
115  Group( Group const & ) = delete;
116 
120  Group( Group const && ) = delete;
121 
126  Group & operator=( Group const & ) = delete;
127 
132  Group & operator=( Group && ) = delete;
133 
135 
136 
140 
146 
151  static CatalogInterface::CatalogType & GetCatalog();
152 
154 
158 
164  virtual const std::type_info & get_typeid() const
165  {
166  return typeid(*this);
167  }
168 
174  bool CheckTypeID( std::type_info const & typeToCheck ) const
175  {
176  return typeToCheck == get_typeid();
177  }
178 
183  void PrintDataHierarchy( integer indent = 0 );
184 
188  string dumpInputOptions() const;
189 
191 
192  //START_SPHINX_INCLUDE_REGISTER_GROUP
196 
208  template< typename T = Group >
209  T * RegisterGroup( std::string const & name, std::unique_ptr< T > newObject );
210 
221  template< typename T = Group >
222  T * RegisterGroup( std::string const & name,
223  T * newObject );
224 
234  template< typename T = Group >
235  T * RegisterGroup( std::string const & name )
236  {
237  return RegisterGroup< T >( name, std::move( std::make_unique< T >( name, this )) );
238  }
239 
250  template< typename T = Group >
251  T * RegisterGroup( subGroupMap::KeyIndex const & keyIndex )
252  {
253  T * rval = RegisterGroup< T >( keyIndex.Key(), std::move( std::make_unique< T >( keyIndex.Key(), this )) );
254  keyIndex.setIndex( this->m_subGroups.getIndex( keyIndex.Key()) );
255  return rval;
256  }
257 
269  template< typename T = Group, typename TBASE = Group >
270  T * RegisterGroup( std::string const & name, std::string const & catalogName )
271  {
272  std::unique_ptr< TBASE > newGroup = TBASE::CatalogInterface::Factory( catalogName, name, this );
273  return RegisterGroup< T >( name, std::move( newGroup ) );
274  }
275 
280  void deregisterGroup( std::string const & name );
281 
290  virtual Group * CreateChild( string const & childKey, string const & childName );
291 
293 
294  //END_SPHINX_INCLUDE_REGISTER_GROUP
295 
299 
307  template< typename T >
308  static T group_cast( Group * group )
309  {
310  return dynamicCast< T >( group );
311  }
312 
319  template< typename T >
320  static T group_cast( Group const * group )
321  {
322  return dynamicCast< T >( group );
323  }
324 
330  template< typename T >
332  {
333  return dynamicCast< T >( this );
334  }
335 
341  template< typename T >
342  T group_cast() const
343  {
344  return dynamicCast< T >( this );
345  }
346 
348 
349  //START_SPHINX_INCLUDE_GET_GROUP
365 
373  template< typename T = Group >
374  T * GetGroup( localIndex index )
375  {
376  return group_cast< T * >( m_subGroups[index] );
377  }
378 
382  template< typename T = Group >
383  T const * GetGroup( localIndex index ) const
384  {
385  return group_cast< T const * >( m_subGroups[index] );
386  }
387 
394  template< typename T = Group >
395  T * GetGroup( string const & name )
396  {
397  return group_cast< T * >( m_subGroups[name] );
398  }
399 
403  template< typename T = Group >
404  T const * GetGroup( string const & name ) const
405  { return group_cast< T const * >( m_subGroups[name] ); }
406 
413  template< typename T = Group >
414  T & getGroupReference( string const & key )
415  { return dynamicCast< T & >( *m_subGroups[ key ] ); }
416 
420  template< typename T = Group >
421  T const & getGroupReference( string const & key ) const
422  { return dynamicCast< T const & >( *m_subGroups[ key ] ); }
423 
427  template< typename T = Group >
429  { return dynamicCast< T & >( *m_subGroups[key] ); }
430 
434  template< typename T = Group >
435  T const & GetGroupReference( subGroupMap::KeyIndex const & key ) const
436  { return dynamicCast< T const & >( *m_subGroups[key] ); }
437 
444  template< typename T = Group >
445  T * GetGroup( subGroupMap::KeyIndex const & key )
446  {
447  return group_cast< T * >( m_subGroups[key] );
448  }
449 
453  template< typename T = Group >
454  T const * GetGroup( subGroupMap::KeyIndex const & key ) const
455  {
456  return group_cast< T const * >( m_subGroups[key] );
457  }
458 
467  template< typename T = Group >
468  T * GetGroupByPath( string const & path )
469  {
470  return const_cast< T * >(const_cast< Group const * >(this)->GetGroupByPath< T >( path ));
471  }
472 
476  template< typename T = Group >
477  T const * GetGroupByPath( string const & path ) const;
478 
479  //END_SPHINX_INCLUDE_GET_GROUP
480 
486  {
487  return m_subGroups;
488  }
489 
494  subGroupMap const & GetSubGroups() const
495  {
496  return m_subGroups;
497  }
498 
503  localIndex numSubGroups() const { return m_subGroups.size(); }
504 
510  bool hasGroup( std::string const & name ) const
511  {
512  return (m_subGroups[name] != nullptr);
513  }
514 
516 
526 
529  template< typename CASTTYPE, typename CONTAINERTYPE, typename LAMBDA >
530  static bool applyLambdaToContainer( CONTAINERTYPE & container, LAMBDA && lambda )
531  {
532  using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, CASTTYPE const, CASTTYPE >;
533  T * const castedContainer = dynamic_cast< T * >( &container );
534 
535  if( castedContainer != nullptr )
536  {
537  lambda( *castedContainer );
538  return true;
539  }
540 
541  return false;
542  }
556  template< typename T0, typename T1, typename ... CASTTYPES, typename CONTAINERTYPE, typename LAMBDA >
557  static bool applyLambdaToContainer( CONTAINERTYPE & container, LAMBDA && lambda )
558  {
559  using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, T0 const, T0 >;
560  T * const castedContainer = dynamic_cast< T * >( &container );
561 
562  if( castedContainer != nullptr )
563  {
564  lambda( *castedContainer );
565  return true;
566  }
567 
568  return applyLambdaToContainer< T1, CASTTYPES... >( container, std::forward< LAMBDA >( lambda ) );
569  }
571 
572 
573  //START_SPHINX_INCLUDE_LOOP_INTERFACE
583 
592  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
593  void forSubGroups( LAMBDA lambda )
594  {
595  for( auto & subGroupIter : m_subGroups )
596  {
597  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&]( auto & castedSubGroup )
598  {
599  lambda( castedSubGroup );
600  } );
601  }
602  }
603 
607  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
608  void forSubGroups( LAMBDA lambda ) const
609  {
610  for( auto const & subGroupIter : m_subGroups )
611  {
612  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&]( auto const & castedSubGroup )
613  {
614  lambda( castedSubGroup );
615  } );
616  }
617  }
618 
630  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LOOKUP_CONTAINER, typename LAMBDA >
631  void forSubGroups( LOOKUP_CONTAINER const & subGroupKeys, LAMBDA lambda )
632  {
633  localIndex counter = 0;
634  for( auto const & subgroup : subGroupKeys )
635  {
636  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *GetGroup( subgroup ), [&]( auto & castedSubGroup )
637  {
638  lambda( counter, castedSubGroup );
639  } );
640  ++counter;
641  }
642  }
643 
655  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LOOKUP_CONTAINER, typename LAMBDA >
656  void forSubGroups( LOOKUP_CONTAINER const & subGroupKeys, LAMBDA lambda ) const
657  {
658  localIndex counter = 0;
659  for( auto const & subgroup : subGroupKeys )
660  {
661  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *GetGroup( subgroup ), [&]( auto const & castedSubGroup )
662  {
663  lambda( counter, castedSubGroup );
664  } );
665  ++counter;
666  }
667  }
669 
680 
687  template< typename LAMBDA >
688  void forWrappers( LAMBDA lambda )
689  {
690  for( auto & wrapperIter : m_wrappers )
691  {
692  lambda( *wrapperIter.second );
693  }
694  }
695 
699  template< typename LAMBDA >
700  void forWrappers( LAMBDA lambda ) const
701  {
702  for( auto const & wrapperIter : m_wrappers )
703  {
704  lambda( *wrapperIter.second );
705  }
706  }
707 
715  template< typename TYPE, typename ... TYPES, typename LAMBDA >
716  void forWrappers( LAMBDA lambda )
717  {
718  for( auto & wrapperIter : m_wrappers )
719  {
720  applyLambdaToContainer< Wrapper< TYPE >, Wrapper< TYPES >... >( *wrapperIter.second,
721  std::forward< LAMBDA >( lambda ));
722  }
723  }
724 
732  template< typename TYPE, typename ... TYPES, typename LAMBDA >
733  void forWrappers( LAMBDA lambda ) const
734  {
735  for( auto const & wrapperIter : m_wrappers )
736  {
737  applyLambdaToContainer< Wrapper< TYPE >, Wrapper< TYPES >... >( *wrapperIter.second,
738  std::forward< LAMBDA >( lambda ));
739  }
740  }
741 
743  //END_SPHINX_INCLUDE_LOOP_INTERFACE
744 
748 
762  void Initialize( Group * const group );
763 
773  virtual void InitializationOrder( string_array & order );
774 
775 
792  void InitializePostInitialConditions( Group * const group );
793 
801  void postRestartInitializationRecursive( Group * const domain );
802 
808  void ProcessInputFileRecursive( xmlWrapper::xmlNode & targetNode );
809 
814  void PostProcessInputRecursive();
815 
817 
818  //START_SPHINX_INCLUDE_REGISTER_WRAPPER
822 
833  template< typename T, typename TBASE=T >
834  Wrapper< TBASE > * registerWrapper( std::string const & name,
835  wrapperMap::KeyIndex::index_type * const rkey = nullptr );
836 
844  template< typename T, typename TBASE=T >
845  Wrapper< TBASE > * registerWrapper( Group::wrapperMap::KeyIndex const & viewKey );
846 
854  template< typename T >
855  Wrapper< T > * registerWrapper( std::string const & name,
856  std::unique_ptr< T > newObject );
857 
865  template< typename T >
866  Wrapper< T > * registerWrapper( std::string const & name,
867  T * newObject );
868 
875  WrapperBase * registerWrapper( string const & name,
876  std::unique_ptr< WrapperBase > wrapper );
877 
882  void deregisterWrapper( string const & name );
883 
885  //END_SPHINX_INCLUDE_REGISTER_WRAPPER
886 
890 
897  {
898  ExpandObjectCatalogs();
899  std::string indent( level*2, ' ' );
900 
901  for( auto const & subGroupIter : m_subGroups )
902  {
903  std::cout << indent << subGroupIter.second->getName() << std::endl;
904  subGroupIter.second->GenerateDataStructureSkeleton( level + 1 );
905  }
906  }
907 
911  virtual void ExpandObjectCatalogs() {}
912 
919  virtual void SetSchemaDeviations( xmlWrapper::xmlNode schemaRoot,
920  xmlWrapper::xmlNode schemaParent,
921  integer documentationType );
922 
924 
928 
934  virtual void RegisterDataOnMeshRecursive( Group * const meshBodies );
935 
943  virtual void RegisterDataOnMesh( Group * const meshBodies );
944 
946 
950 
960  virtual localIndex PackSize( string_array const & wrapperNames,
961  integer const recursive,
962  bool on_device = false ) const;
963 
973  virtual localIndex PackSize( string_array const & wrapperNames,
974  arrayView1d< localIndex const > const & packList,
975  integer const recursive,
976  bool on_device = false ) const;
977 
993  virtual localIndex Pack( buffer_unit_type * & buffer,
994  string_array const & wrapperNames,
995  integer const recursive,
996  bool on_device = false ) const;
997 
1013  virtual localIndex Pack( buffer_unit_type * & buffer,
1014  string_array const & wrapperNames,
1015  arrayView1d< localIndex const > const & packList,
1016  integer const recursive,
1017  bool on_device = false ) const;
1018 
1034  virtual localIndex Unpack( buffer_unit_type const * & buffer,
1035  arrayView1d< localIndex > & packList,
1036  integer const recursive,
1037  bool on_device = false );
1038 
1040 
1041  //***********************************************************************************************
1042 
1043  //START_SPHINX_INCLUDE_GET_WRAPPER
1051 
1058  WrapperBase const * getWrapperBase( indexType const index ) const
1059  { return m_wrappers[index]; }
1060 
1065  { return m_wrappers[index]; }
1066 
1072  WrapperBase const * getWrapperBase( std::string const & name ) const
1073  { return m_wrappers[name]; }
1074 
1079  { return m_wrappers[name]; }
1080 
1086  WrapperBase const * getWrapperBase( wrapperMap::KeyIndex const & keyIndex ) const
1087  { return m_wrappers[keyIndex]; }
1088 
1093  { return m_wrappers[keyIndex]; }
1094 
1100  indexType getWrapperIndex( std::string const & name ) const
1101  {
1102  return m_wrappers.getIndex( name );
1103  }
1104 
1109  wrapperMap const & wrappers() const
1110  {
1111  return m_wrappers;
1112  }
1113 
1118  {
1119  return m_wrappers;
1120  }
1121 
1123 
1135 
1143  template< typename LOOKUP_TYPE >
1144  bool hasWrapper( LOOKUP_TYPE const & lookup ) const
1145  {
1146  return (m_wrappers[lookup] != nullptr);
1147  }
1148 
1156  template< typename T, typename LOOKUP_TYPE >
1157  Wrapper< T > const * getWrapper( LOOKUP_TYPE const & index ) const
1158  {
1159  return dynamicCast< Wrapper< T > const * >( m_wrappers[index] );
1160  }
1161 
1165  template< typename T, typename LOOKUP_TYPE >
1166  Wrapper< T > * getWrapper( LOOKUP_TYPE const & index )
1167  { return const_cast< Wrapper< T > * >( const_cast< Group const * >(this)->getWrapper< T >( index ) ); }
1168 
1175  template< typename T >
1176  Wrapper< T > const * getWrapper( char const * const key ) const
1177  { return getWrapper< T >( string( key ) ); }
1178 
1182  template< typename T >
1183  Wrapper< T > * getWrapper( char const * const key )
1184  { return getWrapper< T >( string( key ) ); }
1185 
1187 
1197 
1209  template< typename T, typename LOOKUP_TYPE >
1211  getReference( LOOKUP_TYPE const & lookup ) const
1212  {
1213  Wrapper< T > const * const wrapper = getWrapper< T >( lookup );
1214  if( wrapper == nullptr )
1215  {
1216  if( hasWrapper( lookup ) )
1217  {
1218  GEOSX_ERROR( "call to getWrapper results in nullptr but a view exists. Most likely given the incorrect type. lookup : " << lookup );
1219  }
1220  GEOSX_ERROR( "call to getWrapper results in nullptr and a view does not exist. lookup : " << lookup );
1221  }
1222 
1223  return wrapper->reference();
1224  }
1225 
1229  template< typename T, typename LOOKUP_TYPE >
1230  T &
1231  getReference( LOOKUP_TYPE const & lookup )
1232  {
1233  Wrapper< T > * const wrapper = getWrapper< T >( lookup );
1234  if( wrapper == nullptr )
1235  {
1236  if( hasWrapper( lookup ) )
1237  {
1238  GEOSX_ERROR( "call to getWrapper results in nullptr but a view exists. Most likely given the incorrect type. lookup : " << lookup );
1239  }
1240  GEOSX_ERROR( "call to getWrapper results in nullptr and a view does not exist. lookup : " << lookup );
1241  }
1242 
1243  return wrapper->reference();
1244  }
1245 
1255  template< typename T >
1257  getReference( char const * const name ) const
1258  { return getReference< T >( string( name ) ); }
1259 
1263  template< typename T >
1264  T & getReference( char const * const name )
1265  { return getReference< T >( string( name ) ); }
1266 
1267  //END_SPHINX_INCLUDE_GET_WRAPPER
1268 
1270 
1274 
1280  virtual void resize( localIndex const newSize );
1281 
1286  virtual void reserve( indexType const newsize );
1287 
1292  inline localIndex capacity() const
1293  {
1294  return m_capacity;
1295  }
1296 
1301  inline localIndex size() const
1302  {
1303  return m_size;
1304  }
1305 
1307 
1311 
1317  inline const string getName() const
1318  {
1319  return m_name;
1320  }
1321 
1326  Group * getParent() { return m_parent; }
1327 
1331  Group const * getParent() const { return m_parent; }
1332 
1338  {
1339  return m_parent->GetSubGroups().getIndex( this->m_name );
1340  }
1341 
1347  {
1348  return m_sizedFromParent;
1349  }
1350 
1357  {
1358  m_sizedFromParent = val;
1359  return this;
1360  }
1365  RestartFlags getRestartFlags() const { return m_restart_flags; }
1366 
1371  void setRestartFlags( RestartFlags flags ) { m_restart_flags = flags; }
1372 
1377  InputFlags getInputFlags() const { return m_input_flags; }
1378 
1383  void setInputFlags( InputFlags flags ) { m_input_flags = flags; }
1384 
1386 
1390 
1396  conduit::Node & getConduitNode()
1397  {
1398  return m_conduitNode;
1399  }
1400 
1404  void prepareToWrite();
1405 
1409  void finishWriting();
1410 
1414  void loadFromConduit();
1415 
1417  void enableLogLevelInput();
1418 
1420  integer getLogLevel() const { return m_logLevel; }
1422 
1423 protected:
1424 
1431 
1437  virtual void PostProcessInput() {}
1438 
1444  virtual void InitializePreSubGroups( Group * const group )
1445  {
1446  GEOSX_UNUSED_VAR( group );
1447  }
1448 
1454  virtual void InitializePostSubGroups( Group * const group )
1455  {
1456  GEOSX_UNUSED_VAR( group );
1457  }
1458 
1465  {
1466  GEOSX_UNUSED_VAR( group );
1467  }
1468 
1475  {
1476  GEOSX_UNUSED_VAR( group );
1477  }
1478 
1483  virtual void postRestartInitialization( Group * const domain )
1484  {
1485  GEOSX_UNUSED_VAR( domain );
1486  }
1487 
1489 
1490 private:
1496  virtual void ProcessInputFile( xmlWrapper::xmlNode const & targetNode );
1497 
1498  //START_SPHINX_INCLUDE_02
1500  Group * m_parent = nullptr;
1501 
1503  integer m_sizedFromParent;
1504 
1506  wrapperMap m_wrappers;
1507 
1509  subGroupMap m_subGroups;
1510 
1513  indexType m_size;
1514 
1517  indexType m_capacity;
1518 
1520  string m_name;
1521 
1523  integer m_logLevel;
1524  //END_SPHINX_INCLUDE_02
1525 
1527  RestartFlags m_restart_flags;
1528 
1530  InputFlags m_input_flags;
1531 
1533  conduit::Node & m_conduitNode;
1534 
1535 };
1536 
1541 
1545 using ViewKey = Group::wrapperMap::KeyIndex;
1546 
1547 
1548 
1549 template< typename T >
1550 T * Group::RegisterGroup( std::string const & name,
1551  std::unique_ptr< T > newObject )
1552 {
1553  newObject->m_parent = this;
1554  return dynamicCast< T * >( m_subGroups.insert( name, newObject.release(), true ) );
1555 }
1556 
1557 
1558 template< typename T >
1559 T * Group::RegisterGroup( std::string const & name,
1560  T * newObject )
1561 {
1562  return dynamicCast< T * >( m_subGroups.insert( name, newObject, false ) );
1563 }
1564 
1565 // Doxygen bug - sees this as a separate function
1567 template< typename T, typename TBASE >
1568 Wrapper< TBASE > * Group::registerWrapper( std::string const & name,
1569  ViewKey::index_type * const rkey )
1570 {
1571  std::unique_ptr< TBASE > newObj = std::make_unique< T >();
1572  m_wrappers.insert( name,
1573  new Wrapper< TBASE >( name, this, std::move( newObj ) ),
1574  true );
1575 
1576  if( rkey != nullptr )
1577  {
1578  *rkey = m_wrappers.getIndex( name );
1579  }
1580 
1581  Wrapper< TBASE > * const rval = getWrapper< TBASE >( name );
1582  if( rval->sizedFromParent() == 1 )
1583  {
1584  rval->resize( this->size());
1585  }
1586  return rval;
1587 }
1589 
1590 template< typename T, typename TBASE >
1591 Wrapper< TBASE > * Group::registerWrapper( ViewKey const & viewKey )
1592 {
1593  ViewKey::index_type index;
1594  Wrapper< TBASE > * const rval = registerWrapper< T, TBASE >( viewKey.Key(), &index );
1595  viewKey.setIndex( index );
1596 
1597  return rval;
1598 }
1599 
1600 
1601 template< typename T >
1602 Wrapper< T > * Group::registerWrapper( std::string const & name,
1603  std::unique_ptr< T > newObject )
1604 {
1605  m_wrappers.insert( name,
1606  new Wrapper< T >( name, this, std::move( newObject ) ),
1607  true );
1608 
1609  Wrapper< T > * const rval = getWrapper< T >( name );
1610  if( rval->sizedFromParent() == 1 )
1611  {
1612  rval->resize( this->size());
1613  }
1614  return rval;
1615 }
1616 
1617 
1618 
1619 template< typename T >
1620 Wrapper< T > * Group::registerWrapper( std::string const & name,
1621  T * newObject )
1622 {
1623  m_wrappers.insert( name,
1624  new Wrapper< T >( name, this, newObject ),
1625  true );
1626 
1627  Wrapper< T > * const rval = getWrapper< T >( name );
1628  if( rval->sizedFromParent() == 1 )
1629  {
1630  rval->resize( this->size());
1631  }
1632  return rval;
1633 }
1634 
1635 template< typename T >
1636 T const * Group::GetGroupByPath( string const & path ) const
1637 {
1638  // needed for getting root correctly with GetGroupByPath("/");
1639  if( path.empty())
1640  {
1641  return group_cast< T const * >( this );
1642  }
1643 
1644  size_t directoryMarker = path.find( '/' );
1645 
1646  if( directoryMarker == std::string::npos )
1647  {
1648  // Target should be a child of this group
1649  return this->GetGroup< T >( path );
1650  }
1651  else
1652  {
1653  // Split the path
1654  string const child = path.substr( 0, directoryMarker );
1655  string const subPath = path.substr( directoryMarker+1, path.size());
1656 
1657  if( directoryMarker == 0 ) // From root
1658  {
1659  if( this->getParent() == nullptr ) // At root
1660  {
1661  return this->GetGroupByPath< T >( subPath );
1662  }
1663  else // Not at root
1664  {
1665  return this->getParent()->GetGroupByPath< T >( path );
1666  }
1667  }
1668  else if( child[0] == '.' )
1669  {
1670  if( child[1] == '.' ) // '../' = Reverse path
1671  {
1672  return this->getParent()->GetGroupByPath< T >( subPath );
1673  }
1674  else // './' = This path
1675  {
1676  return this->GetGroupByPath< T >( subPath );
1677  }
1678  }
1679  else
1680  {
1681  return m_subGroups[child]->GetGroupByPath< T >( subPath );
1682  }
1683  }
1684 }
1685 
1686 } /* end namespace dataRepository */
1687 } /* end namespace geosx */
1688 
1689 #endif /* GEOSX_DATAREPOSITORY_GROUP_HPP_ */
Wrapper< T > * getWrapper(char const *const key)
Retrieve a Wrapper stored in this group.
Definition: Group.hpp:1183
int sizedFromParent() const
Check whether this wrapper is resized when its parent is resized.
void GenerateDataStructureSkeleton(integer const level)
Build a complete datastructure for schema generation.
Definition: Group.hpp:896
virtual void resize(int ndims, localIndex const *const dims) override
Calls T::resize( num_dims, dims )
Definition: Wrapper.hpp:489
void forWrappers(LAMBDA lambda)
Apply the given functor to wrappers that can be cast to one of specified types.
Definition: Group.hpp:716
void setIndex(INDEX_TYPE const &index) const
Set the index.
Definition: KeyIndexT.hpp:128
T * GetGroup(string const &name)
Retrieve a sub-group from the current Group using a string.
Definition: Group.hpp:395
T & getReference(char const *const name)
Definition: Group.hpp:1264
#define GEOSX_DECLTYPE_AUTO_RETURN
Doxygen can&#39;t parse a decltype( auto ) return type, using this gets around that.
localIndex numSubGroups() const
return the number of sub groups in this Group
Definition: Group.hpp:503
pugi::xml_node xmlNode
Alias for the type of an xml node.
Definition: xmlWrapper.hpp:60
virtual void ExpandObjectCatalogs()
Expand any catalogs in the data structure.
Definition: Group.hpp:911
Group * getParent()
Access the group&#39;s parent.
Definition: Group.hpp:1326
localIndex capacity() const
Get the "capacity" of the group, which determines the capacity of resizable wrappers.
Definition: Group.hpp:1292
void forSubGroups(LOOKUP_CONTAINER const &subGroupKeys, LAMBDA lambda) const
Definition: Group.hpp:656
Wrapper< T > const * getWrapper(char const *const key) const
Retrieve a Wrapper stored in this group.
Definition: Group.hpp:1176
virtual const std::type_info & get_typeid() const
Get typeid for current group.
Definition: Group.hpp:164
Group * setSizedFromParent(int val)
Set whether this wrapper is resized when its parent is resized.
Definition: Group.hpp:1356
T * GetGroupByPath(string const &path)
Retrieve a group from the hierarchy using a path.
Definition: Group.hpp:468
bool hasWrapper(LOOKUP_TYPE const &lookup) const
Check if a wrapper exists.
Definition: Group.hpp:1144
virtual void InitializePostInitialConditions_PreSubGroups(Group *const group)
Called by InitializePostInitialConditions() prior to initializing sub-Groups.
Definition: Group.hpp:1464
integer getLogLevel() const
Definition: Group.hpp:1420
bool hasGroup(std::string const &name) const
Check whether a sub-group exists.
Definition: Group.hpp:510
T const * GetGroup(string const &name) const
Retrieve a sub-group from the current Group using a string.
Definition: Group.hpp:404
virtual void PostProcessInput()
Definition: Group.hpp:1437
This class serves to provide a "view" of a multidimensional array.
Definition: ArrayView.hpp:67
static T group_cast(Group const *group)
Downcast a Group const *.
Definition: Group.hpp:320
T group_cast()
Downcast this Group.
Definition: Group.hpp:331
T const * GetGroup(localIndex index) const
Retrieve a sub-group from the current Group using an index.
Definition: Group.hpp:383
T & getReference(LOOKUP_TYPE const &lookup)
Look up a wrapper and get reference to wrapped object.
Definition: Group.hpp:1231
GEOSX_DECLTYPE_AUTO_RETURN getReference(char const *const name) const
Definition: Group.hpp:1257
virtual void InitializePostInitialConditions_PostSubGroups(Group *const group)
Called by InitializePostInitialConditions() after to initializing sub-Groups.
Definition: Group.hpp:1474
virtual void InitializePostSubGroups(Group *const group)
Called by Initialize() after to initializing sub-Groups.
Definition: Group.hpp:1454
wrapperMap const & wrappers() const
Get access to the internal wrapper storage.
Definition: Group.hpp:1109
void forSubGroups(LOOKUP_CONTAINER const &subGroupKeys, LAMBDA lambda)
Definition: Group.hpp:631
conduit::Node & getConduitNode()
Get the Conduit node object associated with this group.
Definition: Group.hpp:1396
virtual void postRestartInitialization(Group *const domain)
Performs initialization required after reading from a restart file.
Definition: Group.hpp:1483
WrapperBase const * getWrapperBase(std::string const &name) const
Retrieve a WrapperBase stored in this group.
Definition: Group.hpp:1072
Group::wrapperMap::KeyIndex ViewKey
Type alias for KeyIndexT type used for wrapper lookups.
Definition: Group.hpp:1545
WrapperBase * getWrapperBase(wrapperMap::KeyIndex const &keyIndex)
Retrieve a WrapperBase stored in this group.
Definition: Group.hpp:1092
Group const * getParent() const
Access the group&#39;s parent.
Definition: Group.hpp:1331
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:557
virtual void InitializePreSubGroups(Group *const group)
Called by Initialize() prior to initializing sub-Groups.
Definition: Group.hpp:1444
void forWrappers(LAMBDA lambda) const
Apply the given functor to wrappers.
Definition: Group.hpp:700
GEOSX_DECLTYPE_AUTO_RETURN getReference(LOOKUP_TYPE const &lookup) const
Look up a wrapper and get reference to wrapped object.
Definition: Group.hpp:1211
Base class for all wrappers containing common operations.
Definition: WrapperBase.hpp:48
void forSubGroups(LAMBDA lambda) const
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:608
T const & GetGroupReference(subGroupMap::KeyIndex const &key) const
Definition: Group.hpp:435
T * RegisterGroup(std::string const &name)
Register a new Group as a sub-group of current Group.
Definition: Group.hpp:235
string keyType
The default key type for entries in the hierarchy.
Definition: Group.hpp:58
void forWrappers(LAMBDA lambda)
Apply the given functor to wrappers.
Definition: Group.hpp:688
static T group_cast(Group *group)
Downcast a Group *.
Definition: Group.hpp:308
T * RegisterGroup(std::string const &name, std::string const &catalogName)
Register a new Group as a sub-group of current Group.
Definition: Group.hpp:270
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:146
Wrapper< T > const * getWrapper(LOOKUP_TYPE const &index) const
Retrieve a Wrapper stored in this group.
Definition: Group.hpp:1157
localIndex getIndexInParent() const
Get the group&#39;s index withing its parent group.
Definition: Group.hpp:1337
localIndex indexType
The default index type for entries the hierarchy.
Definition: Group.hpp:61
subGroupMap & GetSubGroups()
Get the subgroups object.
Definition: Group.hpp:485
WrapperBase * getWrapperBase(std::string const &name)
Retrieve a WrapperBase stored in this group.
Definition: Group.hpp:1078
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:122
WrapperBase const * getWrapperBase(wrapperMap::KeyIndex const &keyIndex) const
Retrieve a WrapperBase stored in this group.
Definition: Group.hpp:1086
#define GEOSX_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:110
This class provides the base class/interface for the catalog value objects.
T group_cast() const
Downcast this Group.
Definition: Group.hpp:342
KEY_TYPE const & Key() const
Access for the key.
Definition: KeyIndexT.hpp:105
const string getName() const
Get group name.
Definition: Group.hpp:1317
Wrapper< T > * getWrapper(LOOKUP_TYPE const &index)
Retrieve a Wrapper stored in this group.
Definition: Group.hpp:1166
void setRestartFlags(RestartFlags flags)
Set flags that control restart output of this group.
Definition: Group.hpp:1371
#define GEOSX_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:78
RestartFlags getRestartFlags() const
Get flags that control restart output of this group.
Definition: Group.hpp:1365
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers...
Definition: Group.hpp:1301
T & reference()
Accessor for m_data.
Definition: Wrapper.hpp:588
T * RegisterGroup(subGroupMap::KeyIndex const &keyIndex)
Register a new Group as a sub-group of current Group.
Definition: Group.hpp:251
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
void setInputFlags(InputFlags flags)
Set input flags for schema generation.
Definition: Group.hpp:1383
T const & getGroupReference(string const &key) const
Definition: Group.hpp:421
InputFlags getInputFlags() const
Get input flags for schema generation.
Definition: Group.hpp:1377
void forSubGroups(LAMBDA lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:593
T * GetGroup(subGroupMap::KeyIndex const &key)
Retrieve a sub-group from the current Group using a KeyIndexT.
Definition: Group.hpp:445
std::string string
String type.
Definition: DataTypes.hpp:131
void forWrappers(LAMBDA lambda) const
Apply the given functor to wrappers that can be cast to one of specified types.
Definition: Group.hpp:733
bool CheckTypeID(std::type_info const &typeToCheck) const
Check a type_info against the type_info of this Group.
Definition: Group.hpp:174
subGroupMap const & GetSubGroups() const
Get the subgroups object.
Definition: Group.hpp:494
T & GetGroupReference(subGroupMap::KeyIndex const &key)
Definition: Group.hpp:428
WrapperBase const * getWrapperBase(indexType const index) const
Retrieve a WrapperBase stored in this group.
Definition: Group.hpp:1058
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
Definition: Array.hpp:55
T const * GetGroup(subGroupMap::KeyIndex const &key) const
Retrieve a sub-group from the current Group using a KeyIndexT.
Definition: Group.hpp:454
WrapperBase * getWrapperBase(indexType const index)
Retrieve a WrapperBase stored in this group.
Definition: Group.hpp:1064
T * GetGroup(localIndex index)
Retrieve a sub-group from the current Group using an index.
Definition: Group.hpp:374
wrapperMap & wrappers()
Get access to the internal wrapper storage.
Definition: Group.hpp:1117
std::unordered_map< std::string, std::unique_ptr< CatalogInterface< BASETYPE, ARGS... > > > CatalogType
This is the type that will be used for the catalog. The catalog is actually instantiated in the BASET...
T & getGroupReference(string const &key)
Definition: Group.hpp:414
indexType getWrapperIndex(std::string const &name) const
Definition: Group.hpp:1100
integer sizedFromParent() const
Check whether this Group is resized when its parent is resized.
Definition: Group.hpp:1346