GEOS
Group.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 
16 
21 #ifndef GEOS_DATAREPOSITORY_GROUP_HPP_
22 #define GEOS_DATAREPOSITORY_GROUP_HPP_
23 
24 #include "InputFlags.hpp"
25 #include "ObjectCatalog.hpp"
26 #include "MappedVector.hpp"
27 #include "RestartFlags.hpp"
28 #include "Wrapper.hpp"
29 #include "xmlWrapper.hpp"
30 #include "LogLevelsInfo.hpp"
31 #include "LogLevelsRegistry.hpp"
32 
33 
34 #include <iostream>
35 
36 #ifndef NOCHARTOSTRING_KEYLOOKUP
38 #define NOCHARTOSTRING_KEYLOOKUP 0
39 #endif
40 
44 namespace geos
45 {
46 
50 namespace dataRepository
51 {
52 
53 //START_SPHINX_INCLUDE_00
55 using keyType = string;
56 
59 //END_SPHINX_INCLUDE_00
60 
67 class Group
68 {
69 public:
70  //START_SPHINX_INCLUDE_01
73 
76  //END_SPHINX_INCLUDE_01
77 
82 
88  explicit Group( string const & name,
89  Group * const parent );
90 
97  explicit Group( string const & name,
98  conduit::Node & rootNode );
99 
104  Group( Group && source ) = default;
105 
109  virtual ~Group();
110 
114  Group() = delete;
115 
119  Group( Group const & ) = delete;
120 
121 
126  Group & operator=( Group const & ) = delete;
127 
132  Group & operator=( Group && ) = delete;
133 
135 
136 
141 
146 
152 
154 
159 
164  void printDataHierarchy( integer indent = 0 ) const;
165 
169  string dumpInputOptions() const;
170 
174  string dumpSubGroupsNames() const;
175 
179  string dumpWrappersNames() const;
180 
182 
183  //START_SPHINX_INCLUDE_REGISTER_GROUP
187 
199  template< typename T = Group >
200  T & registerGroup( string const & name, std::unique_ptr< T > newObject )
201  {
202  newObject->m_parent = this;
203  return dynamicCast< T & >( *m_subGroups.insert( name, newObject.release(), true ) );
204  }
205 
216  template< typename T = Group >
217  T & registerGroup( string const & name, T * newObject )
218  { return dynamicCast< T & >( *m_subGroups.insert( name, newObject, false ) ); }
219 
220 
230  template< typename T = Group >
231  T & registerGroup( string const & name )
232  { return registerGroup< T >( name, std::make_unique< T >( name, this ) ); }
233 
244  template< typename T = Group >
245  T & registerGroup( subGroupMap::KeyIndex const & keyIndex )
246  {
247  T & rval = registerGroup< T >( keyIndex.key(), std::make_unique< T >( keyIndex.key(), this ) );
248  keyIndex.setIndex( m_subGroups.getIndex( keyIndex.key() ) );
249  return rval;
250  }
251 
263  template< typename T = Group, typename TBASE = Group >
264  T & registerGroup( string const & name, string const & catalogName )
265  {
266  std::unique_ptr< TBASE > newGroup = TBASE::CatalogInterface::Factory( catalogName, name, this );
267  return registerGroup< T >( name, std::move( newGroup ) );
268  }
269 
274  void deregisterGroup( string const & name );
275 
284  virtual Group * createChild( string const & childKey, string const & childName );
285 
287 
288  //END_SPHINX_INCLUDE_REGISTER_GROUP
289 
290  //START_SPHINX_INCLUDE_GET_GROUP
306 
316  template< typename T = Group, typename KEY = void >
317  T * getGroupPointer( KEY const & key )
318  { return dynamicCast< T * >( m_subGroups[ key ] ); }
319 
323  template< typename T = Group, typename KEY = void >
324  T const * getGroupPointer( KEY const & key ) const
325  { return dynamicCast< T const * >( m_subGroups[ key ] ); }
326 
335  template< typename T = Group, typename KEY = void >
336  T & getGroup( KEY const & key )
337  {
338  Group * const child = m_subGroups[ key ];
339  GEOS_THROW_IF( child == nullptr,
340  "Group " << getDataContext() << " has no child named " << key << std::endl
341  << dumpSubGroupsNames(),
342  std::domain_error );
343  T * const castedChild = dynamicCast< T * >( child );
344  GEOS_THROW_IF( castedChild == nullptr,
345  GEOS_FMT( "{} was expected to be a '{}'.",
346  child->getDataContext(), LvArray::system::demangleType< T >() ),
347  BadTypeError );
348  return *castedChild;
349  }
350 
354  template< typename T = Group, typename KEY = void >
355  T const & getGroup( KEY const & key ) const
356  {
357  Group const * const child = m_subGroups[ key ];
358  GEOS_THROW_IF( child == nullptr,
359  "Group " << getDataContext() << " has no child named " << key << std::endl
360  << dumpSubGroupsNames(),
361  std::domain_error );
362  T const * const castedChild = dynamicCast< T const * >( child );
363  GEOS_THROW_IF( castedChild == nullptr,
364  GEOS_FMT( "{} was expected to be a '{}'.",
365  child->getDataContext(), LvArray::system::demangleType< T >() ),
366  BadTypeError );
367  return *castedChild;
368  }
369 
379  template< typename T = Group >
380  T & getGroupByPath( string const & path )
381  { return dynamicCast< T & >( const_cast< Group & >( getBaseGroupByPath( path ) ) ); }
382 
386  template< typename T = Group >
387  T const & getGroupByPath( string const & path ) const
388  { return dynamicCast< T const & >( getBaseGroupByPath( path ) ); }
389 
390  //END_SPHINX_INCLUDE_GET_GROUP
391 
397  { return m_subGroups; }
398 
403  subGroupMap const & getSubGroups() const
404  { return m_subGroups; }
405 
410  localIndex numSubGroups() const { return m_subGroups.size(); }
411 
415  std::vector< string > getSubGroupsNames() const;
416 
422  template< typename T = Group >
423  bool hasGroup( string const & name ) const
424  { return dynamicCast< T const * >( m_subGroups[ name ] ) != nullptr; }
425 
431  template< typename T >
432  bool hasSubGroupOfType( ) const
433  {
434  bool hasSubGroup = false;
435  // since forSubGroups only applies the lambda to groups matching the type,
436  // any calls to the lambda indicates that we have a subgroup of the correct type.
437  forSubGroups< T >( [&]( T const & ){ hasSubGroup = true; } );
438  return hasSubGroup;
439  }
440 
442 
453 
455  template< typename CASTTYPE, typename CONTAINERTYPE, typename LAMBDA >
456  static bool applyLambdaToContainer( CONTAINERTYPE & container, LAMBDA && lambda )
457  {
458  using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, CASTTYPE const, CASTTYPE >;
459  T * const castedContainer = dynamic_cast< T * >( &container );
460  if( castedContainer != nullptr )
461  {
462  lambda( *castedContainer );
463  return true;
464  }
465 
466  return false;
467  }
481  template< typename T0, typename T1, typename ... CASTTYPES, typename CONTAINERTYPE, typename LAMBDA >
482  static bool applyLambdaToContainer( CONTAINERTYPE & container, LAMBDA && lambda )
483  {
484  using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, T0 const, T0 >;
485  T * const castedContainer = dynamic_cast< T * >( &container );
486 
487  if( castedContainer != nullptr )
488  {
489  lambda( *castedContainer );
490  return true;
491  }
492 
493  return applyLambdaToContainer< T1, CASTTYPES... >( container, std::forward< LAMBDA >( lambda ) );
494  }
496 
497 
498  //START_SPHINX_INCLUDE_LOOP_INTERFACE
508 
517  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
518  void forSubGroups( LAMBDA && lambda )
519  {
520  for( auto & subGroupIter : m_subGroups )
521  {
522  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&]( auto & castedSubGroup )
523  {
524  lambda( castedSubGroup );
525  } );
526  }
527  }
528 
532  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
533  void forSubGroups( LAMBDA && lambda ) const
534  {
535  for( auto const & subGroupIter : m_subGroups )
536  {
537  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&]( auto const & castedSubGroup )
538  {
539  lambda( castedSubGroup );
540  } );
541  }
542  }
543 
544 
552  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
553  void forSubGroupsIndex( LAMBDA && lambda )
554  {
555  localIndex counter = 0;
556  for( auto & subGroupIter : m_subGroups )
557  {
558  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second,
559  [&]( auto & castedSubGroup )
560  {
561  lambda( counter, castedSubGroup );
562  } );
563  ++counter;
564  }
565  }
566 
570  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
571  void forSubGroupsIndex( LAMBDA && lambda ) const
572  {
573  localIndex counter = 0;
574  for( auto const & subGroupIter : m_subGroups )
575  {
576  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second,
577  [&]( auto const & castedSubGroup )
578  {
579  lambda( counter, castedSubGroup );
580  } );
581  ++counter;
582  }
583  }
584 
596  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LOOKUP_CONTAINER, typename LAMBDA >
597  void forSubGroups( LOOKUP_CONTAINER const & subGroupKeys, LAMBDA && lambda )
598  {
599  localIndex counter = 0;
600 
601  for( auto const & subgroup : subGroupKeys )
602  {
603  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( getGroup( subgroup ), [&]( auto & castedSubGroup )
604  {
605  lambda( counter, castedSubGroup );
606  } );
607  ++counter;
608  }
609  }
610 
622  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LOOKUP_CONTAINER, typename LAMBDA >
623  void forSubGroups( LOOKUP_CONTAINER const & subGroupKeys, LAMBDA && lambda ) const
624  {
625  localIndex counter = 0;
626  for( auto const & subgroup : subGroupKeys )
627  {
628  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( getGroup( subgroup ), [&]( auto const & castedSubGroup )
629  {
630  lambda( counter, castedSubGroup );
631  } );
632  ++counter;
633  }
634  }
636 
648 
654  template< typename LAMBDA >
655  void forWrappers( LAMBDA && lambda )
656  {
657  for( auto & wrapperIter : m_wrappers )
658  {
659  lambda( *wrapperIter.second );
660  }
661  }
662 
666  template< typename LAMBDA >
667  void forWrappers( LAMBDA && lambda ) const
668  {
669  for( auto const & wrapperIter : m_wrappers )
670  {
671  lambda( *wrapperIter.second );
672  }
673  }
674 
682  template< typename TYPE, typename ... TYPES, typename LAMBDA >
683  void forWrappers( LAMBDA && lambda )
684  {
685  for( auto & wrapperIter : m_wrappers )
686  {
687  applyLambdaToContainer< Wrapper< TYPE >, Wrapper< TYPES >... >( *wrapperIter.second,
688  std::forward< LAMBDA >( lambda ));
689  }
690  }
691 
699  template< typename TYPE, typename ... TYPES, typename LAMBDA >
700  void forWrappers( LAMBDA && lambda ) const
701  {
702  for( auto const & wrapperIter : m_wrappers )
703  {
704  applyLambdaToContainer< Wrapper< TYPE >, Wrapper< TYPES >... >( *wrapperIter.second,
705  std::forward< LAMBDA >( lambda ));
706  }
707  }
708 
710  //END_SPHINX_INCLUDE_LOOP_INTERFACE
711 
716 
720 
721 
734  void initialize();
735 
745  virtual void initializationOrder( string_array & order );
746 
747 
763 
771 
780  xmlWrapper::xmlNode & targetNode );
789  xmlWrapper::xmlNode & targetNode,
790  xmlWrapper::xmlNodePos const & nodePos );
791 
797 
799 
800  //START_SPHINX_INCLUDE_REGISTER_WRAPPER
804 
815  template< typename T, typename TBASE=T >
816  Wrapper< TBASE > & registerWrapper( string const & name,
817  wrapperMap::KeyIndex::index_type * const rkey = nullptr );
818 
826  template< typename T, typename TBASE=T >
828 
837  template< typename T >
838  Wrapper< T > & registerWrapper( string const & name, std::unique_ptr< T > newObject );
839 
848  template< typename T >
849  Wrapper< T > & registerWrapper( string const & name,
850  T * newObject );
851 
857  WrapperBase & registerWrapper( std::unique_ptr< WrapperBase > wrapper );
858 
863  void deregisterWrapper( string const & name );
864 
866  //END_SPHINX_INCLUDE_REGISTER_WRAPPER
867 
874  template< typename LOG_LEVEL_INFO >
875  std::enable_if_t< geos::is_log_level_info< LOG_LEVEL_INFO >, void >
876  addLogLevel();
877 
882 
888  {
890  string indent( level*2, ' ' );
891 
892  for( auto const & subGroupIter : m_subGroups )
893  {
894  std::cout << indent << subGroupIter.second->getName() << std::endl;
895  subGroupIter.second->generateDataStructureSkeleton( level + 1 );
896  }
897  }
898 
902  virtual void expandObjectCatalogs() {}
903 
910  virtual void setSchemaDeviations( xmlWrapper::xmlNode schemaRoot,
911  xmlWrapper::xmlNode schemaParent,
912  integer documentationType )
913  {
914  GEOS_UNUSED_VAR( schemaRoot );
915  GEOS_UNUSED_VAR( schemaParent );
916  GEOS_UNUSED_VAR( documentationType );
917  }
918 
920 
925 
930  virtual void registerDataOnMeshRecursive( Group & meshBodies );
931 
939  virtual void registerDataOnMesh( Group & meshBodies )
940  {
941  GEOS_UNUSED_VAR( meshBodies );
942  }
943 
945 
950 
962  virtual localIndex packSize( string_array const & wrapperNames,
963  integer const recursive,
964  bool onDevice,
965  parallelDeviceEvents & events ) const;
966 
979  virtual localIndex packSize( string_array const & wrapperNames,
980  arrayView1d< localIndex const > const & packList,
981  integer const recursive,
982  bool onDevice,
983  parallelDeviceEvents & events ) const;
984 
997  integer const recursive,
998  bool onDevice,
999  parallelDeviceEvents & events ) const;
1000 
1019  virtual localIndex pack( buffer_unit_type * & buffer,
1020  string_array const & wrapperNames,
1021  integer const recursive,
1022  bool onDevice,
1023  parallelDeviceEvents & events ) const;
1024 
1043  virtual localIndex pack( buffer_unit_type * & buffer,
1044  string_array const & wrapperNames,
1045  arrayView1d< localIndex const > const & packList,
1046  integer const recursive,
1047  bool onDevice,
1048  parallelDeviceEvents & events ) const;
1049 
1068  arrayView1d< localIndex const > const & packList,
1069  integer const recursive,
1070  bool onDevice,
1071  parallelDeviceEvents & events ) const;
1072 
1092  virtual localIndex unpack( buffer_unit_type const * & buffer,
1093  arrayView1d< localIndex > & packList,
1094  integer const recursive,
1095  bool onDevice,
1096  parallelDeviceEvents & events,
1097  MPI_Op op=MPI_REPLACE );
1098 
1100 
1101  //***********************************************************************************************
1102 
1103  //START_SPHINX_INCLUDE_GET_WRAPPER
1111 
1120  template< typename KEY >
1121  WrapperBase const & getWrapperBase( KEY const & key ) const
1122  {
1123  WrapperBase const * const wrapper = m_wrappers[ key ];
1124  GEOS_THROW_IF( wrapper == nullptr,
1125  "Group " << getDataContext() << " has no wrapper named " << key << std::endl
1126  << dumpWrappersNames(),
1127  std::domain_error );
1128 
1129  return *wrapper;
1130  }
1131 
1135  template< typename KEY >
1136  WrapperBase & getWrapperBase( KEY const & key )
1137  {
1138  WrapperBase * const wrapper = m_wrappers[ key ];
1139  GEOS_THROW_IF( wrapper == nullptr,
1140  "Group " << getDataContext() << " has no wrapper named " << key << std::endl
1141  << dumpWrappersNames(),
1142  std::domain_error );
1143 
1144  return *wrapper;
1145  }
1146 
1152  indexType getWrapperIndex( string const & name ) const
1153  { return m_wrappers.getIndex( name ); }
1154 
1159  wrapperMap const & wrappers() const
1160  { return m_wrappers; }
1161 
1166  { return m_wrappers; }
1167 
1173  { return m_wrappers.size(); }
1174 
1178  std::vector< string > getWrappersNames() const;
1179 
1181 
1194 
1201  template< typename LOOKUP_TYPE >
1202  bool hasWrapper( LOOKUP_TYPE const & lookup ) const
1203  { return m_wrappers[ lookup ] != nullptr; }
1204 
1213  template< typename T, typename LOOKUP_TYPE >
1214  Wrapper< T > const & getWrapper( LOOKUP_TYPE const & index ) const
1215  {
1216  WrapperBase const & wrapper = getWrapperBase( index );
1217  return dynamicCast< Wrapper< T > const & >( wrapper );
1218  }
1219 
1223  template< typename T, typename LOOKUP_TYPE >
1224  Wrapper< T > & getWrapper( LOOKUP_TYPE const & index )
1225  {
1226  WrapperBase & wrapper = getWrapperBase( index );
1227  return dynamicCast< Wrapper< T > & >( wrapper );
1228  }
1229 
1238  template< typename T, typename LOOKUP_TYPE >
1239  Wrapper< T > const * getWrapperPointer( LOOKUP_TYPE const & index ) const
1240  { return dynamicCast< Wrapper< T > const * >( m_wrappers[ index ] ); }
1241 
1245  template< typename T, typename LOOKUP_TYPE >
1246  Wrapper< T > * getWrapperPointer( LOOKUP_TYPE const & index )
1247  { return dynamicCast< Wrapper< T > * >( m_wrappers[ index ] ); }
1248 
1250 
1261 
1271  template< typename T, typename LOOKUP_TYPE >
1273  getReference( LOOKUP_TYPE const & lookup ) const
1274  { return getWrapper< T >( lookup ).reference(); }
1275 
1279  template< typename T, typename LOOKUP_TYPE >
1280  T & getReference( LOOKUP_TYPE const & lookup )
1281  { return getWrapper< T >( lookup ).reference(); }
1282 
1283  //END_SPHINX_INCLUDE_GET_WRAPPER
1284 
1286 
1291 
1296  virtual void resize( localIndex const newSize );
1297 
1302  virtual void reserve( indexType const newsize );
1303 
1308  inline localIndex capacity() const
1309  { return m_capacity; }
1310 
1315  inline localIndex size() const
1316  { return m_size; }
1317 
1319 
1324 
1329  inline string const & getName() const
1330  { return m_name; }
1331 
1337  string getPath() const;
1338 
1343  DataContext const & getDataContext() const
1344  { return *m_dataContext; }
1345 
1353  template< typename KEY >
1354  DataContext const & getWrapperDataContext( KEY key ) const
1355  { return getWrapperBase< KEY >( key ).getDataContext(); }
1356 
1363  {
1364  GEOS_THROW_IF( m_parent == nullptr, "Group at " << getDataContext() << " does not have a parent.", std::domain_error );
1365  return *m_parent;
1366  }
1367 
1371  Group const & getParent() const
1372  {
1373  GEOS_THROW_IF( m_parent == nullptr, "Group at " << getDataContext() << " does not have a parent.", std::domain_error );
1374  return *m_parent;
1375  }
1376 
1380  bool hasParent() const
1381  { return m_parent != nullptr; }
1382 
1388  { return m_parent->getSubGroups().getIndex( m_name ); }
1389 
1395  localIndex getSubGroupIndex( keyType const & key ) const;
1396 
1401  int sizedFromParent() const
1402  { return m_sizedFromParent; }
1403 
1410  {
1411  m_sizedFromParent = val;
1412  return *this;
1413  }
1418  RestartFlags getRestartFlags() const { return m_restart_flags; }
1419 
1424  void setRestartFlags( RestartFlags flags ) { m_restart_flags = flags; }
1425 
1430  InputFlags getInputFlags() const { return m_input_flags; }
1431 
1436  void setInputFlags( InputFlags flags ) { m_input_flags = flags; }
1437 
1442  {
1444  static constexpr char const * logLevelString() { return "logLevel"; }
1445  };
1446 
1448 
1455  virtual bool registerCallback( void * func, const std::type_info & funcType )
1456  {
1457  GEOS_UNUSED_VAR( func );
1458  GEOS_UNUSED_VAR( funcType );
1459  return false;
1460  }
1461 
1466 
1471  conduit::Node & getConduitNode()
1472  { return m_conduitNode; }
1473 
1475  conduit::Node const & getConduitNode() const
1476  { return m_conduitNode; }
1477 
1482 
1487 
1492 
1497 
1502  void setLogLevel( integer const logLevel ) { m_logLevel = logLevel; }
1503 
1505  integer getLogLevel() const { return m_logLevel; }
1507 
1511  virtual void reinit() {}
1512 
1517 #if defined(GEOS_USE_PYGEOSX)
1518  virtual PyTypeObject * getPythonType() const;
1519 #endif
1520 
1521 protected:
1522 
1530 
1535  virtual void postInputInitialization() {}
1536 
1540  virtual void initializePreSubGroups()
1541  {}
1542 
1547  {}
1548 
1553  {}
1554 
1559  {}
1560 
1565  {}
1566 
1567 
1568 
1570 
1571 private:
1579  virtual void processInputFile( xmlWrapper::xmlNode const & targetNode,
1580  xmlWrapper::xmlNodePos const & nodePos );
1581 
1582  Group const & getBaseGroupByPath( string const & path ) const;
1583 
1598  template< bool DO_PACKING >
1599  localIndex packImpl( buffer_unit_type * & buffer,
1600  array1d< string > const & wrapperNames,
1601  arrayView1d< localIndex const > const & packList,
1602  integer const recursive,
1603  bool onDevice,
1604  parallelDeviceEvents & events ) const;
1605 
1606  //START_SPHINX_INCLUDE_02
1608  Group * m_parent = nullptr;
1609 
1611  integer m_sizedFromParent;
1612 
1614  wrapperMap m_wrappers;
1615 
1617  subGroupMap m_subGroups;
1618 
1621  indexType m_size;
1622 
1625  indexType m_capacity;
1626 
1628  string m_name;
1629 
1631  integer m_logLevel;
1632 
1633 
1634  //END_SPHINX_INCLUDE_02
1635 
1637  RestartFlags m_restart_flags;
1638 
1640  InputFlags m_input_flags;
1641 
1643  conduit::Node & m_conduitNode;
1644 
1645  // Keep track of log levels & descriptions
1646  std::unique_ptr< LogLevelsRegistry > m_logLevelsRegistry;
1647 
1650  std::unique_ptr< DataContext > m_dataContext;
1651 
1652 };
1653 
1658 
1663 
1664 // Doxygen bug - sees this as a separate function
1666 template< typename T, typename TBASE >
1667 Wrapper< TBASE > & Group::registerWrapper( string const & name,
1668  ViewKey::index_type * const rkey )
1669 {
1670  std::unique_ptr< TBASE > newObj = std::make_unique< T >();
1671  m_wrappers.insert( name,
1672  new Wrapper< TBASE >( name, *this, std::move( newObj ) ),
1673  true );
1674 
1675  if( rkey != nullptr )
1676  {
1677  *rkey = m_wrappers.getIndex( name );
1678  }
1679 
1680  Wrapper< TBASE > & rval = getWrapper< TBASE >( name );
1681  if( rval.sizedFromParent() == 1 )
1682  {
1683  rval.resize( size());
1684  }
1685  return rval;
1686 }
1688 
1689 template< typename T, typename TBASE >
1691 {
1692  ViewKey::index_type index;
1693  Wrapper< TBASE > & rval = registerWrapper< T, TBASE >( viewKey.key(), &index );
1694  viewKey.setIndex( index );
1695 
1696  return rval;
1697 }
1698 
1699 
1700 template< typename T >
1701 Wrapper< T > & Group::registerWrapper( string const & name,
1702  std::unique_ptr< T > newObject )
1703 {
1704  static_assert( !std::is_base_of< WrapperBase, T >::value, "This function should not be used for `WrapperBase`. Use the dedicated `registerWrapper` instead." );
1705  m_wrappers.insert( name,
1706  new Wrapper< T >( name, *this, std::move( newObject ) ),
1707  true );
1708 
1709  Wrapper< T > & rval = getWrapper< T >( name );
1710  if( rval.sizedFromParent() == 1 )
1711  {
1712  rval.resize( size());
1713  }
1714  return rval;
1715 }
1716 
1717 template< typename T >
1718 Wrapper< T > & Group::registerWrapper( string const & name,
1719  T * newObject )
1720 {
1721  static_assert( !std::is_base_of< WrapperBase, T >::value, "This function should not be used for `WrapperBase`. Use the dedicated `registerWrapper` instead." );
1722  m_wrappers.insert( name,
1723  new Wrapper< T >( name, *this, newObject ),
1724  true );
1725 
1726  Wrapper< T > & rval = getWrapper< T >( name );
1727  if( rval.sizedFromParent() == 1 )
1728  {
1729  rval.resize( size());
1730  }
1731  return rval;
1732 }
1733 
1734 template< typename LOG_LEVEL_INFO >
1735 std::enable_if_t< geos::is_log_level_info< LOG_LEVEL_INFO >, void >
1737 {
1738  GEOS_ERROR_IF( m_logLevelsRegistry == nullptr, "You cannot call addLogLevel after schema generation" );
1739 
1740  Wrapper< integer > * wrapper = getWrapperPointer< integer >( viewKeyStruct::logLevelString() );
1741  if( wrapper == nullptr )
1742  {
1743  wrapper = &registerWrapper( viewKeyStruct::logLevelString(), &m_logLevel );
1744  wrapper->setApplyDefaultValue( 0 );
1745  wrapper->setInputFlag( InputFlags::OPTIONAL );
1746  }
1747  m_logLevelsRegistry->addEntry( LOG_LEVEL_INFO::getMinLogLevel(),
1748  LOG_LEVEL_INFO::getDescription() );
1749  wrapper->setDescription( m_logLevelsRegistry->buildLogLevelDescription());
1750 }
1751 
1752 } /* end namespace dataRepository */
1753 } /* end namespace geos */
1754 
1755 #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:84
#define GEOS_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:142
#define GEOS_THROW_IF(EXP, msg, TYPE)
Conditionally throw an exception.
Definition: Logger.hpp:151
INDEX_TYPE index_type
the type used for the index
Definition: KeyIndexT.hpp:48
void setIndex(INDEX_TYPE const &index) const
Set the index.
Definition: KeyIndexT.hpp:129
KEY_TYPE const & key() const
Access for the key.
Definition: KeyIndexT.hpp:106
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:380
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:623
T const & getGroupByPath(string const &path) const
Retrieve a group from the hierarchy using a path.
Definition: Group.hpp:387
virtual void initializePreSubGroups()
Called by Initialize() prior to initializing sub-Groups.
Definition: Group.hpp:1540
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:1308
virtual void postInputInitialization()
Definition: Group.hpp:1535
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:1436
int sizedFromParent() const
Check whether this Group is resized when its parent is resized.
Definition: Group.hpp:1401
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:317
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:1430
DataContext const & getDataContext() const
Definition: Group.hpp:1343
bool hasWrapper(LOOKUP_TYPE const &lookup) const
Check if a wrapper exists.
Definition: Group.hpp:1202
T & registerGroup(string const &name, T *newObject)
Register a new Group as a sub-group of current Group.
Definition: Group.hpp:217
void postInputInitializationRecursive()
Recursively call postInputInitialization() to apply post processing after reading input values.
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:1165
localIndex getIndexInParent() const
Get the group's index within its parent group.
Definition: Group.hpp:1387
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:200
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:683
virtual void expandObjectCatalogs()
Expand any catalogs in the data structure.
Definition: Group.hpp:902
MappedVector< WrapperBase, WrapperBase *, keyType, indexType > wrapperMap
The template specialization of MappedVector to use for the collection wrappers objects.
Definition: Group.hpp:75
virtual void initializePostSubGroups()
Called by Initialize() after to initializing sub-Groups.
Definition: Group.hpp:1546
virtual void reinit()
Performs re-initialization of certain variable depending on the solver being used.
Definition: Group.hpp:1511
void setRestartFlags(RestartFlags flags)
Set flags that control restart output of this group.
Definition: Group.hpp:1424
Wrapper< T > & getWrapper(LOOKUP_TYPE const &index)
Retrieve a Wrapper stored in this group.
Definition: Group.hpp:1224
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:571
string const & getName() const
Get group name.
Definition: Group.hpp:1329
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:1273
WrapperBase & getWrapperBase(KEY const &key)
Return a reference to a WrapperBase stored in this group.
Definition: Group.hpp:1136
WrapperBase const & getWrapperBase(KEY const &key) const
Return a reference to a WrapperBase stored in this group.
Definition: Group.hpp:1121
virtual void registerDataOnMeshRecursive(Group &meshBodies)
Calls RegisterDataOnMesh() recursively.
conduit::Node & getConduitNode()
Return the Conduit node object associated with this group.
Definition: Group.hpp:1471
void forSubGroups(LAMBDA &&lambda) const
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:533
virtual void initializePostInitialConditionsPostSubGroups()
Called by InitializePostInitialConditions() after to initializing sub-Groups.
Definition: Group.hpp:1558
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:245
static CatalogInterface::CatalogType & getCatalog()
Get the singleton catalog for this Group.
void forSubGroupsIndex(LAMBDA &&lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:553
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:1418
void deregisterWrapper(string const &name)
Removes a Wrapper from this group.
std::enable_if_t< geos::is_log_level_info< LOG_LEVEL_INFO >, void > addLogLevel()
Append a levelCondition and a log description to the description of the wrapped object given a log in...
Definition: Group.hpp:1736
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:410
indexType numWrappers() const
Return the number of wrappers.
Definition: Group.hpp:1172
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:336
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:72
Group & getParent()
Access the group's parent.
Definition: Group.hpp:1362
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:1564
Group(string const &name, conduit::Node &rootNode)
Constructor.
bool hasGroup(string const &name) const
Check whether a sub-group exists.
Definition: Group.hpp:423
indexType getWrapperIndex(string const &name) const
Definition: Group.hpp:1152
bool hasSubGroupOfType() const
Check whether a sub-group exists by type.
Definition: Group.hpp:432
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:482
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:324
virtual bool registerCallback(void *func, const std::type_info &funcType)
Register a callback function on the group.
Definition: Group.hpp:1455
void forWrappers(LAMBDA &&lambda) const
Apply the given functor to wrappers.
Definition: Group.hpp:667
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:1214
T & getReference(LOOKUP_TYPE const &lookup)
Look up a wrapper and get reference to wrapped object.
Definition: Group.hpp:1280
virtual void registerDataOnMesh(Group &meshBodies)
Register data on mesh entities.
Definition: Group.hpp:939
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers.
Definition: Group.hpp:1315
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:1246
T const & getGroup(KEY const &key) const
Return a reference to a sub-group of the current Group.
Definition: Group.hpp:355
void forSubGroups(LAMBDA &&lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:518
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:264
integer getLogLevel() const
Definition: Group.hpp:1505
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:700
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:1502
Group const & getParent() const
Access the group's parent.
Definition: Group.hpp:1371
conduit::Node const & getConduitNode() const
Return the Conduit node object associated with this group.
Definition: Group.hpp:1475
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:1409
DataContext const & getWrapperDataContext(KEY key) const
Definition: Group.hpp:1354
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:655
subGroupMap const & getSubGroups() const
Get the subgroups object.
Definition: Group.hpp:403
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:597
void generateDataStructureSkeleton(integer const level)
Build a complete datastructure for schema generation.
Definition: Group.hpp:887
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:910
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:1159
T & registerGroup(string const &name)
Register a new Group as a sub-group of current Group.
Definition: Group.hpp:231
virtual void initializePostInitialConditionsPreSubGroups()
Called by InitializePostInitialConditions() prior to initializing sub-Groups.
Definition: Group.hpp:1552
Wrapper< T > const * getWrapperPointer(LOOKUP_TYPE const &index) const
Retrieve a Wrapper stored in this group.
Definition: Group.hpp:1239
subGroupMap & getSubGroups()
Get the subgroups object.
Definition: Group.hpp:396
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:56
int sizedFromParent() const
Check whether this wrapper is resized when its parent is resized.
Wrapper< T > & setInputFlag(InputFlags const input)
Set the InputFlag of the wrapper.
Definition: Wrapper.hpp:882
std::enable_if_t< !traits::is_array< U > &&DefaultValue< U >::has_default_value, Wrapper< T > & > setApplyDefaultValue(typename DefaultValue< U >::value_type const &defaultVal)
Set and apply for default value.
Definition: Wrapper.hpp:683
Wrapper< T > & setDescription(string const &description)
Set the description string of the wrapper.
Definition: Wrapper.hpp:891
virtual void resize(int ndims, localIndex const *const dims) override
Calls T::resize( num_dims, dims )
Definition: Wrapper.hpp:390
@ OPTIONAL
Optional in input.
Group::wrapperMap::KeyIndex ViewKey
Type alias for KeyIndexT type used for wrapper lookups.
Definition: Group.hpp:1662
localIndex indexType
The default index type for entries the hierarchy.
Definition: Group.hpp:58
string keyType
The default key type for entries in the hierarchy.
Definition: Group.hpp:55
pugi::xml_node xmlNode
Definition: xmlWrapper.hpp:59
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:180
array1d< string > string_array
A 1-dimensional array of geos::string types.
Definition: DataTypes.hpp:392
std::string string
String type.
Definition: DataTypes.hpp:91
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:109
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:176
Exception class used to report errors from type conversion.
Definition: Logger.hpp:564
Structure to hold scoped key names.
Definition: Group.hpp:1442
static constexpr char const * logLevelString()
Definition: Group.hpp:1444