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 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 
15 
20 #ifndef GEOS_DATAREPOSITORY_GROUP_HPP_
21 #define GEOS_DATAREPOSITORY_GROUP_HPP_
22 
23 #include "InputFlags.hpp"
24 #include "ObjectCatalog.hpp"
25 #include "MappedVector.hpp"
26 #include "RestartFlags.hpp"
27 #include "Wrapper.hpp"
28 #include "xmlWrapper.hpp"
29 
30 
31 #include <iostream>
32 
33 #ifndef NOCHARTOSTRING_KEYLOOKUP
35 #define NOCHARTOSTRING_KEYLOOKUP 0
36 #endif
37 
41 namespace geos
42 {
43 
47 namespace dataRepository
48 {
49 
50 //START_SPHINX_INCLUDE_00
52 using keyType = string;
53 
56 //END_SPHINX_INCLUDE_00
57 
64 class Group
65 {
66 public:
67  //START_SPHINX_INCLUDE_01
70 
73  //END_SPHINX_INCLUDE_01
74 
79 
85  explicit Group( string const & name,
86  Group * const parent );
87 
94  explicit Group( string const & name,
95  conduit::Node & rootNode );
96 
101  Group( Group && source ) = default;
102 
106  virtual ~Group();
107 
111  Group() = delete;
112 
116  Group( Group const & ) = delete;
117 
118 
123  Group & operator=( Group const & ) = delete;
124 
129  Group & operator=( Group && ) = delete;
130 
132 
133 
138 
143 
149 
151 
156 
161  void printDataHierarchy( integer indent = 0 ) const;
162 
166  string dumpInputOptions() const;
167 
171  string dumpSubGroupsNames() const;
172 
176  string dumpWrappersNames() const;
177 
179 
180  //START_SPHINX_INCLUDE_REGISTER_GROUP
184 
196  template< typename T = Group >
197  T & registerGroup( string const & name, std::unique_ptr< T > newObject )
198  {
199  newObject->m_parent = this;
200  return dynamicCast< T & >( *m_subGroups.insert( name, newObject.release(), true ) );
201  }
202 
213  template< typename T = Group >
214  T & registerGroup( string const & name, T * newObject )
215  { return dynamicCast< T & >( *m_subGroups.insert( name, newObject, false ) ); }
216 
217 
227  template< typename T = Group >
228  T & registerGroup( string const & name )
229  { return registerGroup< T >( name, std::make_unique< T >( name, this ) ); }
230 
241  template< typename T = Group >
242  T & registerGroup( subGroupMap::KeyIndex const & keyIndex )
243  {
244  T & rval = registerGroup< T >( keyIndex.key(), std::make_unique< T >( keyIndex.key(), this ) );
245  keyIndex.setIndex( m_subGroups.getIndex( keyIndex.key() ) );
246  return rval;
247  }
248 
260  template< typename T = Group, typename TBASE = Group >
261  T & registerGroup( string const & name, string const & catalogName )
262  {
263  std::unique_ptr< TBASE > newGroup = TBASE::CatalogInterface::Factory( catalogName, name, this );
264  return registerGroup< T >( name, std::move( newGroup ) );
265  }
266 
271  void deregisterGroup( string const & name );
272 
281  virtual Group * createChild( string const & childKey, string const & childName );
282 
284 
285  //END_SPHINX_INCLUDE_REGISTER_GROUP
286 
287  //START_SPHINX_INCLUDE_GET_GROUP
303 
313  template< typename T = Group, typename KEY = void >
314  T * getGroupPointer( KEY const & key )
315  { return dynamicCast< T * >( m_subGroups[ key ] ); }
316 
320  template< typename T = Group, typename KEY = void >
321  T const * getGroupPointer( KEY const & key ) const
322  { return dynamicCast< T const * >( m_subGroups[ key ] ); }
323 
332  template< typename T = Group, typename KEY = void >
333  T & getGroup( KEY const & key )
334  {
335  Group * const child = m_subGroups[ key ];
336  GEOS_THROW_IF( child == nullptr,
337  "Group " << getDataContext() << " has no child named " << key << std::endl
338  << dumpSubGroupsNames(),
339  std::domain_error );
340 
341  return dynamicCast< T & >( *child );
342  }
343 
347  template< typename T = Group, typename KEY = void >
348  T const & getGroup( KEY const & key ) const
349  {
350  Group const * const child = m_subGroups[ key ];
351  GEOS_THROW_IF( child == nullptr,
352  "Group " << getDataContext() << " has no child named " << key << std::endl
353  << dumpSubGroupsNames(),
354  std::domain_error );
355 
356  return dynamicCast< T const & >( *child );
357  }
358 
368  template< typename T = Group >
369  T & getGroupByPath( string const & path )
370  { return dynamicCast< T & >( const_cast< Group & >( getBaseGroupByPath( path ) ) ); }
371 
375  template< typename T = Group >
376  T const & getGroupByPath( string const & path ) const
377  { return dynamicCast< T const & >( getBaseGroupByPath( path ) ); }
378 
379  //END_SPHINX_INCLUDE_GET_GROUP
380 
386  { return m_subGroups; }
387 
392  subGroupMap const & getSubGroups() const
393  { return m_subGroups; }
394 
399  localIndex numSubGroups() const { return m_subGroups.size(); }
400 
404  std::vector< string > getSubGroupsNames() const;
405 
411  template< typename T = Group >
412  bool hasGroup( string const & name ) const
413  { return dynamicCast< T const * >( m_subGroups[ name ] ) != nullptr; }
414 
420  template< typename T >
421  bool hasSubGroupOfType( ) const
422  {
423  bool hasSubGroup = false;
424  // since forSubGroups only applies the lambda to groups matching the type,
425  // any calls to the lambda indicates that we have a subgroup of the correct type.
426  forSubGroups< T >( [&]( T const & ){ hasSubGroup = true; } );
427  return hasSubGroup;
428  }
429 
431 
442 
444  template< typename CASTTYPE, typename CONTAINERTYPE, typename LAMBDA >
445  static bool applyLambdaToContainer( CONTAINERTYPE & container, LAMBDA && lambda )
446  {
447  using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, CASTTYPE const, CASTTYPE >;
448  T * const castedContainer = dynamic_cast< T * >( &container );
449 
450  if( castedContainer != nullptr )
451  {
452  lambda( *castedContainer );
453  return true;
454  }
455 
456  return false;
457  }
471  template< typename T0, typename T1, typename ... CASTTYPES, typename CONTAINERTYPE, typename LAMBDA >
472  static bool applyLambdaToContainer( CONTAINERTYPE & container, LAMBDA && lambda )
473  {
474  using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, T0 const, T0 >;
475  T * const castedContainer = dynamic_cast< T * >( &container );
476 
477  if( castedContainer != nullptr )
478  {
479  lambda( *castedContainer );
480  return true;
481  }
482 
483  return applyLambdaToContainer< T1, CASTTYPES... >( container, std::forward< LAMBDA >( lambda ) );
484  }
486 
487 
488  //START_SPHINX_INCLUDE_LOOP_INTERFACE
498 
507  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
508  void forSubGroups( LAMBDA && lambda )
509  {
510  for( auto & subGroupIter : m_subGroups )
511  {
512  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&]( auto & castedSubGroup )
513  {
514  lambda( castedSubGroup );
515  } );
516  }
517  }
518 
522  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
523  void forSubGroups( LAMBDA && lambda ) const
524  {
525  for( auto const & subGroupIter : m_subGroups )
526  {
527  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&]( auto const & castedSubGroup )
528  {
529  lambda( castedSubGroup );
530  } );
531  }
532  }
533 
534 
542  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
543  void forSubGroupsIndex( LAMBDA && lambda )
544  {
545  localIndex counter = 0;
546  for( auto & subGroupIter : m_subGroups )
547  {
548  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second,
549  [&]( auto & castedSubGroup )
550  {
551  lambda( counter, castedSubGroup );
552  } );
553  ++counter;
554  }
555  }
556 
560  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
561  void forSubGroupsIndex( LAMBDA && lambda ) const
562  {
563  localIndex counter = 0;
564  for( auto const & subGroupIter : m_subGroups )
565  {
566  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second,
567  [&]( auto const & castedSubGroup )
568  {
569  lambda( counter, castedSubGroup );
570  } );
571  ++counter;
572  }
573  }
574 
586  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LOOKUP_CONTAINER, typename LAMBDA >
587  void forSubGroups( LOOKUP_CONTAINER const & subGroupKeys, LAMBDA && lambda )
588  {
589  localIndex counter = 0;
590  for( auto const & subgroup : subGroupKeys )
591  {
592  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( getGroup( subgroup ), [&]( auto & castedSubGroup )
593  {
594  lambda( counter, castedSubGroup );
595  } );
596  ++counter;
597  }
598  }
599 
611  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LOOKUP_CONTAINER, typename LAMBDA >
612  void forSubGroups( LOOKUP_CONTAINER const & subGroupKeys, LAMBDA && lambda ) const
613  {
614  localIndex counter = 0;
615  for( auto const & subgroup : subGroupKeys )
616  {
617  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( getGroup( subgroup ), [&]( auto const & castedSubGroup )
618  {
619  lambda( counter, castedSubGroup );
620  } );
621  ++counter;
622  }
623  }
625 
637 
643  template< typename LAMBDA >
644  void forWrappers( LAMBDA && lambda )
645  {
646  for( auto & wrapperIter : m_wrappers )
647  {
648  lambda( *wrapperIter.second );
649  }
650  }
651 
655  template< typename LAMBDA >
656  void forWrappers( LAMBDA && lambda ) const
657  {
658  for( auto const & wrapperIter : m_wrappers )
659  {
660  lambda( *wrapperIter.second );
661  }
662  }
663 
671  template< typename TYPE, typename ... TYPES, typename LAMBDA >
672  void forWrappers( LAMBDA && lambda )
673  {
674  for( auto & wrapperIter : m_wrappers )
675  {
676  applyLambdaToContainer< Wrapper< TYPE >, Wrapper< TYPES >... >( *wrapperIter.second,
677  std::forward< LAMBDA >( lambda ));
678  }
679  }
680 
688  template< typename TYPE, typename ... TYPES, typename LAMBDA >
689  void forWrappers( LAMBDA && lambda ) const
690  {
691  for( auto const & wrapperIter : m_wrappers )
692  {
693  applyLambdaToContainer< Wrapper< TYPE >, Wrapper< TYPES >... >( *wrapperIter.second,
694  std::forward< LAMBDA >( lambda ));
695  }
696  }
697 
699  //END_SPHINX_INCLUDE_LOOP_INTERFACE
700 
705 
709 
710 
723  void initialize();
724 
734  virtual void initializationOrder( string_array & order );
735 
736 
752 
760 
769  xmlWrapper::xmlNode & targetNode );
778  xmlWrapper::xmlNode & targetNode,
779  xmlWrapper::xmlNodePos const & nodePos );
780 
786 
788 
789  //START_SPHINX_INCLUDE_REGISTER_WRAPPER
793 
804  template< typename T, typename TBASE=T >
805  Wrapper< TBASE > & registerWrapper( string const & name,
806  wrapperMap::KeyIndex::index_type * const rkey = nullptr );
807 
815  template< typename T, typename TBASE=T >
817 
826  template< typename T >
827  Wrapper< T > & registerWrapper( string const & name, std::unique_ptr< T > newObject );
828 
837  template< typename T >
838  Wrapper< T > & registerWrapper( string const & name,
839  T * newObject );
840 
846  WrapperBase & registerWrapper( std::unique_ptr< WrapperBase > wrapper );
847 
852  void deregisterWrapper( string const & name );
853 
855  //END_SPHINX_INCLUDE_REGISTER_WRAPPER
856 
861 
867  {
869  string indent( level*2, ' ' );
870 
871  for( auto const & subGroupIter : m_subGroups )
872  {
873  std::cout << indent << subGroupIter.second->getName() << std::endl;
874  subGroupIter.second->generateDataStructureSkeleton( level + 1 );
875  }
876  }
877 
881  virtual void expandObjectCatalogs() {}
882 
889  virtual void setSchemaDeviations( xmlWrapper::xmlNode schemaRoot,
890  xmlWrapper::xmlNode schemaParent,
891  integer documentationType )
892  {
893  GEOS_UNUSED_VAR( schemaRoot );
894  GEOS_UNUSED_VAR( schemaParent );
895  GEOS_UNUSED_VAR( documentationType );
896  }
897 
899 
904 
909  virtual void registerDataOnMeshRecursive( Group & meshBodies );
910 
918  virtual void registerDataOnMesh( Group & meshBodies )
919  {
920  GEOS_UNUSED_VAR( meshBodies );
921  }
922 
924 
929 
941  virtual localIndex packSize( string_array const & wrapperNames,
942  integer const recursive,
943  bool onDevice,
944  parallelDeviceEvents & events ) const;
945 
958  virtual localIndex packSize( string_array const & wrapperNames,
959  arrayView1d< localIndex const > const & packList,
960  integer const recursive,
961  bool onDevice,
962  parallelDeviceEvents & events ) const;
963 
976  integer const recursive,
977  bool onDevice,
978  parallelDeviceEvents & events ) const;
979 
998  virtual localIndex pack( buffer_unit_type * & buffer,
999  string_array const & wrapperNames,
1000  integer const recursive,
1001  bool onDevice,
1002  parallelDeviceEvents & events ) const;
1003 
1022  virtual localIndex pack( buffer_unit_type * & buffer,
1023  string_array const & wrapperNames,
1024  arrayView1d< localIndex const > const & packList,
1025  integer const recursive,
1026  bool onDevice,
1027  parallelDeviceEvents & events ) const;
1028 
1047  arrayView1d< localIndex const > const & packList,
1048  integer const recursive,
1049  bool onDevice,
1050  parallelDeviceEvents & events ) const;
1051 
1071  virtual localIndex unpack( buffer_unit_type const * & buffer,
1072  arrayView1d< localIndex > & packList,
1073  integer const recursive,
1074  bool onDevice,
1075  parallelDeviceEvents & events,
1076  MPI_Op op=MPI_REPLACE );
1077 
1079 
1080  //***********************************************************************************************
1081 
1082  //START_SPHINX_INCLUDE_GET_WRAPPER
1090 
1099  template< typename KEY >
1100  WrapperBase const & getWrapperBase( KEY const & key ) const
1101  {
1102  WrapperBase const * const wrapper = m_wrappers[ key ];
1103  GEOS_THROW_IF( wrapper == nullptr,
1104  "Group " << getDataContext() << " has no wrapper named " << key << std::endl
1105  << dumpWrappersNames(),
1106  std::domain_error );
1107 
1108  return *wrapper;
1109  }
1110 
1114  template< typename KEY >
1115  WrapperBase & getWrapperBase( KEY const & key )
1116  {
1117  WrapperBase * const wrapper = m_wrappers[ key ];
1118  GEOS_THROW_IF( wrapper == nullptr,
1119  "Group " << getDataContext() << " has no wrapper named " << key << std::endl
1120  << dumpWrappersNames(),
1121  std::domain_error );
1122 
1123  return *wrapper;
1124  }
1125 
1131  indexType getWrapperIndex( string const & name ) const
1132  { return m_wrappers.getIndex( name ); }
1133 
1138  wrapperMap const & wrappers() const
1139  { return m_wrappers; }
1140 
1145  { return m_wrappers; }
1146 
1152  { return m_wrappers.size(); }
1153 
1157  std::vector< string > getWrappersNames() const;
1158 
1160 
1173 
1180  template< typename LOOKUP_TYPE >
1181  bool hasWrapper( LOOKUP_TYPE const & lookup ) const
1182  { return m_wrappers[ lookup ] != nullptr; }
1183 
1192  template< typename T, typename LOOKUP_TYPE >
1193  Wrapper< T > const & getWrapper( LOOKUP_TYPE const & index ) const
1194  {
1195  WrapperBase const & wrapper = getWrapperBase( index );
1196  return dynamicCast< Wrapper< T > const & >( wrapper );
1197  }
1198 
1202  template< typename T, typename LOOKUP_TYPE >
1203  Wrapper< T > & getWrapper( LOOKUP_TYPE const & index )
1204  {
1205  WrapperBase & wrapper = getWrapperBase( index );
1206  return dynamicCast< Wrapper< T > & >( wrapper );
1207  }
1208 
1217  template< typename T, typename LOOKUP_TYPE >
1218  Wrapper< T > const * getWrapperPointer( LOOKUP_TYPE const & index ) const
1219  { return dynamicCast< Wrapper< T > const * >( m_wrappers[ index ] ); }
1220 
1224  template< typename T, typename LOOKUP_TYPE >
1225  Wrapper< T > * getWrapperPointer( LOOKUP_TYPE const & index )
1226  { return dynamicCast< Wrapper< T > * >( m_wrappers[ index ] ); }
1227 
1229 
1240 
1250  template< typename T, typename LOOKUP_TYPE >
1252  getReference( LOOKUP_TYPE const & lookup ) const
1253  { return getWrapper< T >( lookup ).reference(); }
1254 
1258  template< typename T, typename LOOKUP_TYPE >
1259  T & getReference( LOOKUP_TYPE const & lookup )
1260  { return getWrapper< T >( lookup ).reference(); }
1261 
1262  //END_SPHINX_INCLUDE_GET_WRAPPER
1263 
1265 
1270 
1275  virtual void resize( localIndex const newSize );
1276 
1281  virtual void reserve( indexType const newsize );
1282 
1287  inline localIndex capacity() const
1288  { return m_capacity; }
1289 
1294  inline localIndex size() const
1295  { return m_size; }
1296 
1298 
1303 
1308  inline string const & getName() const
1309  { return m_name; }
1310 
1316  string getPath() const;
1317 
1322  DataContext const & getDataContext() const
1323  { return *m_dataContext; }
1324 
1332  template< typename KEY >
1333  DataContext const & getWrapperDataContext( KEY key ) const
1334  { return getWrapperBase< KEY >( key ).getDataContext(); }
1335 
1342  {
1343  GEOS_THROW_IF( m_parent == nullptr, "Group at " << getDataContext() << " does not have a parent.", std::domain_error );
1344  return *m_parent;
1345  }
1346 
1350  Group const & getParent() const
1351  {
1352  GEOS_THROW_IF( m_parent == nullptr, "Group at " << getDataContext() << " does not have a parent.", std::domain_error );
1353  return *m_parent;
1354  }
1355 
1359  bool hasParent() const
1360  { return m_parent != nullptr; }
1361 
1367  { return m_parent->getSubGroups().getIndex( m_name ); }
1368 
1374  localIndex getSubGroupIndex( keyType const & key ) const;
1375 
1380  int sizedFromParent() const
1381  { return m_sizedFromParent; }
1382 
1389  {
1390  m_sizedFromParent = val;
1391  return *this;
1392  }
1397  RestartFlags getRestartFlags() const { return m_restart_flags; }
1398 
1403  void setRestartFlags( RestartFlags flags ) { m_restart_flags = flags; }
1404 
1409  InputFlags getInputFlags() const { return m_input_flags; }
1410 
1415  void setInputFlags( InputFlags flags ) { m_input_flags = flags; }
1416 
1418 
1425  virtual bool registerCallback( void * func, const std::type_info & funcType )
1426  {
1427  GEOS_UNUSED_VAR( func );
1428  GEOS_UNUSED_VAR( funcType );
1429  return false;
1430  }
1431 
1436 
1441  conduit::Node & getConduitNode()
1442  { return m_conduitNode; }
1443 
1445  conduit::Node const & getConduitNode() const
1446  { return m_conduitNode; }
1447 
1452 
1457 
1462 
1465 
1470  void setLogLevel( integer const logLevel ) { m_logLevel = logLevel; }
1471 
1473  integer getLogLevel() const { return m_logLevel; }
1475 
1479  virtual void reinit() {}
1480 
1485 #if defined(GEOSX_USE_PYGEOSX)
1486  virtual PyTypeObject * getPythonType() const;
1487 #endif
1488 
1489 protected:
1490 
1498 
1503  virtual void postProcessInput() {}
1504 
1508  virtual void initializePreSubGroups()
1509  {}
1510 
1515  {}
1516 
1521  {}
1522 
1527  {}
1528 
1533  {}
1534 
1535 
1536 
1538 
1539 private:
1547  virtual void processInputFile( xmlWrapper::xmlNode const & targetNode,
1548  xmlWrapper::xmlNodePos const & nodePos );
1549 
1550  Group const & getBaseGroupByPath( string const & path ) const;
1551 
1566  template< bool DO_PACKING >
1567  localIndex packImpl( buffer_unit_type * & buffer,
1568  array1d< string > const & wrapperNames,
1569  arrayView1d< localIndex const > const & packList,
1570  integer const recursive,
1571  bool onDevice,
1572  parallelDeviceEvents & events ) const;
1573 
1574  //START_SPHINX_INCLUDE_02
1576  Group * m_parent = nullptr;
1577 
1579  integer m_sizedFromParent;
1580 
1582  wrapperMap m_wrappers;
1583 
1585  subGroupMap m_subGroups;
1586 
1589  indexType m_size;
1590 
1593  indexType m_capacity;
1594 
1596  string m_name;
1597 
1599  integer m_logLevel;
1600  //END_SPHINX_INCLUDE_02
1601 
1603  RestartFlags m_restart_flags;
1604 
1606  InputFlags m_input_flags;
1607 
1609  conduit::Node & m_conduitNode;
1610 
1613  std::unique_ptr< DataContext > m_dataContext;
1614 
1615 };
1616 
1621 
1626 
1627 // Doxygen bug - sees this as a separate function
1629 template< typename T, typename TBASE >
1630 Wrapper< TBASE > & Group::registerWrapper( string const & name,
1631  ViewKey::index_type * const rkey )
1632 {
1633  std::unique_ptr< TBASE > newObj = std::make_unique< T >();
1634  m_wrappers.insert( name,
1635  new Wrapper< TBASE >( name, *this, std::move( newObj ) ),
1636  true );
1637 
1638  if( rkey != nullptr )
1639  {
1640  *rkey = m_wrappers.getIndex( name );
1641  }
1642 
1643  Wrapper< TBASE > & rval = getWrapper< TBASE >( name );
1644  if( rval.sizedFromParent() == 1 )
1645  {
1646  rval.resize( size());
1647  }
1648  return rval;
1649 }
1651 
1652 template< typename T, typename TBASE >
1654 {
1655  ViewKey::index_type index;
1656  Wrapper< TBASE > & rval = registerWrapper< T, TBASE >( viewKey.key(), &index );
1657  viewKey.setIndex( index );
1658 
1659  return rval;
1660 }
1661 
1662 
1663 template< typename T >
1664 Wrapper< T > & Group::registerWrapper( string const & name,
1665  std::unique_ptr< T > newObject )
1666 {
1667  static_assert( !std::is_base_of< WrapperBase, T >::value, "This function should not be used for `WrapperBase`. Use the dedicated `registerWrapper` instead." );
1668  m_wrappers.insert( name,
1669  new Wrapper< T >( name, *this, std::move( newObject ) ),
1670  true );
1671 
1672  Wrapper< T > & rval = getWrapper< T >( name );
1673  if( rval.sizedFromParent() == 1 )
1674  {
1675  rval.resize( size());
1676  }
1677  return rval;
1678 }
1679 
1680 template< typename T >
1681 Wrapper< T > & Group::registerWrapper( string const & name,
1682  T * newObject )
1683 {
1684  static_assert( !std::is_base_of< WrapperBase, T >::value, "This function should not be used for `WrapperBase`. Use the dedicated `registerWrapper` instead." );
1685  m_wrappers.insert( name,
1686  new Wrapper< T >( name, *this, newObject ),
1687  true );
1688 
1689  Wrapper< T > & rval = getWrapper< T >( name );
1690  if( rval.sizedFromParent() == 1 )
1691  {
1692  rval.resize( size());
1693  }
1694  return rval;
1695 }
1696 
1697 } /* end namespace dataRepository */
1698 } /* end namespace geos */
1699 
1700 #endif /* GEOS_DATAREPOSITORY_GROUP_HPP_ */
#define GEOS_DECLTYPE_AUTO_RETURN
Doxygen can't parse a decltype( auto ) return type, using this gets around that.
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:83
#define GEOS_THROW_IF(EXP, msg, TYPE)
Conditionally throw an exception.
Definition: Logger.hpp:116
INDEX_TYPE index_type
the type used for the index
Definition: KeyIndexT.hpp:47
void setIndex(INDEX_TYPE const &index) const
Set the index.
Definition: KeyIndexT.hpp:128
KEY_TYPE const & key() const
Access for the key.
Definition: KeyIndexT.hpp:105
INDEX_TYPE size() const
function to return the number of entries stored
KeyIndexT< keyType const, indexType > KeyIndex
alias for the KeyIndex itself
T * insert(KEY_TYPE const &keyName, T_PTR source, bool takeOwnership, bool overwrite=false)
insert new entry into MappedVector
INDEX_TYPE getIndex(KEY_TYPE const &key) const
This class provides the base class/interface for the catalog value objects.
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 & getGroupByPath(string const &path)
Retrieve a group from the hierarchy using a path.
Definition: Group.hpp:369
void forSubGroups(LOOKUP_CONTAINER const &subGroupKeys, LAMBDA &&lambda) const
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:612
T const & getGroupByPath(string const &path) const
Retrieve a group from the hierarchy using a path.
Definition: Group.hpp:376
virtual void initializePreSubGroups()
Called by Initialize() prior to initializing sub-Groups.
Definition: Group.hpp:1508
virtual void initialize_postMeshGeneration()
initialization post generation of the mesh.
localIndex capacity() const
Get the "capacity" of the group, which determines the capacity of resizable wrappers.
Definition: Group.hpp:1287
virtual localIndex packSize(string_array const &wrapperNames, arrayView1d< localIndex const > const &packList, integer const recursive, bool onDevice, parallelDeviceEvents &events) const
Get the size required to pack a list of indices within a list of wrappers.
void setInputFlags(InputFlags flags)
Set input flags for schema generation.
Definition: Group.hpp:1415
int sizedFromParent() const
Check whether this Group is resized when its parent is resized.
Definition: Group.hpp:1380
localIndex pack(buffer_unit_type *&buffer, arrayView1d< localIndex const > const &packList, integer const recursive, bool onDevice, parallelDeviceEvents &events) const
Pack a list of indices for all registered wrappers.
void deregisterGroup(string const &name)
Removes a child group from this group.
Wrapper< TBASE > & registerWrapper(string const &name, wrapperMap::KeyIndex::index_type *const rkey=nullptr)
Create and register a Wrapper around a new object.
T * getGroupPointer(KEY const &key)
Return a pointer to a sub-group of the current Group.
Definition: Group.hpp:314
localIndex packSize(arrayView1d< localIndex const > const &packList, integer const recursive, bool onDevice, parallelDeviceEvents &events) const
Get the size required to pack a list of indices for all registered wrappers.
virtual localIndex unpack(buffer_unit_type const *&buffer, arrayView1d< localIndex > &packList, integer const recursive, bool onDevice, parallelDeviceEvents &events, MPI_Op op=MPI_REPLACE)
Unpack a buffer.
InputFlags getInputFlags() const
Get input flags for schema generation.
Definition: Group.hpp:1409
DataContext const & getDataContext() const
Definition: Group.hpp:1322
bool hasWrapper(LOOKUP_TYPE const &lookup) const
Check if a wrapper exists.
Definition: Group.hpp:1181
T & registerGroup(string const &name, T *newObject)
Register a new Group as a sub-group of current Group.
Definition: Group.hpp:214
void processInputFileRecursive(xmlWrapper::xmlDocument &xmlDocument, xmlWrapper::xmlNode &targetNode, xmlWrapper::xmlNodePos const &nodePos)
Same as processInputFileRecursive(xmlWrapper::xmlDocument &, xmlWrapper::xmlNode &) but allow to reus...
Group(Group &&source)=default
Move constructor.
wrapperMap & wrappers()
Get access to the internal wrapper storage.
Definition: Group.hpp:1144
localIndex getIndexInParent() const
Get the group's index within its parent group.
Definition: Group.hpp:1366
void processInputFileRecursive(xmlWrapper::xmlDocument &xmlDocument, xmlWrapper::xmlNode &targetNode)
Recursively read values using ProcessInputFile() from the input file and put them into the wrapped va...
T & registerGroup(string const &name, std::unique_ptr< T > newObject)
Register a new Group as a sub-group of current Group.
Definition: Group.hpp:197
string dumpWrappersNames() const
Group(string const &name, Group *const parent)
Constructor.
void forWrappers(LAMBDA &&lambda)
Apply the given functor to wrappers that can be cast to one of specified types.
Definition: Group.hpp:672
virtual void expandObjectCatalogs()
Expand any catalogs in the data structure.
Definition: Group.hpp:881
MappedVector< WrapperBase, WrapperBase *, keyType, indexType > wrapperMap
The template specialization of MappedVector to use for the collection wrappers objects.
Definition: Group.hpp:72
virtual void initializePostSubGroups()
Called by Initialize() after to initializing sub-Groups.
Definition: Group.hpp:1514
virtual void reinit()
Performs re-initialization of certain variable depending on the solver being used.
Definition: Group.hpp:1479
void setRestartFlags(RestartFlags flags)
Set flags that control restart output of this group.
Definition: Group.hpp:1403
void enableLogLevelInput()
Enable verbosity input for object.
Wrapper< T > & getWrapper(LOOKUP_TYPE const &index)
Retrieve a Wrapper stored in this group.
Definition: Group.hpp:1203
WrapperBase & registerWrapper(std::unique_ptr< WrapperBase > wrapper)
Register and take ownership of an existing Wrapper.
void forSubGroupsIndex(LAMBDA &&lambda) const
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:561
string const & getName() const
Get group name.
Definition: Group.hpp:1308
string dumpSubGroupsNames() const
GEOS_DECLTYPE_AUTO_RETURN getReference(LOOKUP_TYPE const &lookup) const
Look up a wrapper and get reference to wrapped object.
Definition: Group.hpp:1252
WrapperBase & getWrapperBase(KEY const &key)
Return a reference to a WrapperBase stored in this group.
Definition: Group.hpp:1115
WrapperBase const & getWrapperBase(KEY const &key) const
Return a reference to a WrapperBase stored in this group.
Definition: Group.hpp:1100
virtual void registerDataOnMeshRecursive(Group &meshBodies)
Calls RegisterDataOnMesh() recursively.
conduit::Node & getConduitNode()
Return the Conduit node object associated with this group.
Definition: Group.hpp:1441
void forSubGroups(LAMBDA &&lambda) const
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:523
virtual void initializePostInitialConditionsPostSubGroups()
Called by InitializePostInitialConditions() after to initializing sub-Groups.
Definition: Group.hpp:1526
void initialize()
Run initialization functions on this and all subgroups.
Group(Group const &)=delete
Deleted copy constructor.
T & registerGroup(subGroupMap::KeyIndex const &keyIndex)
Register a new Group as a sub-group of current Group.
Definition: Group.hpp:242
static CatalogInterface::CatalogType & getCatalog()
Get the singleton catalog for this class.
void forSubGroupsIndex(LAMBDA &&lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:543
virtual void initializationOrder(string_array &order)
Sets the initialization order for sub-Groups.
RestartFlags getRestartFlags() const
Get flags that control restart output of this group.
Definition: Group.hpp:1397
void deregisterWrapper(string const &name)
Removes a Wrapper from this group.
void initializePostInitialConditions()
Initialization routine to be called after calling ApplyInitialConditions().
localIndex numSubGroups() const
return the number of sub groups in this Group
Definition: Group.hpp:399
indexType numWrappers() const
Return the number of wrappers.
Definition: Group.hpp:1151
virtual void reserve(indexType const newsize)
Set the new capacity and reserve it in all wrappers that resize with parent.
string dumpInputOptions() const
T & getGroup(KEY const &key)
Return a reference to a sub-group of the current Group.
Definition: Group.hpp:333
void loadFromConduit()
Read the group and its wrappers from Conduit.
MappedVector< Group, Group *, keyType, indexType > subGroupMap
The template specialization of MappedVector to use for the collection of sub-Group objects.
Definition: Group.hpp:69
Group & getParent()
Access the group's parent.
Definition: Group.hpp:1341
void finishWriting()
Write the group and its wrappers into Conduit.
virtual void postRestartInitialization()
Performs initialization required after reading from a restart file.
Definition: Group.hpp:1532
Group(string const &name, conduit::Node &rootNode)
Constructor.
bool hasGroup(string const &name) const
Check whether a sub-group exists.
Definition: Group.hpp:412
indexType getWrapperIndex(string const &name) const
Definition: Group.hpp:1131
bool hasSubGroupOfType() const
Check whether a sub-group exists by type.
Definition: Group.hpp:421
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:472
void prepareToWrite()
Register the group and its wrappers with Conduit.
T const * getGroupPointer(KEY const &key) const
Return a pointer to a sub-group of the current Group.
Definition: Group.hpp:321
virtual bool registerCallback(void *func, const std::type_info &funcType)
Register a callback function on the group.
Definition: Group.hpp:1425
void forWrappers(LAMBDA &&lambda) const
Apply the given functor to wrappers.
Definition: Group.hpp:656
virtual localIndex pack(buffer_unit_type *&buffer, string_array const &wrapperNames, arrayView1d< localIndex const > const &packList, integer const recursive, bool onDevice, parallelDeviceEvents &events) const
Pack a list of indices within a list of wrappers.
localIndex getSubGroupIndex(keyType const &key) const
Get the index of a sub-Group within this group.
Wrapper< T > const & getWrapper(LOOKUP_TYPE const &index) const
Retrieve a Wrapper stored in this group.
Definition: Group.hpp:1193
T & getReference(LOOKUP_TYPE const &lookup)
Look up a wrapper and get reference to wrapped object.
Definition: Group.hpp:1259
virtual void registerDataOnMesh(Group &meshBodies)
Register data on mesh entities.
Definition: Group.hpp:918
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers.
Definition: Group.hpp:1294
virtual localIndex packSize(string_array const &wrapperNames, integer const recursive, bool onDevice, parallelDeviceEvents &events) const
Get the size required to pack a list of wrappers.
Group()=delete
Deleted default constructor.
Wrapper< T > * getWrapperPointer(LOOKUP_TYPE const &index)
Retrieve a Wrapper stored in this group.
Definition: Group.hpp:1225
T const & getGroup(KEY const &key) const
Return a reference to a sub-group of the current Group.
Definition: Group.hpp:348
void forSubGroups(LAMBDA &&lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:508
std::vector< string > getWrappersNames() const
T & registerGroup(string const &name, string const &catalogName)
Register a new Group as a sub-group of current Group.
Definition: Group.hpp:261
integer getLogLevel() const
Definition: Group.hpp:1473
virtual Group * createChild(string const &childKey, string const &childName)
Creates a new sub-Group using the ObjectCatalog functionality.
void forWrappers(LAMBDA &&lambda) const
Apply the given functor to wrappers that can be cast to one of specified types.
Definition: Group.hpp:689
std::vector< string > getSubGroupsNames() const
string getPath() const
Return the path of this Group in the data repository. Starts with '/' followed by the hierarchy of th...
Group & operator=(Group const &)=delete
Deleted copy assignment operator.
void setLogLevel(integer const logLevel)
Set verbosity level.
Definition: Group.hpp:1470
Group const & getParent() const
Access the group's parent.
Definition: Group.hpp:1350
conduit::Node const & getConduitNode() const
Return the Conduit node object associated with this group.
Definition: Group.hpp:1445
void postRestartInitializationRecursive()
Initialization routine to be called after calling reading a restart file.
Group & setSizedFromParent(int val)
Set whether this wrapper is resized when its parent is resized.
Definition: Group.hpp:1388
DataContext const & getWrapperDataContext(KEY key) const
Definition: Group.hpp:1333
void postProcessInputRecursive()
Recursively call postProcessInput() to apply post processing after reading input values.
Group & operator=(Group &&)=delete
Deleted move assignment operator.
virtual localIndex pack(buffer_unit_type *&buffer, string_array const &wrapperNames, integer const recursive, bool onDevice, parallelDeviceEvents &events) const
Pack a list of wrappers to a buffer.
virtual ~Group()
Destructor, deletes all Groups and Wrappers owned by this Group.
void forWrappers(LAMBDA &&lambda)
Apply the given functor to wrappers.
Definition: Group.hpp:644
subGroupMap const & getSubGroups() const
Get the subgroups object.
Definition: Group.hpp:392
virtual void postProcessInput()
Definition: Group.hpp:1503
void forSubGroups(LOOKUP_CONTAINER const &subGroupKeys, LAMBDA &&lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:587
void generateDataStructureSkeleton(integer const level)
Build a complete datastructure for schema generation.
Definition: Group.hpp:866
virtual void setSchemaDeviations(xmlWrapper::xmlNode schemaRoot, xmlWrapper::xmlNode schemaParent, integer documentationType)
Inform the schema generator of any deviations between the xml and GEOS data structures.
Definition: Group.hpp:889
void printDataHierarchy(integer indent=0) const
Prints the data hierarchy recursively.
wrapperMap const & wrappers() const
Get access to the internal wrapper storage.
Definition: Group.hpp:1138
T & registerGroup(string const &name)
Register a new Group as a sub-group of current Group.
Definition: Group.hpp:228
virtual void initializePostInitialConditionsPreSubGroups()
Called by InitializePostInitialConditions() prior to initializing sub-Groups.
Definition: Group.hpp:1520
Wrapper< T > const * getWrapperPointer(LOOKUP_TYPE const &index) const
Retrieve a Wrapper stored in this group.
Definition: Group.hpp:1218
subGroupMap & getSubGroups()
Get the subgroups object.
Definition: Group.hpp:385
virtual void resize(localIndex const newSize)
Resize the group and all contained wrappers that resize with parent.
Base class for all wrappers containing common operations.
Definition: WrapperBase.hpp:55
int sizedFromParent() const
Check whether this wrapper is resized when its parent is resized.
virtual void resize(int ndims, localIndex const *const dims) override
Calls T::resize( num_dims, dims )
Definition: Wrapper.hpp:389
Group::wrapperMap::KeyIndex ViewKey
Type alias for KeyIndexT type used for wrapper lookups.
Definition: Group.hpp:1625
localIndex indexType
The default index type for entries the hierarchy.
Definition: Group.hpp:55
string keyType
The default key type for entries in the hierarchy.
Definition: Group.hpp:52
pugi::xml_node xmlNode
Definition: xmlWrapper.hpp:57
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:220
array1d< string > string_array
A 1-dimensional array of geos::string types.
Definition: DataTypes.hpp:432
std::string string
String type.
Definition: DataTypes.hpp:131
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:122
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:149
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:216