diff --git a/src/level_set/redistancing_Sussman/RedistancingSussman.hpp b/src/level_set/redistancing_Sussman/RedistancingSussman.hpp index 25f4510beea99671d2272ce5abb66521bd55a484..ad319c0ad2e1bb83281dc77ea67e65fef30efefa 100644 --- a/src/level_set/redistancing_Sussman/RedistancingSussman.hpp +++ b/src/level_set/redistancing_Sussman/RedistancingSussman.hpp @@ -116,14 +116,14 @@ struct Conv_tol_residual template <typename phi_type=double> struct Redist_options { - size_t min_iter = 1e5; - size_t max_iter = 1e12; + size_t min_iter = 1e3; + size_t max_iter = 1e6; Conv_tol_change<phi_type> convTolChange; Conv_tol_residual<phi_type> convTolResidual; size_t interval_check_convergence = 100; - size_t width_NB_in_grid_points = 8; + size_t width_NB_in_grid_points = 2; bool print_current_iterChangeResidual = false; bool print_steadyState_iter = true; bool save_temp_grid = false; diff --git a/src/level_set/redistancing_Sussman/tests/convergence_test.cpp b/src/level_set/redistancing_Sussman/tests/convergence_test.cpp index 2d090204dcb222ad289e86defa07514e924cd201..b681065cad866aa7a809e486890cdbef1907649e 100644 --- a/src/level_set/redistancing_Sussman/tests/convergence_test.cpp +++ b/src/level_set/redistancing_Sussman/tests/convergence_test.cpp @@ -27,9 +27,9 @@ BOOST_AUTO_TEST_SUITE(ConvergenceTestSuite) space_type sum = 0; for (int d = 0; d < dims; d++) { - sum += 1 / (dx * dx); + sum += 1 / dx; } - return 0.5 / sum; + return 0.1 / sum; } BOOST_AUTO_TEST_CASE(RedistancingSussman_convergence_test_1D) @@ -144,7 +144,6 @@ BOOST_AUTO_TEST_SUITE(ConvergenceTestSuite) for (size_t N=32; N <=128; N*=2) { - const space_type dt = 0.000165334; const size_t sz[grid_dim] = {N, N, N}; const space_type radius = 1.0; const space_type box_lower = 0.0; diff --git a/src/level_set/redistancing_Sussman/tests/redistancingSussman_fast_unit_test.cpp b/src/level_set/redistancing_Sussman/tests/redistancingSussman_fast_unit_test.cpp index b6c00114d2cdfe315615ab8846b37b6dca4c7d19..2178f7aeedf3df0989d450032243a42aa4f375f3 100644 --- a/src/level_set/redistancing_Sussman/tests/redistancingSussman_fast_unit_test.cpp +++ b/src/level_set/redistancing_Sussman/tests/redistancingSussman_fast_unit_test.cpp @@ -15,7 +15,7 @@ #include "analytical_SDF/AnalyticalSDF.hpp" BOOST_AUTO_TEST_SUITE(RedistancingSussmanFastTestSuite) - + BOOST_AUTO_TEST_CASE(RedistancingSussman_unit_sphere_fast_double_test) { typedef double phi_type; @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_SUITE(RedistancingSussmanFastTestSuite) redist_options.convTolResidual.check = false; redist_options.interval_check_convergence = 1e3; - redist_options.width_NB_in_grid_points = 8; + redist_options.width_NB_in_grid_points = 4; redist_options.print_current_iterChangeResidual = true; redist_options.print_steadyState_iter = true; @@ -82,25 +82,19 @@ BOOST_AUTO_TEST_SUITE(RedistancingSussmanFastTestSuite) Ghost<grid_dim, space_type> ghost_vd(0); vd_type vd_narrow_band(0, box, bc, ghost_vd); vd_narrow_band.setPropNames({"error"}); - size_t narrow_band_width = 8; - NarrowBand<grid_in_type, phi_type> narrowBand(g_dist, narrow_band_width); // Instantiation of NarrowBand class + NarrowBand<grid_in_type, phi_type> narrowBand(g_dist, redist_options.width_NB_in_grid_points); // Instantiation of NarrowBand class const size_t Error_vd = 0; narrowBand.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist, vd_narrow_band); - // Compute the L_2- and L_infinity-norm and save to file + // Compute the L_2- and L_infinity-norm LNorms<phi_type> lNorms_vd; lNorms_vd.get_l_norms_vector<Error_vd>(vd_narrow_band); std::cout << lNorms_vd.l2 << ", " << lNorms_vd.linf << std::endl; -// N = 32, precision = double, 1e3 iterations -// Automatically found timestep is 0.00277489 -// 1000,0.000029667373926,0.203437014506586,6032 -// 0.0428668, 0.0763498 - - BOOST_CHECK(lNorms_vd.l2 < 0.0428669); - BOOST_CHECK(lNorms_vd.linf < 0.0763499); + BOOST_CHECK(lNorms_vd.l2 < 0.044693); + BOOST_CHECK(lNorms_vd.linf < 0.066995); } - + BOOST_AUTO_TEST_CASE(RedistancingSussman_unit_sphere_fast_float_test) { typedef float phi_type; @@ -169,28 +163,21 @@ BOOST_AUTO_TEST_SUITE(RedistancingSussmanFastTestSuite) Ghost<grid_dim, space_type> ghost_vd(0); vd_type vd_narrow_band(0, box, bc, ghost_vd); vd_narrow_band.setPropNames({"error"}); - size_t narrow_band_width = 8; - NarrowBand<grid_in_type, phi_type> narrowBand(g_dist, narrow_band_width); // Instantiation of NarrowBand class + NarrowBand<grid_in_type, phi_type> narrowBand(g_dist, redist_options.width_NB_in_grid_points); // Instantiation of NarrowBand class const size_t Error_vd = 0; narrowBand.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist, vd_narrow_band); - // Compute the L_2- and L_infinity-norm and save to file + // Compute the L_2- and L_infinity-norm LNorms<phi_type> lNorms_vd; lNorms_vd.get_l_norms_vector<Error_vd>(vd_narrow_band); std::cout << lNorms_vd.l2 << ", " << lNorms_vd.linf << std::endl; - -// N = 32, precision = float, 1e3 iterations -// Automatically found timestep is 0.00277489 -// 1000,0.000029653310776,0.203437089920044,6032 -// 0.0428669, 0.0763501 - - BOOST_CHECK(lNorms_vd.l2 < 0.0428700); - BOOST_CHECK(lNorms_vd.linf < 0.0763502); + // When using NB-width 4 and single precision, then l2, linf = 0.0500562, 0.0846975 + BOOST_CHECK(lNorms_vd.l2 < 0.0500563); + BOOST_CHECK(lNorms_vd.linf < 0.0846976); } - + BOOST_AUTO_TEST_CASE(RedistancingSussman_unit_sphere_fast_usingDefault_test) - { - typedef double phi_type; + { typedef double phi_type; typedef double space_type; const phi_type EPSILON = std::numeric_limits<phi_type>::epsilon(); const size_t grid_dim = 3; @@ -205,20 +192,21 @@ BOOST_AUTO_TEST_SUITE(RedistancingSussmanFastTestSuite) const size_t Error_grid = 3; size_t N = 32; - const size_t sz[grid_dim] = {N, N, N}; + const size_t sz[grid_dim] = { N, N, N }; const space_type radius = 1.0; const space_type box_lower = -2.0; const space_type box_upper = 2.0; - Box<grid_dim, space_type> box({box_lower, box_lower, box_lower}, {box_upper, box_upper, box_upper}); + Box<grid_dim, space_type> box({ box_lower, box_lower, box_lower }, { box_upper, box_upper, box_upper }); Ghost<grid_dim, long int> ghost(0); typedef aggregate<phi_type, phi_type, phi_type, phi_type> props; typedef grid_dist_id<grid_dim, space_type, props > grid_in_type; grid_in_type g_dist(sz, box, ghost); - g_dist.setPropNames({"Phi_0", "SDF_sussman", "SDF_exact", "Relative error"}); + g_dist.setPropNames({ "Phi_0", "SDF_sussman", "SDF_exact", "Relative error" }); - const space_type center[grid_dim] = {(box_upper+box_lower)/(space_type)2, - (box_upper+box_lower)/(space_type)2, - (box_upper+box_lower)/(space_type)2}; + const space_type center[grid_dim] = { + (box_upper + box_lower) / (space_type) 2, (box_upper + box_lower) / (space_type) 2, + (box_upper + box_lower) / (space_type) 2 + }; init_grid_with_sphere<Phi_0_grid>(g_dist, radius, center[x], center[y], center[z]); // Initialize sphere onto grid @@ -226,14 +214,6 @@ BOOST_AUTO_TEST_SUITE(RedistancingSussmanFastTestSuite) redist_options.min_iter = 1e3; redist_options.max_iter = 1e3; - redist_options.convTolChange.check = false; - redist_options.convTolResidual.check = false; - - redist_options.interval_check_convergence = 1e3; - redist_options.width_NB_in_grid_points = 8; - redist_options.print_current_iterChangeResidual = true; - redist_options.print_steadyState_iter = true; - RedistancingSussman<grid_in_type> redist_obj(g_dist, redist_options); // Instantiation of std::cout << "Automatically found timestep is " << redist_obj.get_time_step() << std::endl; @@ -248,33 +228,23 @@ BOOST_AUTO_TEST_SUITE(RedistancingSussmanFastTestSuite) ///////////////////////////////////////////////////////////////////////////////////////////// // Get narrow band: Place particles on interface (narrow band width e.g. 4 grid points on each side of the // interface) - size_t bc[grid_dim] = {NON_PERIODIC, NON_PERIODIC, NON_PERIODIC}; + size_t bc[grid_dim] = { NON_PERIODIC, NON_PERIODIC, NON_PERIODIC }; typedef aggregate<phi_type> props_nb; typedef vector_dist<grid_dim, space_type, props_nb> vd_type; Ghost<grid_dim, space_type> ghost_vd(0); vd_type vd_narrow_band(0, box, bc, ghost_vd); - vd_narrow_band.setPropNames({"error"}); - size_t narrow_band_width = 8; - NarrowBand<grid_in_type> narrowBand(g_dist, narrow_band_width); // Instantiation of NarrowBand class + vd_narrow_band.setPropNames({ "error" }); + NarrowBand<grid_in_type> narrowBand(g_dist, redist_options.width_NB_in_grid_points); // Instantiation of NarrowBand class const size_t Error_vd = 0; - narrowBand.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist, - vd_narrow_band); - // Compute the L_2- and L_infinity-norm and save to file + narrowBand.get_narrow_band_copy_specific_property<SDF_sussman_grid, Error_grid, Error_vd>(g_dist, vd_narrow_band); + // Compute the L_2- and L_infinity-norm LNorms<> lNorms_vd; lNorms_vd.get_l_norms_vector<Error_vd>(vd_narrow_band); std::cout << lNorms_vd.l2 << ", " << lNorms_vd.linf << std::endl; -// int precision = 6; -// lNorms_vd.write_to_file(N, precision, "l_norms.csv", path_output); - -// N = 32, precision = double, 1e3 iterations -// Automatically found timestep is 0.00277489 -// 1000,0.000029667373926,0.203437014506586,6032 -// 0.0428668, 0.0763498 - - BOOST_CHECK(lNorms_vd.l2 < 0.0428669); - BOOST_CHECK(lNorms_vd.linf < 0.0763499); + // When using default NB-width, which is 2, the l2, lin = 0.0417404, 0.0639716 + BOOST_CHECK(lNorms_vd.l2 < 0.0417405); + BOOST_CHECK(lNorms_vd.linf < 0.0639717); } - BOOST_AUTO_TEST_SUITE_END()