simple_state_wrapper.h
Go to the documentation of this file.
1 /*
2 This file is part of the Ristra Wonton project.
3 Please see the license file at the root of this repository, or at:
4  https://github.com/laristra/wonton/blob/master/LICENSE
5 */
6 
7 #ifndef WONTON_SIMPLE_STATE_WRAPPER_H_
8 #define WONTON_SIMPLE_STATE_WRAPPER_H_
9 
10 #include <string>
11 
13 
14 #include "wonton/support/wonton.h"
15 
20 namespace Wonton {
21 
27 class Simple_State_Wrapper {
28  public:
32  explicit Simple_State_Wrapper(Simple_State & state) : state_(state) { }
33 
36 
39 
40  // void init_from_mesh() { state_.init_from_mesh(); }
41  // void export_to_mesh() { state_.export_to_mesh(); }
42 
47  int num_materials() const {
48  return 0;
49  }
50 
55  std::string material_name(int matid) const {
56  assert(matid >= 0 && matid < num_materials());
57  return "UNKNOWN";
58  }
59 
66  int mat_get_num_cells(int matid) const {
67  assert(matid >= 0 && matid < num_materials());
68  return 0;
69  }
70 
77  void mat_get_cells(int matid, std::vector<int> *matcells) const {
78  assert(matid >= 0 && matid < num_materials());
79  matcells->clear();
80  }
81 
88  int cell_get_num_mats(int cellid) const {
89  return 0;
90  }
91 
98  void cell_get_mats(int cellid, std::vector<int> *cellmats) const {
99  cellmats->clear();
100  }
101 
109  int cell_index_in_material(int meshcell, int matid) const {
110  return -1;
111  }
112 
120  Field_type field_type(Entity_kind on_what, std::string const& var_name)
121  const {
122  return Field_type::MESH_FIELD;
123  }
124 
134  void mesh_get_data(Entity_kind on_what, std::string const& name,
135  double **data) {
136  auto it = state_.find(name, on_what);
137  if (it != state_.end()) {
138  (*data) = &(it->second[0]);
139  return;
140  }
141 
142  std::cerr << "get_data: Could not find state variable " << name
143  << std::endl;
144  (*data) = nullptr;
145  }
146 
156  void mesh_get_data(Entity_kind on_what, std::string const& name,
157  double const **data) const {
158  auto it = state_.find(name, on_what);
159  if (it != state_.end()) {
160  (*data) = &(it->second[0]);
161  return;
162  }
163 
164  std::cerr << "get_data: Could not find state variable " << name
165  << std::endl;
166  (*data) = nullptr;
167  }
168 
176  void mat_get_celldata(std::string const& var_name, int matid,
177  double const **data) const {
178  }
179 
180  // TEMPORARY: UNTIL THIS GETS TEMPLATED ON TYPE OF DATA
181  void mat_get_celldata(std::string const& var_name, int matid,
182  Wonton::Point<2> const **data) const {
183  }
184  void mat_get_celldata(std::string const& var_name, int matid,
185  Wonton::Point<3> const **data) const {
186  }
187 
188 
197  void mat_get_celldata(std::string const& var_name, int matid, double **data) {
198  }
199 
209  void mesh_add_data(Entity_kind on_what, std::string const& name,
210  double const **data) const {
211  auto vec = state_.add(name, on_what, *data);
212  }
213 
226  void mat_add_celldata(std::string const& var_name, double value) {
227  }
228 
229 
242  void mat_add_celldata(std::string const& var_name,
243  double const * const *values = nullptr,
245  }
246 
247 
260  void mat_add_celldata(std::string const& var_name, int matid,
261  double const * values) {
262  }
263 
264 
276  void mat_add_celldata(std::string const& var_name, int matid, double value) {
277  }
278 
279 
286  void mat_add_cells(int matid, std::vector<int> const& newcells) {
287  }
288 
289 
296  void mat_rem_cells(int matid, std::vector<int> const& delcells) {
297  }
298 
299 
305  void add_material(std::string const& matname,
306  std::vector<int> const& matcells) {
307  }
308 
320  Entity_kind get_entity(std::string const& name) const {
321  // Find where the name is in the variable name part of the map's keys
322  auto it = state_.begin();
323  while (it != state_.end()) {
324  if (it->first.first == name)
325  break;
326  else
327  ++it;
328  }
329  // Now get the second part of the key, if it was found
330  if (it != state_.end()) {
331  return it->first.second;
332  } else {
333  // We don't know this variable, so bail.
334  throw std::runtime_error("Requested variable not found.");
335  }
336  }
337 
347  int get_data_size(Entity_kind on_what, std::string const& name) const {
348  auto it = state_.find(name, on_what);
349  if (it != state_.end()) {
350  return it->second.size();
351  }
352 
353  std::cerr << "get_data_size: Could not find state variable " << name
354  << std::endl;
355  return 0;
356  }
357 
358 
362 
363  const std::type_info& get_data_type(std::string const& var_name) const {
364  auto it = state_.find(var_name);
365  if (it != state_.end())
366  return typeid(double); // Thats the only type we can handle for now
367  else
368  return typeid(void);
369  }
370 
373  return state_.names_begin();
374  }
375 
378  return state_.names_end();
379  }
380 
383  typename Simple_State::name_vec names() const {return state_.names();}
384 
385  private:
387  Simple_State & state_;
388 }; // class Simple_State_Wrapper
389 } // namespace Wonton
390 
391 #endif // WONTON_SIMPLE_STATE_WRAPPER_H_
void add_material(std::string const &matname, std::vector< int > const &matcells)
Add a material to state.
Definition: simple_state_wrapper.h:305
void mat_get_celldata(std::string const &var_name, int matid, double const **data) const
Get pointer to read-only scalar cell data for a particular material.
Definition: simple_state_wrapper.h:176
void mesh_get_data(Entity_kind on_what, std::string const &name, double const **data) const
Get a pointer to data from the state manager with a given variable name and on on_what mesh entities...
Definition: simple_state_wrapper.h:156
void mat_add_celldata(std::string const &var_name, int matid, double const *values)
Add a scalar multi-valued data field on cells and add data to one of its materials.
Definition: simple_state_wrapper.h:260
Simple_State::name_vec_it names_end() const
An iterator to the ending of the vector of names in the state manager.
Definition: simple_state_wrapper.h:377
name_vec::iterator name_vec_it
Definition: simple_state.h:61
std::vector< std::string > name_vec
Definition: simple_state.h:60
A very light-weight state manager for a Simple_Mesh.
Definition: simple_state.h:43
Simple_State::name_vec_it names_begin() const
An iterator to the beginning of the vector of names in the state manager.
Definition: simple_state_wrapper.h:372
Factorize a number N into D equal (or nearly equal) factors.
Definition: adaptive_refinement_mesh.h:31
int mat_get_num_cells(int matid) const
Get number of cells containing a particular material.
Definition: simple_state_wrapper.h:66
int get_data_size(Entity_kind on_what, std::string const &name) const
Get the number of elements in a specific variable from the state manager.
Definition: simple_state_wrapper.h:347
void mat_add_celldata(std::string const &var_name, int matid, double value)
Add a scalar multi-valued data field on cells and initialize one of its material data to a uniform va...
Definition: simple_state_wrapper.h:276
void mat_get_celldata(std::string const &var_name, int matid, Wonton::Point< 2 > const **data) const
Definition: simple_state_wrapper.h:181
Entity_kind get_entity(std::string const &name) const
Definition: simple_state_wrapper.h:320
Simple_State::name_vec names() const
Definition: simple_state_wrapper.h:383
Data_layout
Definition: wonton.h:209
void mesh_add_data(Entity_kind on_what, std::string const &name, double const **data) const
Get a pointer to data from the state manager with a given variable name and on on_what mesh entities...
Definition: simple_state_wrapper.h:209
Simple_State_Wrapper & operator=(Simple_State_Wrapper const &)=delete
Assignment operator (disabled).
name_vec names() const
Definition: simple_state.h:78
void mat_rem_cells(int matid, std::vector< int > const &delcells)
Remove cells from material (or remove material from cells)
Definition: simple_state_wrapper.h:296
vec & add(std::string const name, Entity_kind const on_what, double const *const data=nullptr)
Add a field to the state manager.
Definition: simple_state.h:120
int cell_get_num_mats(int cellid) const
Get number of materials contained in a cell.
Definition: simple_state_wrapper.h:88
A thin wrapper that implements state methods for Simple_State needed by Wonton.
Definition: simple_state_mm_wrapper.h:26
Field_type
Field type - whether it is mesh field or multi-material field.
Definition: wonton.h:187
Represents a point in an N-dimensional space.
Definition: Point.h:50
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 t...
Definition: simple_state.h:90
Simple_State_Wrapper(Simple_State &state)
Constructor for the state wrapper.
Definition: simple_state_wrapper.h:32
map_it begin()
An iterator to the beginning of the field map.
Definition: simple_state.h:67
int cell_index_in_material(int meshcell, int matid) const
Get the local index of mesh cell in material cell list.
Definition: simple_state_wrapper.h:109
int num_materials() const
Number of materials in problem.
Definition: simple_state_wrapper.h:47
void mesh_get_data(Entity_kind on_what, std::string const &name, double **data)
Get a pointer to data from the state manager with a given variable name and on on_what mesh entities...
Definition: simple_state_wrapper.h:134
Entity_kind
The type of mesh entity.
Definition: wonton.h:81
name_vec_it names_end()
An iterator to the ending fo the variable names vector.
Definition: simple_state.h:74
void mat_add_celldata(std::string const &var_name, double const *const *values=nullptr, Data_layout layout=Data_layout::MATERIAL_CENTRIC)
Add a scalar multi-valued data field on cells and initialize its material data according to a 2D arra...
Definition: simple_state_wrapper.h:242
void mat_add_celldata(std::string const &var_name, double value)
Add a scalar multi-valued data field on cells and initialize its material data to a single value...
Definition: simple_state_wrapper.h:226
std::string material_name(int matid) const
Name of material.
Definition: simple_state_wrapper.h:55
~Simple_State_Wrapper()
Destructor.
Definition: simple_state_wrapper.h:38
void cell_get_mats(int cellid, std::vector< int > *cellmats) const
Get the IDs of materials in a cell.
Definition: simple_state_wrapper.h:98
map_it end()
An iterator to the ending of the field map.
Definition: simple_state.h:69
void mat_get_celldata(std::string const &var_name, int matid, double **data)
Get pointer to read-write scalar data for a particular material.
Definition: simple_state_wrapper.h:197
void mat_add_cells(int matid, std::vector< int > const &newcells)
Add cells to material (or add material to cells)
Definition: simple_state_wrapper.h:286
A very light-weight state manager for double data living atop a Simple_Mesh.
void mat_get_cells(int matid, std::vector< int > *matcells) const
Get cell indices containing a particular material.
Definition: simple_state_wrapper.h:77
name_vec_it names_begin()
An iterator to the beginning of the variable names vector.
Definition: simple_state.h:72
Field_type field_type(Entity_kind on_what, std::string const &var_name) const
Type of field (MESH_FIELD or MULTIMATERIAL_FIELD)
Definition: simple_state_wrapper.h:120
void mat_get_celldata(std::string const &var_name, int matid, Wonton::Point< 3 > const **data) const
Definition: simple_state_wrapper.h:184
const std::type_info & get_data_type(std::string const &var_name) const
Get the data type of the given field.
Definition: simple_state_wrapper.h:363