Wonton::StateManager< MeshWrapper > Class Template Reference

#include <state_manager.h>

Inheritance diagram for Wonton::StateManager< MeshWrapper >:
Wonton::Flat_State_Wrapper< MeshWrapper > Wonton::Simple_State_Wrapper< MeshWrapper >

Public Member Functions

 StateManager (const MeshWrapper &mesh, std::unordered_map< std::string, int > names={}, std::unordered_map< int, std::vector< int >> material_cells={})
 Constructor. More...
 
void add_material_names (const std::unordered_map< std::string, int > &names)
 Add the names of the materials. More...
 
std::vector< std::string > const names () const
 Return the names registered by the state manager. More...
 
std::string material_name (int m) const
 Return the name of a material from its material id. More...
 
int get_material_id (std::string const &name) const
 Return the material id from its name. More...
 
void add_material_cells (std::unordered_map< int, std::vector< int >> cells)
 Add the material cells. More...
 
std::unordered_map< int, std::vector< int > > const & get_material_cells () const
 Return the material cells. More...
 
std::unordered_map< int, std::unordered_set< int > > const & get_cell_materials () const
 Return the cell materials. More...
 
std::unordered_map< int, int > const get_material_shape () const
 Return the number of cells for each material. More...
 
int num_materials () const
 Return the number of materials in the problem. More...
 
Entity_kind get_entity (std::string const &name) const
 Return the entity kind for a state vector. More...
 
Field_type field_type (Entity_kind kind, std::string const &name) const
 Return the field type of a state vector. More...
 
int get_data_size (Entity_kind on_what, std::string const &name) const
 Return the data size . More...
 
const std::type_info & get_data_type (std::string var_name)
 Get the data type of the given field. More...
 
void add (std::shared_ptr< StateVectorBase > sv)
 Add a StateVectorBase to the state manager. More...
 
template<class T >
void add (std::shared_ptr< StateVectorUni< T >> sv)
 Add a StateVectorUni<T> to the state manager. More...
 
template<class T >
void add (std::shared_ptr< StateVectorMulti< T >> sv)
 Add a StateVectorMulti<T> to the state manager. More...
 
std::shared_ptr< StateVectorBaseget (std::string name)
 Get a shared pointer to a StateVectorBase from the state manager. More...
 
std::shared_ptr< StateVectorBase const > get (std::string name) const
 Get a shared pointer to a const StateVectorBase from the state manager. More...
 
template<typename T >
std::shared_ptr< T > get (std::string name)
 Get a shared pointer to a templated type from the state manager. More...
 
template<typename T >
std::shared_ptr< T > get (std::string name) const
 Get a shared pointer to a templated type from the state manager. More...
 
int num_material_cells (int m) const
 Return the number of cells for this material id. More...
 
std::vector< int > const & get_material_cells (int m) const
 Return the cell ids for this material id. More...
 
void mat_get_cells (int m, std::vector< int > *matcells) const
 Return the cell ids for this material id. More...
 
template<class T >
void mat_get_celldata (std::string const &name, int m, T const **data) const
 Return the cell data for this material id. More...
 
int cell_index_in_material (int c, int m) const
 Return the cell index in this material id. More...
 
template<class T >
void mat_get_celldata (std::string const &name, int m, T **data)
 Return the cell data for this material id. More...
 
int cell_get_num_mats (int c) const
 Return the number of materials in this cell. More...
 
std::unordered_set< int > get_cell_materials (int c) const
 Return the unordered set of materials in this cell. More...
 
void cell_get_mats (int c, std::vector< int > *cellmats) const
 Return the materials in this cell. More...
 
template<class T >
void mesh_get_data (Entity_kind on_what, std::string const &name, T const **data) const
 Return the const cell data for this material id. More...
 
template<class T >
void mesh_get_data (Entity_kind on_what, std::string const &name, T **data)
 Return the cell data for this material id. More...
 
void mat_add_cells (int m, std::vector< int > const &newcells)
 Add cells for a new material to the material cells. More...
 
template<class T >
void mat_add_celldata (std::string const &name, int m, T const *values)
 Add cell data for a new material in a state vector to the state manager. More...
 
void add_material (std::string const &matname, std::vector< int > const &matcells)
 Add cell data for a new material in a state vector to the state manager. More...
 
template<class T = double>
bool shape_is_good (const std::shared_ptr< StateVectorMulti< T >> sv)
 Check that a StateVectorMulti<T> has a shape consistent with the state manager. More...
 
void clear_material_cells ()
 Clear material cells and the inverse map of cell materials. More...
 

Protected Member Functions

void clear ()
 

Protected Attributes

const MeshWrapper & mesh_
 
std::unordered_map< std::string, std::shared_ptr< StateVectorBase > > state_vectors_
 
std::unordered_map< std::string, int > material_ids_
 
std::unordered_map< int, std::string > material_names_
 
std::unordered_map< int, std::vector< int > > material_cells_
 
std::unordered_map< int, std::unordered_map< int, int > > cell_index_in_mat_
 
std::unordered_map< int, std::unordered_set< int > > cell_materials_
 

Constructor & Destructor Documentation

◆ StateManager()

template<class MeshWrapper>
Wonton::StateManager< MeshWrapper >::StateManager ( const MeshWrapper &  mesh,
std::unordered_map< std::string, int >  names = {},
std::unordered_map< int, std::vector< int >>  material_cells = {} 
)
inline

Constructor.

Parameters
[in]meshmesh wrapper
[in]namesmap from material names to material id
[in]material_cellsmap from material id to vector of cells

Constructor that takes the meshwrapper for the underlying mesh and two optional map arguments: the map from material name to id, and the map from material id to the cells containing that material

Member Function Documentation

◆ add() [1/3]

template<class MeshWrapper>
void Wonton::StateManager< MeshWrapper >::add ( std::shared_ptr< StateVectorBase sv)
inline

Add a StateVectorBase to the state manager.

Parameters
[in]svshared pointer to StateVectorBase

Add a shared pointer to a state vector to the state manager. This specialization works directly with a StateVectorBase

◆ add() [2/3]

template<class MeshWrapper>
template<class T >
void Wonton::StateManager< MeshWrapper >::add ( std::shared_ptr< StateVectorUni< T >>  sv)
inline

Add a StateVectorUni<T> to the state manager.

Parameters
[in]svshared pointer to StateVectorUni<T>

Adds a shared pointer to a single material state vector to the state manager. This specialization works with a single material StateVectorUni templated on type T. The code does some error checking, in particular making sure the the length of the data is the same as the number of mesh entities in the underlying mesh.

◆ add() [3/3]

template<class MeshWrapper>
template<class T >
void Wonton::StateManager< MeshWrapper >::add ( std::shared_ptr< StateVectorMulti< T >>  sv)
inline

Add a StateVectorMulti<T> to the state manager.

Parameters
[in]svshared pointer to StateVectorMulti<T>

Adds a shared pointer to a multi material state vector to the state manager. This specialization works with a multi material StateVectorMulti templated on type T. The code does some error checking, in particular making sure the the shape of the data is the same as the shape of the material cells.

◆ add_material()

template<class MeshWrapper>
void Wonton::StateManager< MeshWrapper >::add_material ( std::string const &  matname,
std::vector< int > const &  matcells 
)
inline

Add cell data for a new material in a state vector to the state manager.

Parameters
[in]matnamename of the material
[in]matcellsvector of material cells

NOT IMPLEMENTED AT PRESENT: Starting from scratch, add the material and cell id's I think this is problematic in a distributed sense, and I don't hit it in simple_mash app, so for now don't do anything the problem is that if a rank creates it's own material id, then those could conflict with other ranks. I believe the main caller should have a registry of all materials in the problem. It should not be up to a single node to create a name<->matid association.

◆ add_material_cells()

template<class MeshWrapper>
void Wonton::StateManager< MeshWrapper >::add_material_cells ( std::unordered_map< int, std::vector< int >>  cells)
inline

Add the material cells.

Parameters
[in]cellsmap from material id to vector of cell ids

Add the material cells. The argument is a map from material id to a vector of cells for that material.

◆ add_material_names()

template<class MeshWrapper>
void Wonton::StateManager< MeshWrapper >::add_material_names ( const std::unordered_map< std::string, int > &  names)
inline

Add the names of the materials.

Parameters
[in]namesmap from material names to material id

Add the names of the materials. The map from material name to id.

◆ cell_get_mats()

template<class MeshWrapper>
void Wonton::StateManager< MeshWrapper >::cell_get_mats ( int  c,
std::vector< int > *  cellmats 
) const
inline

Return the materials in this cell.

Parameters
[in]ccell id
[out]cellmatspointer to vector of materials in this cell

Return the unordered set of materials in this cell. While cell id's need to be kept in order within a material, the reverse is not true. Reflecting the use of an unordered set for the underlying data structure, the order of the materials is not guaranteed. NOTE: I don't believe this will handle the case of mixed mesh and multi- mat fields in the same problem. But for now, I just need to get past this. In interpolation the mesh fields are proxied by cell_get_num_mats = 0, but in the mixed case there may be mats, but still be a mesh field. Also anything that calls this should only do so if there are in fact materials which is not the case in intersect_r3d where it is always called if tangram is defined.

◆ cell_get_num_mats()

template<class MeshWrapper>
int Wonton::StateManager< MeshWrapper >::cell_get_num_mats ( int  c) const
inline

Return the number of materials in this cell.

Parameters
[in]ccell id
Returns
number of material in this cell

Return the number of materials in this cell. NOTE: I don't believe this will handle the case of mixed mesh and multi- mat fields in the same problem. But for now, I just need to get past this. In interpolation the mesh fields are proxied by cell_get_num_mats = 0, but in the mixed case there may be mats, but still be a mesh field.

◆ cell_index_in_material()

template<class MeshWrapper>
int Wonton::StateManager< MeshWrapper >::cell_index_in_material ( int  c,
int  m 
) const
inline

Return the cell index in this material id.

Parameters
[in]ccell id
[in]mmaterial id
Returns
index of cell in material

Return the index (location) of this cell within the list of cells for this material.

Get the cell index in material since this uses material dominant structures, I wish the signature was int cell_index_in_material(int m, int c)

◆ clear()

template<class MeshWrapper>
void Wonton::StateManager< MeshWrapper >::clear ( )
inlineprotected

◆ clear_material_cells()

template<class MeshWrapper>
void Wonton::StateManager< MeshWrapper >::clear_material_cells ( )
inline

Clear material cells and the inverse map of cell materials.

◆ field_type()

template<class MeshWrapper>
Field_type Wonton::StateManager< MeshWrapper >::field_type ( Entity_kind  kind,
std::string const &  name 
) const
inline

Return the field type of a state vector.

Parameters
[in]kindWonton::Entity_kind of the state vector (not needed) but required by the signature of mmdrive
[in]namestring of the material name
Returns
field type (UNIMATERIAL, MULTIMATERIAL) of the state vector

Return the field type of a state value. The kind is not required as the names are unique. The original intent was that there could be e.g. a pressure defined on the cells and nodes but with the same same name "pressure". We moved past this, so if the name is unique, the kind is not required. the arguments are entity kind and the name of the state vector, and the return type is the field type.

◆ get() [1/4]

template<class MeshWrapper>
std::shared_ptr<StateVectorBase> Wonton::StateManager< MeshWrapper >::get ( std::string  name)
inline

Get a shared pointer to a StateVectorBase from the state manager.

Parameters
[in]namename of the registered state vector
Returns
shared pointer to StateVectorBase

Gets a shared pointer to a StateVectorBase from the state manager. The pointer is to the base class and can be dynamically pointer cast to any type. The name is checked with the state manager. If the name is not found, a nullptr is returned so validity can be checked with a nullptr test.

◆ get() [2/4]

template<class MeshWrapper>
std::shared_ptr<StateVectorBase const> Wonton::StateManager< MeshWrapper >::get ( std::string  name) const
inline

Get a shared pointer to a const StateVectorBase from the state manager.

Parameters
[in]namename of the registered state vector
Returns
shared pointer to StateVectorBase

Gets a shared pointer to a StateVectorBase from the state manager. The pointer is to the base class and can be dynamically pointer cast to any type. The name is checked with the state manager. If the name is not found, a nullptr is returned so validity can be checked with a nullptr test.

◆ get() [3/4]

template<class MeshWrapper>
template<typename T >
std::shared_ptr<T> Wonton::StateManager< MeshWrapper >::get ( std::string  name)
inline

Get a shared pointer to a templated type from the state manager.

Parameters
[in]namename of the registered state vector
Returns
shared pointer to a type T

Gets a shared pointer to a type T from the state manager. The pointer will be dynamically cast to type T. If the name is not found, a nullptr is returned so validity can be checked with a nullptr test. T is the complete type, which is likely itself templated, e.g. T = StateVectorMulti<double>. With this signature we only need one specialization and it is used for accessing both single material and multi material state vectors.

◆ get() [4/4]

template<class MeshWrapper>
template<typename T >
std::shared_ptr<T> Wonton::StateManager< MeshWrapper >::get ( std::string  name) const
inline

Get a shared pointer to a templated type from the state manager.

Parameters
[in]namename of the registered state vector
Returns
const shared pointer to a type T

Gets a shared pointer to a type T from the state manager. The pointer will be dynamically cast to type T. If the name is not found, a nullptr is returned so validity can be checked with a nullptr test. T is the complete type, which is likely itself templated, e.g. T = StateVectorMulti<double>. With this signature we only need one specialization and it is used for accessing both single material and multi material state vectors. This is a const version of the function, that is used for read only data.

◆ get_cell_materials() [1/2]

template<class MeshWrapper>
std::unordered_map<int, std::unordered_set<int> > const& Wonton::StateManager< MeshWrapper >::get_cell_materials ( ) const
inline

Return the cell materials.

Returns
map from cell id to set of material ids

Return the cell materials. The return value is a map from cell id to a set of material ids.

◆ get_cell_materials() [2/2]

template<class MeshWrapper>
std::unordered_set<int> Wonton::StateManager< MeshWrapper >::get_cell_materials ( int  c) const
inline

Return the unordered set of materials in this cell.

Parameters
[in]ccell id
Returns
unordered set of material ids in this cell

Return the unordered set of materials in this cell. While cell id's need to be kept in order within a material, the reverse is not true. The order of materials in a cell is arbitrary, so use a data structure that reflects this. Using a set makes comparing, interecting, adding etc. easy.

◆ get_data_size()

template<class MeshWrapper>
int Wonton::StateManager< MeshWrapper >::get_data_size ( Entity_kind  on_what,
std::string const &  name 
) const
inline

Return the data size .

◆ get_data_type()

template<class MeshWrapper>
const std::type_info& Wonton::StateManager< MeshWrapper >::get_data_type ( std::string  var_name)
inline

Get the data type of the given field.

Parameters
[in]var_nameThe string name of the data field
Returns
A reference to the type_info struct for the field's data type

◆ get_entity()

template<class MeshWrapper>
Entity_kind Wonton::StateManager< MeshWrapper >::get_entity ( std::string const &  name) const
inline

Return the entity kind for a state vector.

Parameters
[in]namestring of the material name
Returns
entity kind (CELL, NODE) of the state vector

Return the entity kind for a state vector. The input parameter is the name of the state vector, and the return type is a Wonton::Entity_kind

◆ get_material_cells() [1/2]

template<class MeshWrapper>
std::unordered_map<int, std::vector<int> > const& Wonton::StateManager< MeshWrapper >::get_material_cells ( ) const
inline

Return the material cells.

Returns
map from material id to vector of cell ids

Return the material cells. The return value is a map from material id to a vector of cells for that material.

◆ get_material_cells() [2/2]

template<class MeshWrapper>
std::vector<int> const& Wonton::StateManager< MeshWrapper >::get_material_cells ( int  m) const
inline

Return the cell ids for this material id.

Parameters
[in]mmaterial id
Returns
vector of cell indices containing this material

Return a read only reference to the cell ids for this material id. If no materials have been defined, return a reference to an empty vector.

◆ get_material_id()

template<class MeshWrapper>
int Wonton::StateManager< MeshWrapper >::get_material_id ( std::string const &  name) const
inline

Return the material id from its name.

Parameters
[in]namematerial name
Returns
material id

Return the material id from its name.

◆ get_material_shape()

template<class MeshWrapper>
std::unordered_map<int, int> const Wonton::StateManager< MeshWrapper >::get_material_shape ( ) const
inline

Return the number of cells for each material.

Returns
map from material id to the number of cells with this material

Return the number of cells for each material. The return value is a map from material id to the integer number of cells.

◆ mat_add_celldata()

template<class MeshWrapper>
template<class T >
void Wonton::StateManager< MeshWrapper >::mat_add_celldata ( std::string const &  name,
int  m,
T const *  values 
)
inline

Add cell data for a new material in a state vector to the state manager.

Parameters
[in]namename registered with the state manager
[in]mmaterial id
[in]valuesvector of data for this material

Add cell data for a new material in a state vector to the state manager. This function takes three arguments, the name of the state vector, the material id and the data itself. The function then copies the data into the state vector. Add is a bit of a misnomer. At the moment, this sets or replaces. No merge is done.

◆ mat_add_cells()

template<class MeshWrapper>
void Wonton::StateManager< MeshWrapper >::mat_add_cells ( int  m,
std::vector< int > const &  newcells 
)
inline

Add cells for a new material to the material cells.

Parameters
[in]mmaterial id
[in]newcellsvector of cell ids containing this material

Add cells for a new material to the material cells. This function takes two arguments, the material id and the cells containing it. The function then set the cells for this material. Add is a bit of a misnomer. At the moment, this sets or replaces. No merge is done.

◆ mat_get_celldata() [1/2]

template<class MeshWrapper>
template<class T >
void Wonton::StateManager< MeshWrapper >::mat_get_celldata ( std::string const &  name,
int  m,
T const **  data 
) const
inline

Return the cell data for this material id.

Parameters
[in]namename registered with the state manager
[in]mmaterial id
[out]dataa read only pointer to the cell vector data

Return the cell data for this material id. This is the in-place version of the function. The data is returned in a location pointed to by the user argument data. This is read-only version of the function. The vector data cannot be modified.

◆ mat_get_celldata() [2/2]

template<class MeshWrapper>
template<class T >
void Wonton::StateManager< MeshWrapper >::mat_get_celldata ( std::string const &  name,
int  m,
T **  data 
)
inline

Return the cell data for this material id.

Parameters
[in]namename registered with the state manager
[in]mmaterial id
[out]dataa read only pointer to the cell vector data

Return the cell data for this material id. This is the in-place version of the function. The data is returned in a location pointed to by the user argument data. This is the non-const version of the function. The data is both writable and allocated if it doesn't exist.

Discussion points: This function has a side effect. When this function is called, the resulting pointer needs to point to memory that is already allocated of sufficient size. It cannot be a nullptr. At some point in the code we need to do the allocation. In our case this is an std::vector.resize call. This memory management could be done in add_material like Jali does. The downside is that this buries the allocation into a "hidden" location. I (DWS) would personally like to see add_material go away. It is responsible for creating a uid for the material in a distributed environment which is problematic and this memory management which is also problematic. The memory management is hidden here just the same, and my preferred solution is to make the allocate/resize explicit. We should add an allocate api that is called explicitly in mmdriver. That way we know exactly what we are doing when and where. It adds a step, but hopefully that will remove the segfault that developers such as myself got because we didn't know when and where to allocate the target state vectors.

◆ mat_get_cells()

template<class MeshWrapper>
void Wonton::StateManager< MeshWrapper >::mat_get_cells ( int  m,
std::vector< int > *  matcells 
) const
inline

Return the cell ids for this material id.

Parameters
[in]mmaterial id
[out]matcellsvector of cell indices containing this material

Return the cell ids for this material id. This is the in-place version of the function. The cells are returned in a function argument rather than a function return.

◆ material_name()

template<class MeshWrapper>
std::string Wonton::StateManager< MeshWrapper >::material_name ( int  m) const
inline

Return the name of a material from its material id.

Parameters
[in]mmaterial id
Returns
string of the material name

Return the name of a material from its material id.

◆ mesh_get_data() [1/2]

template<class MeshWrapper>
template<class T >
void Wonton::StateManager< MeshWrapper >::mesh_get_data ( Entity_kind  on_what,
std::string const &  name,
T const **  data 
) const
inline

Return the const cell data for this material id.

Parameters
[in]on_whatWonton::Entity_kind of data (unused, but required by the API)
[in]namename registered with the state manager
[out]dataa read only pointer to the cell vector data

Return the uni material data for this state vector. This is the in-place version of the function. The data is returned in a location pointed to by the user argument data. This is read-only version of the function. The vector data cannot be modified.

◆ mesh_get_data() [2/2]

template<class MeshWrapper>
template<class T >
void Wonton::StateManager< MeshWrapper >::mesh_get_data ( Entity_kind  on_what,
std::string const &  name,
T **  data 
)
inline

Return the cell data for this material id.

Parameters
[in]on_whatWonton::Entity_kind of data (unused, but required by the API)
[in]namename registered with the state manager
[out]dataa pointer to the cell vector data

Return the uni material data for this state vector. This is the in-place version of the function. The data is returned in a location pointed to by the user argument data. This is the mutable form of the function. The data may be modified by the caller.

◆ names()

template<class MeshWrapper>
std::vector<std::string> const Wonton::StateManager< MeshWrapper >::names ( ) const
inline

Return the names registered by the state manager.

Returns
vector of strings of state names, e.g. "pressure","temp", etc

Return the names registered by the state manager.

◆ num_material_cells()

template<class MeshWrapper>
int Wonton::StateManager< MeshWrapper >::num_material_cells ( int  m) const
inline

Return the number of cells for this material id.

Parameters
[in]mmaterial id
Returns
number of cells containing this material

Return the number of cells for this material id.

◆ num_materials()

template<class MeshWrapper>
int Wonton::StateManager< MeshWrapper >::num_materials ( ) const
inline

Return the number of materials in the problem.

Returns
the integer number of materials

Return the number of materials in the problem. Uses material_names to ensure that the materials that are expected to be, but haven't been populated with cells yet are accounted for.

◆ shape_is_good()

template<class MeshWrapper>
template<class T = double>
bool Wonton::StateManager< MeshWrapper >::shape_is_good ( const std::shared_ptr< StateVectorMulti< T >>  sv)
inline

Check that a StateVectorMulti<T> has a shape consistent with the state manager.

Parameters
[in]svshared pointer to StateVectorMulti<T>

Check that a StateVectorMulti<T> has a shape consistent with the state manager. Both the number of materials and number of cells per material must match in order to pass the test.

Member Data Documentation

◆ cell_index_in_mat_

template<class MeshWrapper>
std::unordered_map<int, std::unordered_map<int,int> > Wonton::StateManager< MeshWrapper >::cell_index_in_mat_
protected

◆ cell_materials_

template<class MeshWrapper>
std::unordered_map<int, std::unordered_set<int> > Wonton::StateManager< MeshWrapper >::cell_materials_
protected

◆ material_cells_

template<class MeshWrapper>
std::unordered_map<int, std::vector<int> > Wonton::StateManager< MeshWrapper >::material_cells_
protected

◆ material_ids_

template<class MeshWrapper>
std::unordered_map<std::string, int> Wonton::StateManager< MeshWrapper >::material_ids_
protected

◆ material_names_

template<class MeshWrapper>
std::unordered_map<int, std::string> Wonton::StateManager< MeshWrapper >::material_names_
protected

◆ mesh_

template<class MeshWrapper>
const MeshWrapper& Wonton::StateManager< MeshWrapper >::mesh_
protected

◆ state_vectors_

template<class MeshWrapper>
std::unordered_map<std::string, std::shared_ptr<StateVectorBase> > Wonton::StateManager< MeshWrapper >::state_vectors_
protected

The documentation for this class was generated from the following file: