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  "Group " << getDataContext() << " has no child named " << key << std::endl
323  << dumpSubGroupsNames(),
324  std::domain_error );
325  T * const castedChild = dynamicCast< T * >( child );
326  GEOS_THROW_IF( castedChild == nullptr,
327  GEOS_FMT( "{} was expected to be a '{}'.",
328  child->getDataContext(), LvArray::system::demangleType< T >() ),
329  BadTypeError );
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  "Group " << getDataContext() << " has no child named " << key << std::endl
342  << dumpSubGroupsNames(),
343  std::domain_error );
344  T const * const castedChild = dynamicCast< T const * >( child );
345  GEOS_THROW_IF( castedChild == nullptr,
346  GEOS_FMT( "{} was expected to be a '{}'.",
347  child->getDataContext(), LvArray::system::demangleType< T >() ),
348  BadTypeError );
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 
397  std::vector< string > getSubGroupsNames() const;
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  "Group " << getDataContext() << " has no wrapper named " << key << std::endl
1128  << dumpWrappersNames(),
1129  std::domain_error );
1130 
1131  return *wrapper;
1132  }
1133 
1137  template< typename KEY >
1138  WrapperBase & getWrapperBase( KEY const & key )
1139  {
1140  WrapperBase * const wrapper = m_wrappers[ key ];
1141  GEOS_THROW_IF( wrapper == nullptr,
1142  "Group " << getDataContext() << " has no wrapper named " << key << std::endl
1143  << dumpWrappersNames(),
1144  std::domain_error );
1145 
1146  return *wrapper;
1147  }
1148 
1154  indexType getWrapperIndex( string const & name ) const
1155  { return m_wrappers.getIndex( name ); }
1156 
1161  wrapperMap const & wrappers() const
1162  { return m_wrappers; }
1163 
1168  { return m_wrappers; }
1169 
1175  { return m_wrappers.size(); }
1176 
1180  std::vector< string > getWrappersNames() const;
1181 
1183 
1196 
1203  template< typename LOOKUP_TYPE >
1204  bool hasWrapper( LOOKUP_TYPE const & lookup ) const
1205  { return m_wrappers[ lookup ] != nullptr; }
1206 
1215  template< typename T, typename LOOKUP_TYPE >
1216  Wrapper< T > const & getWrapper( LOOKUP_TYPE const & index ) const
1217  {
1218  WrapperBase const & wrapper = getWrapperBase( index );
1219  return dynamicCast< Wrapper< T > const & >( wrapper );
1220  }
1221 
1225  template< typename T, typename LOOKUP_TYPE >
1226  Wrapper< T > & getWrapper( LOOKUP_TYPE const & index )
1227  {
1228  WrapperBase & wrapper = getWrapperBase( index );
1229  return dynamicCast< Wrapper< T > & >( wrapper );
1230  }
1231 
1240  template< typename T, typename LOOKUP_TYPE >
1241  Wrapper< T > const * getWrapperPointer( LOOKUP_TYPE const & index ) const
1242  { return dynamicCast< Wrapper< T > const * >( m_wrappers[ index ] ); }
1243 
1247  template< typename T, typename LOOKUP_TYPE >
1248  Wrapper< T > * getWrapperPointer( LOOKUP_TYPE const & index )
1249  { return dynamicCast< Wrapper< T > * >( m_wrappers[ index ] ); }
1250 
1252 
1263 
1273  template< typename T, typename LOOKUP_TYPE >
1275  getReference( LOOKUP_TYPE const & lookup ) const
1276  { return getWrapper< T >( lookup ).reference(); }
1277 
1281  template< typename T, typename LOOKUP_TYPE >
1282  T & getReference( LOOKUP_TYPE const & lookup )
1283  { return getWrapper< T >( lookup ).reference(); }
1284 
1285  //END_SPHINX_INCLUDE_GET_WRAPPER
1286 
1288 
1293 
1298  virtual void resize( localIndex const newSize );
1299 
1304  virtual void reserve( indexType const newsize );
1305 
1310  inline localIndex capacity() const
1311  { return m_capacity; }
1312 
1317  inline localIndex size() const
1318  { return m_size; }
1319 
1321 
1326 
1331  inline string const & getName() const
1332  { return m_name; }
1333 
1339  string getPath() const;
1340 
1345  DataContext const & getDataContext() const
1346  { return *m_dataContext; }
1347 
1355  template< typename KEY >
1356  DataContext const & getWrapperDataContext( KEY key ) const
1357  { return getWrapperBase< KEY >( key ).getDataContext(); }
1358 
1365  {
1366  GEOS_THROW_IF( m_parent == nullptr, "Group at " << getDataContext() << " does not have a parent.", std::domain_error );
1367  return *m_parent;
1368  }
1369 
1373  Group const & getParent() const
1374  {
1375  GEOS_THROW_IF( m_parent == nullptr, "Group at " << getDataContext() << " does not have a parent.", std::domain_error );
1376  return *m_parent;
1377  }
1378 
1382  bool hasParent() const
1383  { return m_parent != nullptr; }
1384 
1390  { return m_parent->getSubGroups().getIndex( m_name ); }
1391 
1397  localIndex getSubGroupIndex( keyType const & key ) const;
1398 
1403  int sizedFromParent() const
1404  { return m_sizedFromParent; }
1405 
1412  {
1413  m_sizedFromParent = val;
1414  return *this;
1415  }
1420  RestartFlags getRestartFlags() const { return m_restart_flags; }
1421 
1426  void setRestartFlags( RestartFlags flags ) { m_restart_flags = flags; }
1427 
1432  InputFlags getInputFlags() const { return m_input_flags; }
1433 
1438  void setInputFlags( InputFlags flags ) { m_input_flags = flags; }
1439 
1444  {
1446  static constexpr char const * logLevelString() { return "logLevel"; }
1447  };
1448 
1450 
1457  virtual bool registerCallback( void * func, const std::type_info & funcType )
1458  {
1459  GEOS_UNUSED_VAR( func );
1460  GEOS_UNUSED_VAR( funcType );
1461  return false;
1462  }
1463 
1468 
1473  conduit::Node & getConduitNode()
1474  { return m_conduitNode; }
1475 
1477  conduit::Node const & getConduitNode() const
1478  { return m_conduitNode; }
1479 
1484 
1489 
1494 
1499 
1504  void setLogLevel( integer const logLevel ) { m_logLevel = logLevel; }
1505 
1507  integer getLogLevel() const { return m_logLevel; }
1509 
1513  virtual void reinit() {}
1514 
1519 #if defined(GEOS_USE_PYGEOSX)
1520  virtual PyTypeObject * getPythonType() const;
1521 #endif
1522 
1523 protected:
1524 
1532 
1537  virtual void postInputInitialization() {}
1538 
1542  virtual void initializePreSubGroups()
1543  {}
1544 
1549  {}
1550 
1555  {}
1556 
1561  {}
1562 
1567  {}
1568 
1569 
1570 
1572 
1573 private:
1581  virtual void processInputFile( xmlWrapper::xmlNode const & targetNode,
1582  xmlWrapper::xmlNodePos const & nodePos );
1583 
1584  Group const & getBaseGroupByPath( string const & path ) const;
1585 
1600  template< bool DO_PACKING >
1601  localIndex packImpl( buffer_unit_type * & buffer,
1602  array1d< string > const & wrapperNames,
1603  arrayView1d< localIndex const > const & packList,
1604  integer const recursive,
1605  bool onDevice,
1606  parallelDeviceEvents & events ) const;
1607 
1608  //START_SPHINX_INCLUDE_02
1610  Group * m_parent = nullptr;
1611 
1613  integer m_sizedFromParent;
1614 
1616  wrapperMap m_wrappers;
1617 
1619  subGroupMap m_subGroups;
1620 
1623  indexType m_size;
1624 
1627  indexType m_capacity;
1628 
1630  string m_name;
1631 
1633  integer m_logLevel;
1634 
1635 
1636  //END_SPHINX_INCLUDE_02
1637 
1639  RestartFlags m_restart_flags;
1640 
1642  InputFlags m_input_flags;
1643 
1645  conduit::Node & m_conduitNode;
1646 
1647  // Keep track of log levels & descriptions
1648  std::unique_ptr< LogLevelsRegistry > m_logLevelsRegistry;
1649 
1652  std::unique_ptr< DataContext > m_dataContext;
1653 
1654 };
1655 
1660 
1665 
1666 // Doxygen bug - sees this as a separate function
1668 template< typename T, typename TBASE >
1669 Wrapper< TBASE > & Group::registerWrapper( string const & name,
1670  ViewKey::index_type * const rkey )
1671 {
1672  std::unique_ptr< TBASE > newObj = std::make_unique< T >();
1673  m_wrappers.insert( name,
1674  new Wrapper< TBASE >( name, *this, std::move( newObj ) ),
1675  true );
1676 
1677  if( rkey != nullptr )
1678  {
1679  *rkey = m_wrappers.getIndex( name );
1680  }
1681 
1682  Wrapper< TBASE > & rval = getWrapper< TBASE >( name );
1683  if( rval.sizedFromParent() == 1 )
1684  {
1685  rval.resize( size());
1686  }
1687  return rval;
1688 }
1690 
1691 template< typename T, typename TBASE >
1693 {
1694  ViewKey::index_type index;
1695  Wrapper< TBASE > & rval = registerWrapper< T, TBASE >( viewKey.key(), &index );
1696  viewKey.setIndex( index );
1697 
1698  return rval;
1699 }
1700 
1701 
1702 template< typename T >
1703 Wrapper< T > & Group::registerWrapper( string const & name,
1704  std::unique_ptr< T > newObject )
1705 {
1706  static_assert( !std::is_base_of< WrapperBase, T >::value, "This function should not be used for `WrapperBase`. Use the dedicated `registerWrapper` instead." );
1707  m_wrappers.insert( name,
1708  new Wrapper< T >( name, *this, std::move( newObject ) ),
1709  true );
1710 
1711  Wrapper< T > & rval = getWrapper< T >( name );
1712  if( rval.sizedFromParent() == 1 )
1713  {
1714  rval.resize( size());
1715  }
1716  return rval;
1717 }
1718 
1719 template< typename T >
1720 Wrapper< T > & Group::registerWrapper( string const & name,
1721  T * newObject )
1722 {
1723  static_assert( !std::is_base_of< WrapperBase, T >::value, "This function should not be used for `WrapperBase`. Use the dedicated `registerWrapper` instead." );
1724  m_wrappers.insert( name,
1725  new Wrapper< T >( name, *this, newObject ),
1726  true );
1727 
1728  Wrapper< T > & rval = getWrapper< T >( name );
1729  if( rval.sizedFromParent() == 1 )
1730  {
1731  rval.resize( size());
1732  }
1733  return rval;
1734 }
1735 
1736 template< typename LOG_LEVEL_INFO >
1737 std::enable_if_t< geos::is_log_level_info< LOG_LEVEL_INFO >, void >
1739 {
1740  GEOS_ERROR_IF( m_logLevelsRegistry == nullptr, "You cannot call addLogLevel after schema generation" );
1741 
1742  Wrapper< integer > * wrapper = getWrapperPointer< integer >( viewKeyStruct::logLevelString() );
1743  if( wrapper == nullptr )
1744  {
1745  wrapper = &registerWrapper( viewKeyStruct::logLevelString(), &m_logLevel );
1746  wrapper->setApplyDefaultValue( 0 );
1747  wrapper->setInputFlag( InputFlags::OPTIONAL );
1748  }
1749  m_logLevelsRegistry->addEntry( LOG_LEVEL_INFO::getMinLogLevel(),
1750  LOG_LEVEL_INFO::getDescription() );
1751  wrapper->setDescription( m_logLevelsRegistry->buildLogLevelDescription());
1752 }
1753 
1754 } /* end namespace dataRepository */
1755 } /* end namespace geos */
1756 
1757 #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: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:1542
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:1310
virtual void postInputInitialization()
Definition: Group.hpp:1537
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:1438
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:1403
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:1432
DataContext const & getDataContext() const
Definition: Group.hpp:1345
bool hasWrapper(LOOKUP_TYPE const &lookup) const
Check if a wrapper exists.
Definition: Group.hpp:1204
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:1167
localIndex getIndexInParent() const
Get the group's index within its parent group.
Definition: Group.hpp:1389
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:1548
virtual void reinit()
Performs re-initialization of certain variable depending on the solver being used.
Definition: Group.hpp:1513
void setRestartFlags(RestartFlags flags)
Set flags that control restart output of this group.
Definition: Group.hpp:1426
Wrapper< T > & getWrapper(LOOKUP_TYPE const &index)
Retrieve a Wrapper stored in this group.
Definition: Group.hpp:1226
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:1331
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:1275
WrapperBase & getWrapperBase(KEY const &key)
Return a reference to a WrapperBase stored in this group.
Definition: Group.hpp:1138
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:1473
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:1560
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:1420
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:1738
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:1174
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:1364
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:1566
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:1154
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:1457
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:1216
T & getReference(LOOKUP_TYPE const &lookup)
Look up a wrapper and get reference to wrapped object.
Definition: Group.hpp:1282
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:1317
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:1248
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
std::vector< string > getWrappersNames() const
integer getLogLevel() const
Definition: Group.hpp:1507
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
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:1504
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:1477
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:1411
DataContext const & getWrapperDataContext(KEY key) const
Definition: Group.hpp:1356
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:1161
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:1554
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:1241
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: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:1664
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
std::string_view string_view
String type.
Definition: DataTypes.hpp:94
Exception class used to report errors from type conversion.
Definition: Logger.hpp:564
Structure to hold scoped key names.
Definition: Group.hpp:1444
static constexpr char const * logLevelString()
Definition: Group.hpp:1446