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 TotalEnergies
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 
256  void deregisterGroup( string const & name );
257 
266  virtual Group * createChild( string const & childKey, string const & childName );
267 
269 
270  //END_SPHINX_INCLUDE_REGISTER_GROUP
271 
272  //START_SPHINX_INCLUDE_GET_GROUP
288 
298  template< typename T = Group, typename KEY = void >
299  T * getGroupPointer( KEY const & key )
300  { return dynamicCast< T * >( m_subGroups[ key ] ); }
301 
305  template< typename T = Group, typename KEY = void >
306  T const * getGroupPointer( KEY const & key ) const
307  { return dynamicCast< T const * >( m_subGroups[ key ] ); }
308 
317  template< typename T = Group, typename KEY = void >
318  T & getGroup( KEY const & key )
319  {
320  Group * const child = m_subGroups[ key ];
321  GEOS_THROW_IF( child == nullptr,
322  "No child named " << key << " found." << std::endl << dumpSubGroupsNames(),
324  T * const castedChild = dynamicCast< T * >( child );
325  GEOS_THROW_IF( castedChild == nullptr,
326  GEOS_FMT( "'{}' was expected to be a '{}'.",
327  getName(), LvArray::system::demangleType< T >() ),
328  BadTypeError, child->getDataContext() );
329  return *castedChild;
330  }
331 
335  template< typename T = Group, typename KEY = void >
336  T const & getGroup( KEY const & key ) const
337  {
338  Group const * const child = m_subGroups[ key ];
339  GEOS_THROW_IF( child == nullptr,
340  "No child named " << key << " found." << std::endl << dumpSubGroupsNames(),
342  T const * const castedChild = dynamicCast< T const * >( child );
343  GEOS_THROW_IF( castedChild == nullptr,
344  GEOS_FMT( "'{}' was expected to be a '{}'.",
345  getName(), LvArray::system::demangleType< T >() ),
346  BadTypeError, child->getDataContext() );
347  return *castedChild;
348  }
349 
359  template< typename T = Group >
360  T & getGroupByPath( string const & path )
361  { return dynamicCast< T & >( const_cast< Group & >( getBaseGroupByPath( path ) ) ); }
362 
366  template< typename T = Group >
367  T const & getGroupByPath( string const & path ) const
368  { return dynamicCast< T const & >( getBaseGroupByPath( path ) ); }
369 
370  //END_SPHINX_INCLUDE_GET_GROUP
371 
377  { return m_subGroups; }
378 
383  subGroupMap const & getSubGroups() const
384  { return m_subGroups; }
385 
390  localIndex numSubGroups() const { return m_subGroups.size(); }
391 
396 
402  template< typename T = Group >
403  bool hasGroup( string const & name ) const
404  { return dynamicCast< T const * >( m_subGroups[ name ] ) != nullptr; }
405 
411  template< typename T >
412  bool hasSubGroupOfType( ) const
413  {
414  bool hasSubGroup = false;
415  // since forSubGroups only applies the lambda to groups matching the type,
416  // any calls to the lambda indicates that we have a subgroup of the correct type.
417  forSubGroups< T >( [&]( T const & ){ hasSubGroup = true; } );
418  return hasSubGroup;
419  }
420 
422 
433 
435  template< typename CASTTYPE, typename CONTAINERTYPE, typename LAMBDA >
436  static bool applyLambdaToContainer( CONTAINERTYPE & container, LAMBDA && lambda )
437  {
438  using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, CASTTYPE const, CASTTYPE >;
439  T * const castedContainer = dynamic_cast< T * >( &container );
440  if( castedContainer != nullptr )
441  {
442  lambda( *castedContainer );
443  return true;
444  }
445 
446  return false;
447  }
461  template< typename T0, typename T1, typename ... CASTTYPES, typename CONTAINERTYPE, typename LAMBDA >
462  static bool applyLambdaToContainer( CONTAINERTYPE & container, LAMBDA && lambda )
463  {
464  using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, T0 const, T0 >;
465  T * const castedContainer = dynamic_cast< T * >( &container );
466 
467  if( castedContainer != nullptr )
468  {
469  lambda( *castedContainer );
470  return true;
471  }
472 
473  return applyLambdaToContainer< T1, CASTTYPES... >( container, std::forward< LAMBDA >( lambda ) );
474  }
476 
477 
478  //START_SPHINX_INCLUDE_LOOP_INTERFACE
488 
497  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
498  void forSubGroups( LAMBDA && lambda )
499  {
500  for( auto & subGroupIter : m_subGroups )
501  {
502  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&]( auto & castedSubGroup )
503  {
504  lambda( castedSubGroup );
505  } );
506  }
507  }
508 
512  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
513  void forSubGroups( LAMBDA && lambda ) const
514  {
515  for( auto const & subGroupIter : m_subGroups )
516  {
517  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&]( auto const & castedSubGroup )
518  {
519  lambda( castedSubGroup );
520  } );
521  }
522  }
523 
524 
532  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
533  void forSubGroupsIndex( LAMBDA && lambda )
534  {
535  localIndex counter = 0;
536  for( auto & subGroupIter : m_subGroups )
537  {
538  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second,
539  [&]( auto & castedSubGroup )
540  {
541  lambda( counter, castedSubGroup );
542  } );
543  ++counter;
544  }
545  }
546 
550  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
551  void forSubGroupsIndex( LAMBDA && lambda ) const
552  {
553  localIndex counter = 0;
554  for( auto const & subGroupIter : m_subGroups )
555  {
556  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second,
557  [&]( auto const & castedSubGroup )
558  {
559  lambda( counter, castedSubGroup );
560  } );
561  ++counter;
562  }
563  }
564 
576  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LOOKUP_CONTAINER, typename LAMBDA >
577  void forSubGroups( LOOKUP_CONTAINER const & subGroupKeys, LAMBDA && lambda )
578  {
579  localIndex counter = 0;
580 
581  for( auto const & subgroup : subGroupKeys )
582  {
583  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( getGroup( subgroup ), [&]( auto & castedSubGroup )
584  {
585  lambda( counter, castedSubGroup );
586  } );
587  ++counter;
588  }
589  }
590 
602  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LOOKUP_CONTAINER, typename LAMBDA >
603  void forSubGroups( LOOKUP_CONTAINER const & subGroupKeys, LAMBDA && lambda ) const
604  {
605  localIndex counter = 0;
606  for( auto const & subgroup : subGroupKeys )
607  {
608  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( getGroup( subgroup ), [&]( auto const & castedSubGroup )
609  {
610  lambda( counter, castedSubGroup );
611  } );
612  ++counter;
613  }
614  }
616 
628 
634  template< typename LAMBDA >
635  void forWrappers( LAMBDA && lambda )
636  {
637  for( auto & wrapperIter : m_wrappers )
638  {
639  lambda( *wrapperIter.second );
640  }
641  }
642 
646  template< typename LAMBDA >
647  void forWrappers( LAMBDA && lambda ) const
648  {
649  for( auto const & wrapperIter : m_wrappers )
650  {
651  lambda( *wrapperIter.second );
652  }
653  }
654 
662  template< typename TYPE, typename ... TYPES, typename LAMBDA >
663  void forWrappers( LAMBDA && lambda )
664  {
665  for( auto & wrapperIter : m_wrappers )
666  {
667  applyLambdaToContainer< Wrapper< TYPE >, Wrapper< TYPES >... >( *wrapperIter.second,
668  std::forward< LAMBDA >( lambda ));
669  }
670  }
671 
679  template< typename TYPE, typename ... TYPES, typename LAMBDA >
680  void forWrappers( LAMBDA && lambda ) const
681  {
682  for( auto const & wrapperIter : m_wrappers )
683  {
684  applyLambdaToContainer< Wrapper< TYPE >, Wrapper< TYPES >... >( *wrapperIter.second,
685  std::forward< LAMBDA >( lambda ));
686  }
687  }
688 
690  //END_SPHINX_INCLUDE_LOOP_INTERFACE
691 
696 
700 
701 
714  void initialize();
715 
725  virtual void initializationOrder( string_array & order );
726 
727 
743 
751 
766  static string processInputName( xmlWrapper::xmlNode const & targetNode,
767  xmlWrapper::xmlNodePos const & targetNodePos,
768  string_view parentNodeName,
769  xmlWrapper::xmlNodePos const & parentNodePos,
770  std::set< string > & siblingNames );
771 
780  xmlWrapper::xmlNode & targetNode );
789  xmlWrapper::xmlNode & targetNode,
790  xmlWrapper::xmlNodePos const & targetNodePos );
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  "No wrapper named " << key << " found." << std::endl
1126  << dumpWrappersNames(),
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  "No wrapper named " << key << " found." << std::endl
1141  << dumpWrappersNames(),
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 
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,
1365  "Group does not have a parent.",
1367  return *m_parent;
1368  }
1369 
1373  Group const & getParent() const
1374  {
1375  GEOS_THROW_IF( m_parent == nullptr,
1376  "Group does not have a parent.",
1378  return *m_parent;
1379  }
1380 
1384  bool hasParent() const
1385  { return m_parent != nullptr; }
1386 
1392  { return m_parent->getSubGroups().getIndex( m_name ); }
1393 
1399  localIndex getSubGroupIndex( keyType const & key ) const;
1400 
1405  int sizedFromParent() const
1406  { return m_sizedFromParent; }
1407 
1414  {
1415  m_sizedFromParent = val;
1416  return *this;
1417  }
1422  RestartFlags getRestartFlags() const { return m_restart_flags; }
1423 
1428  void setRestartFlags( RestartFlags flags ) { m_restart_flags = flags; }
1429 
1434  InputFlags getInputFlags() const { return m_input_flags; }
1435 
1440  void setInputFlags( InputFlags flags ) { m_input_flags = flags; }
1441 
1446  {
1448  static constexpr char const * logLevelString() { return "logLevel"; }
1449  };
1450 
1452 
1459  virtual bool registerCallback( void * func, const std::type_info & funcType )
1460  {
1461  GEOS_UNUSED_VAR( func );
1462  GEOS_UNUSED_VAR( funcType );
1463  return false;
1464  }
1465 
1470 
1475  conduit::Node & getConduitNode()
1476  { return m_conduitNode; }
1477 
1479  conduit::Node const & getConduitNode() const
1480  { return m_conduitNode; }
1481 
1486 
1491 
1496 
1501  void setLogLevel( integer const logLevel ) { m_logLevel = logLevel; }
1502 
1508  integer getLogLevel() const { return m_logLevel; }
1509 
1511 
1515  virtual void reinit() {}
1516 
1521 #if defined(GEOS_USE_PYGEOSX)
1522  virtual PyTypeObject * getPythonType() const;
1523 #endif
1524 
1525 protected:
1526 
1534 
1539  virtual void postInputInitialization() {}
1540 
1544  virtual void initializePreSubGroups()
1545  {}
1546 
1551  {}
1552 
1557  {}
1558 
1563  {}
1564 
1569  {}
1570 
1571 
1572 
1574 
1575 private:
1583  virtual void processInputFile( xmlWrapper::xmlNode const & targetNode,
1584  xmlWrapper::xmlNodePos const & nodePos );
1585 
1586  Group const & getBaseGroupByPath( string const & path ) const;
1587 
1602  template< bool DO_PACKING >
1603  localIndex packImpl( buffer_unit_type * & buffer,
1604  string_array const & wrapperNames,
1605  arrayView1d< localIndex const > const & packList,
1606  integer const recursive,
1607  bool onDevice,
1608  parallelDeviceEvents & events ) const;
1609 
1610  //START_SPHINX_INCLUDE_02
1612  Group * m_parent = nullptr;
1613 
1615  integer m_sizedFromParent;
1616 
1618  wrapperMap m_wrappers;
1619 
1621  subGroupMap m_subGroups;
1622 
1625  indexType m_size;
1626 
1629  indexType m_capacity;
1630 
1632  string m_name;
1633 
1635  integer m_logLevel;
1636 
1637 
1638  //END_SPHINX_INCLUDE_02
1639 
1641  RestartFlags m_restart_flags;
1642 
1644  InputFlags m_input_flags;
1645 
1647  conduit::Node & m_conduitNode;
1648 
1649  // Keep track of log levels & descriptions
1650  std::unique_ptr< LogLevelsRegistry > m_logLevelsRegistry;
1651 
1654  std::unique_ptr< DataContext > m_dataContext;
1655 
1656 };
1657 
1662 
1667 
1668 // Doxygen bug - sees this as a separate function
1670 template< typename T, typename TBASE >
1671 Wrapper< TBASE > & Group::registerWrapper( string const & name,
1672  ViewKey::index_type * const rkey )
1673 {
1674  std::unique_ptr< TBASE > newObj = std::make_unique< T >();
1675  m_wrappers.insert( name,
1676  new Wrapper< TBASE >( name, *this, std::move( newObj ) ),
1677  true );
1678 
1679  if( rkey != nullptr )
1680  {
1681  *rkey = m_wrappers.getIndex( name );
1682  }
1683 
1684  Wrapper< TBASE > & rval = getWrapper< TBASE >( name );
1685  if( rval.sizedFromParent() == 1 )
1686  {
1687  rval.resize( size());
1688  }
1689  return rval;
1690 }
1692 
1693 template< typename T, typename TBASE >
1695 {
1696  ViewKey::index_type index;
1697  Wrapper< TBASE > & rval = registerWrapper< T, TBASE >( viewKey.key(), &index );
1698  viewKey.setIndex( index );
1699 
1700  return rval;
1701 }
1702 
1703 
1704 template< typename T >
1705 Wrapper< T > & Group::registerWrapper( string const & name,
1706  std::unique_ptr< T > newObject )
1707 {
1708  static_assert( !std::is_base_of< WrapperBase, T >::value, "This function should not be used for `WrapperBase`. Use the dedicated `registerWrapper` instead." );
1709  m_wrappers.insert( name,
1710  new Wrapper< T >( name, *this, std::move( newObject ) ),
1711  true );
1712 
1713  Wrapper< T > & rval = getWrapper< T >( name );
1714  if( rval.sizedFromParent() == 1 )
1715  {
1716  rval.resize( size());
1717  }
1718  return rval;
1719 }
1720 
1721 template< typename T >
1722 Wrapper< T > & Group::registerWrapper( string const & name,
1723  T * newObject )
1724 {
1725  static_assert( !std::is_base_of< WrapperBase, T >::value, "This function should not be used for `WrapperBase`. Use the dedicated `registerWrapper` instead." );
1726  m_wrappers.insert( name,
1727  new Wrapper< T >( name, *this, newObject ),
1728  true );
1729 
1730  Wrapper< T > & rval = getWrapper< T >( name );
1731  if( rval.sizedFromParent() == 1 )
1732  {
1733  rval.resize( size());
1734  }
1735  return rval;
1736 }
1737 
1738 template< typename LOG_LEVEL_INFO >
1739 std::enable_if_t< geos::is_log_level_info< LOG_LEVEL_INFO >, void >
1741 {
1742  GEOS_ERROR_IF( m_logLevelsRegistry == nullptr, "You cannot call addLogLevel after schema generation" );
1743 
1744  Wrapper< integer > * wrapper = getWrapperPointer< integer >( viewKeyStruct::logLevelString() );
1745  if( wrapper == nullptr )
1746  {
1747  wrapper = &registerWrapper( viewKeyStruct::logLevelString(), &m_logLevel );
1748  wrapper->setApplyDefaultValue( 0 );
1749  wrapper->setInputFlag( InputFlags::OPTIONAL );
1750  }
1751  m_logLevelsRegistry->addEntry( LOG_LEVEL_INFO::getMinLogLevel(),
1752  LOG_LEVEL_INFO::getDescription() );
1753  wrapper->setDescription( m_logLevelsRegistry->buildLogLevelDescription());
1754 }
1755 
1756 } /* end namespace dataRepository */
1757 } /* end namespace geos */
1758 
1759 #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(COND,...)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:195
#define GEOS_THROW_IF(COND, MSG,...)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:263
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:360
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:603
T const & getGroupByPath(string const &path) const
Retrieve a group from the hierarchy using a path.
Definition: Group.hpp:367
virtual void initializePreSubGroups()
Called by Initialize() prior to initializing sub-Groups.
Definition: Group.hpp:1544
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:1539
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:1440
void processInputFileRecursive(xmlWrapper::xmlDocument &xmlDocument, xmlWrapper::xmlNode &targetNode, xmlWrapper::xmlNodePos const &targetNodePos)
Same as processInputFileRecursive(xmlWrapper::xmlDocument &, xmlWrapper::xmlNode &) but allow to reus...
int sizedFromParent() const
Check whether this Group is resized when its parent is resized.
Definition: Group.hpp:1405
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:299
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:1434
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.
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:1391
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:663
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:1550
virtual void reinit()
Performs re-initialization of certain variable depending on the solver being used.
Definition: Group.hpp:1515
void setRestartFlags(RestartFlags flags)
Set flags that control restart output of this group.
Definition: Group.hpp:1428
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:551
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:1475
void forSubGroups(LAMBDA &&lambda) const
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:513
virtual void initializePostInitialConditionsPostSubGroups()
Called by InitializePostInitialConditions() after to initializing sub-Groups.
Definition: Group.hpp:1562
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:533
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:1422
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:1740
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:390
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:318
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:1568
Group(string const &name, conduit::Node &rootNode)
Constructor.
bool hasGroup(string const &name) const
Check whether a sub-group exists.
Definition: Group.hpp:403
indexType getWrapperIndex(string const &name) const
Definition: Group.hpp:1152
bool hasSubGroupOfType() const
Check whether a sub-group exists by type.
Definition: Group.hpp:412
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:462
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:306
virtual bool registerCallback(void *func, const std::type_info &funcType)
Register a callback function on the group.
Definition: Group.hpp:1459
void forWrappers(LAMBDA &&lambda) const
Apply the given functor to wrappers.
Definition: Group.hpp:647
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:336
void forSubGroups(LAMBDA &&lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:498
stdVector< string > getWrappersNames() const
stdVector< string > getSubGroupsNames() const
integer getLogLevel() const
Definition: Group.hpp:1508
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:680
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:1501
Group const & getParent() const
Access the group's parent.
Definition: Group.hpp:1373
conduit::Node const & getConduitNode() const
Return the Conduit node object associated with this group.
Definition: Group.hpp:1479
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:1413
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:635
subGroupMap const & getSubGroups() const
Get the subgroups object.
Definition: Group.hpp:383
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:577
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:1556
static string processInputName(xmlWrapper::xmlNode const &targetNode, xmlWrapper::xmlNodePos const &targetNodePos, string_view parentNodeName, xmlWrapper::xmlNodePos const &parentNodePos, std::set< string > &siblingNames)
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:376
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:889
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:690
Wrapper< T > & setDescription(string const &description)
Set the description string of the wrapper.
Definition: Wrapper.hpp:898
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:1666
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:179
stdVector< string > string_array
A 1-dimensional array of geos::string types.
Definition: DataTypes.hpp:361
std::string string
String type.
Definition: DataTypes.hpp:90
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:108
int integer
Signed integer type.
Definition: DataTypes.hpp:81
std::string_view string_view
String type.
Definition: DataTypes.hpp:93
internal::StdVectorWrapper< T, Allocator, USE_STD_CONTAINER_BOUNDS_CHECKING > stdVector
Exception class used to report errors from type conversion.
Exception class used to report domain errors. Generally, the domain of a mathematical function is the...
Structure to hold scoped key names.
Definition: Group.hpp:1446
static constexpr char const * logLevelString()
Definition: Group.hpp:1448