31 #ifndef REDISTANCING_SUSSMAN_REDISTANCINGSUSSMAN_HPP 32 #define REDISTANCING_SUSSMAN_REDISTANCINGSUSSMAN_HPP 39 #include "Vector/vector_dist.hpp" 40 #include "Grid/grid_dist_id.hpp" 41 #include "data_type/aggregate.hpp" 42 #include "Decomposition/CartDecomposition.hpp" 58 template <
typename phi_type=
double>
62 phi_type
value = 1e-15;
74 template <
typename phi_type=
double>
78 phi_type
value = 1e-3;
116 template <
typename phi_type=
double>
119 size_t min_iter = 1e5;
120 size_t max_iter = 1e12;
125 size_t interval_check_convergence = 100;
126 size_t width_NB_in_grid_points = 8;
127 bool print_current_iterChangeResidual =
false;
128 bool print_steadyState_iter =
true;
129 bool save_temp_grid =
false;
138 template <
typename phi_type=
double>
160 template <
typename gr
id_in_type,
typename phi_type=
double>
174 g_temp(grid_in.getDecomposition(),
175 grid_in.getGridInfoVoid().getSize(),
176 Ghost<grid_in_type::dims, long
int>(3))
179 order_upwind_gradient = 1;
181 assure_minimal_thickness_of_NB();
213 template <
size_t Phi_0_in,
size_t Phi_SDF_out>
216 init_temp_grid<Phi_0_in>();
217 init_sign_prop<Phi_n_temp, Phi_0_sign_temp>(
g_temp);
220 get_upwind_gradient<Phi_n_temp, Phi_0_sign_temp, Phi_grad_temp>(
g_temp, order_upwind_gradient,
true);
247 int get_finalIteration()
252 auto get_finalChange()
257 auto get_finalResidual()
262 int get_finalNumberNbPoints()
287 int order_upwind_gradient;
295 void assure_minimal_thickness_of_NB()
299 std::cout <<
"The narrow band thickness that you chose for the convergence check is very small. Consider " 300 "setting redist_options.width_NB_in_grid_points to at least 8" << std::endl;
307 template<
size_t Phi_0_in>
310 phi_type min_value = get_min_val<Phi_0_in>(
r_grid_in);
311 init_grid_and_ghost<Phi_n_temp>(
g_temp, min_value);
325 phi_type
get_phi_nplus1(phi_type phi_n, phi_type phi_n_magnOfGrad,
typename grid_in_type::stype dt, phi_type
328 return phi_n + dt * sgn_phi_n * (1 - phi_n_magnOfGrad);
337 get_upwind_gradient<Phi_n_temp, Phi_0_sign_temp, Phi_grad_temp>(
grid, order_upwind_gradient,
true);
338 grid.template ghost_get<Phi_n_temp, Phi_grad_temp>();
339 auto dom =
grid.getDomainIterator();
342 auto key = dom.get();
343 const phi_type phi_n =
grid.template get<Phi_n_temp>(key);
344 const phi_type phi_n_magnOfGrad = get_vector_magnitude<Phi_grad_temp>(
grid, key);
345 phi_type epsilon = phi_n_magnOfGrad *
grid.getSpacing()[0];
360 return (abs(Phi) <=
kappa);
370 phi_type max_residual = 0;
371 phi_type max_change = 0;
373 auto dom =
grid.getDomainIterator();
376 auto key = dom.get();
380 phi_type phi_n_magnOfGrad = get_vector_magnitude<Phi_grad_temp>(
grid, key);
381 phi_type epsilon = phi_n_magnOfGrad *
grid.getSpacing()[0];
385 if (abs(phi_nplus1 -
grid.template get<Phi_n_temp>(key)) > max_change)
387 max_change = abs(phi_nplus1 -
grid.template get<Phi_n_temp>(key));
390 if (abs(phi_n_magnOfGrad - 1) > max_residual) { max_residual = abs(phi_n_magnOfGrad - 1); }
394 auto &v_cl = create_vcluster();
395 v_cl.max(max_change);
396 v_cl.max(max_residual);
415 auto &v_cl = create_vcluster();
416 if (v_cl.rank() == 0)
420 std::cout <<
"Iteration,MaxChange,MaxResidual,NumberOfNarrowBandPoints" << std::endl;
441 bool steady_state =
false;
479 for (
int j = 0; j <
redistOptions.interval_check_convergence; j++)
490 get_upwind_gradient<Phi_n_temp, Phi_0_sign_temp, Phi_grad_temp>(
g_temp, order_upwind_gradient,
true);
492 g_temp.
save(
"g_temp_redistancing_iteration_" + std::to_string(i) +
".hdf5");
501 auto &v_cl = create_vcluster();
502 if (v_cl.rank() == 0)
504 std::cout <<
"Steady state criterion reached at iteration: " << i << std::endl;
505 std::cout <<
"FinalIteration,MaxChange,MaxResidual" << std::endl;
518 get_upwind_gradient<Phi_n_temp, Phi_0_sign_temp, Phi_grad_temp>(
g_temp, order_upwind_gradient,
true);
520 g_temp.
save(
"g_temp_redistancing_final.hdf5");
526 #endif //REDISTANCING_SUSSMAN_REDISTANCINGSUSSMAN_HPP auto get_time_step()
Access the artificial timestep (private member) which will be used for the iterative redistancing.
bool steady_state_NB(g_temp_type &grid)
Checks steady-state is reached in the narrow band.
static constexpr size_t Phi_n_temp
Property index of Phi_0 on the temporary grid.
aggregate< phi_type, phi_type[grid_in_type::dims], int > props_temp
Aggregated properties for the temporary grid.
Header file containing help-functions that perform on OpenFPM-grids.
void update_distFromSol(g_temp_type &grid)
Re-computes the member variables distFromSol.change, distFromSol.residual, distFromSol....
grid_in_type::stype time_step
Artificial timestep for the redistancing iterations.
phi_type value
redistancing process is considered as steady-state. (see also DistFromSol::change)
DistFromSol< phi_type > distFromSol
Instantiate distance from solution in terms of change, residual, numb.
Structure to bundle options for redistancing.
std::string to_string_with_precision(const T myValue, const size_t n=6)
Converts value into string maintaining a desired precision.
void run_redistancing()
Runs the Sussman-redistancing.
void save(const std::string &filename) const
Save the grid state on HDF5.
Redist_options< phi_type > redistOptions
Instantiate redistancing options.
Class for reinitializing a level-set function into a signed distance function using Sussman redistanc...
Optional convergence criterium checking the total change.
grid_in_type & r_grid_in
Define reference to input grid.
void go_one_redistancing_step_whole_grid(g_temp_type &grid)
Go one re-distancing time-step on the whole grid.
void iterative_redistancing(g_temp_type &grid)
Runs Sussman re-distancing on the internal temporary grid.
void init_temp_grid()
Copies values from input grid to internal temporary grid and initializes ghost layer with minimum val...
g_temp_type g_temp
Create temporary grid, which is only used inside the class for the redistancing.
Approximating upwind gradients on a grid with the following options for the order of accuracy: 1,...
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
static constexpr size_t Phi_grad_temp
Property index of gradient of Phi_n on the temporary grid.
grid_type::stype get_biggest_spacing(grid_type &grid)
Determines the biggest spacing of a grid which is potentially anisotropic when comparing x,...
Bundles total residual and total change over all the grid points.
int count
Integer variable that contains the number of points that could be assigned to the narrow band.
void setPropNames(const openfpm::vector< std::string > &names)
Set the properties names.
phi_type kappa
Transform the half-bandwidth in no_of_grid_points into physical half-bandwidth kappa.
bool lays_inside_NB(phi_type Phi)
Checks if a node lays within the narrow band around the interface.
phi_type get_phi_nplus1(phi_type phi_n, phi_type phi_n_magnOfGrad, typename grid_in_type::stype dt, phi_type sgn_phi_n)
Run one timestep of re-distancing and compute Phi_n+1.
int final_iter
Will be set to the final iteration when redistancing ends.
T smooth_S(T val, T epsilon)
Gets the smoothed sign of a variable.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
RedistancingSussman(grid_in_type &grid_in, Redist_options< phi_type > &redistOptions)
Constructor initializing the redistancing options, the temporary internal grid and reference variable...
static constexpr size_t Phi_0_sign_temp
Property index of sign of initial (input) Phi_0 (temp. grid).
grid_dist_id< grid_in_type::dims, typename grid_in_type::stype, props_temp > g_temp_type
Type definition for the temporary grid.
grid_type::stype get_time_step_CFL(grid_type &grid)
Computes the time step for the iterative re-distancing fulfilling CFL condition.
void set_user_time_step(T dt)
Overwrite the time_step found via CFL condition with an individual time_step.
Header file containing small mathematical help-functions that are needed e.g. for the Sussman redista...
Optional convergence criterium checking the residual.
void print_out_iteration_change_residual(g_temp_type &grid, size_t iter)
Prints out the iteration number, max. change, max. residual and number of points in the narrow band o...