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"
58template <
typename phi_type=
double>
74template <
typename phi_type=
double>
116template <
typename phi_type=
double>
119 size_t min_iter = 1e3;
120 size_t max_iter = 1e6;
125 size_t interval_check_convergence = 100;
126 size_t width_NB_in_grid_points = 2;
127 bool print_current_iterChangeResidual =
false;
128 bool print_steadyState_iter =
true;
129 bool save_temp_grid =
false;
138template <
typename phi_type=
double>
160template <
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))
180 order_upwind_gradient = 1;
182 assure_minimal_thickness_of_NB();
214 template <
size_t Phi_0_in,
size_t Phi_SDF_out>
217 init_temp_grid<Phi_0_in>();
218 init_sign_prop<Phi_n_temp, Phi_0_sign_temp>(
g_temp);
221 get_upwind_gradient<Phi_n_temp, Phi_0_sign_temp, Phi_grad_temp>(
g_temp, order_upwind_gradient,
true);
248 int get_finalIteration()
253 auto get_finalChange()
258 auto get_finalResidual()
263 int get_finalNumberNbPoints()
288 int order_upwind_gradient;
296 void assure_minimal_thickness_of_NB()
300 std::cout <<
"The narrow band thickness that you chose for the convergence check is very small. Consider "
301 "setting redist_options.width_NB_in_grid_points to at least 8" << std::endl;
308 template<size_t Phi_0_in>
311 phi_type min_value = get_min_val<Phi_0_in>(
r_grid_in);
312 init_grid_and_ghost<Phi_n_temp>(
g_temp, min_value);
326 phi_type
get_phi_nplus1(phi_type phi_n, phi_type phi_n_magnOfGrad,
typename grid_in_type::stype dt, phi_type
329 return phi_n + dt * sgn_phi_n * (1 - phi_n_magnOfGrad);
338 get_upwind_gradient<Phi_n_temp, Phi_0_sign_temp, Phi_grad_temp>(
grid, order_upwind_gradient,
true);
339 grid.template ghost_get<Phi_n_temp, Phi_grad_temp>();
340 auto dom =
grid.getDomainIterator();
343 auto key = dom.get();
344 const phi_type phi_n =
grid.template get<Phi_n_temp>(key);
345 const phi_type phi_n_magnOfGrad = get_vector_magnitude<Phi_grad_temp>(
grid, key);
346 phi_type epsilon = phi_n_magnOfGrad *
grid.getSpacing()[0];
361 return (abs(Phi) <=
kappa);
371 phi_type max_residual = 0;
372 phi_type max_change = 0;
374 auto dom =
grid.getDomainIterator();
377 auto key = dom.get();
381 phi_type phi_n_magnOfGrad = get_vector_magnitude<Phi_grad_temp>(
grid, key);
382 phi_type epsilon = phi_n_magnOfGrad *
grid.getSpacing()[0];
386 if (abs(phi_nplus1 -
grid.template get<Phi_n_temp>(key)) > max_change)
388 max_change = abs(phi_nplus1 -
grid.template get<Phi_n_temp>(key));
391 if (abs(phi_n_magnOfGrad - 1) > max_residual) { max_residual = abs(phi_n_magnOfGrad - 1); }
395 auto &v_cl = create_vcluster();
396 v_cl.max(max_change);
397 v_cl.max(max_residual);
416 auto &v_cl = create_vcluster();
417 if (v_cl.rank() == 0)
421 std::cout <<
"Iteration,MaxChange,MaxResidual,NumberOfNarrowBandPoints" << std::endl;
442 bool steady_state =
false;
480 for (
int j = 0; j <
redistOptions.interval_check_convergence; j++)
491 get_upwind_gradient<Phi_n_temp, Phi_0_sign_temp, Phi_grad_temp>(
g_temp, order_upwind_gradient,
true);
493 g_temp.
save(
"g_temp_redistancing_iteration_" + std::to_string(i) +
".hdf5");
502 auto &v_cl = create_vcluster();
503 if (v_cl.rank() == 0)
505 std::cout <<
"Steady state criterion reached at iteration: " << i << std::endl;
506 std::cout <<
"FinalIteration,MaxChange,MaxResidual" << std::endl;
519 get_upwind_gradient<Phi_n_temp, Phi_0_sign_temp, Phi_grad_temp>(
g_temp, order_upwind_gradient,
true);
521 g_temp.
save(
"g_temp_redistancing_final.hdf5");
Header file containing help-functions that perform on OpenFPM-grids.
grid_type::stype get_time_step_CFL(grid_type &grid, typename grid_type::stype u[grid_type::dims], typename grid_type::stype C)
Computes the time step size fulfilling CFL condition according to https://www.cfd-online ....
grid_type::stype get_biggest_spacing(grid_type &grid)
Determines the biggest spacing of a grid which is potentially anisotropic when comparing x,...
Header file containing small mathematical help-functions that are needed e.g. for the Sussman redista...
T smooth_S(T val, T epsilon)
Gets the smoothed sign of a variable.
std::string to_string_with_precision(const T myValue, const size_t n=6)
Converts value into string maintaining a desired precision.
Approximating upwind gradients on a grid with the following options for the order of accuracy: 1,...
Class for reinitializing a level-set function into a signed distance function using Sussman redistanc...
grid_in_type & r_grid_in
Define reference to input grid.
g_temp_type g_temp
Create temporary grid, which is only used inside the class for the redistancing.
int final_iter
Will be set to the final iteration when redistancing ends.
static constexpr size_t Phi_n_temp
Property index of Phi_0 on the temporary grid.
bool steady_state_NB(g_temp_type &grid)
Checks steady-state is reached in the narrow band.
bool lays_inside_NB(phi_type Phi)
Checks if a node lays within the narrow band around the interface.
void init_temp_grid()
Copies values from input grid to internal temporary grid and initializes ghost layer with minimum val...
void run_redistancing()
Runs the Sussman-redistancing.
void update_distFromSol(g_temp_type &grid)
Re-computes the member variables distFromSol.change, distFromSol.residual, distFromSol....
static constexpr size_t Phi_0_sign_temp
Property index of sign of initial (input) Phi_0 (temp. grid).
phi_type kappa
Transform the half-bandwidth in no_of_grid_points into physical half-bandwidth kappa.
DistFromSol< phi_type > distFromSol
Instantiate distance from solution in terms of change, residual, numb.
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.
auto get_time_step()
Access the artificial timestep (private member) which will be used for the iterative redistancing.
grid_in_type::stype time_step
Artificial timestep for the redistancing iterations.
static constexpr size_t Phi_grad_temp
Property index of gradient of Phi_n on the temporary grid.
grid_dist_id< grid_in_type::dims, typename grid_in_type::stype, props_temp > g_temp_type
Type definition for the temporary grid.
void iterative_redistancing(g_temp_type &grid)
Runs Sussman re-distancing on the internal temporary grid.
RedistancingSussman(grid_in_type &grid_in, Redist_options< phi_type > &redistOptions)
Constructor initializing the redistancing options, the temporary internal grid and reference variable...
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...
Redist_options< phi_type > redistOptions
Instantiate redistancing options.
void go_one_redistancing_step_whole_grid(g_temp_type &grid)
Go one re-distancing time-step on the whole grid.
void set_user_time_step(T dt)
Overwrite the time_step found via CFL condition with an individual time_step.
aggregate< phi_type, phi_type[grid_in_type::dims], int > props_temp
Aggregated properties for the temporary grid.
This is a distributed grid.
void save(const std::string &filename) const
Save the grid state on HDF5.
void setPropNames(const openfpm::vector< std::string > &names)
Set the properties names.
Optional convergence criterium checking the total change.
phi_type value
redistancing process is considered as steady-state. (see also DistFromSol::change)
Optional convergence criterium checking the residual.
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.
Structure to bundle options for redistancing.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...