test_adaptive_refinement_utilities.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_ADAPTIVE_REFINEMENT_MESH_UTILITIES_H_
8 #define WONTON_ADAPTIVE_REFINEMENT_MESH_UTILITIES_H_
9 
10 #include <iostream>
11 #include <cmath>
12 #include <vector>
13 
14 #include "wonton/support/wonton.h"
15 #include "wonton/support/Point.h"
16 
17 #include "gtest/gtest.h"
18 
19 // ============================================================================
30 
31 // Getting tired of typing this
32 template<int D>
33 using BoxList = std::pair<std::vector<int>,std::vector<Wonton::BoundingBox<D>>>;
34 
35 // Getting tired of typing Wonton::
36 const int LO = Wonton::LO;
37 const int HI = Wonton::HI;
38 
39 // ============================================================================
40 // Templates
41 
42 template<int D>
43 int refinement_function(const Wonton::Point<D> r, double lo1, double hi1) {
44  return(0);
45 }
46 
47 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48 
49 template<int D>
50 int num_cells() {
51  return(0);
52 }
53 
54 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55 
56 template<int D>
58  BoxList<D> boxes;
59  return boxes;
60 }
61 
62 // ============================================================================
63 // 1D
64 
65 template<>
67  const Wonton::Point<1> r, double lo1, double hi1) {
68  Wonton::Point<1> r_norm;
69  r_norm[0] = (r[0] - lo1) / (hi1 - lo1);
70  int result = (int) std::ceil(2.0 + 3.0*r_norm[0]);
71  return(result);
72 }
73 
74 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75 
76 template<>
77 int num_cells<1>() {
78  return(18);
79 }
80 
81 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82 
83 template<>
85  // Declare storage and counter
86  std::vector<int> id_list;
87  std::vector<Wonton::BoundingBox<1>> box_list;
88  int n;
89  // First sample point
90  // -- Expand lists
91  n = id_list.size();
92  id_list.resize(n+1);
93  box_list.resize(n+1);
94  // -- Save data
95  id_list[n] = 0;
96  box_list[n][0][LO] = 0.0;
97  box_list[n][0][HI] = 1.0 / 8.0;
98  // Second sample point
99  // -- Expand lists
100  n = id_list.size();
101  id_list.resize(n+1);
102  box_list.resize(n+1);
103  // -- Save data
104  id_list[n] = 6;
105  box_list[n][0][LO] = 9.0 / 16.0;
106  box_list[n][0][HI] = 10.0 / 16.0;
107  // Third sample point
108  // -- Expand lists
109  n = id_list.size();
110  id_list.resize(n+1);
111  box_list.resize(n+1);
112  // -- Save data
113  id_list[n] = 14;
114  box_list[n][0][LO] = 1.0 - 4.0 / 32.0;
115  box_list[n][0][HI] = 1.0 - 3.0 / 32.0;
116  // Return
117  return std::make_pair(id_list,box_list);
118 }
119 
120 // ============================================================================
121 
122 template<>
124  const Wonton::Point<2> r, double lo1, double hi1) {
125  Wonton::Point<2> r_norm;
126  for (int d = 0; d < 2; ++d) {
127  r_norm[d] = (r[d] - lo1) / (hi1 - lo1);
128  }
129  int result = (int) std::ceil(1.2 - 1.1*r_norm[0] + 2.4*r_norm[1]);
130  return(result);
131 }
132 
133 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
134 
135 template<>
137  return(46);
138 }
139 
140 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
141 
142 template<>
144  // Declare storage and counter
145  std::vector<int> id_list;
146  std::vector<Wonton::BoundingBox<2>> box_list;
147  int n;
148  // First sample point
149  // -- Expand lists
150  n = id_list.size();
151  id_list.resize(n+1);
152  box_list.resize(n+1);
153  // -- Save data
154  id_list[n] = 4;
155  box_list[n][0][LO] = 0.5;
156  box_list[n][0][HI] = 1.0;
157  box_list[n][1][LO] = 0.0;
158  box_list[n][1][HI] = 0.5;
159  // Second sample point
160  // -- Expand lists
161  n = id_list.size();
162  id_list.resize(n+1);
163  box_list.resize(n+1);
164  // -- Save data
165  id_list[n] = 20;
166  box_list[n][0][LO] = 0.0;
167  box_list[n][0][HI] = 1.0 / 16.0;
168  box_list[n][1][LO] = 1.0 - 1.0 / 16.0;
169  box_list[n][1][HI] = 1.0;
170  // Third sample point
171  // -- Expand lists
172  n = id_list.size();
173  id_list.resize(n+1);
174  box_list.resize(n+1);
175  // -- Save data
176  id_list[n] = 35;
177  box_list[n][0][LO] = 4.0 / 8.0;
178  box_list[n][0][HI] = 5.0 / 8.0;
179  box_list[n][1][LO] = 5.0 / 8.0;
180  box_list[n][1][HI] = 6.0 / 8.0;
181  // Return
182  return std::make_pair(id_list,box_list);
183 }
184 
185 // ============================================================================
186 
187 template<>
189  const Wonton::Point<3> r, double lo1, double hi1) {
190  Wonton::Point<3> r_norm;
191  for (int d = 0; d < 3; ++d) {
192  r_norm[d] = (r[d] - lo1) / (hi1 - lo1);
193  }
194  const int DIM = 3;
195  double radius = 0;
196  for (int d = 0; d < DIM; ++d) {
197  double x = r_norm[d] - 0.5;
198  radius += x * x;
199  }
200  radius = sqrt(radius);
201  int result = (int) std::ceil(2.5 - 6.0*radius*radius);
202  return(result);
203 }
204 
205 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
206 
207 template<>
209  return(120);
210 }
211 
212 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
213 
214 template<>
216  // Declare storage and counter
217  std::vector<int> id_list;
218  std::vector<Wonton::BoundingBox<3>> box_list;
219  int n;
220  // First sample point
221  // -- Expand lists
222  n = id_list.size();
223  id_list.resize(n+1);
224  box_list.resize(n+1);
225  // -- Save data
226  id_list[n] = 0;
227  box_list[n][0][LO] = 0.0;
228  box_list[n][0][HI] = 0.25;
229  box_list[n][1][LO] = 0.0;
230  box_list[n][1][HI] = 0.25;
231  box_list[n][2][LO] = 0.0;
232  box_list[n][2][HI] = 0.25;
233  // Second sample point
234  // -- Expand lists
235  n = id_list.size();
236  id_list.resize(n+1);
237  box_list.resize(n+1);
238  // -- Save data
239  id_list[n] = 92;
240  box_list[n][0][LO] = 3.0 / 8.0;
241  box_list[n][0][HI] = 4.0 / 8.0;
242  box_list[n][1][LO] = 4.0 / 8.0;
243  box_list[n][1][HI] = 5.0 / 8.0;
244  box_list[n][2][LO] = 4.0 / 8.0;
245  box_list[n][2][HI] = 5.0 / 8.0;
246  // Third sample point
247  // -- Expand lists
248  n = id_list.size();
249  id_list.resize(n+1);
250  box_list.resize(n+1);
251  // -- Save data
252  id_list[n] = 119;
253  box_list[n][0][LO] = 0.75;
254  box_list[n][0][HI] = 1.0;
255  box_list[n][1][LO] = 0.75;
256  box_list[n][1][HI] = 1.0;
257  box_list[n][2][LO] = 0.75;
258  box_list[n][2][HI] = 1.0;
259  // Return
260  return std::make_pair(id_list,box_list);
261 }
262 
263 // ============================================================================
264 
265 template<>
267  const Wonton::Point<4> r, double lo1, double hi1) {
268  Wonton::Point<4> r_norm;
269  for (int d = 0; d < 4; ++d) {
270  r_norm[d] = (r[d] - lo1) / (hi1 - lo1);
271  }
272  int result = (int) std::ceil(
273  2.0 - 1e-12 // 1e-12 to deal with round-off issues from rescaling
274  - 3.0*r_norm[0]
275  + 1.2*r_norm[1]
276  - 0.5*r_norm[2]
277  + 0.3*r_norm[3]);
278  return(result);
279 }
280 
281 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
282 
283 template<>
285  return(916);
286 }
287 
288 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
289 
290 template<>
292  // Declare storage and counter
293  std::vector<int> id_list;
294  std::vector<Wonton::BoundingBox<4>> box_list;
295  int n;
296  // First sample point
297  // -- Expand lists
298  n = id_list.size();
299  id_list.resize(n+1);
300  box_list.resize(n+1);
301  // -- Save data
302  id_list[n] = 0;
303  box_list[n][0][LO] = 0.0;
304  box_list[n][0][HI] = 0.25;
305  box_list[n][1][LO] = 0.0;
306  box_list[n][1][HI] = 0.25;
307  box_list[n][2][LO] = 0.0;
308  box_list[n][2][HI] = 0.25;
309  box_list[n][3][LO] = 0.0;
310  box_list[n][3][HI] = 0.25;
311  // Second sample point
312  // -- Expand lists
313  n = id_list.size();
314  id_list.resize(n+1);
315  box_list.resize(n+1);
316  // -- Save data
317  id_list[n] = 92;
318  box_list[n][0][LO] = 1.0 / 8.0;
319  box_list[n][0][HI] = 2.0 / 8.0;
320  box_list[n][1][LO] = 5.0 / 8.0;
321  box_list[n][1][HI] = 6.0 / 8.0;
322  box_list[n][2][LO] = 2.0 / 8.0;
323  box_list[n][2][HI] = 3.0 / 8.0;
324  box_list[n][3][LO] = 1.0 / 8.0;
325  box_list[n][3][HI] = 2.0 / 8.0;
326  // Third sample point
327  // -- Expand lists
328  n = id_list.size();
329  id_list.resize(n+1);
330  box_list.resize(n+1);
331  // -- Save data
332  id_list[n] = 119;
333  box_list[n][0][LO] = 0.0;
334  box_list[n][0][HI] = 1.0 / 8.0;
335  box_list[n][1][LO] = 4.0 / 8.0;
336  box_list[n][1][HI] = 5.0 / 8.0;
337  box_list[n][2][LO] = 1.0 / 8.0;
338  box_list[n][2][HI] = 2.0 / 8.0;
339  box_list[n][3][LO] = 2.0 / 8.0;
340  box_list[n][3][HI] = 3.0 / 8.0;
341  // Return
342  return std::make_pair(id_list,box_list);
343 }
344 
345 // ============================================================================
346 
347 } // namespace Adaptive_Refinement_Utilities
348 
349 #endif // WONTON_ADAPTIVE_REFINEMENT_MESH_UTILITIES_H_
BoxList< 3 > get_sample_points< 3 >()
Definition: test_adaptive_refinement_utilities.h:215
int num_cells< 1 >()
Definition: test_adaptive_refinement_utilities.h:77
BoxList< 2 > get_sample_points< 2 >()
Definition: test_adaptive_refinement_utilities.h:143
int num_cells()
Definition: test_adaptive_refinement_utilities.h:50
int refinement_function< 1 >(const Wonton::Point< 1 > r, double lo1, double hi1)
Definition: test_adaptive_refinement_utilities.h:66
const int HI
Definition: test_adaptive_refinement_utilities.h:37
int num_cells< 2 >()
Definition: test_adaptive_refinement_utilities.h:136
BoxList< 4 > get_sample_points< 4 >()
Definition: test_adaptive_refinement_utilities.h:291
std::pair< std::vector< int >, std::vector< Wonton::BoundingBox< D > >> BoxList
Definition: test_adaptive_refinement_utilities.h:33
int num_cells< 3 >()
Definition: test_adaptive_refinement_utilities.h:208
int num_cells< 4 >()
Definition: test_adaptive_refinement_utilities.h:284
const int LO
Definition: test_adaptive_refinement_utilities.h:36
Represents a point in an N-dimensional space.
Definition: Point.h:50
Definition: test_adaptive_refinement_utilities.h:29
BoxList< D > get_sample_points()
Definition: test_adaptive_refinement_utilities.h:57
int refinement_function< 4 >(const Wonton::Point< 4 > r, double lo1, double hi1)
Definition: test_adaptive_refinement_utilities.h:266
BoxList< 1 > get_sample_points< 1 >()
Definition: test_adaptive_refinement_utilities.h:84
int refinement_function< 3 >(const Wonton::Point< 3 > r, double lo1, double hi1)
Definition: test_adaptive_refinement_utilities.h:188
int refinement_function< 2 >(const Wonton::Point< 2 > r, double lo1, double hi1)
Definition: test_adaptive_refinement_utilities.h:123
const int HI
Definition: BoundingBox.h:24
int refinement_function(const Wonton::Point< D > r, double lo1, double hi1)
Definition: test_adaptive_refinement_utilities.h:43
const int LO
Definition: BoundingBox.h:23