4#define BOOST_TEST_DYN_LINK
6#include <boost/test/unit_test.hpp>
13#include "Draw/DrawSphere.hpp"
19BOOST_AUTO_TEST_SUITE(ConvergenceTestSuite)
20 typedef double phi_type;
21 typedef double space_type;
22 const phi_type EPSILON = std::numeric_limits<phi_type>::epsilon();
24 space_type get_min_required_time_step(
size_t Nmax, space_type b_low, space_type b_up,
int dims)
26 space_type dx = (b_up - b_low) / (space_type) Nmax;
28 for (
int d = 0; d < dims; d++)
35 BOOST_AUTO_TEST_CASE(RedistancingSussman_convergence_test_1D)
39 const size_t grid_dim = 1;
43 const size_t Phi_0_grid = 0;
44 const size_t SDF_sussman_grid = 1;
45 const size_t SDF_exact_grid = 2;
46 const size_t Error_grid = 3;
48 const space_type box_lower = -1.0;
49 const space_type box_upper = 1.0;
58 space_type dt = get_min_required_time_step(Nmax, box_lower, box_upper, grid_dim);
59 for (
size_t N = Nmin; N <= Nmax; N*=2)
61 const size_t sz[grid_dim] = {N};
62 grid_in_type g_dist(sz, box, ghost);
63 g_dist.setPropNames({
"Phi_0",
"SDF_sussman",
"SDF_exact",
"Relative error"});
66 auto dom = g_dist.getDomainIterator();
71 g_dist.template get<Phi_0_grid>(key) =
sgn(coords.
get(x));
72 g_dist.template get<SDF_exact_grid>(key) = coords.
get(x);
78 redist_options.min_iter = 1e3;
79 redist_options.max_iter = 1e16;
82 redist_options.convTolChange.check =
true;
84 redist_options.convTolChange.value = EPSILON;
86 redist_options.convTolResidual.check =
false;
87 redist_options.interval_check_convergence = 1000;
89 redist_options.width_NB_in_grid_points = 10;
92 redist_options.print_current_iterChangeResidual =
true;
93 redist_options.print_steadyState_iter =
true;
97 std::cout <<
"CFL dt = " << redist_obj.get_time_step() << std::endl;
98 redist_obj.set_user_time_step(dt);
99 std::cout <<
"dt set to = " << dt << std::endl;
101 redist_obj.run_redistancing<Phi_0_grid, SDF_sussman_grid>();
104 get_absolute_error<SDF_sussman_grid, SDF_exact_grid, Error_grid>(g_dist);
109 size_t bc[grid_dim] = {NON_PERIODIC};
113 vd_type vd_narrow_band(0, box, bc, ghost_vd);
114 vd_narrow_band.setPropNames({
"error"});
115 const size_t Error_vd = 0;
119 narrowBand_points.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist,
126 lNorms_vd.write_to_file(N, 6,
"l_norms_",
"./");
132 BOOST_AUTO_TEST_CASE(RedistancingSussman_convergence_test_3D)
134 const size_t grid_dim = 3;
140 const size_t Phi_0_grid = 0;
141 const size_t SDF_sussman_grid = 1;
142 const size_t SDF_exact_grid = 2;
143 const size_t Error_grid = 3;
145 for (
size_t N=32; N <=128; N*=2)
147 const size_t sz[grid_dim] = {N, N, N};
148 const space_type radius = 1.0;
149 const space_type box_lower = 0.0;
150 const space_type box_upper = 4.0 * radius;
155 grid_in_type g_dist(sz, box, ghost);
156 g_dist.setPropNames({
"Phi_0",
"SDF_sussman",
"SDF_exact",
"Relative error"});
158 const space_type center[grid_dim] = {0.5*(box_upper+box_lower), 0.5*(box_upper+box_lower), 0.5*(box_upper+box_lower)};
159 init_grid_with_sphere<Phi_0_grid>(g_dist, radius, center[x], center[y], center[z]);
164 redist_options.min_iter = 1e3;
165 redist_options.max_iter = 1e3;
168 redist_options.convTolChange.check =
false;
169 redist_options.convTolResidual.check =
false;
171 redist_options.interval_check_convergence = 100;
173 redist_options.width_NB_in_grid_points = 4;
175 redist_options.print_current_iterChangeResidual =
true;
176 redist_options.print_steadyState_iter =
true;
183 redist_obj.run_redistancing<Phi_0_grid, SDF_sussman_grid>();
186 init_analytic_sdf_sphere<SDF_exact_grid>(g_dist, radius, center[x], center[y], center[z]);
189 get_absolute_error<SDF_sussman_grid, SDF_exact_grid, Error_grid>(g_dist);
195 size_t bc[grid_dim] = {PERIODIC, PERIODIC, PERIODIC};
199 vd_type vd_narrow_band(0, box, bc, ghost_vd);
200 vd_narrow_band.setPropNames({
"error"});
201 const size_t Error_vd = 0;
204 narrowBand_points.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist,
206 vd_narrow_band.write(
"vd_nb4p_error_N" + std::to_string(N) +
"_order" +
207 std::to_string(order), FORMAT_BINARY);
212 lNorms_vd.
write_to_file(N, 6,
"l_norms_vd_absError_4p_order" + std::to_string(order),
"./");
221 BOOST_CHECK(lNorms_vd.l2 < 0.044693);
222 BOOST_CHECK(lNorms_vd.linf < 0.066995);
225 BOOST_CHECK(lNorms_vd.l2 < 0.010543);
226 BOOST_CHECK(lNorms_vd.linf < 0.018397);
229 BOOST_CHECK(lNorms_vd.l2 < 0.003302);
230 BOOST_CHECK(lNorms_vd.linf < 0.009492);
238BOOST_AUTO_TEST_SUITE_END()
Header file containing functions that compute the analytical solution of the signed distance function...
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.
Class for getting the narrow band around the interface.
Header file containing functions for creating files and folders.
Class for reinitializing a level-set function into a signed distance function using Sussman redistanc...
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_vector(vectortype &vd)
Computes the L_2 and L_infinity norm on the basis of the precomputed error on a particle vector.
void write_to_file(const T col_0, const int precision, const std::string &filename, const std::string &path_output)
Writes the N (number of grid points on a square grid) and L-norms as strings to a csv-file.
Class for getting the narrow band around the interface.
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Class for reinitializing a level-set function into a signed distance function using Sussman redistanc...
This is a distributed grid.
Structure to bundle options for redistancing.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
It model an expression expr1 + ... exprn.