5#define BOOST_TEST_DYN_LINK
6#include <boost/test/unit_test.hpp>
10#include "Gaussian.hpp"
14BOOST_AUTO_TEST_SUITE(UpwindGradientTestSuite)
15 const double EPSILON = 1e-14;
16 const size_t F_GAUSSIAN = 0;
17 const size_t VELOCITY = 1;
18 const size_t dF_GAUSSIAN = 2;
19 const size_t dF_UPWIND = 3;
20 const size_t ERROR = 4;
22 BOOST_AUTO_TEST_CASE(Upwind_gradient_order1_1D_test)
24 const int convergence_order = 1;
25 const size_t grid_dim = 1;
27 const double box_lower = -1.0;
28 const double box_upper = 1.0;
34 double mu = 0.5 * (box_upper - abs(box_lower));
35 double sigma = 0.3 * (box_upper - box_lower);
40 const size_t sz[grid_dim] = {N};
41 grid_in_type g_dist(sz, box, ghost);
43 g_dist.setPropNames({
"F_GAUSSIAN",
"VELOCITY",
"dF_GAUSSIAN",
"dF_UPWIND",
"ERROR"});
45 auto gdom = g_dist.getDomainGhostIterator();
48 auto key = gdom.get();
51 g_dist.getProp<F_GAUSSIAN>(key) = gaussian(p, mu, sigma);
53 g_dist.getProp<VELOCITY>(key) =
sgn(g_dist.getProp<F_GAUSSIAN>(key));
57 auto dom = g_dist.getDomainIterator();
63 for (
int d = 0; d < grid_dim; d++)
66 g_dist.getProp<dF_GAUSSIAN>(key)[d] = hermite_polynomial(p.
get(d), sigma, 1) * g_dist.getProp<F_GAUSSIAN>(key);
72 get_upwind_gradient<F_GAUSSIAN, VELOCITY, dF_UPWIND>(g_dist, convergence_order,
false);
75 get_relative_error<dF_UPWIND, dF_GAUSSIAN, ERROR>(g_dist);
80 if (N==32) BOOST_CHECK_MESSAGE(lNorms.l2 <= 0.38954184748195 + EPSILON,
"Checking L2-norm upwind gradient "
81 "order " + std::to_string
87 BOOST_AUTO_TEST_CASE(Upwind_gradient_order3_1D_test)
89 const int convergence_order = 3;
90 const size_t grid_dim = 1;
92 const double box_lower = -1.0;
93 const double box_upper = 1.0;
99 double mu = 0.5 * (box_upper - abs(box_lower));
100 double sigma = 0.3 * (box_upper - box_lower);
105 const size_t sz[grid_dim] = {N};
106 grid_in_type g_dist(sz, box, ghost);
108 g_dist.setPropNames({
"F_GAUSSIAN",
"VELOCITY",
"dF_GAUSSIAN",
"dF_UPWIND",
"ERROR"});
110 auto gdom = g_dist.getDomainGhostIterator();
111 while (gdom.isNext())
113 auto key = gdom.get();
116 g_dist.getProp<F_GAUSSIAN>(key) = gaussian(p, mu, sigma);
118 g_dist.getProp<VELOCITY>(key) =
sgn(g_dist.getProp<F_GAUSSIAN>(key));
122 auto dom = g_dist.getDomainIterator();
125 auto key = dom.get();
128 for (
int d = 0; d < grid_dim; d++)
131 g_dist.getProp<dF_GAUSSIAN>(key)[d] = hermite_polynomial(p.
get(d), sigma, 1) * g_dist.getProp<F_GAUSSIAN>(key);
137 get_upwind_gradient<F_GAUSSIAN, VELOCITY, dF_UPWIND>(g_dist, convergence_order,
false);
140 get_relative_error<dF_UPWIND, dF_GAUSSIAN, ERROR>(g_dist);
145 if (N==32) BOOST_CHECK_MESSAGE(lNorms.l2 <= 0.08667855716144 + EPSILON,
"Checking L2-norm upwind gradient "
147 + std::to_string(convergence_order));
150 BOOST_AUTO_TEST_CASE(Upwind_gradient_order5_1D_test)
152 const int convergence_order = 5;
153 const size_t grid_dim = 1;
155 const double box_lower = -1.0;
156 const double box_upper = 1.0;
162 double mu = 0.5 * (box_upper - abs(box_lower));
163 double sigma = 0.3 * (box_upper - box_lower);
168 const size_t sz[grid_dim] = {N};
169 grid_in_type g_dist(sz, box, ghost);
171 g_dist.setPropNames({
"F_GAUSSIAN",
"VELOCITY",
"dF_GAUSSIAN",
"dF_UPWIND",
"ERROR"});
173 auto gdom = g_dist.getDomainGhostIterator();
174 while (gdom.isNext())
176 auto key = gdom.get();
179 g_dist.getProp<F_GAUSSIAN>(key) = gaussian(p, mu, sigma);
181 g_dist.getProp<VELOCITY>(key) =
sgn(g_dist.getProp<F_GAUSSIAN>(key));
185 auto dom = g_dist.getDomainIterator();
188 auto key = dom.get();
191 for (
int d = 0; d < grid_dim; d++)
194 g_dist.getProp<dF_GAUSSIAN>(key)[d] = hermite_polynomial(p.
get(d), sigma, 1) * g_dist.getProp<F_GAUSSIAN>(key);
200 get_upwind_gradient<F_GAUSSIAN, VELOCITY, dF_UPWIND>(g_dist, convergence_order,
false);
203 get_relative_error<dF_UPWIND, dF_GAUSSIAN, ERROR>(g_dist);
208 if (N==32) BOOST_CHECK_MESSAGE(lNorms.l2 <= 0.03215172234342 + EPSILON,
"Checking L2-norm upwind gradient "
210 + std::to_string(convergence_order));
213 BOOST_AUTO_TEST_CASE(Upwind_gradient_3D_test)
216 const size_t grid_dim = 3;
217 const double box_lower = -1.0;
218 const double box_upper = 1.0;
224 double mu = 0.5 * (box_upper - abs(box_lower));
225 double sigma = 0.3 * (box_upper - box_lower);
230 const size_t sz[grid_dim] = {N, N, N};
231 grid_in_type g_dist(sz, box, ghost);
232 g_dist.setPropNames({
"F_GAUSSIAN",
"VELOCITY",
"dF_GAUSSIAN",
"dF_UPWIND",
"ERROR"});
234 auto gdom = g_dist.getDomainGhostIterator();
235 while (gdom.isNext())
237 auto key = gdom.get();
240 g_dist.getProp<F_GAUSSIAN>(key) = gaussian(p, mu, sigma);
242 g_dist.getProp<VELOCITY>(key) =
sgn(g_dist.getProp<F_GAUSSIAN>(key));
246 auto dom = g_dist.getDomainIterator();
249 auto key = dom.get();
252 for (
int d = 0; d < grid_dim; d++)
255 g_dist.getProp<dF_GAUSSIAN>(key)[d] = hermite_polynomial(p.
get(d), sigma, 1) * g_dist.getProp<F_GAUSSIAN>(key);
260 for (
int convergence_order = 1; convergence_order <=5; convergence_order +=2 )
263 get_upwind_gradient<F_GAUSSIAN, VELOCITY, dF_UPWIND>(g_dist, convergence_order,
false);
265 get_relative_error<dF_UPWIND, dF_GAUSSIAN, ERROR>(g_dist);
272 switch(convergence_order)
275 BOOST_CHECK_MESSAGE(lNorms.l2 <= 0.38954184748194 + EPSILON,
"Checking L2-norm upwind gradient order " + std::to_string(convergence_order));
278 BOOST_CHECK_MESSAGE(lNorms.l2 <= 0.08667855716144 + EPSILON,
"Checking L2-norm upwind gradient order " + std::to_string(convergence_order));
281 BOOST_CHECK_MESSAGE(lNorms.l2 <= 0.02285996528578 + EPSILON,
"Checking L2-norm upwind gradient order " + std::to_string(convergence_order));
285 std::cout <<
"Checking only implemented for convergence order 1, 3 and 5." << std::endl;
294 BOOST_AUTO_TEST_CASE(Upwind_gradient_3D_vector_velocity_test)
297 const size_t grid_dim = 3;
298 const double box_lower = -1.0;
299 const double box_upper = 1.0;
305 double mu = 0.5 * (box_upper - abs(box_lower));
306 double sigma = 0.3 * (box_upper - box_lower);
311 const size_t sz[grid_dim] = {N, N, N};
312 grid_in_type g_dist(sz, box, ghost);
313 g_dist.setPropNames({
"F_GAUSSIAN",
"Velocity",
"dF_GAUSSIAN",
"dF_UPWIND",
"ERROR"});
315 auto gdom = g_dist.getDomainGhostIterator();
316 while (gdom.isNext())
318 auto key = gdom.get();
321 g_dist.getProp<F_GAUSSIAN>(key) = gaussian(p, mu, sigma);
325 auto dom = g_dist.getDomainIterator();
328 auto key = dom.get();
331 for (
int d = 0; d < grid_dim; d++)
334 g_dist.getProp<dF_GAUSSIAN>(key)[d] = hermite_polynomial(p.
get(d), sigma, 1) * g_dist.getProp<F_GAUSSIAN>(key);
336 g_dist.getProp<VELOCITY>(key)[d] = g_dist.getProp<dF_GAUSSIAN>(key)[d];
341 for (
int convergence_order = 1; convergence_order <=5; convergence_order +=2 )
344 get_upwind_gradient<F_GAUSSIAN, VELOCITY, dF_UPWIND>(g_dist, convergence_order,
false);
346 get_relative_error<dF_UPWIND, dF_GAUSSIAN, ERROR>(g_dist);
353 switch(convergence_order)
356 BOOST_CHECK_MESSAGE(lNorms.l2 <= 0.38954184748194 + EPSILON,
"Checking L2-norm upwind"
357 " gradient with vector "
359 std::to_string(convergence_order));
362 BOOST_CHECK_MESSAGE(lNorms.l2 <= 0.08667855716144 + EPSILON,
"Checking L2-norm upwind"
364 "vector velocity order " +
365 std::to_string(convergence_order));
368 BOOST_CHECK_MESSAGE(lNorms.l2 <= 0.02285996528578 + EPSILON,
"Checking L2-norm upwind"
370 "vector velocity order " +
371 std::to_string(convergence_order));
375 std::cout <<
"Checking only implemented for convergence order 1, 3 and 5." << std::endl;
383BOOST_AUTO_TEST_SUITE_END()
Header file containing small mathematical help-functions that are needed e.g. for the Sussman redista...
int sgn(T val)
Gets the sign of a variable.
Header file containing functions for computing the error and the L_2 / L_infinity norm.
Approximating upwind gradients on a grid with the following options for the order of accuracy: 1,...
This class represent an N-dimensional box.
Class for computing the l2/l_infinity norm for distributed grids and vectors based on given errors.
void get_l_norms_grid(gridtype &grid)
Computes the L_2 and L_infinity norm on the basis of the precomputed error on a grid.
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
This is a distributed grid.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...