Wonton::Simple_State Class Reference

A very light-weight state manager for a Simple_Mesh. More...

#include <simple_state.h>

Public Types

typedef std::vector< double > vec
 Convenience types. More...
 
typedef vec::iterator vec_it
 
typedef std::vector< std::string > name_vec
 
typedef name_vec::iterator name_vec_it
 
typedef std::pair< std::string, Entity_kindkey
 
typedef std::map< key, vecmymap
 
typedef mymap::iterator map_it
 

Public Member Functions

 Simple_State (std::shared_ptr< Simple_Mesh > mesh)
 Constructor for creating a Simple_State. More...
 
 ~Simple_State ()
 Destructor. More...
 
int numVars () const
 The number of variables that live in the state manager. More...
 
map_it begin ()
 An iterator to the beginning of the field map. More...
 
map_it end ()
 An iterator to the ending of the field map. More...
 
name_vec_it names_begin ()
 An iterator to the beginning of the variable names vector. More...
 
name_vec_it names_end ()
 An iterator to the ending fo the variable names vector. More...
 
name_vec names () const
 
map_it find (std::string const name, Entity_kind const on_what=Entity_kind::ANY_KIND)
 Search for a specific key (name, Entity_kind) within the map of known fields and return an iterator to its location. More...
 
vecadd (std::string const name, Entity_kind const on_what, double const *const data=nullptr)
 Add a field to the state manager. More...
 
vecadd (std::string const name, Entity_kind const on_what, double const val)
 Add a field to the state manager. More...
 
vecget (std::string const name, Entity_kind const on_what)
 Get a specific variable from the state manager. More...
 

Detailed Description

A very light-weight state manager for a Simple_Mesh.

This class stores double (and only double) data atop a Simple_Mesh. The data can be located at any mesh location (e.g. CELL or NODE) that Simple_Mesh understands. The field variables are stored in a map and are identified by key composed of a string name and an Entity_kind; for example, pair("pressure", CELL). The actual data corresponding to any field is stored as a std::vector of double's.

In addition to the map, this class stores (and exposes) a vector containing just the string variable names.

Member Typedef Documentation

◆ key

typedef std::pair<std::string, Entity_kind> Wonton::Simple_State::key

◆ map_it

typedef mymap::iterator Wonton::Simple_State::map_it

◆ mymap

typedef std::map<key, vec> Wonton::Simple_State::mymap

◆ name_vec

typedef std::vector<std::string> Wonton::Simple_State::name_vec

◆ name_vec_it

typedef name_vec::iterator Wonton::Simple_State::name_vec_it

◆ vec

typedef std::vector<double> Wonton::Simple_State::vec

Convenience types.

◆ vec_it

typedef vec::iterator Wonton::Simple_State::vec_it

Constructor & Destructor Documentation

◆ Simple_State()

Wonton::Simple_State::Simple_State ( std::shared_ptr< Simple_Mesh mesh)
inlineexplicit

Constructor for creating a Simple_State.

Parameters
[in]meshA smart pointer to the Simple_Mesh where this data lives.

◆ ~Simple_State()

Wonton::Simple_State::~Simple_State ( )
inline

Destructor.

Member Function Documentation

◆ add() [1/2]

vec& Wonton::Simple_State::add ( std::string const  name,
Entity_kind const  on_what,
double const *const  data = nullptr 
)
inline

Add a field to the state manager.

Parameters
[in]nameThe variable name of the field to be added.
[in]on_whatThe Entity_kind (e.g. CELL) on which the data should live.
[in]dataA pointer to some data to initialize. This defaults to nullptr, which allows you to not initialize any of the data, but the underlying std::vector will be sized appropriately.
Returns
A reference to the underlying std::vector for further modification/use.

If the requested variable (name, on_what) pair already exists, this will output a message to std::cerr, but will simply return the reference to the underlying std::vector.

◆ add() [2/2]

vec& Wonton::Simple_State::add ( std::string const  name,
Entity_kind const  on_what,
double const  val 
)
inline

Add a field to the state manager.

Parameters
[in]nameThe variable name of the field to be added.
[in]on_whatThe Entity_kind (e.g. CELL) on which the data should live.
[in]valA value with which to iniitalize the underlying std::vector data.
Returns
A reference to the underlying std::vector for further modification/use.

If the requested variable (name, on_what) pair already exists, this will output a message to std::cerr, but will simply return the reference to the underlying std::vector.

◆ begin()

map_it Wonton::Simple_State::begin ( )
inline

An iterator to the beginning of the field map.

◆ end()

map_it Wonton::Simple_State::end ( )
inline

An iterator to the ending of the field map.

◆ find()

map_it Wonton::Simple_State::find ( std::string const  name,
Entity_kind const  on_what = Entity_kind::ANY_KIND 
)
inline

Search for a specific key (name, Entity_kind) within the map of known fields and return an iterator to its location.

Parameters
[in]nameThe variable name we wish to find.
[in]on_whatThe Entity_kind (e.g. CELL) where the data we wish to find lives.
Returns
An iterator to the location of the requested key in the map; if this is the same as Simple_State::end(), then the variable was not found in the map.

◆ get()

vec& Wonton::Simple_State::get ( std::string const  name,
Entity_kind const  on_what 
)
inline

Get a specific variable from the state manager.

Parameters
[in]nameThe variable name of the field to be retrieved.
[in]on_whatThe Entity_kind (e.g. CELL) on whih the requested data lives.
Returns
A reference to the underlying std::vector of data for further modification/use.
Exceptions
std::runtime_errorThe requested variable is not in the state manager.

◆ names()

name_vec Wonton::Simple_State::names ( ) const
inline

The above iterator functions fail sometimes for optimized code, so here we allow access to the complete list of names.

◆ names_begin()

name_vec_it Wonton::Simple_State::names_begin ( )
inline

An iterator to the beginning of the variable names vector.

◆ names_end()

name_vec_it Wonton::Simple_State::names_end ( )
inline

An iterator to the ending fo the variable names vector.

◆ numVars()

int Wonton::Simple_State::numVars ( ) const
inline

The number of variables that live in the state manager.


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