Skip to content
Snippets Groups Projects
Commit 9a83684d authored by Pietro Incardona's avatar Pietro Incardona
Browse files

Merge remote-tracking branch 'origin/master'

parents eef5bccf a48facbf
No related branches found
No related tags found
No related merge requests found
Pipeline #4150 failed
// //
// Created by jstark on 2020-05-18. // Created by jstark on 2020-05-18. Updated on 2022-01-05.
// //
/** /**
* @file example_sussman_disk/main.cpp * @file example_sussman_disk/main.cpp
...@@ -125,6 +125,7 @@ ...@@ -125,6 +125,7 @@
//! @cond [Initialization and output folder] @endcond //! @cond [Initialization and output folder] @endcond
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
typedef double phi_type;
// initialize library // initialize library
openfpm_init(&argc, &argv); openfpm_init(&argc, &argv);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -169,7 +170,7 @@ int main(int argc, char* argv[]) ...@@ -169,7 +170,7 @@ int main(int argc, char* argv[])
* * Define the grid size in terms of number of grid points per dimension * * Define the grid size in terms of number of grid points per dimension
* * Create a Box that defines our domain * * Create a Box that defines our domain
* * Create a Ghost object that will define the extension of the ghost part * * Create a Ghost object that will define the extension of the ghost part
* * Create a 2D grid with two properties of type double, one for the pre-redistancing Phi_initial and one, where * * Create a 2D grid with two properties of type phi_type, one for the pre-redistancing Phi_initial and one, where
* the post-redistancing Phi_SDF should be written to. * the post-redistancing Phi_SDF should be written to.
* * Set some property names (optionally. These names show up when opening the grid vtk in Paraview.) * * Set some property names (optionally. These names show up when opening the grid vtk in Paraview.)
* *
...@@ -181,10 +182,10 @@ int main(int argc, char* argv[]) ...@@ -181,10 +182,10 @@ int main(int argc, char* argv[])
// Prop1: store the initial Phi; // Prop1: store the initial Phi;
// Prop2: here the re-initialized Phi (signed distance function) will be written to in the re-distancing step // Prop2: here the re-initialized Phi (signed distance function) will be written to in the re-distancing step
size_t sz[grid_dim] = {128, 128}; // Grid size in terms of number of grid points per dimension size_t sz[grid_dim] = {128, 128}; // Grid size in terms of number of grid points per dimension
Box<grid_dim, double> box({0.0, 0.0}, {5.0, 5.0}); // 2D Box<grid_dim, phi_type> box({0.0, 0.0}, {5.0, 5.0}); // 2D
Ghost<grid_dim, long int> ghost(0); Ghost<grid_dim, long int> ghost(0);
typedef aggregate<double, double> props; typedef aggregate<phi_type, phi_type> props;
typedef grid_dist_id<grid_dim, double, props > grid_in_type; typedef grid_dist_id<grid_dim, phi_type, props > grid_in_type;
grid_in_type g_dist(sz, box, ghost); grid_in_type g_dist(sz, box, ghost);
g_dist.setPropNames({"Phi_0", "Phi_SDF"}); g_dist.setPropNames({"Phi_0", "Phi_SDF"});
//! @cond [Grid creation] @endcond //! @cond [Grid creation] @endcond
...@@ -210,7 +211,7 @@ int main(int argc, char* argv[]) ...@@ -210,7 +211,7 @@ int main(int argc, char* argv[])
*/ */
//! @cond [Get disk] @endcond //! @cond [Get disk] @endcond
// Now we initialize the grid with a disk. Outside the disk, the value of Phi_0 will be -1, inside +1. // Now we initialize the grid with a disk. Outside the disk, the value of Phi_0 will be -1, inside +1.
double radius = 1.0; // Radius of the disk phi_type radius = 1.0; // Radius of the disk
init_grid_with_disk<Phi_0_grid>(g_dist, radius, 2.5, 2.5); // Initialize disk onto grid, centered at (2.5, 2.5) init_grid_with_disk<Phi_0_grid>(g_dist, radius, 2.5, 2.5); // Initialize disk onto grid, centered at (2.5, 2.5)
g_dist.write(path_output + "/grid_disk_preRedistancing_radius" + std::to_string((int)radius) , FORMAT_BINARY); // Save the disk as vtk file g_dist.write(path_output + "/grid_disk_preRedistancing_radius" + std::to_string((int)radius) , FORMAT_BINARY); // Save the disk as vtk file
...@@ -247,7 +248,8 @@ int main(int argc, char* argv[]) ...@@ -247,7 +248,8 @@ int main(int argc, char* argv[])
* w.r.t the previous iteration and the residual is printed (Default: false). * w.r.t the previous iteration and the residual is printed (Default: false).
* * \p print_steadyState_iter: If true, the number of the steady-state-iteration, the corresponding change * * \p print_steadyState_iter: If true, the number of the steady-state-iteration, the corresponding change
* w.r.t the previous iteration and the residual is printed (Default: false). * w.r.t the previous iteration and the residual is printed (Default: false).
* * \p save_temp_grid: If true, save the temporary grid as hdf5 that can be reloaded onto a grid (Default: false). * * \p save_temp_grid: If true, save the temporary grid every interval_check_convergence as hdf5 that can be
* reloaded onto a grid (Default: false).
* *
* *
* @snippet example/Numerics/Sussman_redistancing/example_sussman_disk/main.cpp Redistancing options * @snippet example/Numerics/Sussman_redistancing/example_sussman_disk/main.cpp Redistancing options
...@@ -256,7 +258,7 @@ int main(int argc, char* argv[]) ...@@ -256,7 +258,7 @@ int main(int argc, char* argv[])
//! @cond [Redistancing options] @endcond //! @cond [Redistancing options] @endcond
// Now we want to convert the initial Phi into a signed distance function (SDF) with magnitude of gradient = 1. // Now we want to convert the initial Phi into a signed distance function (SDF) with magnitude of gradient = 1.
// For the initial re-distancing we use the Sussman method. First of all, we can set some redistancing options. // For the initial re-distancing we use the Sussman method. First of all, we can set some redistancing options.
Redist_options redist_options; Redist_options<phi_type> redist_options;
redist_options.min_iter = 1e3; redist_options.min_iter = 1e3;
redist_options.max_iter = 1e4; redist_options.max_iter = 1e4;
...@@ -293,7 +295,8 @@ int main(int argc, char* argv[]) ...@@ -293,7 +295,8 @@ int main(int argc, char* argv[])
* @snippet example/Numerics/Sussman_redistancing/example_sussman_disk/main.cpp Run redistancing * @snippet example/Numerics/Sussman_redistancing/example_sussman_disk/main.cpp Run redistancing
*/ */
//! @cond [Run redistancing] @endcond //! @cond [Run redistancing] @endcond
RedistancingSussman<grid_in_type> redist_obj(g_dist, redist_options); // Instantiation of Sussman-redistancing class RedistancingSussman<grid_in_type, phi_type> redist_obj(g_dist, redist_options); // Instantiation of
// Sussman-redistancing class
// std::cout << "dt = " << redist_obj.get_time_step() << std::endl; // std::cout << "dt = " << redist_obj.get_time_step() << std::endl;
// Run the redistancing. In the <> brackets provide property-index where 1.) your initial Phi is stored and 2.) // 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. // where the resulting SDF should be written to.
...@@ -325,9 +328,9 @@ int main(int argc, char* argv[]) ...@@ -325,9 +328,9 @@ int main(int argc, char* argv[])
// Minimum is 1 property, to which the Phi_SDF can be written // Minimum is 1 property, to which the Phi_SDF can be written
// In this example we chose 3 properties. The 1st for the Phi_SDF, the 2nd for the gradient of phi and the 3rd for // In this example we chose 3 properties. The 1st for the Phi_SDF, the 2nd for the gradient of phi and the 3rd for
// the magnitude of the gradient // the magnitude of the gradient
typedef aggregate<double, double[grid_dim], double> props_nb; typedef aggregate<phi_type, phi_type[grid_dim], phi_type> props_nb;
typedef vector_dist<grid_dim, double, props_nb> vd_type; typedef vector_dist<grid_dim, phi_type, props_nb> vd_type;
Ghost<grid_dim, double> ghost_vd(0); Ghost<grid_dim, phi_type> ghost_vd(0);
vd_type vd_narrow_band(0, box, bc, ghost_vd); vd_type vd_narrow_band(0, box, bc, ghost_vd);
vd_narrow_band.setPropNames({"Phi_SDF", "Phi_grad", "Phi_magnOfGrad"}); vd_narrow_band.setPropNames({"Phi_SDF", "Phi_grad", "Phi_magnOfGrad"});
//! @cond [Initialize narrow band] @endcond //! @cond [Initialize narrow band] @endcond
...@@ -345,14 +348,15 @@ int main(int argc, char* argv[]) ...@@ -345,14 +348,15 @@ int main(int argc, char* argv[])
* belonged to the narrow band. * belonged to the narrow band.
* *
* Depending on the type of the variable which you define, the width can be either set in terms of number of * Depending on the type of the variable which you define, the width can be either set in terms of number of
* grid points (size_t), physical width (double) or extension of narrow band as physical width inside of object * grid points (size_t), physical width (phi_type) or extension of narrow band as physical width inside of object
* and outside the object (double, double). * and outside the object (phi_type, phi_type).
* *
* @snippet example/Numerics/Sussman_redistancing/example_sussman_disk/main.cpp Instantiate narrow band * @snippet example/Numerics/Sussman_redistancing/example_sussman_disk/main.cpp Instantiate narrow band
*/ */
//! @cond [Instantiate narrow band] @endcond //! @cond [Instantiate narrow band] @endcond
size_t thickness_of_narrowBand_in_grid_points = 6; size_t thickness_of_narrowBand_in_grid_points = 6;
NarrowBand<grid_in_type> narrowBand(g_dist, thickness_of_narrowBand_in_grid_points); // Instantiation of NarrowBand class NarrowBand<grid_in_type, phi_type> narrowBand(g_dist, thickness_of_narrowBand_in_grid_points); // Instantiation of
// NarrowBand class
//! @cond [Instantiate narrow band] @endcond //! @cond [Instantiate narrow band] @endcond
/** /**
......
// //
// Created by jstark on 2020-05-18. // Created by jstark on 2020-05-18. Updated on 2022-01-05.
// //
/** /**
* @file example_sussman_images_2D/main.cpp * @file example_sussman_images_2D/main.cpp
...@@ -77,8 +77,8 @@ int main(int argc, char* argv[]) ...@@ -77,8 +77,8 @@ int main(int argc, char* argv[])
// std::string image_name = "triangle"; // std::string image_name = "triangle";
// std::string image_name = "face"; // std::string image_name = "face";
std::string image_name = "dolphin"; std::string image_name = "dolphin";
typedef double phi_type;
// initialize library // initialize library
openfpm_init(&argc, &argv); openfpm_init(&argc, &argv);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -86,7 +86,7 @@ int main(int argc, char* argv[]) ...@@ -86,7 +86,7 @@ int main(int argc, char* argv[])
std::string cwd = get_cwd(); std::string cwd = get_cwd();
const std::string path_output = cwd + "/output_" + image_name; const std::string path_output = cwd + "/output_" + image_name;
// const std::string path_output = cwd + "/output_face"; // const std::string path_output = cwd + "/output_face";
create_directory_if_not_exist(path_output); create_directory_if_not_exist(path_output);
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
...@@ -95,7 +95,7 @@ int main(int argc, char* argv[]) ...@@ -95,7 +95,7 @@ int main(int argc, char* argv[])
const std::string path_input ="input/"; const std::string path_input ="input/";
const std::string path_to_image = path_input + image_name + ".bin"; const std::string path_to_image = path_input + image_name + ".bin";
const std::string path_to_size = path_input + "size_" + image_name + ".csv"; const std::string path_to_size = path_input + "size_" + image_name + ".csv";
/* /*
* in case of 2D (single image): * in case of 2D (single image):
*/ */
...@@ -127,7 +127,7 @@ int main(int argc, char* argv[]) ...@@ -127,7 +127,7 @@ int main(int argc, char* argv[])
* *
*/ */
//! @cond [Refinement] @endcond //! @cond [Refinement] @endcond
const double refinement [] = {0.5, 0.5}; // (2D) factor by which grid should be finer / coarser as const phi_type refinement [] = {0.5, 0.5}; // (2D) factor by which grid should be finer / coarser as
// underlying image in each dimension (e.g. to get isotropic grid from anisotropic image resolution) // underlying image in each dimension (e.g. to get isotropic grid from anisotropic image resolution)
//! @cond [Refinement] @endcond //! @cond [Refinement] @endcond
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -161,7 +161,7 @@ int main(int argc, char* argv[]) ...@@ -161,7 +161,7 @@ int main(int argc, char* argv[])
// Array with grid dimensions after refinement. This size-array will be used for the grid creation. // Array with grid dimensions after refinement. This size-array will be used for the grid creation.
const size_t sz[grid_dim] = {(size_t)std::round(stack_size[x] * refinement[x]), (size_t)std::round(stack_size[y] * const size_t sz[grid_dim] = {(size_t)std::round(stack_size[x] * refinement[x]), (size_t)std::round(stack_size[y] *
refinement[y])}; // 2D refinement[y])}; // 2D
//! @cond [Size] @endcond //! @cond [Size] @endcond
// Here we create a 2D grid that stores 2 properties: // Here we create a 2D grid that stores 2 properties:
// Prop1: store the initial Phi; // Prop1: store the initial Phi;
...@@ -180,24 +180,24 @@ int main(int argc, char* argv[]) ...@@ -180,24 +180,24 @@ int main(int argc, char* argv[])
* *
*/ */
//! @cond [Redistancing] @endcond //! @cond [Redistancing] @endcond
Box<grid_dim, double> box({0.0, 0.0}, {5.0, 5.0}); // 2D Box<grid_dim, phi_type> box({0.0, 0.0}, {5.0, 5.0}); // 2D
Ghost<grid_dim, long int> ghost(0); Ghost<grid_dim, long int> ghost(0);
typedef aggregate<double, double> props; typedef aggregate<phi_type, phi_type> props;
typedef grid_dist_id<grid_dim, double, props > grid_in_type; typedef grid_dist_id<grid_dim, phi_type, props > grid_in_type;
grid_in_type g_dist(sz, box, ghost); grid_in_type g_dist(sz, box, ghost);
g_dist.setPropNames({"Phi_0", "Phi_SDF"}); g_dist.setPropNames({"Phi_0", "Phi_SDF"});
// Now we can initialize the grid with the pixel values from the image stack // Now we can initialize the grid with the pixel values from the image stack
load_pixel_onto_grid<Phi_0_grid>(g_dist, path_to_image, stack_size); load_pixel_onto_grid<Phi_0_grid>(g_dist, path_to_image, stack_size);
g_dist.write(path_output + "/grid_from_images_initial", FORMAT_BINARY); // Save the initial grid as vtk file g_dist.write(path_output + "/grid_from_images_initial", FORMAT_BINARY); // Save the initial grid as vtk file
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Now we want to convert the initial Phi into a signed distance function (SDF) with magnitude of gradient = 1 // Now we want to convert the initial Phi into a signed distance function (SDF) with magnitude of gradient = 1
// For the initial re-distancing we use the Sussman method // For the initial re-distancing we use the Sussman method
// 1.) Set some redistancing options (for details see example sussman disk or sphere) // 1.) Set some redistancing options (for details see example sussman disk or sphere)
Redist_options redist_options; Redist_options<phi_type> redist_options;
redist_options.min_iter = 1e3; redist_options.min_iter = 1e3;
redist_options.max_iter = 1e4; redist_options.max_iter = 1e4;
...@@ -212,7 +212,8 @@ int main(int argc, char* argv[]) ...@@ -212,7 +212,8 @@ int main(int argc, char* argv[])
redist_options.print_steadyState_iter = true; redist_options.print_steadyState_iter = true;
redist_options.save_temp_grid = true; redist_options.save_temp_grid = true;
RedistancingSussman<grid_in_type> redist_obj(g_dist, redist_options); // Instantiation of Sussman-redistancing class RedistancingSussman<grid_in_type, phi_type> redist_obj(g_dist, redist_options); // Instantiation of Sussman-redistancing
// class
// std::cout << "dt = " << redist_obj.get_time_step() << std::endl; // std::cout << "dt = " << redist_obj.get_time_step() << std::endl;
// 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. // 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.
redist_obj.run_redistancing<Phi_0_grid, Phi_SDF_grid>(); redist_obj.run_redistancing<Phi_0_grid, Phi_SDF_grid>();
...@@ -226,13 +227,14 @@ int main(int argc, char* argv[]) ...@@ -226,13 +227,14 @@ int main(int argc, char* argv[])
// Minimum is 1 property, to which the Phi_SDF can be written // Minimum is 1 property, to which the Phi_SDF can be written
// In this example we chose 3 properties. The 1st for the Phi_SDF, the 2nd for the gradient of phi and the 3rd for // In this example we chose 3 properties. The 1st for the Phi_SDF, the 2nd for the gradient of phi and the 3rd for
// the magnitude of the gradient // the magnitude of the gradient
typedef aggregate<double, Point<grid_dim, double>, double> props_nb; typedef aggregate<phi_type, Point<grid_dim, phi_type>, phi_type> props_nb;
typedef vector_dist<grid_dim, double, props_nb> vd_type; typedef vector_dist<grid_dim, phi_type, props_nb> vd_type;
Ghost<grid_dim, double> ghost_vd(0); Ghost<grid_dim, phi_type> ghost_vd(0);
vd_type vd_narrow_band(0, box, bc, ghost_vd); vd_type vd_narrow_band(0, box, bc, ghost_vd);
vd_narrow_band.setPropNames({"Phi_SDF", "Phi_grad", "Phi_magnOfGrad"}); vd_narrow_band.setPropNames({"Phi_SDF", "Phi_grad", "Phi_magnOfGrad"});
NarrowBand<grid_in_type> narrowBand(g_dist, redist_options.width_NB_in_grid_points); // Instantiation of NarrowBand class NarrowBand<grid_in_type, phi_type> narrowBand(g_dist, redist_options.width_NB_in_grid_points); // Instantiation of
// NarrowBand class
// Get the narrow band. You can decide, if you only want the Phi_SDF saved to your particles or // Get the narrow band. You can decide, if you only want the Phi_SDF saved to your particles or
// if you also want the gradients or gradients and magnitude of gradient. // if you also want the gradients or gradients and magnitude of gradient.
...@@ -244,7 +246,7 @@ int main(int argc, char* argv[]) ...@@ -244,7 +246,7 @@ int main(int argc, char* argv[])
narrowBand.get_narrow_band<Phi_SDF_grid, Phi_SDF_vd, Phi_grad_vd, Phi_magnOfGrad_vd>(g_dist, vd_narrow_band); narrowBand.get_narrow_band<Phi_SDF_grid, Phi_SDF_vd, Phi_grad_vd, Phi_magnOfGrad_vd>(g_dist, vd_narrow_band);
vd_narrow_band.write(path_output + "/vd_narrow_band_images", FORMAT_BINARY); // Save particles as vtk file vd_narrow_band.write(path_output + "/vd_narrow_band_images", FORMAT_BINARY); // Save particles as vtk file
openfpm_finalize(); // Finalize openFPM library openfpm_finalize(); // Finalize openFPM library
return 0; return 0;
} }
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
//! @cond [Initialization] @endcond //! @cond [Initialization] @endcond
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
typedef double phi_type;
// initialize library // initialize library
openfpm_init(&argc, &argv); openfpm_init(&argc, &argv);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -120,8 +121,8 @@ int main(int argc, char* argv[]) ...@@ -120,8 +121,8 @@ int main(int argc, char* argv[])
* *
*/ */
//! @cond [Refinement] @endcond //! @cond [Refinement] @endcond
const double refinement [] = {1.0, 1.0, 1.0}; // without refinement const phi_type refinement [] = {1.0, 1.0, 1.0}; // without refinement
// const double refinement [] = {0.8, 1.5, 2.0}; // factors by which grid should be finer as underlying image stack in each dimension (e.g. to get isotropic grid from anisotropic stack resolution) // const phi_type refinement [] = {0.8, 1.5, 2.0}; // factors by which grid should be finer as underlying image stack in each dimension (e.g. to get isotropic grid from anisotropic stack resolution)
//! @cond [Refinement] @endcond //! @cond [Refinement] @endcond
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// read the stack size (number of pixel values per dimension) from a binary file // read the stack size (number of pixel values per dimension) from a binary file
...@@ -173,11 +174,11 @@ int main(int argc, char* argv[]) ...@@ -173,11 +174,11 @@ int main(int argc, char* argv[])
* *
*/ */
//! @cond [Redistancing] @endcond //! @cond [Redistancing] @endcond
Box<grid_dim, double> box({0.0, 0.0, 0.0}, {5.0, 5.0, 5.0}); // 3D Box<grid_dim, phi_type> box({0.0, 0.0, 0.0}, {5.0, 5.0, 5.0}); // 3D
Ghost<grid_dim, long int> ghost(0); Ghost<grid_dim, long int> ghost(0);
typedef aggregate<double, double> props; typedef aggregate<phi_type, phi_type> props;
typedef grid_dist_id<grid_dim, double, props > grid_in_type; typedef grid_dist_id<grid_dim, phi_type, props > grid_in_type;
grid_in_type g_dist(sz, box, ghost); grid_in_type g_dist(sz, box, ghost);
g_dist.setPropNames({"Phi_0", "Phi_SDF"}); g_dist.setPropNames({"Phi_0", "Phi_SDF"});
...@@ -190,7 +191,7 @@ int main(int argc, char* argv[]) ...@@ -190,7 +191,7 @@ int main(int argc, char* argv[])
// Now we want to convert the initial Phi into a signed distance function (SDF) with magnitude of gradient = 1 // Now we want to convert the initial Phi into a signed distance function (SDF) with magnitude of gradient = 1
// For the initial re-distancing we use the Sussman method // For the initial re-distancing we use the Sussman method
// 1.) Set some redistancing options (for details see example sussman disk or sphere) // 1.) Set some redistancing options (for details see example sussman disk or sphere)
Redist_options redist_options; Redist_options<phi_type> redist_options;
redist_options.min_iter = 1e3; redist_options.min_iter = 1e3;
redist_options.max_iter = 1e4; redist_options.max_iter = 1e4;
...@@ -204,7 +205,8 @@ int main(int argc, char* argv[]) ...@@ -204,7 +205,8 @@ int main(int argc, char* argv[])
redist_options.print_current_iterChangeResidual = true; redist_options.print_current_iterChangeResidual = true;
redist_options.print_steadyState_iter = true; redist_options.print_steadyState_iter = true;
redist_options.save_temp_grid = true; redist_options.save_temp_grid = true;
RedistancingSussman<grid_in_type> redist_obj(g_dist, redist_options); // Instantiation of Sussman-redistancing class RedistancingSussman<grid_in_type, phi_type> redist_obj(g_dist, redist_options); // Instantiation of Sussman-redistancing
// class
// std::cout << "dt = " << redist_obj.get_time_step() << std::endl; // std::cout << "dt = " << redist_obj.get_time_step() << std::endl;
// 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. // 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.
redist_obj.run_redistancing<Phi_0_grid, Phi_SDF_grid>(); redist_obj.run_redistancing<Phi_0_grid, Phi_SDF_grid>();
...@@ -218,13 +220,14 @@ int main(int argc, char* argv[]) ...@@ -218,13 +220,14 @@ int main(int argc, char* argv[])
// Minimum is 1 property, to which the Phi_SDF can be written // Minimum is 1 property, to which the Phi_SDF can be written
// In this example we chose 3 properties. The 1st for the Phi_SDF, the 2nd for the gradient of phi and the 3rd for // In this example we chose 3 properties. The 1st for the Phi_SDF, the 2nd for the gradient of phi and the 3rd for
// the magnitude of the gradient // the magnitude of the gradient
typedef aggregate<double, Point<grid_dim, double>, double> props_nb; typedef aggregate<phi_type, Point<grid_dim, phi_type>, phi_type> props_nb;
typedef vector_dist<grid_dim, double, props_nb> vd_type; typedef vector_dist<grid_dim, phi_type, props_nb> vd_type;
Ghost<grid_dim, double> ghost_vd(0); Ghost<grid_dim, phi_type> ghost_vd(0);
vd_type vd_narrow_band(0, box, bc, ghost_vd); vd_type vd_narrow_band(0, box, bc, ghost_vd);
vd_narrow_band.setPropNames({"Phi_SDF", "Phi_grad", "Phi_magnOfGrad"}); vd_narrow_band.setPropNames({"Phi_SDF", "Phi_grad", "Phi_magnOfGrad"});
NarrowBand<grid_in_type> narrowBand(g_dist, redist_options.width_NB_in_grid_points); // Instantiation of NarrowBand class NarrowBand<grid_in_type, phi_type> narrowBand(g_dist, redist_options.width_NB_in_grid_points); // Instantiation of
// NarrowBand class
// Get the narrow band. You can decide, if you only want the Phi_SDF saved to your particles or // Get the narrow band. You can decide, if you only want the Phi_SDF saved to your particles or
// if you also want the gradients or gradients and magnitude of gradient. // if you also want the gradients or gradients and magnitude of gradient.
......
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
//! @cond [Initialization and output folder] @endcond //! @cond [Initialization and output folder] @endcond
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
typedef double phi_type;
// initialize library // initialize library
openfpm_init(&argc, &argv); openfpm_init(&argc, &argv);
// Set current working directory, define output paths and create folders where output will be saved // Set current working directory, define output paths and create folders where output will be saved
...@@ -129,7 +130,7 @@ int main(int argc, char* argv[]) ...@@ -129,7 +130,7 @@ int main(int argc, char* argv[])
* * Define the grid size in terms of number of grid points per dimension * * Define the grid size in terms of number of grid points per dimension
* * Create a Box that defines our domain * * Create a Box that defines our domain
* * Create a Ghost object that will define the extension of the ghost part * * Create a Ghost object that will define the extension of the ghost part
* * Create a 3D grid with two properties of type double, one for the pre-redistancing Phi_initial and one, where * * Create a 3D grid with two properties of type phi_type, one for the pre-redistancing Phi_initial and one, where
* the post-redistancing Phi_SDF should be written to. * the post-redistancing Phi_SDF should be written to.
* * Set some property names (optionally. These names show up when opening the grid vtk in Paraview.) * * Set some property names (optionally. These names show up when opening the grid vtk in Paraview.)
* *
...@@ -141,10 +142,10 @@ int main(int argc, char* argv[]) ...@@ -141,10 +142,10 @@ int main(int argc, char* argv[])
// Prop1: store the initial Phi; // Prop1: store the initial Phi;
// Prop2: here the re-initialized Phi (signed distance function) will be written to in the re-distancing step // Prop2: here the re-initialized Phi (signed distance function) will be written to in the re-distancing step
const size_t sz[grid_dim] = {128, 128, 128}; const size_t sz[grid_dim] = {128, 128, 128};
Box<grid_dim, double> box({0.0, 0.0, 0.0}, {10.0, 10.0, 10.0}); Box<grid_dim, phi_type> box({0.0, 0.0, 0.0}, {10.0, 10.0, 10.0});
Ghost<grid_dim, long int> ghost(0); Ghost<grid_dim, long int> ghost(0);
typedef aggregate<double, double> props; typedef aggregate<phi_type, phi_type> props;
typedef grid_dist_id<grid_dim, double, props > grid_in_type; typedef grid_dist_id<grid_dim, phi_type, props > grid_in_type;
grid_in_type g_dist(sz, box, ghost); grid_in_type g_dist(sz, box, ghost);
g_dist.setPropNames({"Phi_0", "Phi_SDF"}); g_dist.setPropNames({"Phi_0", "Phi_SDF"});
//! @cond [Grid creation] @endcond //! @cond [Grid creation] @endcond
...@@ -170,7 +171,7 @@ int main(int argc, char* argv[]) ...@@ -170,7 +171,7 @@ int main(int argc, char* argv[])
*/ */
//! @cond [Get sphere] @endcond //! @cond [Get sphere] @endcond
// Now we initialize the grid with a filled sphere. Outside the sphere, the value of Phi_0 will be -1, inside +1. // Now we initialize the grid with a filled sphere. Outside the sphere, the value of Phi_0 will be -1, inside +1.
double radius = 1.0; // Radius of the sphere phi_type radius = 1.0; // Radius of the sphere
init_grid_with_sphere<Phi_0_grid>(g_dist, radius, 5, 5, 5); // Initialize sphere onto grid, centered at (5, 5, 5) init_grid_with_sphere<Phi_0_grid>(g_dist, radius, 5, 5, 5); // Initialize sphere onto grid, centered at (5, 5, 5)
g_dist.write(path_output + "/grid_initial_sphere_preRedistancing_radius" + std::to_string((int)radius) , FORMAT_BINARY); // Save the sphere as vtk file g_dist.write(path_output + "/grid_initial_sphere_preRedistancing_radius" + std::to_string((int)radius) , FORMAT_BINARY); // Save the sphere as vtk file
...@@ -217,7 +218,7 @@ int main(int argc, char* argv[]) ...@@ -217,7 +218,7 @@ int main(int argc, char* argv[])
//! @cond [Redistancing options] @endcond //! @cond [Redistancing options] @endcond
// Now we want to convert the initial Phi into a signed distance function (SDF) with magnitude of gradient = 1. // Now we want to convert the initial Phi into a signed distance function (SDF) with magnitude of gradient = 1.
// For the initial re-distancing we use the Sussman method. First of all, we can set some redistancing options. // For the initial re-distancing we use the Sussman method. First of all, we can set some redistancing options.
Redist_options redist_options; Redist_options<phi_type> redist_options;
redist_options.min_iter = 1e3; redist_options.min_iter = 1e3;
redist_options.max_iter = 1e4; redist_options.max_iter = 1e4;
...@@ -253,7 +254,8 @@ int main(int argc, char* argv[]) ...@@ -253,7 +254,8 @@ int main(int argc, char* argv[])
* @snippet example/Numerics/Sussman_redistancing/example_sussman_sphere/main.cpp Run redistancing * @snippet example/Numerics/Sussman_redistancing/example_sussman_sphere/main.cpp Run redistancing
*/ */
//! @cond [Run redistancing] @endcond //! @cond [Run redistancing] @endcond
RedistancingSussman<grid_in_type> redist_obj(g_dist, redist_options); // Instantiation of Sussman-redistancing class RedistancingSussman<grid_in_type, phi_type> redist_obj(g_dist, redist_options); // Instantiation of
// Sussman-redistancing class
// std::cout << "dt = " << redist_obj.get_time_step() << std::endl; // std::cout << "dt = " << redist_obj.get_time_step() << std::endl;
// Run the redistancing. in the <> brackets provide property-index where 1.) your initial Phi is stored and 2.) // 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. // where the resulting SDF should be written to.
...@@ -285,9 +287,9 @@ int main(int argc, char* argv[]) ...@@ -285,9 +287,9 @@ int main(int argc, char* argv[])
// Minimum is 1 property, to which the Phi_SDF can be written // Minimum is 1 property, to which the Phi_SDF can be written
// In this example we chose 3 properties. The 1st for the Phi_SDF, the 2nd for the gradient of phi and the 3rd for // In this example we chose 3 properties. The 1st for the Phi_SDF, the 2nd for the gradient of phi and the 3rd for
// the magnitude of the gradient // the magnitude of the gradient
typedef aggregate<double, Point<grid_dim, double>, double> props_nb; typedef aggregate<phi_type, Point<grid_dim, phi_type>, phi_type> props_nb;
typedef vector_dist<grid_dim, double, props_nb> vd_type; typedef vector_dist<grid_dim, phi_type, props_nb> vd_type;
Ghost<grid_dim, double> ghost_vd(0); Ghost<grid_dim, phi_type> ghost_vd(0);
vd_type vd_narrow_band(0, box, bc, ghost_vd); vd_type vd_narrow_band(0, box, bc, ghost_vd);
vd_narrow_band.setPropNames({"Phi_SDF", "Phi_grad", "Phi_magnOfGrad"}); vd_narrow_band.setPropNames({"Phi_SDF", "Phi_grad", "Phi_magnOfGrad"});
//! @cond [Initialize narrow band] @endcond //! @cond [Initialize narrow band] @endcond
...@@ -305,14 +307,15 @@ int main(int argc, char* argv[]) ...@@ -305,14 +307,15 @@ int main(int argc, char* argv[])
* belonged to the narrow band. * belonged to the narrow band.
* *
* Depending on the type of the variable which you define, the width can be either set in terms of number of * Depending on the type of the variable which you define, the width can be either set in terms of number of
* grid points (size_t), physical width (double) or extension of narrow band as physical width inside of object * grid points (size_t), physical width (phi_type) or extension of narrow band as physical width inside of object
* and outside the object (double, double). * and outside the object (phi_type, phi_type).
* *
* @snippet example/Numerics/Sussman_redistancing/example_sussman_sphere/main.cpp Instantiate narrow band * @snippet example/Numerics/Sussman_redistancing/example_sussman_sphere/main.cpp Instantiate narrow band
*/ */
//! @cond [Instantiate narrow band] @endcond //! @cond [Instantiate narrow band] @endcond
size_t thickness_of_narrowBand_in_grid_points = 6; size_t thickness_of_narrowBand_in_grid_points = 6;
NarrowBand<grid_in_type> narrowBand(g_dist, redist_options.width_NB_in_grid_points); // Instantiation of NarrowBand class NarrowBand<grid_in_type, phi_type> narrowBand(g_dist, redist_options.width_NB_in_grid_points); // Instantiation of
// NarrowBand class
//! @cond [Instantiate narrow band] @endcond //! @cond [Instantiate narrow band] @endcond
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment