flecsi_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 */
9 
10 #pragma once
11 
12 // system includes
13 #include <utility>
14 #include <cstring>
15 #include <string>
16 #include <vector>
17 #include <typeinfo>
18 
19 #include "wonton/support/wonton.h"
20 
21 namespace Wonton {
22 
26 template< typename M >
28  //============================================================================
29  // Typedefs
30  //============================================================================
31 
33  using mesh_t = M;
35  using size_t = typename mesh_t::size_t;
37  using real_t = typename mesh_t::real_t;
38 
39 
41  using entity_kind_t = Entity_kind;
43  using entity_type_t = Entity_type;
44 
45  public:
46  //============================================================================
47  // Constructors
48  //============================================================================
49 
52  explicit flecsi_state_t(mesh_t & mesh) : mesh_(&mesh)
53  {}
54 
56  flecsi_state_t() = default;
57 
59  flecsi_state_t(const flecsi_state_t &) = default;
60 
62  flecsi_state_t & operator=(const flecsi_state_t &) = default;
63 
64  //============================================================================
65  // Public Members
66  //============================================================================
67 
68 
70 
71  int num_materials() const {
72  return 0;
73  }
74 
76 
77  std::string material_name(int matid) const {
78  assert(matid >= 0 && matid < num_materials());
79  return "UNKNOWN";
80  }
81 
85 
86  int mat_get_num_cells(int matid) const {
87  assert(matid >= 0 && matid < num_materials());
88  return 0;
89  }
90 
94 
95  void mat_get_cells(int matid, std::vector<int> *matcells) const {
96  assert(matid >= 0 && matid < num_materials());
97  matcells->clear();
98  }
99 
103 
104  int cell_get_num_mats(int cellid) const {
105  return 0;
106  }
107 
111 
112  void cell_get_mats(int cellid, std::vector<int> *cellmats) const {
113  cellmats->clear();
114  }
115 
120 
121  int cell_index_in_material(int meshcell, int matid) const {
122  return -1;
123  }
124 
129 
130  Field_type field_type(Entity_kind on_what, std::string const& var_name)
131  const {
132  return Field_type::MESH_FIELD; // MULTI-MATERIAL FIELDS NOT ACCESSED YET
133  }
134 
135 
146  entity_kind_t get_entity(std::string const& var_name) const {
147  auto cell_field_list = flecsi_get_accessors_all(
148  *mesh_, real_t, dense, 0, flecsi_is_at(cells));
149 
150  for (auto var : cell_field_list)
151  if (var.label() == var_name)
152  return entity_kind_t::CELL;
153 
154  auto nodal_field_list = flecsi_get_accessors_all(
155  *mesh_, real_t, dense, 0, flecsi_is_at(vertices));
156  for (auto var : nodal_field_list)
157  if (var.label() == var_name)
158  return entity_kind_t::NODE;
159 
161  }
162 
163 
168  template <class T>
169  void mesh_get_data(entity_kind_t on_what, std::string const& var_name,
170  T ** data) const {
171  // Ignore on_what here - the state manager knows where it lives
172  // based on its name
173 
174  // first check cells
175  auto cell_field_list = flecsi_get_accessors_all(
176  *mesh_, real_t, dense, 0, flecsi_is_at(cells));
177  for (auto var : cell_field_list)
178  if (var.label() == var_name) {
179  *data = &var[0];
180  return;
181  }
182 
183  // now check nodes
184  auto nodal_field_list = flecsi_get_accessors_all(
185  *mesh_, real_t, dense, 0, flecsi_is_at(vertices));
186  for (auto var : nodal_field_list)
187  if (var.label() == var_name) {
188  *data = &var[0];
189  return;
190  }
191 
192  // if we got here, there is something wrong
193  raise_runtime_error("Could not find variable to ReMAP!");
194  }
195 
196 
202  template<typename T>
203  void mat_get_celldata(std::string const& var_name, int matid, T const **data) const {}
204 
211  template<typename T>
212  void mat_get_celldata(std::string const& var_name, int matid, T **data) {}
213 
220 
221  void mesh_add_data(Entity_kind on_what, std::string const& name,
222  double const **data) const {
223  }
224 
229 
233 
234  void mat_add_celldata(std::string const& var_name, double value) {
235  }
236 
237 
249 
250  void mat_add_celldata(std::string const& var_name,
251  double const * const *values = nullptr,
253  }
254 
255 
265 
266  void mat_add_celldata(std::string const& var_name, int matid,
267  double const * values) {
268  }
269 
270  void mat_add_celldata(std::string const& var_name, int matid,
271  Point<2> const *values) {
272  }
273 
274  void mat_add_celldata(std::string const& var_name, int matid,
275  Point<3> const *values) {
276  }
277 
278 
286 
287  void mat_add_celldata(std::string const& var_name, int matid, double value) {
288  }
289 
290 
294 
295  void mat_add_cells(int matid, std::vector<int> const& newcells) {
296  }
297 
298 
302 
303  void mat_rem_cells(int matid, std::vector<int> const& delcells) {
304  }
305 
306 
310 
311  void add_material(std::string const& matname,
312  std::vector<int> const& matcells) {
313  }
314 
315 
316  int get_data_size(entity_kind_t on_what, std::string const& var_name) const {
317  raise_runtime_error("get_data_size not implemented yet!");
318  }
319 
320 
321 
326 
327  const std::type_info& get_data_type(std::string const& var_name) const {
328  return typeid(double); // thats the only type we can represent
329  }
330 
335  std::vector<std::string> names() const {
336  return std::vector<std::string>{};
337  }
338 
339 
340 #if 0
341 
346  template <class T>
347  void mesh_get_data(entity_kind_t on_what,
348  std::string const& var_name, T** data) {
349  // Ignore on_what here - the state manager knows where it lives
350  // based on its name
351  // NOTE: access_state needs a const_string_t, which is a flecsi
352  // datatype that apparently can't convert from a std::string...
353  // I added to the case where it can create from a char*
354  const const_string_t flecsiname(var_name.c_str());
355  auto dat = access_state(flecsi_mesh_,
356  std::forward<const const_string_t>(flecsiname),
357  real_t);
358  // note this might be fragile in the case of non-dense storage
359  *data = &dat[0];
360  }
361 
367  int get_data_size(entity_kind_t on_what, std::string const& var_name) const {
368  const const_string_t flecsiname(var_name.c_str());
369  auto dat = access_state(flecsi_mesh_,
370  std::forward<const const_string_t>(flecsiname),
371  real_t);
372  return (dat.size());
373  }
374 
375 #endif
376 
377  private:
379  mesh_t * mesh_ = nullptr;
380 }; // Flecsi_State_Wrapper
381 
382 } // namespace Wonton
void mat_add_celldata(std::string const &var_name, int matid, Point< 3 > const *values)
Definition: flecsi_state_wrapper.h:274
Definition: wonton.h:84
int mat_get_num_cells(int matid) const
Get number of cells containing a particular material.
Definition: flecsi_state_wrapper.h:86
void mat_add_celldata(std::string const &var_name, int matid, Point< 2 > const *values)
Definition: flecsi_state_wrapper.h:270
void cell_get_mats(int cellid, std::vector< int > *cellmats) const
Get the IDs of materials in a cell.
Definition: flecsi_state_wrapper.h:112
std::vector< std::string > names() const
Vector of names.
Definition: flecsi_state_wrapper.h:335
Factorize a number N into D equal (or nearly equal) factors.
Definition: adaptive_refinement_mesh.h:31
flecsi_state_t()=default
Default constructor deleted.
int num_materials() const
Number of materials in problem.
Definition: flecsi_state_wrapper.h:71
Entity_type
The parallel type of a given entity.
Definition: wonton.h:124
void mat_add_cells(int matid, std::vector< int > const &newcells)
Add cells to material (or add material to cells)
Definition: flecsi_state_wrapper.h:295
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: flecsi_state_wrapper.h:266
Definition: wonton.h:85
Data_layout
Definition: wonton.h:209
flecsi_state_t(mesh_t &mesh)
Default constructor.
Definition: flecsi_state_wrapper.h:52
const std::type_info & get_data_type(std::string const &var_name) const
Get the data type of the given field.
Definition: flecsi_state_wrapper.h:327
void mat_get_cells(int matid, std::vector< int > *matcells) const
Get cell indices containing a particular material.
Definition: flecsi_state_wrapper.h:95
std::string material_name(int matid) const
Name of material.
Definition: flecsi_state_wrapper.h:77
void mesh_get_data(entity_kind_t on_what, std::string const &var_name, T **data) const
Get pointer to scalar data.
Definition: flecsi_state_wrapper.h:169
Definition: wonton.h:88
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
void mat_get_celldata(std::string const &var_name, int matid, T const **data) const
Get pointer to read-only scalar cell data for a particular material.
Definition: flecsi_state_wrapper.h:203
Provides access to data stored in Flecsi_State.
Definition: flecsi_state_wrapper.h:27
int get_data_size(entity_kind_t on_what, std::string const &var_name) const
Definition: flecsi_state_wrapper.h:316
Entity_kind
The type of mesh entity.
Definition: wonton.h:81
flecsi_state_t & operator=(const flecsi_state_t &)=default
Default assignment operator.
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: flecsi_state_wrapper.h:221
Field_type field_type(Entity_kind on_what, std::string const &var_name) const
Type of field (MESH_FIELD or MULTIMATERIAL_FIELD)
Definition: flecsi_state_wrapper.h:130
void mat_get_celldata(std::string const &var_name, int matid, T **data)
Get pointer to read-write scalar data for a particular material.
Definition: flecsi_state_wrapper.h:212
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: flecsi_state_wrapper.h:234
entity_kind_t get_entity(std::string const &var_name) const
Get the entity type on which the given field is defined.
Definition: flecsi_state_wrapper.h:146
int cell_get_num_mats(int cellid) const
Get number of materials contained in a cell.
Definition: flecsi_state_wrapper.h:104
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: flecsi_state_wrapper.h:250
int cell_index_in_material(int meshcell, int matid) const
Get the local index of mesh cell in material cell list.
Definition: flecsi_state_wrapper.h:121
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: flecsi_state_wrapper.h:287
void add_material(std::string const &matname, std::vector< int > const &matcells)
Add a material to state.
Definition: flecsi_state_wrapper.h:311
void mat_rem_cells(int matid, std::vector< int > const &delcells)
Remove cells from material (or remove material from cells)
Definition: flecsi_state_wrapper.h:303