portage.h
Go to the documentation of this file.
1 /*
2 This file is part of the Ristra portage project.
3 Please see the license file at the root of this repository, or at:
4  https://github.com/laristra/portage/blob/master/LICENSE
5 */
6 
7 #ifndef PORTAGE_SUPPORT_PORTAGE_H_
8 #define PORTAGE_SUPPORT_PORTAGE_H_
9 
10 // Autogenerated file that contains configuration specific defines
11 // like PORTAGE_ENABLE_MPI and PORTAGE_ENABLE_THRUST
12 #include "portage-config.h"
13 
14 
15 #ifdef PORTAGE_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 #include <limits>
29 
30 #endif
31 
32 #include "wonton/support/Point.h"
33 #include "wonton/support/Vector.h"
34 #include "wonton/support/Matrix.h"
35 #include "wonton/support/wonton.h"
36 
37 /*
38  @file portage.h
39  @brief Several utility types and functions within the Portage namespace.
40  */
41 
42 /*
43  @namespace Portage
44  The Portage namespace houses all of the code within Portage.
45 
46  Cells (aka zones/elements) are the highest dimension entities in a mesh
47  Nodes (aka vertices) are lowest dimension entities in a mesh
48  Faces in a 3D mesh are 2D entities, in a 2D mesh are 1D entities
49  BOUNDARY_FACE is a special type of entity that is need so that process
50  kernels can define composite vectors (see src/data_structures) on
51  exterior boundary faces of the mesh only
52 
53  Wedges are special subcell entities that are a simplicial
54  decomposition of cell. In 3D, a wedge is tetrahedron formed by one
55  point of the edge, the midpoint of the edge, the "center" of the
56  face and the "center" of the cell volume. In 2D, a wedge is a
57  triangle formed by an end-point of the edge, the mid-point of the
58  edge and the center of the cell. In 1D, wedges are lines, that are
59  formed by the endpoint of the cell and the midpoint of the
60  cell. There are two wedges associated with an edge of cell face in
61  3D.
62 
63  Corners are also subcell entities that are associated uniquely with
64  a node of a cell. Each corner is the union of all the wedges incident
65  upon that node in the cell
66 
67  Facets are the boundary entity between two wedges in adjacent
68  cells. In 3D, a facet is a triangular subface of the cell face
69  shared by two wedges in adjacent cells. In 2D, a facet is half of
70  an edge that is shared by two wedges in adjacent cells
71  */
72 namespace Portage {
73 
74 using Wonton::Matrix;
75 
76 // useful enums
77 using Wonton::Entity_kind;
78 using Wonton::Entity_type;
79 using Wonton::Element_type;
80 using Wonton::Field_type;
81 using Wonton::Data_layout;
82 using Wonton::Weights_t;
83 
86 constexpr int NUM_LIMITER_TYPE = 2;
87 
89 
92 constexpr int NUM_Boundary_Limiter_type = 2;
93 
95 
96 inline std::string to_string(Limiter_type limiter_type) {
97  switch(limiter_type) {
98  case NOLIMITER: return std::string("Limiter_type::NOLIMITER");
99  case BARTH_JESPERSEN: return std::string("Limiter_type::BARTH_JESPERSEN");
100  default: return std::string("INVALID LIMITER TYPE");
101  }
102 }
103 
104 inline std::string to_string(Boundary_Limiter_type boundary_limiter_type) {
105  switch(boundary_limiter_type) {
106  case BND_NOLIMITER: return std::string("Boundary_Limiter_type::BND_NOLIMITER");
107  case BND_ZERO_GRADIENT: return std::string("Boundary_Limiter_type::BND_ZERO_GRADIENT");
108  case BND_BARTH_JESPERSEN: return std::string("Boundary_Limiter_type::BND_BARTH_JESPERSEN");
109  default: return std::string("INVALID BOUNDARY LIMITER TYPE");
110  }
111 }
112 
116 constexpr int NUM_PARTIAL_FIXUP_TYPE = 3;
117 
118 constexpr Partial_fixup_type DEFAULT_PARTIAL_FIXUP_TYPE =
120 
121 inline std::string to_string(Partial_fixup_type partial_fixup_type) {
122  static const std::string type2string[NUM_PARTIAL_FIXUP_TYPE] =
123  {"Partial_fixup_type::CONSTANT",
124  "Partial_fixup_type::LOCALLY_CONSERVATIVE",
125  "Partial_fixup_type::SHIFTED_CONSERVATIVE"};
126 
127  int itype = static_cast<int>(partial_fixup_type);
128  return (itype >= 0 && itype < NUM_PARTIAL_FIXUP_TYPE) ? type2string[itype] :
129  "INVALID PARTIAL FIXUP TYPE";
130 }
131 
132 
134 typedef enum {LEAVE_EMPTY, EXTRAPOLATE, FILL}
136 constexpr int NUM_EMPTY_FIXUP_TYPE = 3;
137 
139 
140 inline std::string to_string(Empty_fixup_type empty_fixup_type) {
141  static const std::string type2string[NUM_EMPTY_FIXUP_TYPE] =
142  {"Empty_fixup_type::LEAVE_EMPTY",
143  "Empty_fixup_type::EXTRAPOLATE",
144  "Empty_fixup_type::FILL"};
145 
146  int itype = static_cast<int>(empty_fixup_type);
147  return (itype >= 0 && itype < NUM_EMPTY_FIXUP_TYPE) ? type2string[itype] :
148  "INVALID EMPTY FIXUP TYPE";
149 }
150 
153  // Flag if custom tolerances were used. If user is setting his own
154  // tolerances, this flaq need to be set to true.
156 
157  // Check wheather the volume returned by r2d reduce is positive
158  // (or slightly negative). If the volume is smaller, we throw an
159  // error.
161 
162  // Distance tolerance: two points within that distance from each
163  // other are considered coincident. Used for bounding box check
164  // in Portage intersect and passed to Tangram in multi-material runs
166 
167  // Volume tolerance: intersections and material polytopes with
168  // the volume below this tolerance are ignored. In multi-material
169  // runs this tolerance is passed to Tangram. Target multi-material
170  // cells will not contain any material with volume below tolerance,
171  // interface reconstruction results on the source mesh will not
172  // contain material polytopes for materials with volume below this
173  // tolerance.
175 
176  // Default relative tolerance on aggregated field values to detect
177  // mesh mismatch
179 
180  // Default number of iterations for mismatch repair
182 };
183 
184 // Default values for tolerances
185 template <int D>
187  false, //user_tolerances
188  -1.0e-14, //minimal_intersection_volume
189  sqrt(D)*std::numeric_limits<double>::epsilon(), //min_absolute_distance: for two points
190  // to be distinct, we need at least one coordinate to differ by machine epsilon or more.
191  // In the worst case, when difference along all coordinate axes is the same, it corresponds to
192  // the distance of sqrt(D)*machine_epsilon or more. Because we use distance criterion in
193  // order to not introduce a direction bias, we have to impose the worst case tolerance even
194  // though some points that are closer can technically be distinguished.
195  std::numeric_limits<double>::epsilon(), //min_absolute_volume
196  100*std::numeric_limits<double>::epsilon(), //relative_conservation_eps
197  5 //max_num_fixup_iter
198 };
199 
200 // Iterators and transforms that depend on Thrust vs. std
201 #ifdef PORTAGE_ENABLE_THRUST
202 
203 template<typename T>
204  using vector = thrust::device_vector<T>;
205 
206 template<typename T>
207  using pointer = thrust::device_ptr<T>;
208 
209 typedef thrust::counting_iterator<unsigned int> counting_iterator;
210 inline counting_iterator make_counting_iterator(unsigned int const i) {
212 }
213 
214 template<typename InputIterator, typename OutputIterator,
215  typename UnaryFunction>
216 inline OutputIterator transform(InputIterator first, InputIterator last,
217  OutputIterator result, UnaryFunction op) {
218  return thrust::transform(first, last, result, op);
219 }
220 
221 template<typename InputIterator1, typename InputIterator2,
222  typename OutputIterator, typename BinaryFunction>
223 inline OutputIterator transform(InputIterator1 first1, InputIterator1 last1,
224  InputIterator2 first2, OutputIterator result,
225  BinaryFunction op) {
226  return thrust::transform(first1, last1, first2, result, op);
227 }
228 
229 template<typename InputIterator, typename UnaryFunction>
230 inline void for_each(InputIterator first, InputIterator last,
231  UnaryFunction f) {
232  thrust::for_each(first, last, f);
233 }
234 
235 #else // no thrust
236 
237 template<typename T>
238  using vector = std::vector<T>;
239 
240 template<typename T>
241  using pointer = T*;
242 
243 typedef boost::counting_iterator<unsigned int> counting_iterator;
244 inline counting_iterator make_counting_iterator(unsigned int const i) {
245  return boost::make_counting_iterator<unsigned int>(i);
246 }
247 
248 template<typename InputIterator, typename OutputIterator,
249  typename UnaryFunction>
250 inline OutputIterator transform(InputIterator first, InputIterator last,
251  OutputIterator result, UnaryFunction op) {
252  return std::transform(first, last, result, op);
253 }
254 
255 template<typename InputIterator1, typename InputIterator2,
256  typename OutputIterator, typename BinaryFunction>
257 inline OutputIterator transform(InputIterator1 first1, InputIterator1 last1,
258  InputIterator2 first2, OutputIterator result,
259  BinaryFunction op) {
260  return std::transform(first1, last1, first2, result, op);
261 }
262 
263 template<typename InputIterator, typename UnaryFunction>
264 inline void for_each(InputIterator first, InputIterator last,
265  UnaryFunction f) {
266  std::for_each(first, last, f);
267 }
268 
269 #endif
270 
271 } // namespace Portage
272 
273 #endif // PORTAGE_SUPPORT_PORTAGE_H_
double min_absolute_distance
Definition: portage.h:165
double relative_conservation_eps
Definition: portage.h:178
constexpr int NUM_LIMITER_TYPE
Definition: portage.h:86
Definition: portage.h:91
const NumericTolerances_t DEFAULT_NUMERIC_TOLERANCES
Definition: portage.h:186
Boundary_Limiter_type
Boundary limiter type.
Definition: portage.h:91
constexpr Boundary_Limiter_type DEFAULT_BND_LIMITER
Definition: portage.h:94
constexpr int NUM_Boundary_Limiter_type
Definition: portage.h:92
std::vector< T > vector
Definition: portage.h:238
OutputIterator transform(InputIterator first, InputIterator last, OutputIterator result, UnaryFunction op)
Definition: portage.h:250
constexpr Empty_fixup_type DEFAULT_EMPTY_FIXUP_TYPE
Definition: portage.h:138
Intersection and other tolerances to handle tiny values.
Definition: portage.h:152
constexpr int NUM_EMPTY_FIXUP_TYPE
Definition: portage.h:136
T * pointer
Definition: portage.h:241
int max_num_fixup_iter
Definition: portage.h:181
Definition: portage.h:91
double minimal_intersection_volume
Definition: portage.h:160
constexpr int NUM_PARTIAL_FIXUP_TYPE
Definition: portage.h:116
void for_each(InputIterator first, InputIterator last, UnaryFunction f)
Definition: portage.h:264
Definition: portage.h:114
Partial_fixup_type
Fixup options for partially filled cells.
Definition: portage.h:114
Definition: portage.h:134
double const epsilon
Numerical tolerance.
Definition: weight.h:34
Definition: portage.h:85
Limiter_type
Limiter type.
Definition: portage.h:85
bool user_tolerances
Definition: portage.h:155
Definition: portage.h:134
double min_absolute_volume
Definition: portage.h:174
Definition: portage.h:114
Definition: coredriver.h:42
constexpr Limiter_type DEFAULT_LIMITER
Definition: portage.h:88
Definition: portage.h:134
Definition: portage.h:114
counting_iterator make_counting_iterator(unsigned int const i)
Definition: portage.h:244
Definition: portage.h:91
boost::counting_iterator< unsigned int > counting_iterator
Definition: portage.h:243
std::string to_string(Limiter_type limiter_type)
Definition: portage.h:96
OutputIterator transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryFunction op)
Definition: portage.h:257
constexpr Partial_fixup_type DEFAULT_PARTIAL_FIXUP_TYPE
Definition: portage.h:118
Empty_fixup_type
Fixup options for empty cells.
Definition: portage.h:134
Definition: portage.h:85