OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
redistancingSussman_fast_unit_test.cpp
1//
2// Created by jstark on 04.01.22.
3//
4#define BOOST_TEST_DYN_LINK
5//#define BOOST_TEST_MAIN // in only one cpp file
6#include <boost/test/unit_test.hpp>
7
8// Include redistancing files
12// Include header files for testing
13#include "Draw/DrawSphere.hpp"
14#include "l_norms/LNorms.hpp"
16
17BOOST_AUTO_TEST_SUITE(RedistancingSussmanFastTestSuite)
18
19 BOOST_AUTO_TEST_CASE(RedistancingSussman_unit_sphere_fast_double_test)
20 {
21 typedef double phi_type;
22 typedef double space_type;
23 const phi_type EPSILON = std::numeric_limits<phi_type>::epsilon();
24 const size_t grid_dim = 3;
25 // some indices
26 const size_t x = 0;
27 const size_t y = 1;
28 const size_t z = 2;
29
30 const size_t Phi_0_grid = 0;
31 const size_t SDF_sussman_grid = 1;
32 const size_t SDF_exact_grid = 2;
33 const size_t Error_grid = 3;
34
35 size_t N = 32;
36 const size_t sz[grid_dim] = {N, N, N};
37 const space_type radius = 1.0;
38 const space_type box_lower = -2.0;
39 const space_type box_upper = 2.0;
40 Box<grid_dim, space_type> box({box_lower, box_lower, box_lower}, {box_upper, box_upper, box_upper});
44 grid_in_type g_dist(sz, box, ghost);
45 g_dist.setPropNames({"Phi_0", "SDF_sussman", "SDF_exact", "Relative error"});
46
47 const space_type center[grid_dim] = {(box_upper+box_lower)/(space_type)2,
48 (box_upper+box_lower)/(space_type)2,
49 (box_upper+box_lower)/(space_type)2};
50
51 init_grid_with_sphere<Phi_0_grid>(g_dist, radius, center[x], center[y], center[z]); // Initialize sphere onto grid
52
53 Redist_options<phi_type> redist_options;
54 redist_options.min_iter = 1e3;
55 redist_options.max_iter = 1e3;
56
57 redist_options.convTolChange.check = false;
58 redist_options.convTolResidual.check = false;
59
60 redist_options.interval_check_convergence = 1e3;
61 redist_options.width_NB_in_grid_points = 4;
62 redist_options.print_current_iterChangeResidual = true;
63 redist_options.print_steadyState_iter = true;
64
65 RedistancingSussman<grid_in_type, phi_type> redist_obj(g_dist, redist_options); // Instantiation of
66
67 std::cout << "Automatically found timestep is " << redist_obj.get_time_step() << std::endl;
68 // Run the redistancing. in the <> brackets provide property-index where 1.) your initial Phi is stored and 2.) where the resulting SDF should be written to.
69 redist_obj.run_redistancing<Phi_0_grid, SDF_sussman_grid>();
70
71 // Compute exact signed distance function at each grid point
72 init_analytic_sdf_sphere<SDF_exact_grid>(g_dist, radius, center[x], center[y], center[z]);
73
74 // Compute the absolute error between analytical and numerical solution at each grid point
75 get_absolute_error<SDF_sussman_grid, SDF_exact_grid, Error_grid>(g_dist);
77 // Get narrow band: Place particles on interface (narrow band width e.g. 4 grid points on each side of the
78 // interface)
79 size_t bc[grid_dim] = {NON_PERIODIC, NON_PERIODIC, NON_PERIODIC};
80 typedef aggregate<phi_type> props_nb;
83 vd_type vd_narrow_band(0, box, bc, ghost_vd);
84 vd_narrow_band.setPropNames({"error"});
85 NarrowBand<grid_in_type, phi_type> narrowBand(g_dist, redist_options.width_NB_in_grid_points); // Instantiation of NarrowBand class
86 const size_t Error_vd = 0;
87 narrowBand.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist,
88 vd_narrow_band);
89 // Compute the L_2- and L_infinity-norm
90 LNorms<phi_type> lNorms_vd;
91 lNorms_vd.get_l_norms_vector<Error_vd>(vd_narrow_band);
92 std::cout << lNorms_vd.l2 << ", " << lNorms_vd.linf << std::endl;
93
94 BOOST_CHECK(lNorms_vd.l2 < 0.044693);
95 BOOST_CHECK(lNorms_vd.linf < 0.066995);
96 }
97
98 BOOST_AUTO_TEST_CASE(RedistancingSussman_unit_sphere_fast_float_test)
99 {
100 typedef float phi_type;
101 typedef float space_type;
102 const phi_type EPSILON = std::numeric_limits<phi_type>::epsilon();
103 const size_t grid_dim = 3;
104 // some indices
105 const size_t x = 0;
106 const size_t y = 1;
107 const size_t z = 2;
108
109 const size_t Phi_0_grid = 0;
110 const size_t SDF_sussman_grid = 1;
111 const size_t SDF_exact_grid = 2;
112 const size_t Error_grid = 3;
113
114 size_t N = 32;
115 const size_t sz[grid_dim] = {N, N, N};
116 const space_type radius = 1.0;
117 const space_type box_lower = -2.0;
118 const space_type box_upper = 2.0;
119 Box<grid_dim, space_type> box({box_lower, box_lower, box_lower}, {box_upper, box_upper, box_upper});
123 grid_in_type g_dist(sz, box, ghost);
124 g_dist.setPropNames({"Phi_0", "SDF_sussman", "SDF_exact", "Relative error"});
125
126 const space_type center[grid_dim] = {(box_upper+box_lower)/(space_type)2,
127 (box_upper+box_lower)/(space_type)2,
128 (box_upper+box_lower)/(space_type)2};
129
130 init_grid_with_sphere<Phi_0_grid>(g_dist, radius, center[x], center[y], center[z]); // Initialize sphere onto grid
131
132 Redist_options<phi_type> redist_options;
133 redist_options.min_iter = 1e3;
134 redist_options.max_iter = 1e3;
135
136 redist_options.convTolChange.check = false;
137 redist_options.convTolResidual.check = false;
138
139 redist_options.interval_check_convergence = 1e3;
140 redist_options.width_NB_in_grid_points = 8;
141 redist_options.print_current_iterChangeResidual = true;
142 redist_options.print_steadyState_iter = true;
143
144 redist_options.save_temp_grid = false;
145
146 RedistancingSussman<grid_in_type, phi_type> redist_obj(g_dist, redist_options); // Instantiation of
147
148 std::cout << "Automatically found timestep is " << redist_obj.get_time_step() << std::endl;
149 // Run the redistancing. in the <> brackets provide property-index where 1.) your initial Phi is stored and 2.) where the resulting SDF should be written to.
150 redist_obj.run_redistancing<Phi_0_grid, SDF_sussman_grid>();
151
152 // Compute exact signed distance function at each grid point
153 init_analytic_sdf_sphere<SDF_exact_grid>(g_dist, radius, center[x], center[y], center[z]);
154
155 // Compute the absolute error between analytical and numerical solution at each grid point
156 get_absolute_error<SDF_sussman_grid, SDF_exact_grid, Error_grid>(g_dist);
158 // Get narrow band: Place particles on interface (narrow band width e.g. 4 grid points on each side of the
159 // interface)
160 size_t bc[grid_dim] = {NON_PERIODIC, NON_PERIODIC, NON_PERIODIC};
161 typedef aggregate<phi_type> props_nb;
163 Ghost<grid_dim, space_type> ghost_vd(0);
164 vd_type vd_narrow_band(0, box, bc, ghost_vd);
165 vd_narrow_band.setPropNames({"error"});
166 NarrowBand<grid_in_type, phi_type> narrowBand(g_dist, redist_options.width_NB_in_grid_points); // Instantiation of NarrowBand class
167 const size_t Error_vd = 0;
168 narrowBand.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist,
169 vd_narrow_band);
170 // Compute the L_2- and L_infinity-norm
171 LNorms<phi_type> lNorms_vd;
172 lNorms_vd.get_l_norms_vector<Error_vd>(vd_narrow_band);
173 std::cout << lNorms_vd.l2 << ", " << lNorms_vd.linf << std::endl;
174 // When using NB-width 4 and single precision, then l2, linf = 0.0500562, 0.0846975
175 BOOST_CHECK(lNorms_vd.l2 < 0.0500563);
176 BOOST_CHECK(lNorms_vd.linf < 0.0846976);
177 }
178
179 BOOST_AUTO_TEST_CASE(RedistancingSussman_unit_sphere_fast_usingDefault_test)
180 { typedef double phi_type;
181 typedef double space_type;
182 const phi_type EPSILON = std::numeric_limits<phi_type>::epsilon();
183 const size_t grid_dim = 3;
184 // some indices
185 const size_t x = 0;
186 const size_t y = 1;
187 const size_t z = 2;
188
189 const size_t Phi_0_grid = 0;
190 const size_t SDF_sussman_grid = 1;
191 const size_t SDF_exact_grid = 2;
192 const size_t Error_grid = 3;
193
194 size_t N = 32;
195 const size_t sz[grid_dim] = { N, N, N };
196 const space_type radius = 1.0;
197 const space_type box_lower = -2.0;
198 const space_type box_upper = 2.0;
199 Box<grid_dim, space_type> box({ box_lower, box_lower, box_lower }, { box_upper, box_upper, box_upper });
203 grid_in_type g_dist(sz, box, ghost);
204 g_dist.setPropNames({ "Phi_0", "SDF_sussman", "SDF_exact", "Relative error" });
205
206 const space_type center[grid_dim] = {
207 (box_upper + box_lower) / (space_type) 2, (box_upper + box_lower) / (space_type) 2,
208 (box_upper + box_lower) / (space_type) 2
209 };
210
211 init_grid_with_sphere<Phi_0_grid>(g_dist, radius, center[x], center[y], center[z]); // Initialize sphere onto grid
212
213 Redist_options<> redist_options;
214 redist_options.min_iter = 1e3;
215 redist_options.max_iter = 1e3;
216
217 RedistancingSussman<grid_in_type> redist_obj(g_dist, redist_options); // Instantiation of
218
219 std::cout << "Automatically found timestep is " << redist_obj.get_time_step() << std::endl;
220 // Run the redistancing. in the <> brackets provide property-index where 1.) your initial Phi is stored and 2.) where the resulting SDF should be written to.
221 redist_obj.run_redistancing<Phi_0_grid, SDF_sussman_grid>();
222
223 // Compute exact signed distance function at each grid point
224 init_analytic_sdf_sphere<SDF_exact_grid>(g_dist, radius, center[x], center[y], center[z]);
225
226 // Compute the absolute error between analytical and numerical solution at each grid point
227 get_absolute_error<SDF_sussman_grid, SDF_exact_grid, Error_grid>(g_dist);
229 // Get narrow band: Place particles on interface (narrow band width e.g. 4 grid points on each side of the
230 // interface)
231 size_t bc[grid_dim] = { NON_PERIODIC, NON_PERIODIC, NON_PERIODIC };
232 typedef aggregate<phi_type> props_nb;
234 Ghost<grid_dim, space_type> ghost_vd(0);
235 vd_type vd_narrow_band(0, box, bc, ghost_vd);
236 vd_narrow_band.setPropNames({ "error" });
237 NarrowBand<grid_in_type> narrowBand(g_dist, redist_options.width_NB_in_grid_points); // Instantiation of NarrowBand class
238 const size_t Error_vd = 0;
239 narrowBand.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist, vd_narrow_band);
240 // Compute the L_2- and L_infinity-norm
241 LNorms<> lNorms_vd;
242 lNorms_vd.get_l_norms_vector<Error_vd>(vd_narrow_band);
243 std::cout << lNorms_vd.l2 << ", " << lNorms_vd.linf << std::endl;
244 // When using default NB-width, which is 2, the l2, lin = 0.0417404, 0.0639716
245 BOOST_CHECK(lNorms_vd.l2 < 0.0417405);
246 BOOST_CHECK(lNorms_vd.linf < 0.0639717);
247 }
248BOOST_AUTO_TEST_SUITE_END()
249
250
Header file containing functions that compute the analytical solution of the signed distance function...
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.
Definition Box.hpp:61
Class for computing the l2/l_infinity norm for distributed grids and vectors based on given errors.
Definition LNorms.hpp:105
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.
Definition LNorms.hpp:155
Class for getting the narrow band around the interface.
Class for reinitializing a level-set function into a signed distance function using Sussman redistanc...
This is a distributed grid.
Distributed vector.
Structure to bundle options for redistancing.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...