35#include "CSVReader/CSVReader.hpp"
41#include "RemoveLines.hpp"
44#include "level_set/redistancing_Sussman/AnalyticalSDF.hpp"
45#include "FiniteDifference/FD_simple.hpp"
46#include "Decomposition/Distribution/BoxDistribution.hpp"
50#include "include/DiffusionSpace_sparseGrid.hpp"
51#include "include/HelpFunctions_diffusion.hpp"
59const std::string path_to_redistancing_result =
60"/INPUT_PATH/benchmarks/CaCO3/sussman_redistancing/build/output_sussman_maxIter6e3_CaCO3_fluidPhase_531x531x531/";
63const std::string redistancing_filename =
"grid_CaCO3_post_redistancing.hdf5";
64const std::string path_to_size = path_to_redistancing_result;
67const std::string output_name =
"output_inhomogDiffusion_CaCO3_fluid_phase";
71const size_t PHI_FULL = 0;
78const size_t PHI_PHASE = 0;
79const size_t CONC_N = 1;
80const size_t CONC_NPLUS1 = 2;
81const size_t DIFFUSION_COEFFICIENT = 3;
88 "DIFFUSION_COEFFICIENT"};
91constexpr size_t x = 0, y = 1, z = 2;
112int main(
int argc,
char* argv[])
115 openfpm_init(&argc, &argv);
116 auto & v_cl = create_vcluster();
119 timer t_iterative_diffusion_total;
120 timer t_iteration_wct;
129 const std::string path_output = cwd +
"/" + output_name +
"/";
132 if(v_cl.rank()==0) std::cout <<
"Redistancing result will be loaded from " << path_to_redistancing_result << redistancing_filename << std::endl;
134 if(v_cl.rank()==0) std::cout <<
"Outputs will be saved to " << path_output << std::endl;
156 read_csv_to_vector(path_to_size +
"/N.csv", v_sz, m, n);
157 read_csv_to_vector(path_to_size +
"/L.csv", v_L, m, n);
159 const float Lx_low = 0.0;
160 const float Lx_up = v_L.get(x);
161 const float Ly_low = 0.0;
162 const float Ly_up = v_L.get(y);
163 const float Lz_low = 0.0;
164 const float Lz_up = v_L.get(z);
167 size_t sz[dims] = {v_sz.get(x), v_sz.get(y), v_sz.get(z)};
174 grid_in_type g_dist(sz, box, ghost);
176 g_dist.load(path_to_redistancing_result +
"/" + redistancing_filename);
196 std::cout <<
"Rank " << v_cl.rank() <<
" starts creating sparse grid." << std::endl;
197 typedef sgrid_dist_id_gpu<dims, float, props_sparse, CudaMemory, Dec> sparse_grid_type;
198 sparse_grid_type g_sparse(sz, box, ghost);
199 g_sparse.setPropNames(prop_names_sparse);
202 const float d_low = 0.0, d_up = Lx_up;
208 get_diffusion_domain_sparse_grid<PHI_FULL, PHI_PHASE>(g_dist, g_sparse, d_low, d_up);
209 std::cout <<
"Rank " << v_cl.rank() <<
" finished creating sparse grid." << std::endl;
230 const float min_porosity = 0.0;
231 const float max_porosity = 1.0;
233 float D_molecular = 1.0;
234 float D_min = D_molecular * min_porosity;
235 float D_max = D_molecular * max_porosity;
237 float min_sdf_calcite = get_min_val<PHI_PHASE>(g_sparse);
239 float x_stretch = 4.0 * g_sparse.spacing(x);
240 float x_shift = min_sdf_calcite * x_stretch;
242 float y_max = D_max - D_min;
244 const float c0 = 10.0;
246 auto dom = g_sparse.getDomainIterator();
249 auto key = dom.get();
252 if(coords.
get(x) <= 0.05 * Lx_up)
254 g_sparse.template insertFlush<CONC_N>(key) = c0;
256 else g_sparse.template insertFlush<CONC_N>(key) = 0.0;
259 g_sparse.template insertFlush<DIFFUSION_COEFFICIENT>(key) =
260 get_smooth_sigmoidal(
261 g_sparse.template getProp<PHI_PHASE>(key) - min_sdf_calcite,
287 typedef typename GetCpBlockType<
decltype(g_sparse),0,1>::type CpBlockType;
289 const float dx = g_sparse.spacing(x), dy = g_sparse.spacing(y), dz = g_sparse.spacing(z);
291 const float dt = diffusion_time_step(g_sparse, D_max);
293 std::cout <<
"dx = " << dx <<
"dy = " << dy <<
"dz = " << dz << std::endl;
294 std::cout <<
"dt = " << dt << std::endl;
297 auto func_inhomogDiffusion = [dx, dy, dz, dt, d_low] __device__ (
314 float u_c = u(i, j, k);
315 float u_px = u(i+1, j, k);
316 float u_mx = u(i-1, j, k);
317 float u_py = u(i, j+1, k);
318 float u_my = u(i, j-1, k);
319 float u_pz = u(i, j, k+1);
320 float u_mz = u(i, j, k-1);
323 float phi_c = phi(i, j, k);
324 float phi_px = phi(i+1, j, k);
325 float phi_mx = phi(i-1, j, k);
326 float phi_py = phi(i, j+1, k);
327 float phi_my = phi(i, j-1, k);
328 float phi_pz = phi(i, j, k+1);
329 float phi_mz = phi(i, j, k-1);
332 float D_c =
D(i, j, k);
333 float D_px =
D(i+1, j, k);
334 float D_mx =
D(i-1, j, k);
335 float D_py =
D(i, j+1, k);
336 float D_my =
D(i, j-1, k);
337 float D_pz =
D(i, j, k+1);
338 float D_mz =
D(i, j, k-1);
341 if (phi_px <= d_low + std::numeric_limits<float>::epsilon()) {u_px = u_c; D_px = D_c;}
342 if (phi_mx <= d_low + std::numeric_limits<float>::epsilon()) {u_mx = u_c; D_mx = D_c;}
343 if (phi_py <= d_low + std::numeric_limits<float>::epsilon()) {u_py = u_c; D_py = D_c;}
344 if (phi_my <= d_low + std::numeric_limits<float>::epsilon()) {u_my = u_c; D_my = D_c;}
345 if (phi_pz <= d_low + std::numeric_limits<float>::epsilon()) {u_pz = u_c; D_pz = D_c;}
346 if (phi_mz <= d_low + std::numeric_limits<float>::epsilon()) {u_mz = u_c; D_mz = D_c;}
349 float D_half_px = (D_c + D_px)/2.0;
350 float D_half_mx = (D_c + D_mx)/2.0;
351 float D_half_py = (D_c + D_py)/2.0;
352 float D_half_my = (D_c + D_my)/2.0;
353 float D_half_pz = (D_c + D_pz)/2.0;
354 float D_half_mz = (D_c + D_mz)/2.0;
358 (1/(dx*dx) * (D_half_px * (u_px - u_c) - D_half_mx * (u_c - u_mx)) +
359 1/(dy*dy) * (D_half_py * (u_py - u_c) - D_half_my * (u_c - u_my)) +
360 1/(dz*dz) * (D_half_pz * (u_pz - u_c) - D_half_mz * (u_c - u_mz)));
381 std::string path_time_filewct = path_output +
"/time_wct_incl_ghostCommunication" + std::to_string(v_cl.rank()) +
".txt";
382 std::ofstream out_wct_file(path_time_filewct, std::ios_base::app);
385 std::string path_time_filegpu = path_output +
"/time_GPU" + std::to_string(v_cl.rank()) +
".txt";
386 std::ofstream out_GPUtime_file(path_time_filegpu, std::ios_base::app);
389 const size_t iterations = 103;
390 const size_t number_write_outs = 10;
391 const size_t interval_write = iterations / number_write_outs;
396 g_sparse.template hostToDevice<CONC_N, CONC_NPLUS1, DIFFUSION_COEFFICIENT, PHI_PHASE>();
397 g_sparse.template ghost_get<DIFFUSION_COEFFICIENT, PHI_PHASE>(RUN_ON_DEVICE | SKIP_LABELLING);
398 t_iterative_diffusion_total.
start();
399 while(iter <= iterations)
403 t_iteration_wct.
start();
404 g_sparse.template ghost_get<CONC_N>(RUN_ON_DEVICE | SKIP_LABELLING);
406 g_sparse.template conv3_b<
408 DIFFUSION_COEFFICIENT,
411 DIFFUSION_COEFFICIENT,
414 {(
long int) sz[x]-1, (
long int) sz[y]-1, (
long int) sz[z]-1},
415 func_inhomogDiffusion);
417 t_iteration_wct.
stop();
420 out_wct_file << t_iteration_wct.
getwct() <<
",";
421 out_GPUtime_file << t_GPU.getwctGPU() <<
",";
425 t_iteration_wct.
start();
426 g_sparse.template ghost_get<CONC_NPLUS1>(RUN_ON_DEVICE | SKIP_LABELLING);
428 g_sparse.template conv3_b<
430 DIFFUSION_COEFFICIENT,
433 DIFFUSION_COEFFICIENT,
436 {(
long int) sz[x]-1, (
long int) sz[y]-1, (
long int) sz[z]-1},
437 func_inhomogDiffusion);
439 t_iteration_wct.
stop();
441 out_wct_file << t_iteration_wct.
getwct() <<
",";
442 out_GPUtime_file << t_GPU.getwctGPU() <<
",";
446 if (iter % interval_write == 0)
449 g_sparse.template deviceToHost<CONC_N, CONC_NPLUS1, DIFFUSION_COEFFICIENT, PHI_PHASE>();
452 g_sparse.write_frame(path_output +
"g_sparse_diffuse", iter, FORMAT_BINARY);
455 g_sparse.save(path_output +
"g_sparse_diffuse_" + std::to_string(iter) +
".hdf5");
459 monitor_total_concentration<CONC_N>(g_sparse, t, iter, path_output,
"total_conc.csv");
463 monitor_total_concentration<CONC_NPLUS1>(g_sparse, t, iter, path_output,
"total_conc.csv");
471 t_iterative_diffusion_total.
stop();
472 out_GPUtime_file.close();
476 std::cout <<
"Rank " << v_cl.rank() <<
" total time for the whole programm : " << t_total.
getwct() << std::endl;
Header file containing help-functions that perform on OpenFPM-grids.
Header file containing functions for loading pixel values from 2D image or 3D image stack (volume) st...
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.
This class decompose a space into sub-sub-domains and distribute them across processors.
Derivative second order on h (spacing)
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
This is a distributed grid.
Implementation of 1-D std::vector like structure.
Class for cpu time benchmarking.
void stop()
Stop the timer.
void start()
Start the timer.
double getwct()
Return the elapsed real time.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
get the type of the block
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...