3 #include "DCPSE/DCPSE_op/DCPSE_op.hpp"
4 #include "Vector/vector_dist.hpp"
7 #include "ellipsoid_helpfunctions.h"
8 #include "kernel_functions.h"
14 const int curvature = 2;
16 const int surf_flag = 4;
21 const int vel_prev = 9;
22 const int pos_prev = 10;
24 typedef aggregate<double, double[2], double, double[2], int, double, double, Point<2, double>,
Point<2, double>,
Point<2, double>,
Point<2, double>>
props;
29 const std::string filebasename =
"Geometry_2Ddroplet";
34 const double A = 0.75;
37 const double dp = 1/32.0;
39 const double H = 3.0*dp;
41 const double H_1D = H;
43 const double gamma_eos = 7.0;
45 const double c = 100.0;
47 const double rho_0 = 1.0;
49 const double eta = 0.5;
50 const double nu =
eta*rho_0;
52 const double alpha = 50.0;
54 const double dt = 2.0*1e-4;
61 const double band_width = 15.0*dp;
62 const double rdist_cutoff_factor = 2.8;
65 const double l = 2.44;
67 const double t_end = 0.1;
69 const double t_end = 1.0;
72 const double M = l*l*rho_0;
83 template <
typename CellList>
inline void density_summation(
particles & vd,
CellList & NN)
85 vd.template ghost_get<rho>();
96 auto Np = NN.getNNIteratorBox(NN.getCell(vd.
getPos(a)));
98 while (Np.isNext() ==
true)
103 double r2 = norm2(dr);
107 double r = std::sqrt(r2);
108 V_inv += kernel2D.Wab(r);
126 double dens = vd.
getProp<rho>(a);
128 vd.
getProp<p>(a) = (c*c*rho_0/gamma_eos)*(std::pow(dens/rho_0, gamma_eos) - 1);
134 template<
typename CellList>
inline void calc_forces(
particles & vd,
CellList & NN)
136 vd.template ghost_get<rho, p, vel, normal>();
143 double max_eta = 0.0;
144 double avg_alpha = 0.0;
146 int numparticles = 0;
147 int numsurfparticles = 0;
150 while (part.isNext())
161 for(
int k;k<2;k++) p_force[k] = 0.0;
162 for(
int k;k<2;k++) eta_force[k] = 0.0;
168 double rhoa = vd.
getProp<rho>(a);
178 auto Np = NN.getNNIteratorBox(NN.getCell(vd.
getPos(a)));
181 while (Np.isNext() ==
true)
189 if (a.getKey() == b) {++Np;
continue;};
193 double rhob = vd.
getProp<rho>(b);
199 double r2 = norm2(dr);
210 kernel2D.DWab(dr,DW,r,
false,dwdrab);
212 double factor_p = - (Va*Va + Vb*Vb)*(rhoa*Pb + rhob*Pa)/(rhoa + rhob)/m;
214 double factor_visc =
eta*(Va*Va + Vb*Vb)*dwdrab/r/m;
216 p_force[0] += factor_p * DW.
get(0);
217 p_force[1] += factor_p * DW.
get(1);
218 eta_force[0] += factor_visc*v_rel[0];
219 eta_force[1] += factor_visc*v_rel[1];
226 vd.
getProp<force>(a)[0] += p_force[0] + eta_force[0];
227 vd.
getProp<force>(a)[1] += p_force[1] + eta_force[1];
230 if (std::abs(vd.
getProp<sdf>(a)) < (2.0*H_1D))
235 double smoothing_factor = kernel1D.Wab(std::abs(vd.
getProp<sdf>(a)))/rhoa;
238 double sign_corr = 1.0;
239 if (return_sign(vd.
getProp<sdf>(a) > 0)) sign_corr = -1.0;
242 stf0 = smoothing_factor*alpha*vd.
getProp<curvature>(a)*vd.
getProp<normal>(a)[0]*sign_corr;
243 stf1 = smoothing_factor*alpha*vd.
getProp<curvature>(a)*vd.
getProp<normal>(a)[1]*sign_corr;
246 vd.
getProp<force>(a)[0] += stf0;
247 vd.
getProp<force>(a)[1] += stf1;
250 avg_alpha += vd.
getProp<curvature>(a);
255 if (va.norm() > maxvel) maxvel = va.norm();
256 if (p_force.norm() > max_p) max_p = p_force.norm();
257 if (eta_force.
norm() > max_eta) max_eta = eta_force.
norm();
261 avg_alpha = avg_alpha/numsurfparticles;
262 if ((corr) && (((
int) std::round(t/dt)%5) == 0)) std::cout<<
"Time step: "<<t<<
", Max p force: "<<max_p<<
", Max eta force: "<<max_eta<<
", Max vel: "<<maxvel<<
", Average curvature: "<<avg_alpha<<
", number of particles: "<<numparticles<<std::endl;
263 if (numparticles == 0)
throw std::invalid_argument(
"no particles");
266 void pred_corr_int(
particles & vd,
double dt,
int & corr)
272 while (part.isNext())
304 int main(
int argc,
char* argv[])
307 openfpm_init(&argc, &argv);
310 size_t sz[2] = {(size_t)(l/dp),(size_t)(l/dp)};
313 size_t bc[2] = {PERIODIC, PERIODIC};
319 particles vd(0, domain, bc, g, DEC_GRAN(512));
328 while (particle_it.isNext())
330 double x = -l/2.0 + dp/2.0 + particle_it.get().get(0)*dp;
331 double y = -l/2.0 + dp/2.0 + particle_it.get().get(1)*dp;
339 vd.template getLastProp<surf_flag>() = 0;
344 double dist = DistancePointEllipse(A, B, abs(x), abs(y), xcp, ycp);
345 dist = -1.0*return_sign(1 - sqrt((x/A)*(x/A) + (y/B)*(y/B)))*dist;
347 vd.template getLastProp<sdf>() = dist;
348 vd.template getLastProp<normal>()[0] = 0.0;
349 vd.template getLastProp<normal>()[1] = 0.0;
350 vd.template getLastProp<curvature>() = 0.0;
351 vd.template getLastProp<vel>()[0] = 0.0;
352 vd.template getLastProp<vel>()[1] = 0.0;
353 vd.template getLastProp<vel_prev>()[0] = 0.0;
354 vd.template getLastProp<vel_prev>()[1] = 0.0;
355 vd.template getLastProp<force>()[0] = 0.0;
356 vd.template getLastProp<force>()[1] = 0.0;
357 vd.template getLastProp<rho>() = 0.0;
358 vd.template getLastProp<p>() = 0.0;
372 std::cout<<
"dt should be smaller than:\n"<<0.25*H/(c+3.0)<<
"\t"<<0.125*rho_0*H*H/
eta<<
"\t"<<0.25*sqrt(rho_0*H*H*H/(2*M_PI*alpha))<<std::endl;
379 density_summation(vd, NN);
385 vd.
write(filebasename +
"_init_before_redistancing");
393 rdistoptions.r_cutoff_factor = rdist_cutoff_factor;
395 rdistoptions.sampling_radius = 0.75*band_width;
398 rdistoptions.tolerance = 1e-12;
400 rdistoptions.compute_normals = 1;
401 rdistoptions.compute_curvatures = 1;
404 rdistoptions.write_sdf = 0;
406 rdistoptions.write_cp = 1;
408 rdistoptions.minter_poly_degree = 4;
410 rdistoptions.minter_lp_degree = 1.0;
412 static constexpr
unsigned int num_coeffs = minter_lp_degree_one_num_coeffs(2,4);
416 std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
418 pcprdist_init.run_redistancing();
420 vd.
write(filebasename +
"_init");
424 rdistoptions.write_sdf = 1;
428 size_t write_interim = 0;
445 density_summation(vd, NN);
454 std::cout<<
"Increased sampling radius for dt."<<std::endl;
455 rdistoptions.sampling_radius = 3.0*band_width;
460 pcprdist.run_redistancing();
465 rdistoptions.sampling_radius = 0.75*band_width;
476 pred_corr_int(vd, dt, corr);
478 if (corr == 0) t +=dt;
480 if (write_interim < t*10)
482 vd.
save(filebasename +
"_interim_save");
495 {std::cout <<
"TIME: " << t << std::endl;}
499 std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
500 std::cout <<
"Time required for simulation = " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() <<
"[ms]" << std::endl;
This class represent an N-dimensional box.
Class for FAST cell list implementation.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
__device__ __host__ T norm() const
norm of the vector
void execute()
Execute all the requests.
void sum(T &num)
Sum the numbers across all processors and get the result.
size_t getProcessUnitID()
Get the process unit id.
Implementation of VCluster class.
Class for reinitializing a level-set function into a signed distance function using the Closest-Point...
Class for cpu time benchmarking.
size_t size_local() const
return the local size of the vector
bool write_frame(std::string out, size_t iteration, int opt=VTK_WRITER)
Output particle position and properties.
auto getProp(vect_dist_key_dx vec_key) -> decltype(vPrp.template get< id >(vec_key.getKey()))
Get the property of an element.
void updateCellList(CellL &cellList, bool no_se3=false)
Update a cell list using the stored particles.
void setPropNames(const openfpm::vector< std::string > &names)
Set the properties names.
grid_dist_id_iterator_dec< Decomposition > getGridIterator(const size_t(&sz)[dim])
auto getPos(vect_dist_key_dx vec_key) -> decltype(vPos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
vector_dist_iterator getDomainIterator() const
Get an iterator that traverse the particles in the domain.
void ghost_get(size_t opt=WITH_POSITION)
It synchronize the properties and position of the ghost particles.
void map(size_t opt=NONE)
It move all the particles that does not belong to the local processor to the respective processor.
bool write(std::string out, int opt=VTK_WRITER)
Output particle position and properties.
void save(const std::string &filename) const
Save the distributed vector on HDF5 file.
void add()
Add local particle.
CellList_type getCellList(St r_cut, size_t opt=CL_NON_SYMMETRIC|CL_LINEAR_CELL_KEYS, bool no_se3=false, float ghostEnlargeFactor=1.013)
Construct a cell list starting from the stored particles.
void deleteGhost()
Delete the particles on the ghost.
auto getLastPos() -> decltype(vPos.template get< 0 >(0))
Get the position of the last element.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
Structure to bundle options for redistancing.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
[Definition of the system]