4 #define BOOST_TEST_DYN_LINK 6 #include <boost/test/unit_test.hpp> 13 #include "Draw/DrawSphere.hpp" 19 BOOST_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;
117 size_t narrow_band_width = redist_options.width_NB_in_grid_points - 2;
120 narrowBand_points.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist,
127 lNorms_vd.write_to_file(N, 6,
"l_norms_",
"./");
133 BOOST_AUTO_TEST_CASE(RedistancingSussman_convergence_test_3D)
135 const size_t grid_dim = 3;
141 const size_t Phi_0_grid = 0;
142 const size_t SDF_sussman_grid = 1;
143 const size_t SDF_exact_grid = 2;
144 const size_t Error_grid = 3;
146 for (
size_t N=32; N <=128; N*=2)
148 const space_type dt = 0.000165334;
149 const size_t sz[grid_dim] = {N, N, N};
150 const space_type radius = 1.0;
151 const space_type box_lower = 0.0;
152 const space_type box_upper = 4.0 * radius;
157 grid_in_type g_dist(sz, box, ghost);
158 g_dist.setPropNames({
"Phi_0",
"SDF_sussman",
"SDF_exact",
"Relative error"});
160 const space_type center[grid_dim] = {0.5*(box_upper+box_lower), 0.5*(box_upper+box_lower), 0.5*(box_upper+box_lower)};
161 init_grid_with_sphere<Phi_0_grid>(g_dist, radius, center[x], center[y], center[z]);
166 redist_options.min_iter = 1e4;
167 redist_options.max_iter = 1e4;
170 redist_options.convTolChange.check =
false;
171 redist_options.convTolResidual.check =
false;
173 redist_options.interval_check_convergence = 100;
175 redist_options.width_NB_in_grid_points = 8;
176 redist_options.print_current_iterChangeResidual =
true;
177 redist_options.print_steadyState_iter =
true;
181 redist_obj.set_user_time_step(dt);
182 std::cout <<
"dt set to = " << dt << std::endl;
184 redist_obj.run_redistancing<Phi_0_grid, SDF_sussman_grid>();
187 init_analytic_sdf_sphere<SDF_exact_grid>(g_dist, radius, center[x], center[y], center[z]);
190 get_absolute_error<SDF_sussman_grid, SDF_exact_grid, Error_grid>(g_dist);
196 size_t bc[grid_dim] = {PERIODIC, PERIODIC, PERIODIC};
200 vd_type vd_narrow_band(0, box, bc, ghost_vd);
201 vd_narrow_band.setPropNames({
"error"});
202 const size_t Error_vd = 0;
204 size_t narrow_band_width = 8;
206 narrowBand_points.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist,
214 lNorms_vd.write_to_file(N, 6,
"l_norms_vd_absError_8p_order" + std::to_string(order),
"./");
236 BOOST_AUTO_TEST_SUITE_END()
Class for getting the narrow band around the interface.
Class for reinitializing a level-set function into a signed distance function using Sussman redistanc...
Header file containing functions for computing the error and the L_2 / L_infinity norm.
This class implement the point shape in an N-dimensional space.
Structure to bundle options for redistancing.
int sgn(T val)
Gets the sign of a variable.
Class for reinitializing a level-set function into a signed distance function using Sussman redistanc...
This is a distributed grid.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
This class represent an N-dimensional box.
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.
Header file containing functions for creating files and folders.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
It model an expression expr1 + ... exprn.
Class for getting the narrow band around the interface.
Header file containing functions that compute the analytical solution of the signed distance function...
Class for computing the l2/l_infinity norm for distributed grids and vectors based on given errors.