20 #ifndef GEOS_DATAREPOSITORY_GROUP_HPP_
21 #define GEOS_DATAREPOSITORY_GROUP_HPP_
33 #ifndef NOCHARTOSTRING_KEYLOOKUP
35 #define NOCHARTOSTRING_KEYLOOKUP 0
47 namespace dataRepository
85 explicit Group(
string const & name,
86 Group *
const parent );
94 explicit Group(
string const & name,
95 conduit::Node & rootNode );
196 template<
typename T = Group >
199 newObject->m_parent =
this;
200 return dynamicCast< T & >( *m_subGroups.
insert( name, newObject.release(),
true ) );
213 template<
typename T = Group >
215 {
return dynamicCast< T & >( *m_subGroups.
insert( name, newObject,
false ) ); }
227 template<
typename T = Group >
229 {
return registerGroup< T >( name, std::make_unique< T >( name,
this ) ); }
241 template<
typename T = Group >
244 T & rval = registerGroup< T >( keyIndex.
key(), std::make_unique< T >( keyIndex.
key(),
this ) );
260 template<
typename T = Group,
typename TBASE = Group >
263 std::unique_ptr< TBASE > newGroup = TBASE::CatalogInterface::Factory( catalogName, name,
this );
264 return registerGroup< T >( name, std::move( newGroup ) );
313 template<
typename T = Group,
typename KEY =
void >
315 {
return dynamicCast< T * >( m_subGroups[ key ] ); }
320 template<
typename T = Group,
typename KEY =
void >
322 {
return dynamicCast< T const * >( m_subGroups[ key ] ); }
332 template<
typename T = Group,
typename KEY =
void >
335 Group *
const child = m_subGroups[ key ];
337 "Group " <<
getDataContext() <<
" has no child named " << key << std::endl
341 return dynamicCast< T & >( *child );
347 template<
typename T = Group,
typename KEY =
void >
350 Group const *
const child = m_subGroups[ key ];
352 "Group " <<
getDataContext() <<
" has no child named " << key << std::endl
356 return dynamicCast< T const & >( *child );
368 template<
typename T = Group >
370 {
return dynamicCast< T & >(
const_cast< Group &
>( getBaseGroupByPath( path ) ) ); }
375 template<
typename T = Group >
377 {
return dynamicCast< T const & >( getBaseGroupByPath( path ) ); }
386 {
return m_subGroups; }
393 {
return m_subGroups; }
411 template<
typename T = Group >
413 {
return dynamicCast< T const * >( m_subGroups[ name ] ) !=
nullptr; }
420 template<
typename T >
423 bool hasSubGroup =
false;
426 forSubGroups< T >( [&]( T
const & ){ hasSubGroup =
true; } );
444 template<
typename CASTTYPE,
typename CONTAINERTYPE,
typename LAMBDA >
447 using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, CASTTYPE
const, CASTTYPE >;
448 T *
const castedContainer =
dynamic_cast< T *
>( &container );
450 if( castedContainer !=
nullptr )
452 lambda( *castedContainer );
471 template<
typename T0,
typename T1,
typename ... CASTTYPES,
typename CONTAINERTYPE,
typename LAMBDA >
474 using T = std::conditional_t< std::is_const< CONTAINERTYPE >::value, T0
const, T0 >;
475 T *
const castedContainer =
dynamic_cast< T *
>( &container );
477 if( castedContainer !=
nullptr )
479 lambda( *castedContainer );
507 template<
typename GROUPTYPE =
Group,
typename ... GROUPTYPES,
typename LAMBDA >
510 for(
auto & subGroupIter : m_subGroups )
514 lambda( castedSubGroup );
522 template<
typename GROUPTYPE =
Group,
typename ... GROUPTYPES,
typename LAMBDA >
525 for(
auto const & subGroupIter : m_subGroups )
527 applyLambdaToContainer< GROUPTYPE, GROUPTYPES... >( *subGroupIter.second, [&](
auto const & castedSubGroup )
529 lambda( castedSubGroup );
542 template<
typename GROUPTYPE =
Group,
typename ... GROUPTYPES,
typename LAMBDA >
546 for(
auto & subGroupIter : m_subGroups )
549 [&](
auto & castedSubGroup )
551 lambda( counter, castedSubGroup );
560 template<
typename GROUPTYPE =
Group,
typename ... GROUPTYPES,
typename LAMBDA >
564 for(
auto const & subGroupIter : m_subGroups )
567 [&](
auto const & castedSubGroup )
569 lambda( counter, castedSubGroup );
586 template<
typename GROUPTYPE =
Group,
typename ... GROUPTYPES,
typename LOOKUP_CONTAINER,
typename LAMBDA >
587 void forSubGroups( LOOKUP_CONTAINER
const & subGroupKeys, LAMBDA && lambda )
590 for(
auto const & subgroup : subGroupKeys )
594 lambda( counter, castedSubGroup );
611 template<
typename GROUPTYPE =
Group,
typename ... GROUPTYPES,
typename LOOKUP_CONTAINER,
typename LAMBDA >
612 void forSubGroups( LOOKUP_CONTAINER
const & subGroupKeys, LAMBDA && lambda )
const
615 for(
auto const & subgroup : subGroupKeys )
619 lambda( counter, castedSubGroup );
643 template<
typename LAMBDA >
646 for(
auto & wrapperIter : m_wrappers )
648 lambda( *wrapperIter.second );
655 template<
typename LAMBDA >
658 for(
auto const & wrapperIter : m_wrappers )
660 lambda( *wrapperIter.second );
671 template<
typename TYPE,
typename ... TYPES,
typename LAMBDA >
674 for(
auto & wrapperIter : m_wrappers )
676 applyLambdaToContainer< Wrapper< TYPE >,
Wrapper< TYPES >... >( *wrapperIter.second,
677 std::forward< LAMBDA >( lambda ));
688 template<
typename TYPE,
typename ... TYPES,
typename LAMBDA >
691 for(
auto const & wrapperIter : m_wrappers )
693 applyLambdaToContainer< Wrapper< TYPE >,
Wrapper< TYPES >... >( *wrapperIter.second,
694 std::forward< LAMBDA >( lambda ));
804 template<
typename T,
typename TBASE=T >
815 template<
typename T,
typename TBASE=T >
826 template<
typename T >
837 template<
typename T >
869 string indent( level*2,
' ' );
871 for(
auto const & subGroupIter : m_subGroups )
873 std::cout << indent << subGroupIter.second->getName() << std::endl;
874 subGroupIter.second->generateDataStructureSkeleton( level + 1 );
944 parallelDeviceEvents & events )
const;
962 parallelDeviceEvents & events )
const;
978 parallelDeviceEvents & events )
const;
1002 parallelDeviceEvents & events )
const;
1027 parallelDeviceEvents & events )
const;
1050 parallelDeviceEvents & events )
const;
1075 parallelDeviceEvents & events,
1076 MPI_Op op=MPI_REPLACE );
1099 template<
typename KEY >
1102 WrapperBase const *
const wrapper = m_wrappers[ key ];
1104 "Group " <<
getDataContext() <<
" has no wrapper named " << key << std::endl
1106 std::domain_error );
1114 template<
typename KEY >
1119 "Group " <<
getDataContext() <<
" has no wrapper named " << key << std::endl
1121 std::domain_error );
1132 {
return m_wrappers.
getIndex( name ); }
1139 {
return m_wrappers; }
1145 {
return m_wrappers; }
1152 {
return m_wrappers.
size(); }
1180 template<
typename LOOKUP_TYPE >
1182 {
return m_wrappers[ lookup ] !=
nullptr; }
1192 template<
typename T,
typename LOOKUP_TYPE >
1196 return dynamicCast< Wrapper< T >
const & >( wrapper );
1202 template<
typename T,
typename LOOKUP_TYPE >
1206 return dynamicCast< Wrapper< T > & >( wrapper );
1217 template<
typename T,
typename LOOKUP_TYPE >
1219 {
return dynamicCast< Wrapper< T >
const * >( m_wrappers[ index ] ); }
1224 template<
typename T,
typename LOOKUP_TYPE >
1226 {
return dynamicCast< Wrapper< T > * >( m_wrappers[ index ] ); }
1250 template<
typename T,
typename LOOKUP_TYPE >
1253 {
return getWrapper< T >( lookup ).reference(); }
1258 template<
typename T,
typename LOOKUP_TYPE >
1260 {
return getWrapper< T >( lookup ).reference(); }
1288 {
return m_capacity; }
1323 {
return *m_dataContext; }
1332 template<
typename KEY >
1334 {
return getWrapperBase< KEY >( key ).getDataContext(); }
1360 {
return m_parent !=
nullptr; }
1381 {
return m_sizedFromParent; }
1390 m_sizedFromParent = val;
1442 {
return m_conduitNode; }
1446 {
return m_conduitNode; }
1485 #if defined(GEOSX_USE_PYGEOSX)
1486 virtual PyTypeObject * getPythonType()
const;
1550 Group const & getBaseGroupByPath(
string const & path )
const;
1566 template<
bool DO_PACKING >
1572 parallelDeviceEvents & events )
const;
1576 Group * m_parent =
nullptr;
1609 conduit::Node & m_conduitNode;
1613 std::unique_ptr< DataContext > m_dataContext;
1629 template<
typename T,
typename TBASE >
1631 ViewKey::index_type *
const rkey )
1633 std::unique_ptr< TBASE > newObj = std::make_unique< T >();
1638 if( rkey !=
nullptr )
1640 *rkey = m_wrappers.
getIndex( name );
1652 template<
typename T,
typename TBASE >
1655 ViewKey::index_type index;
1656 Wrapper< TBASE > & rval = registerWrapper< T, TBASE >( viewKey.key(), &index );
1657 viewKey.setIndex( index );
1663 template<
typename T >
1665 std::unique_ptr< T > newObject )
1667 static_assert( !std::is_base_of< WrapperBase, T >::value,
"This function should not be used for `WrapperBase`. Use the dedicated `registerWrapper` instead." );
1669 new Wrapper< T >( name, *
this, std::move( newObject ) ),
1680 template<
typename T >
1684 static_assert( !std::is_base_of< WrapperBase, T >::value,
"This function should not be used for `WrapperBase`. Use the dedicated `registerWrapper` instead." );
#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.
#define GEOS_THROW_IF(EXP, msg, TYPE)
Conditionally throw an exception.
INDEX_TYPE index_type
the type used for the index
void setIndex(INDEX_TYPE const &index) const
Set the index.
KEY_TYPE const & key() const
Access for the key.
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.
void forSubGroups(LOOKUP_CONTAINER const &subGroupKeys, LAMBDA &&lambda) const
Apply the given functor to subgroups that can be casted to one of specified types.
T const & getGroupByPath(string const &path) const
Retrieve a group from the hierarchy using a path.
virtual void initializePreSubGroups()
Called by Initialize() prior to initializing sub-Groups.
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.
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.
int sizedFromParent() const
Check whether this Group is resized when its parent is resized.
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.
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.
DataContext const & getDataContext() const
bool hasWrapper(LOOKUP_TYPE const &lookup) const
Check if a wrapper exists.
T & registerGroup(string const &name, T *newObject)
Register a new Group as a sub-group of current Group.
void processInputFileRecursive(xmlWrapper::xmlDocument &xmlDocument, xmlWrapper::xmlNode &targetNode, xmlWrapper::xmlNodePos const &nodePos)
Same as processInputFileRecursive(xmlWrapper::xmlDocument &, xmlWrapper::xmlNode &) but allow to reus...
Group(Group &&source)=default
Move constructor.
wrapperMap & wrappers()
Get access to the internal wrapper storage.
localIndex getIndexInParent() const
Get the group's index within its parent group.
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.
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.
virtual void expandObjectCatalogs()
Expand any catalogs in the data structure.
MappedVector< WrapperBase, WrapperBase *, keyType, indexType > wrapperMap
The template specialization of MappedVector to use for the collection wrappers objects.
virtual void initializePostSubGroups()
Called by Initialize() after to initializing sub-Groups.
virtual void reinit()
Performs re-initialization of certain variable depending on the solver being used.
void setRestartFlags(RestartFlags flags)
Set flags that control restart output of this group.
void enableLogLevelInput()
Enable verbosity input for object.
Wrapper< T > & getWrapper(LOOKUP_TYPE const &index)
Retrieve a Wrapper stored in this group.
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.
string const & getName() const
Get group name.
string dumpSubGroupsNames() const
GEOS_DECLTYPE_AUTO_RETURN getReference(LOOKUP_TYPE const &lookup) const
Look up a wrapper and get reference to wrapped object.
WrapperBase & getWrapperBase(KEY const &key)
Return a reference to a WrapperBase stored in this group.
WrapperBase const & getWrapperBase(KEY const &key) const
Return a reference to a WrapperBase stored in this group.
virtual void registerDataOnMeshRecursive(Group &meshBodies)
Calls RegisterDataOnMesh() recursively.
conduit::Node & getConduitNode()
Return the Conduit node object associated with this group.
void forSubGroups(LAMBDA &&lambda) const
Apply the given functor to subgroups that can be casted to one of specified types.
virtual void initializePostInitialConditionsPostSubGroups()
Called by InitializePostInitialConditions() after to initializing sub-Groups.
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.
static CatalogInterface::CatalogType & getCatalog()
Get the singleton catalog for this class.
void forSubGroupsIndex(LAMBDA &&lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
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.
void deregisterWrapper(string const &name)
Removes a Wrapper from this group.
void initializePostInitialConditions()
Initialization routine to be called after calling ApplyInitialConditions().
localIndex numSubGroups() const
return the number of sub groups in this Group
indexType numWrappers() const
Return the number of wrappers.
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.
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.
Group & getParent()
Access the group's parent.
void finishWriting()
Write the group and its wrappers into Conduit.
virtual void postRestartInitialization()
Performs initialization required after reading from a restart file.
Group(string const &name, conduit::Node &rootNode)
Constructor.
bool hasGroup(string const &name) const
Check whether a sub-group exists.
indexType getWrapperIndex(string const &name) const
bool hasSubGroupOfType() const
Check whether a sub-group exists by type.
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.
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.
virtual bool registerCallback(void *func, const std::type_info &funcType)
Register a callback function on the group.
void forWrappers(LAMBDA &&lambda) const
Apply the given functor to wrappers.
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.
T & getReference(LOOKUP_TYPE const &lookup)
Look up a wrapper and get reference to wrapped object.
virtual void registerDataOnMesh(Group &meshBodies)
Register data on mesh entities.
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers.
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.
T const & getGroup(KEY const &key) const
Return a reference to a sub-group of the current Group.
void forSubGroups(LAMBDA &&lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
std::vector< string > getWrappersNames() const
T & registerGroup(string const &name, string const &catalogName)
Register a new Group as a sub-group of current Group.
integer getLogLevel() const
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.
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.
Group const & getParent() const
Access the group's parent.
conduit::Node const & getConduitNode() const
Return the Conduit node object associated with this group.
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.
DataContext const & getWrapperDataContext(KEY key) const
void postProcessInputRecursive()
Recursively call postProcessInput() to apply post processing after reading input values.
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.
subGroupMap const & getSubGroups() const
Get the subgroups object.
virtual void postProcessInput()
void forSubGroups(LOOKUP_CONTAINER const &subGroupKeys, LAMBDA &&lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
void generateDataStructureSkeleton(integer const level)
Build a complete datastructure for schema generation.
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.
void printDataHierarchy(integer indent=0) const
Prints the data hierarchy recursively.
wrapperMap const & wrappers() const
Get access to the internal wrapper storage.
T & registerGroup(string const &name)
Register a new Group as a sub-group of current Group.
virtual void initializePostInitialConditionsPreSubGroups()
Called by InitializePostInitialConditions() prior to initializing sub-Groups.
Wrapper< T > const * getWrapperPointer(LOOKUP_TYPE const &index) const
Retrieve a Wrapper stored in this group.
subGroupMap & getSubGroups()
Get the subgroups object.
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.
int sizedFromParent() const
Check whether this wrapper is resized when its parent is resized.
virtual void resize(int ndims, localIndex const *const dims) override
Calls T::resize( num_dims, dims )
Group::wrapperMap::KeyIndex ViewKey
Type alias for KeyIndexT type used for wrapper lookups.
localIndex indexType
The default index type for entries the hierarchy.
string keyType
The default key type for entries in the hierarchy.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
array1d< string > string_array
A 1-dimensional array of geos::string types.
std::string string
String type.
std::int32_t integer
Signed integer type.
signed char buffer_unit_type
Type stored in communication buffers.
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Array< T, 1 > array1d
Alias for 1D array.