wonton.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_SUPPORT_WONTON_H_
8 #define WONTON_SUPPORT_WONTON_H_
9 
10 // Autogenerated file that contains configuration specific defines
11 // like WONTON_ENABLE_MPI and WONTON_ENABLE_THRUST
12 #include "wonton-config.h"
13 
14 
15 #ifdef WONTON_ENABLE_THRUST
16 
17 #include "thrust/device_vector.h"
18 #include "thrust/iterator/counting_iterator.h"
19 #include "thrust/transform.h"
20 
21 #else // no thrust
22 
23 #include <boost/iterator/counting_iterator.hpp>
24 
25 #include <vector>
26 #include <algorithm>
27 #include <string>
28 
29 #endif
30 
31 #ifdef WONTON_ENABLE_MPI
32 #include "mpi.h"
33 #endif
34 
35 #ifdef WONTON_ENABLE_KOKKOS
36 #include <Kokkos_Macros.hpp>
37 #endif
38 
39 /*
40  @file wonton.h
41  @brief Several utility types and functions within the Wonton namespace.
42  */
43 
44 /*
45  @namespace Wonton
46  The Wonton namespace houses all of the code within Wonton.
47 
48  Cells (aka zones/elements) are the highest dimension entities in a mesh
49  Nodes (aka vertices) are lowest dimension entities in a mesh
50  Faces in a 3D mesh are 2D entities, in a 2D mesh are 1D entities
51  BOUNDARY_FACE is a special type of entity that is need so that process
52  kernels can define composite vectors (see src/data_structures) on
53  exterior boundary faces of the mesh only
54 
55  Wedges are special subcell entities that are a simplicial
56  decomposition of cell. In 3D, a wedge is tetrahedron formed by one
57  point of the edge, the midpoint of the edge, the "center" of the
58  face and the "center" of the cell volume. In 2D, a wedge is a
59  triangle formed by an end-point of the edge, the mid-point of the
60  edge and the center of the cell. In 1D, wedges are lines, that are
61  formed by the endpoint of the cell and the midpoint of the
62  cell. There are two wedges associated with an edge of cell face in
63  3D.
64 
65  Corners are also subcell entities that are associated uniquely with
66  a node of a cell. Each corner is the union of all the wedges incident
67  upon that node in the cell
68 
69  Facets are the boundary entity between two wedges in adjacent
70  cells. In 3D, a facet is a triangular subface of the cell face
71  shared by two wedges in adjacent cells. In 2D, a facet is half of
72  an edge that is shared by two wedges in adjacent cells
73  */
74 namespace Wonton {
75 
76 typedef int64_t GID_t;
80 enum Entity_kind {
82  ALL_KIND = -3,
83  ANY_KIND = -2,
84  UNKNOWN_KIND = -1,
85  NODE = 0,
95 };
96 constexpr int NUM_ENTITY_KIND = 13;
97 
98 // Method to get Entity_kind in string form
99 inline std::string to_string(Entity_kind entkind) {
100  static const std::string kind2string[NUM_ENTITY_KIND] =
101  {"Entity_kind::ALL_KIND",
102  "Entity_kind::ANY_KIND",
103  "Entity_kind::UNKNOWN_KIND",
104  "Entity_kind::NODE",
105  "Entity_kind::EDGE",
106  "Entity_kind::FACE",
107  "Entity_kind::CELL",
108  "Entity_kind::SIDE",
109  "Entity_kind::WEDGE",
110  "Entity_kind::CORNER",
111  "Entity_kind::FACET",
112  "Entity_kind::BOUNDARY_FACE",
113  "Entity_kind::PARTICLE"};
114 
115  int itype = static_cast<int>(entkind)+3;
116  return ((itype >= 0 && itype < NUM_ENTITY_KIND) ? kind2string[itype] :
117  "INVALID Entity_kind");
118 }
119 
120 
121 
122 // Parallel status of entity
126  DELETED = 0,
130  ALL = 4
131 };
132 constexpr int NUM_ENTITY_TYPE = 6;
133 
134 // Method to get Entity_type in string form
135 inline std::string to_string(Entity_type enttype) {
136  static const std::string type2string[NUM_ENTITY_TYPE] =
137  {"Entity_type::TYPE_UNKNOWN",
138  "Entity_type::DELETED",
139  "Entity_type::PARALLEL_OWNED",
140  "Entity_type::PARALLEL_GHOST",
141  "Entity_type::BOUNDARY_GHOST",
142  "Entity_type::ALL"};
143 
144  int itype = static_cast<int>(enttype)+1;
145  return ((itype >= 0 && itype < NUM_ENTITY_TYPE) ? type2string[itype] :
146  "INVALID Entity_type");
147 }
148 
149 
150 
151 
163 };
164 constexpr int NUM_ELEMENT_TYPE = 9;
165 
166 // Method to get Element_type in string form
167 inline std::string to_string(Element_type elemtype) {
168  static const std::string type2string[NUM_ELEMENT_TYPE] =
169  {"Element_type::UNKNOWN_TOPOLOGY",
170  "Element_type::TRI",
171  "Element_type::QUAD",
172  "Element_type::POLYGON",
173  "Element_type::TET",
174  "Element_type::PRISM",
175  "Element_type::PYRAMID",
176  "Element_type::HEX",
177  "Element_type::POLYHEDRON"};
178 
179  int itype = static_cast<int>(elemtype)+1;
180  return ((itype >= 0 && itype < NUM_ELEMENT_TYPE) ? type2string[itype] :
181  "INVALID Element_type");
182 }
183 
184 
185 
187 enum class Field_type {
188  UNKNOWN_TYPE_FIELD = -1,
189  MESH_FIELD,
191 };
192 constexpr int NUM_FIELD_TYPE = 3;
193 
194 inline std::string to_string(Field_type field_type) {
195  static const std::string type2string[NUM_FIELD_TYPE] =
196  {"Field_type::UNKNOWN_TYPE_FIELD",
197  "Field_type::MESH_FIELD",
198  "Field_type::MULTIMATERIAL_FIELD"};
199 
200  int itype = static_cast<int>(field_type)+1;
201  return ((itype >= 0 && itype < NUM_FIELD_TYPE) ? type2string[itype] :
202  "INVALID FIELD TYPE");
203 }
204 
205 
210 constexpr int NUM_DATA_LAYOUT = 2;
211 
212 inline std::string to_string(Data_layout layout) {
213  static const std::string type2string[NUM_DATA_LAYOUT] =
214  {"Data_layout::CELL_CENTRIC", "Data_layout::MATERIAL_CENTRIC"};
215 
216  int itype = static_cast<int>(layout)+1;
217  return ((itype >= 0 && itype < NUM_DATA_LAYOUT) ? type2string[itype] :
218  "INVALID DATA LAYOUT");
219 }
220 
221 
222 
226  virtual ~Executor_type() = default;
227 };
228 
229 struct SerialExecutor_type : Executor_type {}; // for RTTI
230 
231 #if !defined(WONTON_INLINE)
232  #ifdef WONTON_ENABLE_KOKKOS
233  #define WONTON_INLINE KOKKOS_INLINE_FUNCTION
234  #else
235  #define WONTON_INLINE inline
236  #endif
237 #endif
238 
239 #ifdef WONTON_ENABLE_MPI
240 struct MPIExecutor_type : Executor_type {
241  MPIExecutor_type(MPI_Comm comm) : mpicomm(comm) {}
242  MPI_Comm mpicomm = MPI_COMM_WORLD;
243 };
244 #endif
245 
246 
247 
248 #ifdef WONTON_ENABLE_THRUST
249 
250 template<typename T>
251  using vector = thrust::device_vector<T>;
252 
253 template<typename T>
254  using pointer = thrust::device_ptr<T>;
255 
256 typedef thrust::counting_iterator<int> counting_iterator;
257 inline counting_iterator make_counting_iterator(int const i) {
259 }
260 
261 template<typename InputIterator, typename OutputIterator,
262  typename UnaryFunction>
263 inline OutputIterator transform(InputIterator first, InputIterator last,
264  OutputIterator result, UnaryFunction op) {
265  return thrust::transform(first, last, result, op);
266 }
267 
268 template<typename InputIterator1, typename InputIterator2,
269  typename OutputIterator, typename BinaryFunction>
270 inline OutputIterator transform(InputIterator1 first1, InputIterator1 last1,
271  InputIterator2 first2, OutputIterator result,
272  BinaryFunction op) {
273  return thrust::transform(first1, last1, first2, result, op);
274 }
275 
276 template<typename InputIterator, typename UnaryFunction>
277 inline void for_each(InputIterator first, InputIterator last,
278  UnaryFunction f) {
279  thrust::for_each(first, last, f);
280 }
281 
282 #else // no thrust
283 
284 template<typename T>
285  using vector = std::vector<T>;
286 
287 template<typename T>
288  using pointer = T*;
289 
290 typedef boost::counting_iterator<int> counting_iterator;
291 inline counting_iterator make_counting_iterator(int const i) {
292  return boost::make_counting_iterator<int>(i);
293 }
294 
295 template<typename InputIterator, typename OutputIterator,
296  typename UnaryFunction>
297 inline OutputIterator transform(InputIterator first, InputIterator last,
298  OutputIterator result, UnaryFunction op) {
299  return std::transform(first, last, result, op);
300 }
301 
302 template<typename InputIterator1, typename InputIterator2,
303  typename OutputIterator, typename BinaryFunction>
304 inline OutputIterator transform(InputIterator1 first1, InputIterator1 last1,
305  InputIterator2 first2, OutputIterator result,
306  BinaryFunction op) {
307  return std::transform(first1, last1, first2, result, op);
308 }
309 
310 template<typename InputIterator, typename UnaryFunction>
311 inline void for_each(InputIterator first, InputIterator last,
312  UnaryFunction f) {
313  std::for_each(first, last, f);
314 }
315 #endif
316 
317 
318 struct Weights_t {
319  Weights_t() : entityID(-1) {}
320  Weights_t(int const entityID_in, std::vector<double> const& weights_in) :
321  entityID(entityID_in), weights(weights_in) {}
322  Weights_t(Weights_t const& source) :
323  entityID(source.entityID), weights(source.weights) {}
324 
325  int entityID;
326  std::vector<double> weights;
327 };
328 
329 inline double pow2(double x) { return x*x; }
330 
331 
332 // Convert from some Portage types to MPI types
333 #ifdef WONTON_ENABLE_MPI
334 template<typename T> MPI_Datatype to_MPI_Datatype();
335 template<> inline MPI_Datatype to_MPI_Datatype<GID_t>() {
336  return (sizeof(GID_t) == 8 ? MPI_LONG_LONG : MPI_INT);
337 }
338 #endif
339 
340 
341 } // namespace Wonton
342 
343 #endif // WONTON_SUPPORT_WONTON_H_
Definition: wonton.h:157
Definition: wonton.h:130
Definition: wonton.h:128
constexpr int NUM_FIELD_TYPE
Definition: wonton.h:192
OutputIterator transform(InputIterator first, InputIterator last, OutputIterator result, UnaryFunction op)
Definition: wonton.h:297
Definition: wonton.h:156
Definition: wonton.h:84
Definition: wonton.h:129
Weights_t(Weights_t const &source)
Definition: wonton.h:322
Definition: wonton.h:93
Factorize a number N into D equal (or nearly equal) factors.
Definition: adaptive_refinement_mesh.h:31
Definition: wonton.h:162
std::vector< T > vector
Definition: wonton.h:285
Definition: wonton.h:87
Definition: wonton.h:160
Weights_t()
Definition: wonton.h:319
Definition: wonton.h:90
Definition: wonton.h:155
constexpr int NUM_ENTITY_KIND
Definition: wonton.h:96
Entity_type
The parallel type of a given entity.
Definition: wonton.h:124
Definition: wonton.h:125
T * pointer
Definition: wonton.h:288
Definition: wonton.h:225
Definition: wonton.h:85
Definition: wonton.h:161
Definition: wonton.h:158
Definition: wonton.h:318
Data_layout
Definition: wonton.h:209
boost::counting_iterator< int > counting_iterator
Definition: wonton.h:290
constexpr int NUM_ENTITY_TYPE
Definition: wonton.h:132
std::vector< double > weights
Definition: wonton.h:326
constexpr int NUM_ELEMENT_TYPE
Definition: wonton.h:164
Definition: wonton.h:88
Field_type
Field type - whether it is mesh field or multi-material field.
Definition: wonton.h:187
Definition: wonton.h:86
counting_iterator make_counting_iterator(int const i)
Definition: wonton.h:291
Entity_kind
The type of mesh entity.
Definition: wonton.h:81
Definition: wonton.h:89
Definition: wonton.h:126
Weights_t(int const entityID_in, std::vector< double > const &weights_in)
Definition: wonton.h:320
int64_t GID_t
Definition: wonton.h:76
Definition: wonton.h:91
void for_each(InputIterator first, InputIterator last, UnaryFunction f)
Definition: wonton.h:311
double pow2(double x)
Definition: wonton.h:329
Definition: wonton.h:154
constexpr int NUM_DATA_LAYOUT
Definition: wonton.h:210
Element_type
Element (cell topology) type.
Definition: wonton.h:153
Definition: wonton.h:159
Definition: wonton.h:92
OutputIterator transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryFunction op)
Definition: wonton.h:304
Definition: wonton.h:83
Definition: wonton.h:127
Definition: wonton.h:94
std::string to_string(Entity_kind entkind)
Definition: wonton.h:99
Definition: wonton.h:229
int entityID
Definition: wonton.h:325
Definition: wonton.h:82