jali_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 */
6 
7 #ifndef JALI_MESH_WRAPPER_H_
8 #define JALI_MESH_WRAPPER_H_
9 
10 #include <cassert>
11 #include <algorithm>
12 #include <vector>
13 #include <array>
14 #include <utility>
15 
16 #include "Mesh.hh" // Jali mesh header
17 
19 #include "wonton/support/wonton.h"
20 #include "wonton/support/Point.h"
21 
22 namespace Wonton {
23 
41 template <int D>
43 Point<D> toWontonPoint(const JaliGeometry::Point& jp) {
44  Point<D> pp;
45  assert(jp.dim() == D);
46  for (int d = 0; d < D; ++d)
47  pp[d] = jp[d];
48  return pp;
49 }
50 
51 class Jali_Mesh_Wrapper : public AuxMeshTopology<Jali_Mesh_Wrapper> {
52  public:
53 
58 
59  explicit Jali_Mesh_Wrapper(Jali::Mesh const & mesh,
60  bool request_sides = true,
61  bool request_wedges = true,
62  bool request_corners = true) :
64  (request_sides, request_wedges, request_corners),
65  jali_mesh_(mesh) {
66 
67  // base class (AuxMeshTopology) method that has to be called here
68  // and not in the constructor of the base class because it needs
69  // access to methods in this class which in turn need access to
70  // its member variables. But these member vars don't get
71  // initialized until the base class is constructed
72 
74  }
75 
77  Jali_Mesh_Wrapper(Jali_Mesh_Wrapper const & inmesh) = delete;
78 
80  Jali_Mesh_Wrapper & operator=(Jali_Mesh_Wrapper const & inmesh) = delete;
81 
84 
86  int space_dimension() const {
87  return jali_mesh_.space_dimension();
88  }
89 
91  int num_owned_cells() const {
92  return jali_mesh_.num_entities(Jali::Entity_kind::CELL,
94  }
95 
97  int num_owned_faces() const {
98  return jali_mesh_.num_entities(Jali::Entity_kind::FACE,
100  }
101 
103  int num_owned_nodes() const {
104  return jali_mesh_.num_entities(Jali::Entity_kind::NODE,
106  }
107 
109  int num_ghost_cells() const {
110  return jali_mesh_.num_entities(Jali::Entity_kind::CELL,
112  }
113 
115  int num_ghost_faces() const {
116  return jali_mesh_.num_entities(Jali::Entity_kind::FACE,
118  }
119 
121  int num_ghost_nodes() const {
122  return jali_mesh_.num_entities(Jali::Entity_kind::NODE,
124  }
125 
129 
130  Wonton::Entity_type cell_get_type(int const cellid) const {
131  Jali::Entity_type etype =
132  jali_mesh_.entity_get_type(Jali::Entity_kind::CELL, cellid);
133  return jali2wonton_type(etype);
134  }
135 
139 
140  Wonton::Entity_type node_get_type(int const nodeid) const {
141  Jali::Entity_type etype =
142  jali_mesh_.entity_get_type(Jali::Entity_kind::NODE, nodeid);
143  return jali2wonton_type(etype);
144  }
145 
148 
149  Wonton::Element_type cell_get_element_type(int const cellid) const {
150  Jali::Cell_type ctype = jali_mesh_.cell_get_type(cellid);
151  return jali2wonton_elemtype(ctype);
152  }
153 
155  void cell_get_faces_and_dirs(int const cellid, std::vector<int> *cfaces,
156  std::vector<int> *cfdirs) const {
157  std::vector<Jali::dir_t> fdirs;
158 
159  jali_mesh_.cell_get_faces_and_dirs(cellid, cfaces, &fdirs);
160 
161  cfdirs->resize(fdirs.size());
162  int const nb_dirs = fdirs.size();
163  for (int i = 0; i < nb_dirs; ++i)
164  (*cfdirs)[i] = static_cast<int>(fdirs[i]);
165  }
166 
168  void cell_get_nodes(int cellid, std::vector<int> *nodes) const {
169  jali_mesh_.cell_get_nodes(cellid, nodes);
170  }
171 
173  void cell_get_node_adj_cells(int const cellid,
174  Entity_type const ptype,
175  std::vector<int> *adjcells) const {
176  jali_mesh_.cell_get_node_adj_cells(cellid, (Jali::Entity_type) ptype,
177  adjcells);
178  }
179 
181  void face_get_nodes(int const faceid, std::vector<int> *fnodes) const {
182  jali_mesh_.face_get_nodes(faceid, fnodes);
183  }
184 
185 
187  void node_get_cells(int const nodeid,
188  Entity_type const ptype,
189  std::vector<int> *nodecells) const {
190  jali_mesh_.node_get_cells(nodeid, (Jali::Entity_type) ptype,
191  nodecells);
192  }
193 
195  GID_t get_global_id(int const id, Entity_kind const kind) const {
196  return jali_mesh_.GID(id, (Jali::Entity_kind)kind);
197  }
198 
200  template <int D>
201  void node_get_coordinates(int const nodeid, Point<D>* pp) const {
202  JaliGeometry::Point jp;
203  jali_mesh_.node_get_coordinates(nodeid, &jp);
204  assert(jp.dim() == D);
205  *pp = toWontonPoint<D>(jp);
206  }
207 
208  private:
209 
210  Wonton::Entity_type jali2wonton_type(Jali::Entity_type etype) const {
211  static Wonton::Entity_type jali2wonton_type_[5] =
213  return jali2wonton_type_[static_cast<int>(etype)];
214  }
215 
216  Wonton::Element_type jali2wonton_elemtype(Jali::Cell_type elemtype) const {
217  static Wonton::Element_type jali2wonton_elemtype_[9] =
219  POLYHEDRON};
220  return jali2wonton_elemtype_[static_cast<int>(elemtype)];
221  }
222 
223  Jali::Mesh const & jali_mesh_;
224 }; // class Jali_Mesh_Wrapper
225 
226 
227 } // end namespace Wonton
228 
229 #endif // JALI_MESH_WRAPPER_H_
Definition: wonton.h:157
Definition: wonton.h:130
Definition: wonton.h:128
Definition: wonton.h:156
Wonton::Entity_type cell_get_type(int const cellid) const
Definition: jali_mesh_wrapper.h:130
Jali_Mesh_Wrapper(Jali::Mesh const &mesh, bool request_sides=true, bool request_wedges=true, bool request_corners=true)
Definition: jali_mesh_wrapper.h:59
Definition: wonton.h:129
Factorize a number N into D equal (or nearly equal) factors.
Definition: adaptive_refinement_mesh.h:31
Definition: wonton.h:162
Point< D > toWontonPoint(const JaliGeometry::Point &jp)
helper function: convert Jali point to Wonton point
Definition: jali_mesh_wrapper.h:43
Definition: wonton.h:87
int num_owned_faces() const
Number of owned faces in the mesh.
Definition: jali_mesh_wrapper.h:97
void cell_get_nodes(int cellid, std::vector< int > *nodes) const
Get list of nodes for a cell.
Definition: jali_mesh_wrapper.h:168
Definition: wonton.h:160
~Jali_Mesh_Wrapper()
Empty destructor.
Definition: jali_mesh_wrapper.h:83
int num_ghost_nodes() const
Number of ghost nodes in the mesh.
Definition: jali_mesh_wrapper.h:121
void node_get_cells(int const nodeid, Entity_type const ptype, std::vector< int > *nodecells) const
Get cells of a node.
Definition: jali_mesh_wrapper.h:187
Definition: wonton.h:155
Entity_type
The parallel type of a given entity.
Definition: wonton.h:124
void face_get_nodes(int const faceid, std::vector< int > *fnodes) const
Get nodes of a face.
Definition: jali_mesh_wrapper.h:181
Jali_Mesh_Wrapper & operator=(Jali_Mesh_Wrapper const &inmesh)=delete
Assignment operator (Deleted)
Definition: wonton.h:85
Definition: wonton.h:161
Definition: wonton.h:158
void cell_get_node_adj_cells(int const cellid, Entity_type const ptype, std::vector< int > *adjcells) const
Get node connected neighbors of cell.
Definition: jali_mesh_wrapper.h:173
int space_dimension() const
Dimension of space or mesh points.
Definition: jali_mesh_wrapper.h:86
void node_get_coordinates(int const nodeid, Point< D > *pp) const
coords of a node
Definition: jali_mesh_wrapper.h:201
Definition: wonton.h:88
Represents a point in an N-dimensional space.
Definition: Point.h:50
int num_owned_cells() const
Number of owned cells in the mesh.
Definition: jali_mesh_wrapper.h:91
int num_owned_nodes() const
Number of owned nodes in the mesh.
Definition: jali_mesh_wrapper.h:103
Entity_kind
The type of mesh entity.
Definition: wonton.h:81
Definition: wonton.h:126
Jali_Mesh_Wrapper implements mesh methods for Jali.
Definition: jali_mesh_wrapper.h:51
Wonton::Element_type cell_get_element_type(int const cellid) const
Definition: jali_mesh_wrapper.h:149
int num_ghost_cells() const
Number of ghost cells in the mesh.
Definition: jali_mesh_wrapper.h:109
void build_aux_entities()
Definition: AuxMeshTopology.h:1331
int64_t GID_t
Definition: wonton.h:76
Wonton::Entity_type node_get_type(int const nodeid) const
Definition: jali_mesh_wrapper.h:140
Definition: wonton.h:154
Element_type
Element (cell topology) type.
Definition: wonton.h:153
Definition: wonton.h:159
int num_ghost_faces() const
Number of ghost faces in the mesh.
Definition: jali_mesh_wrapper.h:115
Definition: wonton.h:127
GID_t get_global_id(int const id, Entity_kind const kind) const
Get global id.
Definition: jali_mesh_wrapper.h:195
void cell_get_faces_and_dirs(int const cellid, std::vector< int > *cfaces, std::vector< int > *cfdirs) const
Get cell faces and the directions in which they are used.
Definition: jali_mesh_wrapper.h:155