OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
redistancingSussman_unit_test.cpp
1//
2// Created by jstark on 12.05.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
12// Include header files for testing
13#include "Draw/DrawSphere.hpp"
14#include "l_norms/LNorms.hpp"
16
17BOOST_AUTO_TEST_SUITE(RedistancingSussmanTestSuite)
18
19 BOOST_AUTO_TEST_CASE(RedistancingSussman_unit_sphere)
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 = 128;
36 const space_type dt = 0.000165334; // CFL-condition for N=128
37 const size_t sz[grid_dim] = {N, N, N};
38 const space_type radius = 1.0;
39 const space_type box_lower = -2.0;
40 const space_type box_upper = 2.0;
41 Box<grid_dim, space_type> box({box_lower, box_lower, box_lower}, {box_upper, box_upper, box_upper});
45 grid_in_type g_dist(sz, box, ghost);
46 g_dist.setPropNames({"Phi_0", "SDF_sussman", "SDF_exact", "Relative error"});
47
48 const space_type center[grid_dim] = {0.5*(box_upper+box_lower),
49 0.5*(box_upper+box_lower),
50 0.5*(box_upper+box_lower)};
51 init_grid_with_sphere<Phi_0_grid>(g_dist, radius, center[x], center[y], center[z]); // Initialize sphere onto grid
52
53
54 Redist_options<phi_type> redist_options;
55 redist_options.min_iter = 1e4;
56 redist_options.max_iter = 1e4;
57
58 redist_options.convTolChange.check = false;
59 redist_options.convTolResidual.check = false;
60
61 redist_options.interval_check_convergence = 1e3;
62 redist_options.width_NB_in_grid_points = 8;
63 redist_options.print_current_iterChangeResidual = true;
64 redist_options.print_steadyState_iter = true;
65
66 RedistancingSussman<grid_in_type, phi_type> redist_obj(g_dist, redist_options); // Instantiation of
67 // Sussman-redistancing class
68 std::cout << "New CFL timestep = " << redist_obj.get_time_step() << std::endl;
69// redist_obj.set_user_time_step(dt);
70// std::cout << "dt set to = " << dt << std::endl;
71 // 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.
72 redist_obj.run_redistancing<Phi_0_grid, SDF_sussman_grid>();
73
74 // Compute exact signed distance function at each grid point
75 init_analytic_sdf_sphere<SDF_exact_grid>(g_dist, radius, center[x], center[y], center[z]);
76
77 // Compute the absolute error between analytical and numerical solution at each grid point
78 get_absolute_error<SDF_sussman_grid, SDF_exact_grid, Error_grid>(g_dist);
79
80
82 // Get narrow band: Place particles on interface (narrow band width e.g. 4 grid points on each side of the
83 // interface)
84 size_t bc[grid_dim] = {NON_PERIODIC, NON_PERIODIC, NON_PERIODIC};
85 typedef aggregate<phi_type> props_nb;
88 vd_type vd_narrow_band(0, box, bc, ghost_vd);
89 vd_narrow_band.setPropNames({"error"});
90 size_t narrow_band_width = 8;
91 NarrowBand<grid_in_type, phi_type> narrowBand(g_dist, narrow_band_width); // Instantiation of NarrowBand class
92 const size_t Error_vd = 0;
93 narrowBand.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist,
94 vd_narrow_band);
95 // Compute the L_2- and L_infinity-norm and save to file
96 LNorms<phi_type> lNorms_vd;
97 lNorms_vd.get_l_norms_vector<Error_vd>(vd_narrow_band);
98 std::cout << lNorms_vd.l2 << ", " << lNorms_vd.linf << std::endl;
99
100 // l-norms original implementation of 1st order upwinding:
101 // 32,0.033643,0.063065; dt = 0.000165334; 1e4 iterations
102 // 0.0336846, 0.0630651
103 // new impl
104 // order 1: 0.0336846, 0.0630651
105 // order 3: 0.02794, 0.0586704
106 // order 5: 0.0187199, 0.0367638
107
108
109 BOOST_CHECK(lNorms_vd.l2 < 0.03369 + EPSILON);
110 BOOST_CHECK(lNorms_vd.linf < 0.06307 + EPSILON);
111
112 }
113
114
115BOOST_AUTO_TEST_SUITE_END()
116
117
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...