diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23f3784fd94eacca56368e3d7d4643e2e8456ab1..9175d31578ea592b23ea9a41fe38d700c6379a73 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,7 +47,7 @@ add_executable(numerics ${OPENFPM_INIT_FILE} ${CUDA_SOURCES} ../../src/lib/pdata.cpp BoundaryConditions/tests/method_of_images_cylinder_unit_test.cpp # level_set/closest_point/closest_point_unit_tests.cpp - level_set/redistancing_Sussman/tests/redistancingSussman_unit_test.cpp +# level_set/redistancing_Sussman/tests/redistancingSussman_unit_test.cpp # level_set/redistancing_Sussman/tests/convergence_test.cpp ) @@ -252,6 +252,8 @@ install(FILES level_set/redistancing_Sussman/HelpFunctions.hpp level_set/redistancing_Sussman/HelpFunctionsForGrid.hpp level_set/redistancing_Sussman/NarrowBand.hpp level_set/redistancing_Sussman/RedistancingSussman.hpp + level_set/redistancing_Sussman/tests/l_norms/LNorms.hpp + level_set/redistancing_Sussman/tests/analytical_SDF/AnalyticalSDF.hpp DESTINATION openfpm_numerics/include/level_set/redistancing_Sussman COMPONENT OpenFPM) diff --git a/src/level_set/redistancing_Sussman/RedistancingSussman.hpp b/src/level_set/redistancing_Sussman/RedistancingSussman.hpp index 4cb072335d27f2c4b605f5700c7ca0a23b9099b6..78cdf6031751de833d4c692b90c340a757564321 100644 --- a/src/level_set/redistancing_Sussman/RedistancingSussman.hpp +++ b/src/level_set/redistancing_Sussman/RedistancingSussman.hpp @@ -240,7 +240,27 @@ public: /// This timestep is computed according to the grid spacing fulfilling the CFL condition. return time_step; } - + + int get_finalIteration() + { + return final_iter; + } + + double get_finalChange() + { + return distFromSol.change; + } + + double get_finalResidual() + { + return distFromSol.residual; + } + + int get_finalNumberNbPoints() + { + return distFromSol.count; + } + private: // Some indices for better readability static constexpr size_t Phi_n_temp = 0; ///< Property index of Phi_0 on the temporary grid. @@ -251,6 +271,9 @@ private: Redist_options redistOptions; ///< Instantiate redistancing options. grid_in_type &r_grid_in; ///< Define reference to input grid. + DistFromSol distFromSol; ///< Instantiate distance from solution in terms of change, residual, numb. point in NB. + int final_iter = 0; ///< Will be set to the final iteration when redistancing ends. + /// Transform the half-bandwidth in no_of_grid_points into physical half-bandwidth kappa. double kappa = ceil(redistOptions.width_NB_in_grid_points / 2.0) * get_biggest_spacing(g_temp); /**@brief Artificial timestep for the redistancing iterations. @@ -332,14 +355,12 @@ private: return (abs(Phi) <= kappa); } - /** @brief Checks how far current solution is from fulfilling the user-defined convergence criteria. + /** @brief Re-computes the member variables distFromSol.change, distFromSol.residual, distFromSol.count for the + * Phi of the current iteration. Needed to check how far current solution is from fulfilling the user-defined convergence criteria. * * @param grid Internal temporary grid. - * - * @return Total residual (1 - phi_gradient_magnitude) and total change from the last time step, - * both normalized by the number of grid nodes in the narrow band. */ - DistFromSol get_residual_and_change_NB(g_temp_type &grid) + void update_distFromSol(g_temp_type &grid) { double max_residual = 0; double max_change = 0; @@ -370,20 +391,22 @@ private: v_cl.max(max_residual); v_cl.sum(count); v_cl.execute(); - return {max_change, max_residual, count}; + + // Update member variable distFromSol + distFromSol.change = max_change; + distFromSol.residual = max_residual; + distFromSol.count = count; } - /** @brief Prints out the iteration number, residual and change of the current re-distancing iteration + /** @brief Prints out the iteration number, max. change, max. residual and number of points in the narrow band of + * the current re-distancing iteration. * * @param grid Internal temporary grid. * @param iter Current re-distancing iteration. - * - * @return Total residual (1 - phi_gradient_magnitude) and total change from the last time step, - * both normalized by the number of grid nodes in the narrow band. */ void print_out_iteration_change_residual(g_temp_type &grid, size_t iter) { - DistFromSol distFromSol = get_residual_and_change_NB(grid); + update_distFromSol(grid); auto &v_cl = create_vcluster(); if (v_cl.rank() == 0) { @@ -411,7 +434,7 @@ private: bool steady_state_NB(g_temp_type &grid) { bool steady_state = false; - DistFromSol distFromSol = get_residual_and_change_NB(grid); + update_distFromSol(grid); if (redistOptions.convTolChange.check && redistOptions.convTolResidual.check) { steady_state = ( @@ -475,11 +498,13 @@ private: } } } + update_distFromSol(grid); + final_iter = i; // If save_temp_grid set true, save the temporary grid as hdf5 that can be reloaded onto a grid if (redistOptions.save_temp_grid) { get_upwind_gradient<Phi_n_temp, Phi_0_sign_temp, Phi_grad_temp>(g_temp, order_upwind_gradient, true); - g_temp.setPropNames({"Phi_n", "Phi_nplus1_temp", "Phi_grad_temp", "Phi_0_sign_temp"}); + g_temp.setPropNames({"Phi_n", "Phi_grad_temp", "Phi_0_sign_temp"}); g_temp.save("g_temp_redistancing.hdf5"); // HDF5 file} } }