20 #ifndef GEOSX_DATAREPOSITORY_GROUP_HPP_ 21 #define GEOSX_DATAREPOSITORY_GROUP_HPP_ 32 #ifndef NOCHARTOSTRING_KEYLOOKUP 33 #define NOCHARTOSTRING_KEYLOOKUP 0 53 namespace dataRepository
93 Group *
const parent );
166 return typeid(*this);
176 return typeToCheck == get_typeid();
183 void PrintDataHierarchy(
integer indent = 0 );
188 string dumpInputOptions()
const;
208 template<
typename T = Group >
209 T * RegisterGroup(
std::string const & name, std::unique_ptr< T > newObject );
221 template<
typename T = Group >
234 template<
typename T = Group >
237 return RegisterGroup< T >( name, std::move( std::make_unique< T >( name,
this )) );
250 template<
typename T = Group >
253 T * rval = RegisterGroup< T >( keyIndex.
Key(), std::move( std::make_unique< T >( keyIndex.
Key(), this )) );
254 keyIndex.
setIndex( this->m_subGroups.getIndex( keyIndex.
Key()) );
269 template<
typename T = Group,
typename TBASE = Group >
272 std::unique_ptr< TBASE > newGroup = TBASE::CatalogInterface::Factory( catalogName, name,
this );
273 return RegisterGroup< T >( name, std::move( newGroup ) );
290 virtual Group * CreateChild(
string const & childKey,
string const & childName );
307 template<
typename T >
310 return dynamicCast< T >( group );
319 template<
typename T >
322 return dynamicCast< T >( group );
330 template<
typename T >
333 return dynamicCast< T >( this );
341 template<
typename T >
344 return dynamicCast< T >( this );
373 template<
typename T = Group >
376 return group_cast< T * >( m_subGroups[index] );
382 template<
typename T = Group >
385 return group_cast< T
const * >( m_subGroups[index] );
394 template<
typename T = Group >
397 return group_cast< T * >( m_subGroups[name] );
403 template<
typename T = Group >
405 {
return group_cast< T
const * >( m_subGroups[name] ); }
413 template<
typename T = Group >
415 {
return dynamicCast< T & >( *m_subGroups[ key ] ); }
420 template<
typename T = Group >
422 {
return dynamicCast< T const & >( *m_subGroups[ key ] ); }
427 template<
typename T = Group >
429 {
return dynamicCast< T & >( *m_subGroups[key] ); }
434 template<
typename T = Group >
436 {
return dynamicCast< T const & >( *m_subGroups[key] ); }
444 template<
typename T = Group >
447 return group_cast< T * >( m_subGroups[key] );
453 template<
typename T = Group >
456 return group_cast< T
const * >( m_subGroups[key] );
467 template<
typename T = Group >
470 return const_cast< T *
>(
const_cast< Group const *
>(
this)->GetGroupByPath< T >( path ));
476 template<
typename T = Group >
477 T
const * GetGroupByPath(
string const & path )
const;
512 return (m_subGroups[name] !=
nullptr);
529 template<
typename CASTTYPE,
typename CONTAINERTYPE,
typename LAMBDA >
530 static bool applyLambdaToContainer( CONTAINERTYPE & container, LAMBDA && lambda )
532 using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, CASTTYPE
const, CASTTYPE >;
533 T *
const castedContainer =
dynamic_cast< T *
>( &container );
535 if( castedContainer !=
nullptr )
537 lambda( *castedContainer );
556 template<
typename T0,
typename T1,
typename ... CASTTYPES,
typename CONTAINERTYPE,
typename LAMBDA >
559 using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, T0
const, T0 >;
560 T *
const castedContainer =
dynamic_cast< T *
>( &container );
562 if( castedContainer !=
nullptr )
564 lambda( *castedContainer );
568 return applyLambdaToContainer< T1, CASTTYPES... >( container, std::forward< LAMBDA >( lambda ) );
592 template<
typename GROUPTYPE =
Group,
typename ... GROUPTYPES,
typename LAMBDA >
595 for(
auto & subGroupIter : m_subGroups )
597 applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&](
auto & castedSubGroup )
599 lambda( castedSubGroup );
607 template<
typename GROUPTYPE =
Group,
typename ... GROUPTYPES,
typename LAMBDA >
610 for(
auto const & subGroupIter : m_subGroups )
612 applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&](
auto const & castedSubGroup )
614 lambda( castedSubGroup );
630 template<
typename GROUPTYPE =
Group,
typename ... GROUPTYPES,
typename LOOKUP_CONTAINER,
typename LAMBDA >
631 void forSubGroups( LOOKUP_CONTAINER
const & subGroupKeys, LAMBDA lambda )
634 for(
auto const & subgroup : subGroupKeys )
636 applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *GetGroup( subgroup ), [&](
auto & castedSubGroup )
638 lambda( counter, castedSubGroup );
655 template<
typename GROUPTYPE =
Group,
typename ... GROUPTYPES,
typename LOOKUP_CONTAINER,
typename LAMBDA >
656 void forSubGroups( LOOKUP_CONTAINER
const & subGroupKeys, LAMBDA lambda )
const 659 for(
auto const & subgroup : subGroupKeys )
661 applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *GetGroup( subgroup ), [&](
auto const & castedSubGroup )
663 lambda( counter, castedSubGroup );
687 template<
typename LAMBDA >
690 for(
auto & wrapperIter : m_wrappers )
692 lambda( *wrapperIter.second );
699 template<
typename LAMBDA >
702 for(
auto const & wrapperIter : m_wrappers )
704 lambda( *wrapperIter.second );
715 template<
typename TYPE,
typename ... TYPES,
typename LAMBDA >
718 for(
auto & wrapperIter : m_wrappers )
720 applyLambdaToContainer< Wrapper< TYPE >,
Wrapper< TYPES >... >( *wrapperIter.second,
721 std::forward< LAMBDA >( lambda ));
732 template<
typename TYPE,
typename ... TYPES,
typename LAMBDA >
735 for(
auto const & wrapperIter : m_wrappers )
737 applyLambdaToContainer< Wrapper< TYPE >,
Wrapper< TYPES >... >( *wrapperIter.second,
738 std::forward< LAMBDA >( lambda ));
762 void Initialize(
Group *
const group );
773 virtual void InitializationOrder(
string_array & order );
792 void InitializePostInitialConditions(
Group *
const group );
801 void postRestartInitializationRecursive(
Group *
const domain );
814 void PostProcessInputRecursive();
833 template<
typename T,
typename TBASE=T >
835 wrapperMap::KeyIndex::index_type *
const rkey =
nullptr );
844 template<
typename T,
typename TBASE=T >
845 Wrapper< TBASE > * registerWrapper( Group::wrapperMap::KeyIndex
const & viewKey );
854 template<
typename T >
856 std::unique_ptr< T > newObject );
865 template<
typename T >
875 WrapperBase * registerWrapper(
string const & name,
876 std::unique_ptr< WrapperBase > wrapper );
882 void deregisterWrapper(
string const & name );
898 ExpandObjectCatalogs();
901 for(
auto const & subGroupIter : m_subGroups )
903 std::cout << indent << subGroupIter.second->getName() << std::endl;
904 subGroupIter.second->GenerateDataStructureSkeleton( level + 1 );
934 virtual void RegisterDataOnMeshRecursive(
Group *
const meshBodies );
943 virtual void RegisterDataOnMesh(
Group *
const meshBodies );
962 bool on_device =
false )
const;
976 bool on_device =
false )
const;
996 bool on_device =
false )
const;
1017 bool on_device =
false )
const;
1037 bool on_device =
false );
1059 {
return m_wrappers[index]; }
1065 {
return m_wrappers[index]; }
1073 {
return m_wrappers[name]; }
1079 {
return m_wrappers[name]; }
1087 {
return m_wrappers[keyIndex]; }
1093 {
return m_wrappers[keyIndex]; }
1102 return m_wrappers.getIndex( name );
1143 template<
typename LOOKUP_TYPE >
1146 return (m_wrappers[lookup] !=
nullptr);
1156 template<
typename T,
typename LOOKUP_TYPE >
1159 return dynamicCast< Wrapper< T >
const * >( m_wrappers[index] );
1165 template<
typename T,
typename LOOKUP_TYPE >
1167 {
return const_cast< Wrapper< T > *
>(
const_cast< Group const *
>(
this)->getWrapper< T >( index ) ); }
1175 template<
typename T >
1177 {
return getWrapper< T >(
string( key ) ); }
1182 template<
typename T >
1184 {
return getWrapper< T >(
string( key ) ); }
1209 template<
typename T,
typename LOOKUP_TYPE >
1213 Wrapper< T > const *
const wrapper = getWrapper< T >( lookup );
1214 if( wrapper ==
nullptr )
1216 if( hasWrapper( lookup ) )
1218 GEOSX_ERROR(
"call to getWrapper results in nullptr but a view exists. Most likely given the incorrect type. lookup : " << lookup );
1220 GEOSX_ERROR(
"call to getWrapper results in nullptr and a view does not exist. lookup : " << lookup );
1229 template<
typename T,
typename LOOKUP_TYPE >
1233 Wrapper< T > *
const wrapper = getWrapper< T >( lookup );
1234 if( wrapper ==
nullptr )
1236 if( hasWrapper( lookup ) )
1238 GEOSX_ERROR(
"call to getWrapper results in nullptr but a view exists. Most likely given the incorrect type. lookup : " << lookup );
1240 GEOSX_ERROR(
"call to getWrapper results in nullptr and a view does not exist. lookup : " << lookup );
1255 template<
typename T >
1258 {
return getReference< T >(
string( name ) ); }
1263 template<
typename T >
1265 {
return getReference< T >(
string( name ) ); }
1280 virtual void resize(
localIndex const newSize );
1286 virtual void reserve(
indexType const newsize );
1339 return m_parent->GetSubGroups().getIndex( this->m_name );
1348 return m_sizedFromParent;
1358 m_sizedFromParent = val;
1398 return m_conduitNode;
1404 void prepareToWrite();
1409 void finishWriting();
1414 void loadFromConduit();
1417 void enableLogLevelInput();
1500 Group * m_parent =
nullptr;
1533 conduit::Node & m_conduitNode;
1549 template<
typename T >
1551 std::unique_ptr< T > newObject )
1553 newObject->m_parent =
this;
1554 return dynamicCast< T * >( m_subGroups.insert( name, newObject.release(), true ) );
1558 template<
typename T >
1562 return dynamicCast< T * >( m_subGroups.insert( name, newObject,
false ) );
1567 template<
typename T,
typename TBASE >
1569 ViewKey::index_type *
const rkey )
1571 std::unique_ptr< TBASE > newObj = std::make_unique< T >();
1572 m_wrappers.insert( name,
1576 if( rkey !=
nullptr )
1578 *rkey = m_wrappers.getIndex( name );
1584 rval->
resize( this->size());
1590 template<
typename T,
typename TBASE >
1593 ViewKey::index_type index;
1594 Wrapper< TBASE > *
const rval = registerWrapper< T, TBASE >( viewKey.Key(), &index );
1595 viewKey.setIndex( index );
1601 template<
typename T >
1603 std::unique_ptr< T > newObject )
1605 m_wrappers.insert( name,
1606 new Wrapper< T >( name,
this, std::move( newObject ) ),
1612 rval->
resize( this->size());
1619 template<
typename T >
1623 m_wrappers.insert( name,
1630 rval->
resize( this->size());
1635 template<
typename T >
1636 T
const * Group::GetGroupByPath(
string const & path )
const 1641 return group_cast< T
const * >( this );
1644 size_t directoryMarker = path.find(
'/' );
1646 if( directoryMarker == std::string::npos )
1649 return this->GetGroup< T >( path );
1654 string const child = path.substr( 0, directoryMarker );
1655 string const subPath = path.substr( directoryMarker+1, path.size());
1657 if( directoryMarker == 0 )
1659 if( this->getParent() == nullptr )
1661 return this->GetGroupByPath< T >( subPath );
1665 return this->getParent()->GetGroupByPath< T >( path );
1668 else if( child[0] ==
'.' )
1670 if( child[1] ==
'.' )
1672 return this->getParent()->GetGroupByPath< T >( subPath );
1676 return this->GetGroupByPath< T >( subPath );
1681 return m_subGroups[child]->GetGroupByPath< T >( subPath );
Wrapper< T > * getWrapper(char const *const key)
Retrieve a Wrapper stored in this group.
int sizedFromParent() const
Check whether this wrapper is resized when its parent is resized.
void GenerateDataStructureSkeleton(integer const level)
Build a complete datastructure for schema generation.
virtual void resize(int ndims, localIndex const *const dims) override
Calls T::resize( num_dims, dims )
void forWrappers(LAMBDA lambda)
Apply the given functor to wrappers that can be cast to one of specified types.
void setIndex(INDEX_TYPE const &index) const
Set the index.
T * GetGroup(string const &name)
Retrieve a sub-group from the current Group using a string.
T & getReference(char const *const name)
#define GEOSX_DECLTYPE_AUTO_RETURN
Doxygen can't parse a decltype( auto ) return type, using this gets around that.
localIndex numSubGroups() const
return the number of sub groups in this Group
pugi::xml_node xmlNode
Alias for the type of an xml node.
virtual void ExpandObjectCatalogs()
Expand any catalogs in the data structure.
Group * getParent()
Access the group's parent.
localIndex capacity() const
Get the "capacity" of the group, which determines the capacity of resizable wrappers.
void forSubGroups(LOOKUP_CONTAINER const &subGroupKeys, LAMBDA lambda) const
Wrapper< T > const * getWrapper(char const *const key) const
Retrieve a Wrapper stored in this group.
virtual const std::type_info & get_typeid() const
Get typeid for current group.
Group * setSizedFromParent(int val)
Set whether this wrapper is resized when its parent is resized.
T * GetGroupByPath(string const &path)
Retrieve a group from the hierarchy using a path.
bool hasWrapper(LOOKUP_TYPE const &lookup) const
Check if a wrapper exists.
virtual void InitializePostInitialConditions_PreSubGroups(Group *const group)
Called by InitializePostInitialConditions() prior to initializing sub-Groups.
integer getLogLevel() const
bool hasGroup(std::string const &name) const
Check whether a sub-group exists.
T const * GetGroup(string const &name) const
Retrieve a sub-group from the current Group using a string.
virtual void PostProcessInput()
This class serves to provide a "view" of a multidimensional array.
static T group_cast(Group const *group)
Downcast a Group const *.
T group_cast()
Downcast this Group.
T const * GetGroup(localIndex index) const
Retrieve a sub-group from the current Group using an index.
T & getReference(LOOKUP_TYPE const &lookup)
Look up a wrapper and get reference to wrapped object.
GEOSX_DECLTYPE_AUTO_RETURN getReference(char const *const name) const
virtual void InitializePostInitialConditions_PostSubGroups(Group *const group)
Called by InitializePostInitialConditions() after to initializing sub-Groups.
virtual void InitializePostSubGroups(Group *const group)
Called by Initialize() after to initializing sub-Groups.
wrapperMap const & wrappers() const
Get access to the internal wrapper storage.
void forSubGroups(LOOKUP_CONTAINER const &subGroupKeys, LAMBDA lambda)
conduit::Node & getConduitNode()
Get the Conduit node object associated with this group.
virtual void postRestartInitialization(Group *const domain)
Performs initialization required after reading from a restart file.
WrapperBase const * getWrapperBase(std::string const &name) const
Retrieve a WrapperBase stored in this group.
Group::wrapperMap::KeyIndex ViewKey
Type alias for KeyIndexT type used for wrapper lookups.
WrapperBase * getWrapperBase(wrapperMap::KeyIndex const &keyIndex)
Retrieve a WrapperBase stored in this group.
Group const * getParent() const
Access the group's parent.
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...
virtual void InitializePreSubGroups(Group *const group)
Called by Initialize() prior to initializing sub-Groups.
void forWrappers(LAMBDA lambda) const
Apply the given functor to wrappers.
GEOSX_DECLTYPE_AUTO_RETURN getReference(LOOKUP_TYPE const &lookup) const
Look up a wrapper and get reference to wrapped object.
Base class for all wrappers containing common operations.
void forSubGroups(LAMBDA lambda) const
Apply the given functor to subgroups that can be casted to one of specified types.
T const & GetGroupReference(subGroupMap::KeyIndex const &key) const
T * RegisterGroup(std::string const &name)
Register a new Group as a sub-group of current Group.
string keyType
The default key type for entries in the hierarchy.
void forWrappers(LAMBDA lambda)
Apply the given functor to wrappers.
static T group_cast(Group *group)
Downcast a Group *.
T * RegisterGroup(std::string const &name, std::string const &catalogName)
Register a new Group as a sub-group of current Group.
signed char buffer_unit_type
Type stored in communication buffers.
Wrapper< T > const * getWrapper(LOOKUP_TYPE const &index) const
Retrieve a Wrapper stored in this group.
localIndex getIndexInParent() const
Get the group's index withing its parent group.
localIndex indexType
The default index type for entries the hierarchy.
subGroupMap & GetSubGroups()
Get the subgroups object.
WrapperBase * getWrapperBase(std::string const &name)
Retrieve a WrapperBase stored in this group.
std::int32_t integer
Signed integer type.
WrapperBase const * getWrapperBase(wrapperMap::KeyIndex const &keyIndex) const
Retrieve a WrapperBase stored in this group.
#define GEOSX_ERROR(msg)
Raise a hard error and terminate the program.
This class provides the base class/interface for the catalog value objects.
T group_cast() const
Downcast this Group.
KEY_TYPE const & Key() const
Access for the key.
const string getName() const
Get group name.
Wrapper< T > * getWrapper(LOOKUP_TYPE const &index)
Retrieve a Wrapper stored in this group.
void setRestartFlags(RestartFlags flags)
Set flags that control restart output of this group.
#define GEOSX_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
RestartFlags getRestartFlags() const
Get flags that control restart output of this group.
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers...
T & reference()
Accessor for m_data.
T * RegisterGroup(subGroupMap::KeyIndex const &keyIndex)
Register a new Group as a sub-group of current Group.
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
void setInputFlags(InputFlags flags)
Set input flags for schema generation.
T const & getGroupReference(string const &key) const
InputFlags getInputFlags() const
Get input flags for schema generation.
void forSubGroups(LAMBDA lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
T * GetGroup(subGroupMap::KeyIndex const &key)
Retrieve a sub-group from the current Group using a KeyIndexT.
std::string string
String type.
void forWrappers(LAMBDA lambda) const
Apply the given functor to wrappers that can be cast to one of specified types.
bool CheckTypeID(std::type_info const &typeToCheck) const
Check a type_info against the type_info of this Group.
subGroupMap const & GetSubGroups() const
Get the subgroups object.
T & GetGroupReference(subGroupMap::KeyIndex const &key)
WrapperBase const * getWrapperBase(indexType const index) const
Retrieve a WrapperBase stored in this group.
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
T const * GetGroup(subGroupMap::KeyIndex const &key) const
Retrieve a sub-group from the current Group using a KeyIndexT.
WrapperBase * getWrapperBase(indexType const index)
Retrieve a WrapperBase stored in this group.
T * GetGroup(localIndex index)
Retrieve a sub-group from the current Group using an index.
wrapperMap & wrappers()
Get access to the internal wrapper storage.
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 & getGroupReference(string const &key)
indexType getWrapperIndex(std::string const &name) const
integer sizedFromParent() const
Check whether this Group is resized when its parent is resized.