OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
single_point_convergence_test.cpp
1 //
2 // Created by jstark on 12.07.21.
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
9 #include "util/PathsAndFiles.hpp"
12 // Include header files for testing
13 #include "Draw/DrawSphere.hpp"
14 #include "Draw/DrawDisk.hpp"
15 #include "l_norms/LNorms.hpp"
17 
18 BOOST_AUTO_TEST_SUITE(RedistancingSussmanSinglePointConvergenceTestSuite)
19 #if 0
20  BOOST_AUTO_TEST_CASE(RedistancingSussmanSinglePoint_1D_test)
21  {
22 
23  // CFL dt in 1D for N=64 and c=1 is 0.000503905
24  const double EPSILON = std::numeric_limits<double>::epsilon();
25 
26  std::cout << "epsilon = " << EPSILON << std::endl;
27  const size_t grid_dim = 1;
28  // some indices
29  const size_t x = 0;
30 
31  const size_t Phi_0_grid = 0;
32  const size_t SDF_sussman_grid = 1;
33  const size_t SDF_exact_grid = 2;
34  const size_t Error_grid = 3;
35 
36  size_t N = 64;
37  double dt = 0.000503905;
38  double tf = 1e4 * dt;
39  dt *= 2.0;
40 // for (int i = 0; i < 3; i++)
41  int i = 0;
42  {
43  dt /= 2.0;
44  size_t max_iter = (size_t) std::round(tf / dt);
45  const size_t sz[grid_dim] = {N};
46  const double box_lower = -1.0;
47  const double box_upper = 1.0;
48  Box<grid_dim, double> box({box_lower}, {box_upper});
51  typedef grid_dist_id<grid_dim, double, props> grid_in_type;
52  grid_in_type g_dist(sz, box, ghost);
53  g_dist.setPropNames({"Phi_0", "SDF_sussman", "SDF_exact", "Relative error"});
54 
55  // Now we initialize the grid with the indicator function and the analytical solution
56  auto dom = g_dist.getDomainIterator();
57  while(dom.isNext())
58  {
59  auto key = dom.get();
60  Point<grid_dim, double> coords = g_dist.getPos(key);
61  g_dist.template get<Phi_0_grid>(key) = sgn(coords.get(x));
62  g_dist.template get<SDF_exact_grid>(key) = coords.get(x);
63  ++dom;
64  }
65 
66  g_dist.write("grid_1D_preRedistancing", FORMAT_BINARY); // Save the grid
67 
68  Redist_options redist_options;
69 // redist_options.min_iter = max_iter;
70 // redist_options.max_iter = max_iter;
71  redist_options.order_space_op = 1;
72  redist_options.order_timestepper = 1;
73  // set both convergence criteria to false s.t. termination only when max_iterations reached
74  redist_options.convTolChange.check = true; // define here which of the convergence criteria above should
75  // be used. If both are true, termination only occurs when both are fulfilled or when iter > max_iter
76  redist_options.convTolChange.value = EPSILON;
77 
78  redist_options.convTolResidual.check = false; // (default: false)
79  redist_options.interval_check_convergence = 100; // interval of #iterations at which
80  // convergence is checked (default: 100)
81  redist_options.width_NB_in_grid_points = 32; // width of narrow band in number of grid points. Must
82  // be at least 4, in order to have at least 2 grid points on each side of the interface. (default: 4)
83  redist_options.print_current_iterChangeResidual = true; // if true, prints out every current iteration + corresponding change from the previous iteration + residual from SDF (default: false)
84  redist_options.print_steadyState_iter = true; // if true, prints out the final iteration number when steady state was reached + final change + residual (default: true)
85 
86  RedistancingSussman<grid_in_type> redist_obj(g_dist,
87  redist_options); // Instantiation of Sussman-redistancing class
88  redist_obj.set_user_time_step(dt);
89 // std::cout << "CFL dt = " << redist_obj.get_time_step() << std::endl;
90  std::cout << "dt set to = " << dt << std::endl;
91  // 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.
92  redist_obj.run_redistancing<Phi_0_grid, SDF_sussman_grid>();
93 
94  // Compute the absolute error between analytical and numerical solution at each grid point
95  get_absolute_error<SDF_sussman_grid, SDF_exact_grid, Error_grid>(g_dist);
96  g_dist.write("grid_RKorder" + std::to_string(redist_options.order_timestepper) + "_i_" + std::to_string(i),
97  FORMAT_BINARY);
99 // // Get narrow band: Place particles on interface (narrow band width e.g. 4 grid points on each side of the
100 // // interface)
101 // size_t bc[grid_dim] = {NON_PERIODIC};
102 // typedef aggregate<double> props_nb;
103 // typedef vector_dist<grid_dim, double, props_nb> vd_type;
104 // Ghost<grid_dim, double> ghost_vd(0);
105 // vd_type vd_narrow_band(0, box, bc, ghost_vd);
106 // vd_narrow_band.setPropNames({"error"});
107 // const size_t Error_vd = 0;
108 // // Compute the L_2- and L_infinity-norm and save to file
109 // size_t narrow_band_width = 64;
110 // NarrowBand<grid_in_type> narrowBand_points(g_dist, narrow_band_width); // Instantiation of NarrowBand class
111 // narrowBand_points.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist,
112 // vd_narrow_band);
113 // vd_narrow_band.write(
114 // "vd_error_N" + std::to_string(N) + "_RKorder" + std::to_string(redist_options.order_timestepper),
115 // FORMAT_BINARY);
117 // // Compute the L_2- and L_infinity-norm and save to file
118 // L_norms lNorms_vd;
119 // lNorms_vd = get_l_norms_vector<Error_vd>(vd_narrow_band);
120 // write_lnorms_to_file(dt, lNorms_vd, "l_norms_RKorder" + std::to_string(redist_options.order_timestepper),
121 // "./");
122 
123  }
124  }
125 #endif
126  BOOST_AUTO_TEST_CASE(RedistancingSussmanSinglePoint_2D_test)
127  {
128  // CFL dt for N=64 and c=1 is 0.00100781
129  const double EPSILON = std::numeric_limits<double>::epsilon();
130 
131  const size_t grid_dim = 2;
132  // some indices
133  const size_t x = 0;
134  const size_t y = 1;
135 
136  const size_t Phi_0_grid = 0;
137  const size_t SDF_sussman_grid = 1;
138  const size_t SDF_exact_grid = 2;
139  const size_t Error_grid = 3;
140 
141  size_t N = 64;
142  double dt = 0.00100781;
143  double tf = 1e4 * dt;
144  dt *= 2.0;
145 // for (int i = 0; i < 5; i++)
146  {
147  dt /= 2.0;
148  size_t max_iter = (size_t) std::round(tf / dt);
149  const size_t sz[grid_dim] = {N, N};
150  const double radius = 1.0;
151  const double box_lower = 0.0;
152  const double box_upper = 4.0 * radius;
153  Box<grid_dim, double> box({box_lower, box_lower}, {box_upper, box_upper});
154  Ghost<grid_dim, long int> ghost(0);
156  typedef grid_dist_id<grid_dim, double, props> grid_in_type;
157  grid_in_type g_dist(sz, box, ghost);
158  g_dist.setPropNames({"Phi_0", "SDF_sussman", "SDF_exact", "Relative error"});
159 
160  const double center[grid_dim] = {0.5 * (box_upper + box_lower), 0.5 * (box_upper + box_lower)};
161  init_grid_with_disk<Phi_0_grid>(g_dist, radius, center[x], center[y]); // Initialize sphere onto grid
162 
163 
164 // for (int order=1; order<=5; order+=2)
165  {
166  Redist_options redist_options;
167  redist_options.min_iter = max_iter;
168  redist_options.max_iter = max_iter;
169 
170  redist_options.order_space_op = 1;
171  redist_options.order_timestepper = 1;
172 
173  // set both convergence criteria to false s.t. termination only when max_iterations reached
174  redist_options.convTolChange.check = false; // define here which of the convergence criteria above should be used. If both are true, termination only occurs when both are fulfilled or when iter > max_iter
175  redist_options.convTolResidual.check = false; // (default: false)
176 
177  redist_options.interval_check_convergence = 100; // interval of #iterations at which
178  // convergence is checked (default: 100)
179  redist_options.width_NB_in_grid_points = 8; // width of narrow band in number of grid points. Must be at least 4, in order to have at least 2 grid points on each side of the interface. (default: 4)
180  redist_options.print_current_iterChangeResidual = true; // if true, prints out every current iteration + corresponding change from the previous iteration + residual from SDF (default: false)
181  redist_options.print_steadyState_iter = true; // if true, prints out the final iteration number when steady state was reached + final change + residual (default: true)
182 
183  RedistancingSussman<grid_in_type> redist_obj(g_dist,
184  redist_options); // Instantiation of Sussman-redistancing class
185  redist_obj.set_user_time_step(dt);
186  std::cout << "dt set to = " << dt << std::endl;
187 // std::cout << "dt for N = " << N << " is " << redist_obj.get_time_step() << std::endl;
188  // 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.
189  redist_obj.run_redistancing<Phi_0_grid, SDF_sussman_grid>();
190 
191  // Compute exact signed distance function at each grid point
192  init_analytic_sdf_circle<SDF_exact_grid>(g_dist, radius, center[x], center[y]);
193 
194  // Compute the absolute error between analytical and numerical solution at each grid point
195  get_absolute_error<SDF_sussman_grid, SDF_exact_grid, Error_grid>(g_dist);
196 
197 // g_dist.write(
198 // "grid_RKorder" + std::to_string(redist_options.order_timestepper) + "_i_" + std::to_string(i),
199 // FORMAT_BINARY);
200 // /////////////////////////////////////////////////////////////////////////////////////////////
201 // // Get narrow band: Place particles on interface (narrow band width e.g. 4 grid points on each side of the
202 // // interface)
203 // size_t bc[grid_dim] = {PERIODIC, PERIODIC};
204 // typedef aggregate<double> props_nb;
205 // typedef vector_dist<grid_dim, double, props_nb> vd_type;
206 // Ghost<grid_dim, double> ghost_vd(0);
207 // vd_type vd_narrow_band(0, box, bc, ghost_vd);
208 // vd_narrow_band.setPropNames({"error"});
209 // const size_t Error_vd = 0;
210 // // Compute the L_2- and L_infinity-norm and save to file
211 // size_t narrow_band_width = 8;
212 // NarrowBand<grid_in_type> narrowBand_points(g_dist,
213 // narrow_band_width); // Instantiation of NarrowBand class
214 // narrowBand_points.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist,
215 // vd_narrow_band);
216 // vd_narrow_band.write("vd_error_N" + std::to_string(N) + "_RKorder" +
217 // std::to_string(redist_options.order_timestepper), FORMAT_BINARY);
219 // // Compute the L_2- and L_infinity-norm and save to file
220 // L_norms lNorms_vd;
221 // lNorms_vd = get_l_norms_vector<Error_vd>(vd_narrow_band);
222 // write_lnorms_to_file(dt, lNorms_vd,
223 // "l_norms_RKorder" + std::to_string(redist_options.order_timestepper), "./");
224 
225 
226  }
227  }
228  }
229 
230 BOOST_AUTO_TEST_SUITE_END()
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.
Definition: Point.hpp:27
Structure to bundle options for redistancing.
Definition: Ghost.hpp:39
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.
Definition: Point.hpp:172
This class represent an N-dimensional box.
Definition: Box.hpp:60
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...
Definition: aggregate.hpp:214
Class for getting the narrow band around the interface.
Header file containing functions that compute the analytical solution of the signed distance function...