OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1//
2// Created by jstark on 2020-05-18. Updated on 2022-01-05.
3//
104
105
106// Include Redistancing header files
107#include "util/PathsAndFiles.hpp"
110#include "Draw/DrawDisk.hpp"
112
126int main(int argc, char* argv[])
127{
128 typedef double phi_type;
129 // initialize library
130 openfpm_init(&argc, &argv);
132 // Set current working directory, define output paths and create folders where output will be saved
133 std::string cwd = get_cwd();
134 const std::string path_output = cwd + "/output_disk";
135
138
154 // Grid dimension
155 const unsigned int grid_dim = 2;
156 // Some indices for the grid / grid properties
157 const size_t x = 0;
158 const size_t y = 1;
159
160 const size_t Phi_0_grid = 0;
161 const size_t Phi_SDF_grid = 1;
164
181 // Here we create a 2D grid that stores 2 properties:
182 // Prop1: store the initial Phi;
183 // Prop2: here the re-initialized Phi (signed distance function) will be written to in the re-distancing step
184 size_t sz[grid_dim] = {128, 128}; // Grid size in terms of number of grid points per dimension
185 Box<grid_dim, phi_type> box({0.0, 0.0}, {5.0, 5.0}); // 2D
187 typedef aggregate<phi_type, phi_type> props;
188 typedef grid_dist_id<grid_dim, phi_type, props > grid_in_type;
189 grid_in_type g_dist(sz, box, ghost);
190 g_dist.setPropNames({"Phi_0", "Phi_SDF"});
192
193
213 // Now we initialize the grid with a disk. Outside the disk, the value of Phi_0 will be -1, inside +1.
214 phi_type radius = 1.0; // Radius of the disk
215 init_grid_with_disk<Phi_0_grid>(g_dist, radius, 2.5, 2.5); // Initialize disk onto grid, centered at (2.5, 2.5)
216
217 g_dist.write(path_output + "/grid_disk_preRedistancing_radius" + std::to_string((int)radius) , FORMAT_BINARY); // Save the disk as vtk file
219
220
259 // Now we want to convert the initial Phi into a signed distance function (SDF) with magnitude of gradient = 1.
260 // For the initial re-distancing we use the Sussman method. First of all, we can set some redistancing options.
261 Redist_options<phi_type> redist_options;
262 redist_options.min_iter = 1e3;
263 redist_options.max_iter = 1e4;
264
265 redist_options.convTolChange.value = 1e-7;
266 redist_options.convTolChange.check = true;
267 redist_options.convTolResidual.value = 1e-6; // is ignored if convTolResidual.check = false;
268 redist_options.convTolResidual.check = false;
269
270 redist_options.interval_check_convergence = 1e3;
271 redist_options.width_NB_in_grid_points = 10;
272 redist_options.print_current_iterChangeResidual = true;
273 redist_options.print_steadyState_iter = true;
274 redist_options.save_temp_grid = true;
276
298 RedistancingSussman<grid_in_type, phi_type> redist_obj(g_dist, redist_options); // Instantiation of
299 // Sussman-redistancing class
300 // std::cout << "dt = " << redist_obj.get_time_step() << std::endl;
301 // Run the redistancing. In the <> brackets provide property-index where 1.) your initial Phi is stored and 2.)
302 // where the resulting SDF should be written to.
303 redist_obj.run_redistancing<Phi_0_grid, Phi_SDF_grid>();
304
305 g_dist.write(path_output + "/grid_disk_postRedistancing", FORMAT_BINARY); // Save the result as vtk file
306 g_dist.save(path_output + "/grid_disk_postRedistancing" + ".bin"); // Save the result as hdf5 file that can be
307 // reloaded onto an openFPM grid
310
325 // Get narrow band: Place particles on interface (narrow band width e.g. 2 grid points on each side of the interface)
326 size_t bc[grid_dim] = {PERIODIC, PERIODIC};
327 // Create an empty vector to which narrow-band particles will be added. You can choose, how many properties you want.
328 // Minimum is 1 property, to which the Phi_SDF can be written
329 // In this example we chose 3 properties. The 1st for the Phi_SDF, the 2nd for the gradient of phi and the 3rd for
330 // the magnitude of the gradient
333 Ghost<grid_dim, phi_type> ghost_vd(0);
334 vd_type vd_narrow_band(0, box, bc, ghost_vd);
335 vd_narrow_band.setPropNames({"Phi_SDF", "Phi_grad", "Phi_magnOfGrad"});
337
357 size_t thickness_of_narrowBand_in_grid_points = 6;
358 NarrowBand<grid_in_type, phi_type> narrowBand(g_dist, thickness_of_narrowBand_in_grid_points); // Instantiation of
359 // NarrowBand class
361
375 // Some indices
376 const size_t Phi_SDF_vd = 0;
377 const size_t Phi_grad_vd = 1;
378 const size_t Phi_magnOfGrad_vd = 2;
380
403 // Get the narrow band. You can decide, if you only want the Phi_SDF saved to your particles or
404 // if you also want the gradients or gradients and magnitude of gradient.
405 // The function will know depending on how many property-indices you provide in the <> brackets.
406 // First property-index must always be the index of the SDF on the grid!
407 // E.g.: The following line would only write only the Phi_SDF from the grid to your narrow-band particles
408 // narrowBand.get_narrow_band<Phi_SDF_grid, Phi_SDF_vd>(g_dist, vd_narrow_band);
409 // Whereas this will give you the gradients and magnOfGrad of Phi as well:
411 narrowBand.get_narrow_band<Phi_SDF_grid, Phi_SDF_vd, Phi_grad_vd, Phi_magnOfGrad_vd>(g_dist, vd_narrow_band);
412
413 vd_narrow_band.write(path_output + "/vd_narrow_band_disk", FORMAT_BINARY); // Save particles as vtk file
414 vd_narrow_band.save(path_output + "/vd_narrow_band_disk.bin"); // Save particles as hdf5 file -> can be reloaded as particles
416
427 openfpm_finalize(); // Finalize openFPM library
428 return 0;
429}
431
Class for getting the narrow band around the interface.
Header file containing functions for creating files and folders.
static void create_directory_if_not_exist(std::string path, bool silent=0)
Creates a directory if not already existent.
static std::string get_cwd()
Gets the current working directory and returns path as string.
Class for reinitializing a level-set function into a signed distance function using Sussman redistanc...
This class represent an N-dimensional box.
Definition Box.hpp:61
Class for getting the narrow band around the interface.
Class for reinitializing a level-set function into a signed distance function using Sussman redistanc...
This is a distributed grid.
Distributed vector.
Structure to bundle options for redistancing.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...