OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
method_of_images_unit_test.cpp
1//
2// Created by jstark on 01.06.21.
3//
4
5#define BOOST_TEST_DYN_LINK
6
7#include <boost/test/unit_test.hpp>
8
9// Include header files for testing
10#include "BoundaryConditions/MethodOfImages.hpp"
11#include "BoundaryConditions/SurfaceNormal.hpp"
12#include "libForTesting/HelpFunctionsForTestingNBCs.hpp"
13
14BOOST_AUTO_TEST_SUITE(MethodOfImagesTestSuite)
15
16 BOOST_AUTO_TEST_CASE(DiffusionWithNoFluxNBCs)
17 {
18 const size_t dims = 2;
19 const double L_low = 0.0;
20 const double L_up = 1.0;
21 const double R_disk = 0.25;
22 const double D = 0.005; // Diffusion constant.
23 const double a = R_disk;
24 const double t0 = 0; // Must be 0 in order to fit the IC from Eq. 28
25 const double tmax = 20;
26 constexpr size_t Phi_SDF = 0, dPhi = 1, dPhi_magn = 2, SurfaceNormal = 3, Conc_n = 4, Conc_nplus1 = 5, Lap_conc = 6,
27 Radius = 7, Conc_exact = 8, Error = 9;
28 constexpr size_t x = 0, y = 1;
29
30// for (size_t N = 32; N <= 512; N *= 2)
31 size_t N = 32;
32 {
33 auto &v_cl = create_vcluster();
34
35
37 // Some indices for the grid / grid properties
38 const size_t Phi_0_grid = 0;
39 const size_t Phi_SDF_grid = 1;
41 // Here we create a 2D grid that stores 2 properties:
42 // Prop1: store the initial Phi;
43 // Prop2: here the re-initialized Phi (signed distance function) will be written to in the re-distancing step
44 size_t sz[dims] = {N, N}; // Grid size in terms of number of grid points per dimension
45 Box<dims, double> box({L_low, L_low}, {L_up, L_up}); // 2D
46 Ghost<dims, long int> ghost(0);
47 typedef aggregate<double, double> props;
48 typedef grid_dist_id<dims, double, props > grid_in_type;
49 grid_in_type g_dist(sz, box, ghost);
50 g_dist.setPropNames({"Phi_0", "Phi_SDF"});
51 g_dist.load("/Users/jstark/Desktop/diffusion/simple_geometries/get_diffusion_space/disk_analytical_sdf"
52 "/output_circle_" + std::to_string(N) + "/grid_disk_analyticalSdf.bin"); // Load SDF of a disk
53 // from hdf5 file.
54 double p_spacing = g_dist.spacing(x);
55
57 // Place particles into diffusion space according to SDF stored in grid. Copy Phi_SDF, dPhi and dPhi_magn from the
58 // grid onto the particles.
60 size_t bc[dims] = {NON_PERIODIC, NON_PERIODIC};
61 Ghost<dims, double> ghost_vd(p_spacing * 4);
62 std::cout << "Ghost layer thickness: " << p_spacing * 10 << std::endl;
63 typedef aggregate<double, double[dims], double, Point<dims, double>, double, double, double, double, double, double>
64 props_diffSpace;
66 vd_type vd(0, box, bc, ghost_vd);
67 vd.setPropNames({"Phi_SDF", "dPhi", "dPhi_magn", "SurfaceNormal", "Conc_n", "Conc_n+1", "Lap_conc", "Radius",
68 "Conc_exact", "Error"});
69
70
71 // Get diffusion domain
72 double dlow = 0, dup = 2*L_up;
73 get_diffusion_domain<Phi_SDF_grid, Phi_SDF, dPhi, dPhi_magn>(g_dist, vd, dlow, dup);
74// vd.write(path_output + "/vd_diffusionSpace_real", FORMAT_BINARY); // VTK file
75// vd.save(path_output + "/vd_diffusionSpace_real.bin"); // HDF5 file
76
78 // Initialize the mass
80 // Get polar radius from cartesian coordinates
81 double center_disk [] = {0.5, 0.5};
82 get_radius<Radius>(vd, center_disk);
83
84 // Initialize with exact solution for diffusion on disk at t=0
85 // get_Eq27<Radius, Conc_n>(vd, a, D, t0);
86 get_IC_Eq28<Radius, Conc_n>(vd, a);
87
88 vd.template ghost_get<Conc_n>(KEEP_PROPERTIES);
89
91 // Place mirror particles for noflux boundary conditions.
93 size_t mirror_width = 3; // Mirror width in number of particles
94// size_t mirror_width = std::round(0.1/p_spacing); // Mirror width in number of particles
95
96 if (v_cl.rank() == 0) std::cout << "Width of mirror layer: " << mirror_width << " particles." << std::endl;
97 double b_low = 0, b_up = mirror_width * p_spacing;
99 get_source_particle_ids<Phi_SDF>(vd, keys_source, b_low, b_up);
100
101 get_surface_normal_sdf_subset<Phi_SDF, dPhi, SurfaceNormal>(vd, keys_source);
102
103 MethodOfImages<SurfaceNormal, vd_type> NBCs(vd, keys_source, 0, 1);
104 NBCs.get_mirror_particles(vd);
105
106 }
107
108
109 }
110BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
Definition Box.hpp:61
Derivative second order on h (spacing)
Class for getting mirror particles to impose Neumann BCs.
This is a distributed grid.
Implementation of 1-D std::vector like structure.
Out-of-bound policy kill the program.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...