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  GEOS_FMT( "No child named '{}' found.\n{}", geos::format::toStringForFmt( key ), dumpSubGroupsNames() ),
324 
325  T * const castedChild = dynamicCast< T * >( child );
326  GEOS_THROW_IF( castedChild == nullptr,
327  GEOS_FMT( "'{}' was expected to be a '{}'.",
328  getName(), LvArray::system::demangleType< T >() ),
329  BadTypeError, child->getDataContext() );
330  return *castedChild;
331  }
332 
336  template< typename T = Group, typename KEY = void >
337  T const & getGroup( KEY const & key ) const
338  {
339  Group const * const child = m_subGroups[ key ];
340  GEOS_THROW_IF( child == nullptr,
341  GEOS_FMT( "No child named '{}' found.\n{}", geos::format::toStringForFmt( key ), dumpSubGroupsNames() ),
343 
344  T const * const castedChild = dynamicCast< T const * >( child );
345  GEOS_THROW_IF( castedChild == nullptr,
346  GEOS_FMT( "'{}' was expected to be a '{}'.",
347  getName(), LvArray::system::demangleType< T >() ),
348  BadTypeError, child->getDataContext() );
349  return *castedChild;
350  }
351 
361  template< typename T = Group >
362  T & getGroupByPath( string const & path )
363  { return dynamicCast< T & >( const_cast< Group & >( getBaseGroupByPath( path ) ) ); }
364 
368  template< typename T = Group >
369  T const & getGroupByPath( string const & path ) const
370  { return dynamicCast< T const & >( getBaseGroupByPath( path ) ); }
371 
372  //END_SPHINX_INCLUDE_GET_GROUP
373 
379  { return m_subGroups; }
380 
385  subGroupMap const & getSubGroups() const
386  { return m_subGroups; }
387 
392  localIndex numSubGroups() const { return m_subGroups.size(); }
393 
398 
404  template< typename T = Group >
405  bool hasGroup( string const & name ) const
406  { return dynamicCast< T const * >( m_subGroups[ name ] ) != nullptr; }
407 
413  template< typename T >
414  bool hasSubGroupOfType( ) const
415  {
416  bool hasSubGroup = false;
417  // since forSubGroups only applies the lambda to groups matching the type,
418  // any calls to the lambda indicates that we have a subgroup of the correct type.
419  forSubGroups< T >( [&]( T const & ){ hasSubGroup = true; } );
420  return hasSubGroup;
421  }
422 
424 
435 
437  template< typename CASTTYPE, typename CONTAINERTYPE, typename LAMBDA >
438  static bool applyLambdaToContainer( CONTAINERTYPE & container, LAMBDA && lambda )
439  {
440  using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, CASTTYPE const, CASTTYPE >;
441  T * const castedContainer = dynamic_cast< T * >( &container );
442  if( castedContainer != nullptr )
443  {
444  lambda( *castedContainer );
445  return true;
446  }
447 
448  return false;
449  }
463  template< typename T0, typename T1, typename ... CASTTYPES, typename CONTAINERTYPE, typename LAMBDA >
464  static bool applyLambdaToContainer( CONTAINERTYPE & container, LAMBDA && lambda )
465  {
466  using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, T0 const, T0 >;
467  T * const castedContainer = dynamic_cast< T * >( &container );
468 
469  if( castedContainer != nullptr )
470  {
471  lambda( *castedContainer );
472  return true;
473  }
474 
475  return applyLambdaToContainer< T1, CASTTYPES... >( container, std::forward< LAMBDA >( lambda ) );
476  }
478 
479 
480  //START_SPHINX_INCLUDE_LOOP_INTERFACE
490 
499  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
500  void forSubGroups( LAMBDA && lambda )
501  {
502  for( auto & subGroupIter : m_subGroups )
503  {
504  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&]( auto & castedSubGroup )
505  {
506  lambda( castedSubGroup );
507  } );
508  }
509  }
510 
514  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
515  void forSubGroups( LAMBDA && lambda ) const
516  {
517  for( auto const & subGroupIter : m_subGroups )
518  {
519  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&]( auto const & castedSubGroup )
520  {
521  lambda( castedSubGroup );
522  } );
523  }
524  }
525 
526 
534  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
535  void forSubGroupsIndex( LAMBDA && lambda )
536  {
537  localIndex counter = 0;
538  for( auto & subGroupIter : m_subGroups )
539  {
540  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second,
541  [&]( auto & castedSubGroup )
542  {
543  lambda( counter, castedSubGroup );
544  } );
545  ++counter;
546  }
547  }
548 
552  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LAMBDA >
553  void forSubGroupsIndex( LAMBDA && lambda ) const
554  {
555  localIndex counter = 0;
556  for( auto const & subGroupIter : m_subGroups )
557  {
558  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second,
559  [&]( auto const & castedSubGroup )
560  {
561  lambda( counter, castedSubGroup );
562  } );
563  ++counter;
564  }
565  }
566 
578  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LOOKUP_CONTAINER, typename LAMBDA >
579  void forSubGroups( LOOKUP_CONTAINER const & subGroupKeys, LAMBDA && lambda )
580  {
581  localIndex counter = 0;
582 
583  for( auto const & subgroup : subGroupKeys )
584  {
585  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( getGroup( subgroup ), [&]( auto & castedSubGroup )
586  {
587  lambda( counter, castedSubGroup );
588  } );
589  ++counter;
590  }
591  }
592 
604  template< typename GROUPTYPE = Group, typename ... GROUPTYPES, typename LOOKUP_CONTAINER, typename LAMBDA >
605  void forSubGroups( LOOKUP_CONTAINER const & subGroupKeys, LAMBDA && lambda ) const
606  {
607  localIndex counter = 0;
608  for( auto const & subgroup : subGroupKeys )
609  {
610  applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( getGroup( subgroup ), [&]( auto const & castedSubGroup )
611  {
612  lambda( counter, castedSubGroup );
613  } );
614  ++counter;
615  }
616  }
618 
630 
636  template< typename LAMBDA >
637  void forWrappers( LAMBDA && lambda )
638  {
639  for( auto & wrapperIter : m_wrappers )
640  {
641  lambda( *wrapperIter.second );
642  }
643  }
644 
648  template< typename LAMBDA >
649  void forWrappers( LAMBDA && lambda ) const
650  {
651  for( auto const & wrapperIter : m_wrappers )
652  {
653  lambda( *wrapperIter.second );
654  }
655  }
656 
664  template< typename TYPE, typename ... TYPES, typename LAMBDA >
665  void forWrappers( LAMBDA && lambda )
666  {
667  for( auto & wrapperIter : m_wrappers )
668  {
669  applyLambdaToContainer< Wrapper< TYPE >, Wrapper< TYPES >... >( *wrapperIter.second,
670  std::forward< LAMBDA >( lambda ));
671  }
672  }
673 
681  template< typename TYPE, typename ... TYPES, typename LAMBDA >
682  void forWrappers( LAMBDA && lambda ) const
683  {
684  for( auto const & wrapperIter : m_wrappers )
685  {
686  applyLambdaToContainer< Wrapper< TYPE >, Wrapper< TYPES >... >( *wrapperIter.second,
687  std::forward< LAMBDA >( lambda ));
688  }
689  }
690 
692  //END_SPHINX_INCLUDE_LOOP_INTERFACE
693 
698 
702 
703 
716  void initialize();
717 
727  virtual void initializationOrder( string_array & order );
728 
729 
745 
753 
768  static string processInputName( xmlWrapper::xmlNode const & targetNode,
769  xmlWrapper::xmlNodePos const & targetNodePos,
770  string_view parentNodeName,
771  xmlWrapper::xmlNodePos const & parentNodePos,
772  std::set< string > & siblingNames );
773 
782  xmlWrapper::xmlNode & targetNode );
791  xmlWrapper::xmlNode & targetNode,
792  xmlWrapper::xmlNodePos const & targetNodePos );
793 
799 
801 
802  //START_SPHINX_INCLUDE_REGISTER_WRAPPER
806 
817  template< typename T, typename TBASE=T >
818  Wrapper< TBASE > & registerWrapper( string const & name,
819  wrapperMap::KeyIndex::index_type * const rkey = nullptr );
820 
828  template< typename T, typename TBASE=T >
830 
839  template< typename T >
840  Wrapper< T > & registerWrapper( string const & name, std::unique_ptr< T > newObject );
841 
850  template< typename T >
851  Wrapper< T > & registerWrapper( string const & name,
852  T * newObject );
853 
859  WrapperBase & registerWrapper( std::unique_ptr< WrapperBase > wrapper );
860 
865  void deregisterWrapper( string const & name );
866 
868  //END_SPHINX_INCLUDE_REGISTER_WRAPPER
869 
876  template< typename LOG_LEVEL_INFO >
877  std::enable_if_t< geos::is_log_level_info< LOG_LEVEL_INFO >, void >
878  addLogLevel();
879 
884 
890  {
892  string indent( level*2, ' ' );
893 
894  for( auto const & subGroupIter : m_subGroups )
895  {
896  std::cout << indent << subGroupIter.second->getName() << std::endl;
897  subGroupIter.second->generateDataStructureSkeleton( level + 1 );
898  }
899  }
900 
904  virtual void expandObjectCatalogs() {}
905 
912  virtual void setSchemaDeviations( xmlWrapper::xmlNode schemaRoot,
913  xmlWrapper::xmlNode schemaParent,
914  integer documentationType )
915  {
916  GEOS_UNUSED_VAR( schemaRoot );
917  GEOS_UNUSED_VAR( schemaParent );
918  GEOS_UNUSED_VAR( documentationType );
919  }
920 
922 
927 
932  virtual void registerDataOnMeshRecursive( Group & meshBodies );
933 
941  virtual void registerDataOnMesh( Group & meshBodies )
942  {
943  GEOS_UNUSED_VAR( meshBodies );
944  }
945 
947 
952 
964  virtual localIndex packSize( string_array const & wrapperNames,
965  integer const recursive,
966  bool onDevice,
967  parallelDeviceEvents & events ) const;
968 
981  virtual localIndex packSize( string_array const & wrapperNames,
982  arrayView1d< localIndex const > const & packList,
983  integer const recursive,
984  bool onDevice,
985  parallelDeviceEvents & events ) const;
986 
999  integer const recursive,
1000  bool onDevice,
1001  parallelDeviceEvents & events ) const;
1002 
1021  virtual localIndex pack( buffer_unit_type * & buffer,
1022  string_array const & wrapperNames,
1023  integer const recursive,
1024  bool onDevice,
1025  parallelDeviceEvents & events ) const;
1026 
1045  virtual localIndex pack( buffer_unit_type * & buffer,
1046  string_array const & wrapperNames,
1047  arrayView1d< localIndex const > const & packList,
1048  integer const recursive,
1049  bool onDevice,
1050  parallelDeviceEvents & events ) const;
1051 
1070  arrayView1d< localIndex const > const & packList,
1071  integer const recursive,
1072  bool onDevice,
1073  parallelDeviceEvents & events ) const;
1074 
1094  virtual localIndex unpack( buffer_unit_type const * & buffer,
1095  arrayView1d< localIndex > & packList,
1096  integer const recursive,
1097  bool onDevice,
1098  parallelDeviceEvents & events,
1099  MPI_Op op=MPI_REPLACE );
1100 
1102 
1103  //***********************************************************************************************
1104 
1105  //START_SPHINX_INCLUDE_GET_WRAPPER
1113 
1122  template< typename KEY >
1123  WrapperBase const & getWrapperBase( KEY const & key ) const
1124  {
1125  WrapperBase const * const wrapper = m_wrappers[ key ];
1126  GEOS_THROW_IF( wrapper == nullptr,
1127  GEOS_FMT( "No wrapper named '{}' found.\n{}", geos::format::toStringForFmt( key ), dumpWrappersNames() ),
1129 
1130  return *wrapper;
1131  }
1132 
1136  template< typename KEY >
1137  WrapperBase & getWrapperBase( KEY const & key )
1138  {
1139  WrapperBase * const wrapper = m_wrappers[ key ];
1140  GEOS_THROW_IF( wrapper == nullptr,
1141  GEOS_FMT( "No wrapper named '{}' found.\n{}", geos::format::toStringForFmt( key ), 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:217
#define GEOS_THROW_IF(COND, MSG,...)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:308
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:362
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:605
T const & getGroupByPath(string const &path) const
Retrieve a group from the hierarchy using a path.
Definition: Group.hpp:369
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:665
virtual void expandObjectCatalogs()
Expand any catalogs in the data structure.
Definition: Group.hpp:904
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:553
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:1137
WrapperBase const & getWrapperBase(KEY const &key) const
Return a reference to a WrapperBase stored in this group.
Definition: Group.hpp:1123
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:515
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:535
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:392
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:405
indexType getWrapperIndex(string const &name) const
Definition: Group.hpp:1152
bool hasSubGroupOfType() const
Check whether a sub-group exists by type.
Definition: Group.hpp:414
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:464
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:649
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:941
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:337
void forSubGroups(LAMBDA &&lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:500
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:682
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:637
subGroupMap const & getSubGroups() const
Get the subgroups object.
Definition: Group.hpp:385
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:579
void generateDataStructureSkeleton(integer const level)
Build a complete datastructure for schema generation.
Definition: Group.hpp:889
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:912
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:378
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