flecsi_mesh_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 
13 // library includes
14 #include <wonton/support/wonton.h>
15 #include <wonton/support/Point.h>
17 
18 // system includes
19 #include <algorithm>
20 #include <map>
21 #include <memory>
22 #include <vector>
23 #include <iostream>
24 
25 namespace Wonton {
26 
30 // @{
31 template<
32  typename T,
33  template<typename, std::size_t> class A
34 >
35 Point<3> make_point(const A<T, 3> & a) {
36  return { a[0], a[1], a[2] };
37 }
38 
39 template<
40  typename T,
41  template<typename, std::size_t> class A
42 >
43 Point<2> make_point(const A<T, 2> & a) {
44  return { a[0], a[1] };
45 }
46 
47 template<typename T>
49  return { std::forward<T>(a)[0] };
50 }
51 
52 template<typename T>
54  return { std::forward<T>(a)[0], std::forward<T>(a)[1] };
55 }
56 
57 template<typename T>
59  return {
60  std::forward<T>(a)[0], std::forward<T>(a)[1], std::forward<T>(a)[2]
61  };
62 }
63 // @}
64 
65 
69 template< typename M >
70 class flecsi_mesh_t : public AuxMeshTopology<flecsi_mesh_t<M>> {
71  public:
72  //============================================================================
73  // Typedefs
74  //============================================================================
75 
78 
80  using mesh_t = M;
82  using size_t = typename mesh_t::size_t;
84  using real_t = typename mesh_t::real_t;
86  using shape_t = typename mesh_t::shape_t;
87 
96 
98  using shape_map_t = std::map< shape_t, element_type_t >;
99 
106 
107  //============================================================================
108  // Public Static Data
109  //============================================================================
110 
113 
114  //============================================================================
115  // Constructors
116  //============================================================================
117 
120  explicit flecsi_mesh_t(const mesh_t & mesh,
121  bool request_sides = true,
122  bool request_wedges = true,
123  bool request_corners = true) :
124  cells_(mesh.cells()), faces_(mesh.faces()),
125  vertices_(mesh.vertices()), mesh_(&mesh),
126  wonton_mesh_aux_t(request_sides, request_wedges, request_corners) {
127  // base class (AuxMeshTopology) method that has to be called here
128  // and not in the constructor of the base class because it needs
129  // access to methods in this class which in turn need access to
130  // its member variables. But these member vars don't get
131  // initialized until the base class is constructed
133  }
134 
136  flecsi_mesh_t() = default;
137 
139  flecsi_mesh_t(const flecsi_mesh_t &) = default;
140 
142  flecsi_mesh_t & operator=(const flecsi_mesh_t &) = default;
143 
144  //============================================================================
145  // Public Members Required By Wonton
146  //============================================================================
147 
149  constexpr auto space_dimension() const {
150  return mesh_t::num_dimensions;
151  }
152 
154  auto cell_volume(size_t cell_id) const {
155  return cells_[cell_id]->volume();
156  }
157 
160  auto dual_cell_volume(size_t node_id) const {
161  // auto v = mesh_->vertices()[node_id];
162  // real_t vol = 0.0;
163  // for (auto corner : mesh_->corners(v))
164  // vol += corner->area();
165  // return vol;
166 
167  // raise_implemented_error("dual_cell_volume not implemented yet!");
168  std::cerr << "dual_cell_volume not implemented yet!\n";
169  return 0.0;
170  }
171 
173  size_t num_owned_cells() const {
174  return mesh_->num_cells();
175  }
176 
178  size_t num_owned_faces() const {
179  return mesh_->num_faces();
180  }
181 
183  size_t num_owned_edges() const {
184  return mesh_->num_edges();
185  }
186 
188  size_t num_owned_nodes() const {
189  return mesh_->num_vertices();
190  }
191 
193  size_t num_ghost_cells() const {
194  return 0;
195  }
196 
198  size_t num_ghost_faces() const {
199  return 0;
200  }
201 
203  size_t num_ghost_nodes() const {
204  return 0;
205  }
206 
211  size_t num_entities(
212  entity_kind_t entity,
213  entity_type_t entity_type = entity_type_t::ALL) const {
214  switch (entity) {
215  case entity_kind_t::NODE :
216  return num_owned_nodes();
217  case entity_kind_t::EDGE :
218  return num_owned_edges();
219  case entity_kind_t::FACE :
220  return num_owned_faces();
221  case entity_kind_t::CELL :
222  return num_owned_cells();
223  case entity_kind_t::WEDGE :
224  return mesh_->num_wedges();
225  break;
226  case entity_kind_t::CORNER :
227  return mesh_->num_corners();
228  default :
229  // raise_runtime_error("Unknown entity type");
230  std::cerr << "Unknown entity type\n";
231  return 0;
232  }
233  }
234 
239  auto begin(
240  entity_kind_t entity,
241  entity_type_t entity_type = entity_type_t::ALL) const {
242  int start_index = 0;
243  return make_counting_iterator(start_index);
244  }
245 
250  auto end(
251  entity_kind_t entity,
252  entity_type_t entity_type = entity_type_t::ALL) const {
253  return begin(entity, entity_type) + num_entities(entity, entity_type);
254  }
255 
259  template< typename T >
260  void cell_get_nodes(size_t cell_id, std::vector<T> * nodes) const {
261  auto c = cells_[cell_id];
262  nodes->clear();
263  for (auto v : mesh_->vertices(c))
264  nodes->emplace_back(v.id());
265  }
266 
267 
268 
273  template< typename T >
275  size_t cell_id,
276  std::vector<T> *faces,
277  std::vector<T> *face_dirs) const {
278  faces->clear();
279  face_dirs->clear();
280  auto c = cells_[cell_id];
281  for (auto f : mesh_->faces(c)) {
282  faces->emplace_back(f.id());
283  face_dirs->emplace_back(mesh_->cells(f)[0] == c ? 1 : -1);
284  }
285  }
286 
290  template< typename T >
292  size_t face_id,
293  std::vector<T> *nodes) const {
294  auto f = faces_[face_id];
295  nodes->clear();
296  for (auto v : mesh_->vertices(f))
297  nodes->emplace_back(v.id());
298  // std::reverse(nodes->begin(), nodes->end());
299  }
300 
311  template< typename T >
313  size_t node_id,
314  entity_type_t type,
315  std::vector<T> *adj_cells) const {
316  adj_cells->clear();
317  auto this_node = vertices_[node_id];
318  for (auto cell : mesh_->cells(this_node))
319  adj_cells->emplace_back(cell.id());
320  }
321 
328  template < typename T >
330  size_t node_id,
331  entity_type_t const type,
332  std::vector<T> *adj_nodes) const {
333  auto this_node = vertices_[node_id];
334  adj_nodes->clear();
335  // Loop over cells associated with this node
336  for (auto cell : mesh_->cells(this_node)) {
337  // Loop over the nodes associated with this cell
338  for (auto node : mesh_->vertices(cell)) {
339  if (this_node != node)
340  adj_nodes->emplace_back(node.id());
341  }
342  }
343 
344  //remove duplicates
345  std::sort(adj_nodes->begin(), adj_nodes->end());
346  adj_nodes->erase(std::unique(adj_nodes->begin(), adj_nodes->end()), adj_nodes->end());
347 
348  }
349 
350 
351 
359  size_t node_id,
360  point_1d_t * pp) const {
361  auto v = vertices_[node_id];
362  *pp = make_1d_point(v->coordinates());
363  }
364 
366  size_t node_id,
367  point_2d_t * pp) const {
368  auto v = vertices_[node_id];
369  *pp = make_2d_point(v->coordinates());
370  }
371 
373  size_t node_id,
374  point_3d_t * pp) const {
375  auto v = vertices_[node_id];
376  *pp = make_3d_point(v->coordinates());
377  }
378 
379 
387  size_t const cell_id,
388  std::vector<point_t> *point_list) const {
389  // Get this cell object
390  auto cell = cells_[cell_id];
391 
392  // Loop over vertices of this cell to get their coordinates
393  point_list->clear();
394  auto verts = mesh_->vertices(cell);
395  for (auto v : verts)
396  point_list->emplace_back(make_point(v->coordinates()));
397  }
398 
413  size_t node_id,
414  std::vector<point_t> *point_list) const {
415  // raise_implemented_error("dual_cell_get_coordinates not implemented yet!");
416  std::cerr << "dual_cell_get_coordinates not implemented yet!\n";
417  }
418 
425  size_t cell_id,
426  point_t * centroid) const {
427  auto this_cell = cells_[cell_id];
428  *centroid = make_point(this_cell->centroid());
429  }
430 
442  size_t node_id,
443  point_t *centroid) const {
444  auto this_node = vertices_[node_id];
445  *centroid = make_point(this_node->coordinates());
446  }
447 
448 
449  //============================================================================
450  // Public Members Required By Wonton
451  // These are only needed in 3D
452  //============================================================================
453 
462  auto cell_get_type(size_t cell_id) const {
464  }
465 
468 
475  auto cell_get_element_type(size_t cell_id) const {
476  // search for the type in the map
477  /*auto tp = cells_[cell_id]->type();
478  auto it = shapes_to_wonton.find(tp);
479  // if it was found, return the mapped type
480  if (it != shapes_to_wonton.end())
481  return it->second;
482  // otherwise we dont know what it is
483  return element_type_t::UNKNOWN_TOPOLOGY;*/
484 
485  auto this_cell = cells_[cell_id];
486  auto conn = mesh_->vertices(this_cell);
487  if (conn.size() == 8)
488  return element_type_t::HEX;
489  else
491  }
492 
501  auto node_get_type(size_t node_id) const {
503  }
504 
506  GID_t get_global_id(size_t id, entity_kind_t const kind) const {
507  std::cerr << "get_global_id not implemented yet!\n";
508  return 0;
509  }
510 
511  /*int get_global_id(size_t id, entity_kind_t const kind) const
512  {
513  if (kind == entity_kind_t::NODE)
514  {
515  auto ent = vertices_[id];
516  auto gid = ent.global_id();
517  return gid.global();
518  }
519  else if (kind == entity_kind_t::CELL)
520  {
521  auto ent = cells_[id];
522  auto gid = ent.global_id();
523  return gid.global();
524  }
525  else
526  return 0;
527  }*/
528 
529  //============================================================================
530  // Private Members
531  //============================================================================
532 
533  private:
535  const mesh_t * mesh_ = nullptr;
537  decltype(mesh_->cells()) cells_;
539  decltype(mesh_->faces()) faces_;
541  decltype(mesh_->vertices()) vertices_;
542 }; // class flecsi_mesh_t
543 
545 // Static Initialization
547 
548 /*template< typename M >
549 const typename wonton_mesh_t<M>::shape_map_t
550  wonton_mesh_t<M>::shapes_to_wonton =
551 {
552  {
553  shape_t::triangle,
554  element_type_t::TRI
555  },
556  {
557  shape_t::quadrilateral,
558  element_type_t::QUAD
559  },
560  {
561  shape_t::polygon,
562  element_type_t::POLYGON
563  },
564  {
565  shape_t::tetrahedron,
566  element_type_t::TET
567  },
568  {
569  shape_t::hexahedron,
570  element_type_t::HEX
571  },
572  {
573  shape_t::polyhedron,
574  element_type_t::POLYHEDRON
575  }
576 };*/
577 
578 
579 } // namespace Wonton
size_t num_ghost_faces() const
Number of ghost faces in the mesh.
Definition: flecsi_mesh_wrapper.h:198
Point< 1 > make_1d_point(T &&a)
Definition: flecsi_mesh_wrapper.h:48
Definition: wonton.h:130
flecsi_mesh_t & operator=(const flecsi_mesh_t &)=default
Default assignment operator.
flecsi_mesh_t()=default
Default constructor deleted.
Point< 3 > make_3d_point(T &&a)
Definition: flecsi_mesh_wrapper.h:58
Point< 2 > make_2d_point(T &&a)
Definition: flecsi_mesh_wrapper.h:53
size_t num_owned_edges() const
Number of owned edges in the mesh.
Definition: flecsi_mesh_wrapper.h:183
auto cell_get_type(size_t cell_id) const
Get the type of the cell - PARALLEL_OWNED or PARALLEL_GHOST.
Definition: flecsi_mesh_wrapper.h:462
Factorize a number N into D equal (or nearly equal) factors.
Definition: adaptive_refinement_mesh.h:31
Definition: wonton.h:87
flecsi_mesh_t(const mesh_t &mesh, bool request_sides=true, bool request_wedges=true, bool request_corners=true)
Constructor for creating a serial, 2D/3D Cartesian mesh.
Definition: flecsi_mesh_wrapper.h:120
size_t num_entities(entity_kind_t entity, entity_type_t entity_type=entity_type_t::ALL) const
Definition: flecsi_mesh_wrapper.h:211
Definition: wonton.h:90
auto cell_get_element_type(size_t cell_id) const
Get the element type of a cell.
Definition: flecsi_mesh_wrapper.h:475
Entity_type
The parallel type of a given entity.
Definition: wonton.h:124
void node_get_cells(size_t node_id, entity_type_t type, std::vector< T > *adj_cells) const
Get connected cells of given node.
Definition: flecsi_mesh_wrapper.h:312
Definition: wonton.h:85
Definition: wonton.h:161
size_t num_owned_cells() const
Number of owned cells in the mesh.
Definition: flecsi_mesh_wrapper.h:173
size_t num_ghost_nodes() const
Number of ghost nodes in the mesh.
Definition: flecsi_mesh_wrapper.h:203
void cell_get_coordinates(size_t const cell_id, std::vector< point_t > *point_list) const
Get the coodinates of the nodes of a cell.
Definition: flecsi_mesh_wrapper.h:386
Definition: wonton.h:88
Represents a point in an N-dimensional space.
Definition: Point.h:50
Definition: wonton.h:86
void node_get_coordinates(size_t node_id, point_2d_t *pp) const
Definition: flecsi_mesh_wrapper.h:365
void node_get_coordinates(size_t node_id, point_1d_t *pp) const
Get the coords of a node.
Definition: flecsi_mesh_wrapper.h:358
void cell_centroid(size_t cell_id, point_t *centroid) const
Centroid of a cell.
Definition: flecsi_mesh_wrapper.h:424
counting_iterator make_counting_iterator(int const i)
Definition: wonton.h:291
auto cell_volume(size_t cell_id) const
Cell area/volume.
Definition: flecsi_mesh_wrapper.h:154
Entity_kind
The type of mesh entity.
Definition: wonton.h:81
void dual_cell_get_node_adj_cells(size_t node_id, entity_type_t const type, std::vector< T > *adj_nodes) const
Get adjacent "dual cells" of a given "dual cell".
Definition: flecsi_mesh_wrapper.h:329
size_t num_ghost_cells() const
Number of ghost cells in the mesh.
Definition: flecsi_mesh_wrapper.h:193
void cell_get_nodes(size_t cell_id, std::vector< T > *nodes) const
Definition: flecsi_mesh_wrapper.h:260
void node_get_coordinates(size_t node_id, point_3d_t *pp) const
Definition: flecsi_mesh_wrapper.h:372
size_t num_owned_nodes() const
Number of owned nodes in the mesh.
Definition: flecsi_mesh_wrapper.h:188
void build_aux_entities()
Definition: AuxMeshTopology.h:1331
typename mesh_t::shape_t shape_t
the gometric shape
Definition: flecsi_mesh_wrapper.h:86
int64_t GID_t
Definition: wonton.h:76
auto begin(entity_kind_t entity, entity_type_t entity_type=entity_type_t::ALL) const
Definition: flecsi_mesh_wrapper.h:239
typename mesh_t::real_t real_t
the real type
Definition: flecsi_mesh_wrapper.h:84
Definition: wonton.h:91
auto end(entity_kind_t entity, entity_type_t entity_type=entity_type_t::ALL) const
Definition: flecsi_mesh_wrapper.h:250
auto node_get_type(size_t node_id) const
Get the type of the node - PARALLEL_OWNED or PARALLEL_GHOST.
Definition: flecsi_mesh_wrapper.h:501
void dual_cell_centroid(size_t node_id, point_t *centroid) const
Centroid of a dual cell.
Definition: flecsi_mesh_wrapper.h:441
static const shape_map_t shapes_to_wonton
the map between
Definition: flecsi_mesh_wrapper.h:112
Definition: wonton.h:154
void dual_cell_get_coordinates(size_t node_id, std::vector< point_t > *point_list) const
2D version of coords of nodes of a dual cell
Definition: flecsi_mesh_wrapper.h:412
size_t num_owned_faces() const
Number of owned faces in the mesh.
Definition: flecsi_mesh_wrapper.h:178
void face_get_nodes(size_t face_id, std::vector< T > *nodes) const
Definition: flecsi_mesh_wrapper.h:291
Element_type
Element (cell topology) type.
Definition: wonton.h:153
std::map< shape_t, element_type_t > shape_map_t
a map type for mapping mesh shapes to wonton shapes
Definition: flecsi_mesh_wrapper.h:98
auto dual_cell_volume(size_t node_id) const
Definition: flecsi_mesh_wrapper.h:160
GID_t get_global_id(size_t id, entity_kind_t const kind) const
Get global id.
Definition: flecsi_mesh_wrapper.h:506
M mesh_t
The mesh type.
Definition: flecsi_mesh_wrapper.h:80
Definition: wonton.h:127
void cell_get_faces_and_dirs(size_t cell_id, std::vector< T > *faces, std::vector< T > *face_dirs) const
Definition: flecsi_mesh_wrapper.h:274
Implements a mesh wrapper for Wonton mesh queries.
Definition: flecsi_mesh_wrapper.h:70
Point< 3 > make_point(const A< T, 3 > &a)
A utility function to convert a type to a wonton point.
Definition: flecsi_mesh_wrapper.h:35
constexpr auto space_dimension() const
Dimension of space or mesh points.
Definition: flecsi_mesh_wrapper.h:149