63 #include "Vector/vector_dist.hpp"
64 #include "Operators/Vector/vector_dist_operators.hpp"
65 #include "Draw/DrawParticles.hpp"
121 const double dp = 0.0085;
127 const double coeff_sound = 20.0;
130 const double gamma_ = 7.0;
133 const double H = 0.0147224318643;
136 const double Eta2 = 0.01 * H*H;
139 const double visco = 0.1;
145 const double MassFluid = 0.000614125;
148 const double MassBound = 0.000614125;
152 const double t_end = 0.001;
154 const double t_end = 1.5;
158 const double gravity = 9.81;
161 const double RhoZero = 1000.0;
167 const double CFLnumber = 0.2;
170 const double DtMin = 0.00001;
173 const double RhoMin = 700.0;
176 const double RhoMax = 1300.0;
179 double max_fluid_height = 0.0;
184 const size_t TYPE = 0;
190 const int RHO_PREV = 2;
194 const int RHO_TMP = 8;
197 const int PRESSURE = 3;
206 const int VELOCITY = 6;
209 const int VELOCITY_PREV = 7;
213 const int VELOCITY_TMP = 9;
233 template<
typename Decomposition,
typename vector>
inline void addComputation(
Decomposition & dec,
238 if (vectorDist.template getProp<TYPE>(p) == FLUID)
239 dec.addComputationCost(v,4);
241 dec.addComputationCost(v,3);
244 template<
typename Decomposition>
inline void applyModel(
Decomposition & dec,
size_t v)
246 dec.setSubSubDomainComputationCost(v, dec.getSubSubDomainComputationCost(v) * dec.getSubSubDomainComputationCost(v));
249 double distributionTol()
280 double rho_a = vectorDist.template getProp<RHO>(a);
281 double rho_frac = rho_a / RhoZero;
283 vectorDist.template getProp<PRESSURE>(a) = B*( rho_frac*rho_frac*rho_frac*rho_frac*rho_frac*rho_frac*rho_frac - 1.0);
307 const double a2 = 1.0/M_PI/H/H/H;
309 inline double Wab(
double r)
314 return (1.0 - 3.0/2.0*r*r + 3.0/4.0*r*r*r)*a2;
316 return (1.0/4.0*(2.0 - r)*(2.0 - r)*(2.0 - r))*a2;
338 const double c1 = -3.0/M_PI/H/H/H/H;
339 const double d1 = 9.0/4.0/M_PI/H/H/H/H;
340 const double c2 = -3.0/4.0/M_PI/H/H/H/H;
341 const double a2_4 = 0.25*a2;
349 double qq2 = qq * qq;
350 double fac1 = (c1*qq + d1*qq2)/r;
351 double b1 = (qq < 1.0)?1.0f:0.0f;
353 double wqq = (2.0 - qq);
354 double fac2 = c2 * wqq * wqq / r;
355 double b2 = (qq >= 1.0 && qq < 2.0)?1.0f:0.0f;
357 double factor = (b1*fac1 + b2*fac2);
359 DW.
get(0) = factor * dx.
get(0);
360 DW.
get(1) = factor * dx.
get(1);
361 DW.
get(2) = factor * dx.
get(2);
385 inline double Tensile(
double r,
double rhoa,
double rhob,
double prs1,
double prs2)
393 double wqq2=wqq1*wqq1;
395 wab=a2_4*(wqq2*wqq1);
402 wab=a2*(1.0f-1.5f*wqq2+0.75f*wqq3);
406 double fab=wab*W_dap;
408 const double tensilp1=(prs1/(rhoa*rhoa))*(prs1>0? 0.01: -0.2);
409 const double tensilp2=(prs2/(rhob*rhob))*(prs2>0? 0.01: -0.2);
411 return (fab*(tensilp1+tensilp2));
435 const double dot_rr2 = dot/(rr2+Eta2);
436 visc=std::max(dot_rr2,visc);
440 const float amubar=H*dot_rr2;
441 const float robar=(rhoa+rhob)*0.5f;
442 const float pi_visc=(-visco*cbar*amubar/robar);
467 template<
typename CellList>
inline void calc_forces(
vector_dist_type & vectorDist,
CellList & NN,
double & max_visc)
475 while (part.isNext())
484 double massa = (vectorDist.
getProp<TYPE>(a) == FLUID)?MassFluid:MassBound;
487 double rhoa = vectorDist.
getProp<RHO>(a);
490 double Pa = vectorDist.
getProp<PRESSURE>(a);
496 vectorDist.template getProp<FORCE>(a)[0] = 0.0;
497 vectorDist.template getProp<FORCE>(a)[1] = 0.0;
498 vectorDist.template getProp<FORCE>(a)[2] = -gravity;
499 vectorDist.template getProp<DRHO>(a) = 0.0;
502 if (vectorDist.
getProp<TYPE>(a) != FLUID)
506 auto Np = NN.getNNIteratorBox(NN.getCell(vectorDist.
getPos(a)));
509 while (Np.isNext() ==
true)
518 if (a.getKey() == b) {++Np;
continue;};
521 double massb = (vectorDist.
getProp<TYPE>(b) == FLUID)?MassFluid:MassBound;
527 double Pb = vectorDist.
getProp<PRESSURE>(b);
528 double rhob = vectorDist.
getProp<RHO>(b);
533 double r2 = norm2(dr);
546 const double dot = dr.get(0)*dv.
get(0) + dr.get(1)*dv.
get(1) + dr.get(2)*dv.
get(2);
547 const double dot_rr2 = dot/(r2+Eta2);
548 max_visc=std::max(dot_rr2,max_visc);
561 auto Np = NN.getNNIteratorBox(NN.getCell(vectorDist.
getPos(a)));
564 while (Np.isNext() ==
true)
573 if (a.getKey() == b) {++Np;
continue;};
575 double massb = (vectorDist.
getProp<TYPE>(b) == FLUID)?MassFluid:MassBound;
577 double Pb = vectorDist.
getProp<PRESSURE>(b);
578 double rhob = vectorDist.
getProp<RHO>(b);
583 double r2 = norm2(dr);
595 double factor = - massb*((vectorDist.
getProp<PRESSURE>(a) + vectorDist.
getProp<PRESSURE>(b)) / (rhoa * rhob) + Tensile(r,rhoa,rhob,Pa,Pb) + Pi(dr,r2,v_rel,rhoa,rhob,massb,max_visc));
597 vectorDist.
getProp<FORCE>(a)[0] += factor * DW.
get(0);
598 vectorDist.
getProp<FORCE>(a)[1] += factor * DW.
get(1);
599 vectorDist.
getProp<FORCE>(a)[2] += factor * DW.
get(2);
630 void max_acceleration_and_velocity(
vector_dist_type & vectorDist,
double & max_acc,
double & max_vel)
635 while (part.isNext())
640 double acc2 = norm2(acc);
643 double vel2 = norm2(vel);
653 max_acc = sqrt(max_acc);
654 max_vel = sqrt(max_vel);
691 max_acceleration_and_velocity(vectorDist,Maxacc,Maxvel);
694 const double dt_f = (Maxacc)?sqrt(H/Maxacc):std::numeric_limits<int>::max();
697 const double dt_cv = H/(std::max(cbar,Maxvel*10.) + H*ViscDtMax);
700 double dt=double(CFLnumber)*std::min(dt_f,dt_cv);
749 double dt205 = dt*dt*0.5;
752 auto posExpression = getV<POS_PROP>(vectorDist);
753 auto forceExpression = getV<FORCE>(vectorDist);
754 auto drhoExpression = getV<DRHO>(vectorDist);
755 auto typeExpression = getV<TYPE>(vectorDist);
757 auto rhoExpression = getV<RHO>(vectorDist);
758 auto rho_tmpExpression = getV<RHO_TMP>(vectorDist);
759 auto rho_prevExpression = getV<RHO_PREV>(vectorDist);
761 auto velocityExpression = getV<VELOCITY>(vectorDist);
762 auto velocity_tmpExpression = getV<VELOCITY_TMP>(vectorDist);
763 auto velocity_prevExpression = getV<VELOCITY_PREV>(vectorDist);
765 rho_tmpExpression = rhoExpression;
766 rhoExpression = rho_prevExpression + dt2*drhoExpression;
767 rho_prevExpression = rho_tmpExpression;
769 posExpression[0] = posExpression[0] + velocityExpression[0]*dt + forceExpression[0]*dt205 * typeExpression;
770 posExpression[1] = posExpression[1] + velocityExpression[1]*dt + forceExpression[1]*dt205 * typeExpression;
771 posExpression[2] = posExpression[2] + velocityExpression[2]*dt + forceExpression[2]*dt205 * typeExpression;
773 velocity_tmpExpression[0] = velocityExpression[0];
774 velocity_tmpExpression[1] = velocityExpression[1];
775 velocity_tmpExpression[2] = velocityExpression[2];
777 velocityExpression[0] = velocity_prevExpression[0] + forceExpression[0]*dt2 * typeExpression;
778 velocityExpression[1] = velocity_prevExpression[1] + forceExpression[1]*dt2 * typeExpression;
779 velocityExpression[2] = velocity_prevExpression[2] + forceExpression[2]*dt2 * typeExpression;
781 velocity_prevExpression[0] = velocity_tmpExpression[0];
782 velocity_prevExpression[1] = velocity_tmpExpression[1];
783 velocity_prevExpression[2] = velocity_tmpExpression[2];
789 while (part.isNext())
795 if (vectorDist.template getProp<TYPE>(a) == BOUNDARY)
797 double rho = vectorDist.template getProp<RHO>(a);
800 vectorDist.template getProp<RHO>(a) = RhoZero;
807 if (vectorDist.
getPos(a)[0] < 0.000263878 || vectorDist.
getPos(a)[1] < 0.000263878 || vectorDist.
getPos(a)[2] < 0.000263878 ||
808 vectorDist.
getPos(a)[0] > 0.000263878+1.59947 || vectorDist.
getPos(a)[1] > 0.000263878+0.672972 || vectorDist.
getPos(a)[2] > 0.000263878+0.903944 ||
809 vectorDist.template getProp<RHO>(a) < RhoMin || vectorDist.template getProp<RHO>(a) > RhoMax)
811 to_remove.add(a.getKey());
818 vectorDist.
remove(to_remove,0);
829 double dt205 = dt*dt*0.5;
832 auto posExpression = getV<POS_PROP>(vectorDist);
833 auto forceExpression = getV<FORCE>(vectorDist);
834 auto drhoExpression = getV<DRHO>(vectorDist);
835 auto typeExpression = getV<TYPE>(vectorDist);
837 auto rhoExpression = getV<RHO>(vectorDist);
838 auto rho_prevExpression = getV<RHO_PREV>(vectorDist);
840 auto velocityExpression = getV<VELOCITY>(vectorDist);
841 auto velocity_prevExpression = getV<VELOCITY_PREV>(vectorDist);
843 rho_prevExpression = rhoExpression;
844 rhoExpression = rhoExpression + dt*drhoExpression;
846 posExpression[0] = posExpression[0] + velocityExpression[0]*dt + forceExpression[0]*dt205 * typeExpression;
847 posExpression[1] = posExpression[1] + velocityExpression[1]*dt + forceExpression[1]*dt205 * typeExpression;
848 posExpression[2] = posExpression[2] + velocityExpression[2]*dt + forceExpression[2]*dt205 * typeExpression;
850 velocity_prevExpression[0] = velocityExpression[0];
851 velocity_prevExpression[1] = velocityExpression[1];
852 velocity_prevExpression[2] = velocityExpression[2];
854 velocityExpression[0] = velocityExpression[0] + forceExpression[0]*dt * typeExpression;
855 velocityExpression[1] = velocityExpression[1] + forceExpression[1]*dt * typeExpression;
856 velocityExpression[2] = velocityExpression[2] + forceExpression[2]*dt * typeExpression;
862 while (part.isNext())
868 if (vectorDist.template getProp<TYPE>(a) == BOUNDARY)
870 double rho = vectorDist.template getProp<RHO>(a);
873 vectorDist.template getProp<RHO>(a) = RhoZero;
880 if (vectorDist.
getPos(a)[0] < 0.000263878 || vectorDist.
getPos(a)[1] < 0.000263878 || vectorDist.
getPos(a)[2] < 0.000263878 ||
881 vectorDist.
getPos(a)[0] > 0.000263878+1.59947 || vectorDist.
getPos(a)[1] > 0.000263878+0.672972 || vectorDist.
getPos(a)[2] > 0.000263878+0.903944 ||
882 vectorDist.template getProp<RHO>(a) < RhoMin || vectorDist.template getProp<RHO>(a) > RhoMax)
884 to_remove.add(a.getKey());
891 vectorDist.
remove(to_remove,0);
924 template<
typename Vector,
typename CellList>
925 inline void sensor_pressure(
Vector & vectorDist,
934 for (
size_t i = 0 ; i < probes.size() ; i++)
936 float press_tmp = 0.0f;
940 if (vectorDist.getDecomposition().isLocal(probes.get(i)) ==
true)
946 auto itg = NN.getNNIteratorBox(NN.getCell(probes.get(i)));
952 if (vectorDist.template getProp<TYPE>(q) != FLUID)
963 double r = sqrt(norm2(xp - xq));
965 double ker = Wab(r) * (MassFluid / RhoZero);
972 press_tmp += vectorDist.template getProp<PRESSURE>(q) * ker;
983 press_tmp = 1.0 / tot_ker * press_tmp;
994 press_t.last().add(press_tmp);
1000 int main(
int argc,
char* argv[])
1020 openfpm_init(&argc,&argv);
1026 probes.add({0.8779,0.3,0.02});
1027 probes.add({0.754,0.31,0.02});
1030 Box<3,double> domain({-0.05,-0.05,-0.05},{1.7010,0.7065,0.5025});
1031 size_t sz[3] = {207,90,66};
1034 W_dap = 1.0/Wab(H/1.5);
1037 size_t bc[3]={NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
1123 Box<3,double> fluid_box({dp/2.0,dp/2.0,dp/2.0},{0.4+dp/2.0,0.67-dp/2.0,0.3+dp/2.0});
1129 max_fluid_height = fluid_it.getBoxMargins().
getHigh(2);
1130 h_swl = fluid_it.getBoxMargins().
getHigh(2) - fluid_it.getBoxMargins().
getLow(2);
1131 B = (coeff_sound)*(coeff_sound)*gravity*h_swl*RhoZero / gamma_;
1132 cbar = coeff_sound * sqrt(gravity * h_swl);
1135 while (fluid_it.isNext())
1141 vectorDist.getLastPos()[0] = fluid_it.get().get(0);
1142 vectorDist.getLastPos()[1] = fluid_it.get().get(1);
1143 vectorDist.getLastPos()[2] = fluid_it.get().get(2);
1146 vectorDist.template getLastProp<TYPE>() = FLUID;
1155 vectorDist.template getLastProp<PRESSURE>() = RhoZero * gravity * (max_fluid_height - fluid_it.get().get(2));
1157 vectorDist.template getLastProp<RHO>() = pow(vectorDist.template getLastProp<PRESSURE>() / B + 1, 1.0/gamma_) * RhoZero;
1158 vectorDist.template getLastProp<RHO_PREV>() = vectorDist.template getLastProp<RHO>();
1159 vectorDist.template getLastProp<VELOCITY>()[0] = 0.0;
1160 vectorDist.template getLastProp<VELOCITY>()[1] = 0.0;
1161 vectorDist.template getLastProp<VELOCITY>()[2] = 0.0;
1163 vectorDist.template getLastProp<VELOCITY_PREV>()[0] = 0.0;
1164 vectorDist.template getLastProp<VELOCITY_PREV>()[1] = 0.0;
1165 vectorDist.template getLastProp<VELOCITY_PREV>()[2] = 0.0;
1199 Box<3,double> recipient1({0.0,0.0,0.0},{1.6+dp/2.0,0.67+dp/2.0,0.4+dp/2.0});
1200 Box<3,double> recipient2({dp,dp,dp},{1.6-dp/2.0,0.67-dp/2.0,0.4+dp/2.0});
1202 Box<3,double> obstacle1({0.9,0.24-dp/2.0,0.0},{1.02+dp/2.0,0.36,0.45+dp/2.0});
1203 Box<3,double> obstacle2({0.9+dp,0.24+dp/2.0,0.0},{1.02-dp/2.0,0.36-dp,0.45-dp/2.0});
1204 Box<3,double> obstacle3({0.9+dp,0.24,0.0},{1.02,0.36,0.45});
1207 holes.add(recipient2);
1208 holes.add(obstacle1);
1211 while (bound_box.isNext())
1215 vectorDist.getLastPos()[0] = bound_box.get().get(0);
1216 vectorDist.getLastPos()[1] = bound_box.get().get(1);
1217 vectorDist.getLastPos()[2] = bound_box.get().get(2);
1219 vectorDist.template getLastProp<TYPE>() = BOUNDARY;
1220 vectorDist.template getLastProp<RHO>() = RhoZero;
1221 vectorDist.template getLastProp<RHO_PREV>() = RhoZero;
1222 vectorDist.template getLastProp<VELOCITY>()[0] = 0.0;
1223 vectorDist.template getLastProp<VELOCITY>()[1] = 0.0;
1224 vectorDist.template getLastProp<VELOCITY>()[2] = 0.0;
1226 vectorDist.template getLastProp<VELOCITY_PREV>()[0] = 0.0;
1227 vectorDist.template getLastProp<VELOCITY_PREV>()[1] = 0.0;
1228 vectorDist.template getLastProp<VELOCITY_PREV>()[2] = 0.0;
1255 while (obstacle_box.isNext())
1259 vectorDist.getLastPos()[0] = obstacle_box.get().get(0);
1260 vectorDist.getLastPos()[1] = obstacle_box.get().get(1);
1261 vectorDist.getLastPos()[2] = obstacle_box.get().get(2);
1263 vectorDist.template getLastProp<TYPE>() = BOUNDARY;
1264 vectorDist.template getLastProp<RHO>() = RhoZero;
1265 vectorDist.template getLastProp<RHO_PREV>() = RhoZero;
1266 vectorDist.template getLastProp<VELOCITY>()[0] = 0.0;
1267 vectorDist.template getLastProp<VELOCITY>()[1] = 0.0;
1268 vectorDist.template getLastProp<VELOCITY>()[2] = 0.0;
1270 vectorDist.template getLastProp<VELOCITY_PREV>()[0] = 0.0;
1271 vectorDist.template getLastProp<VELOCITY_PREV>()[1] = 0.0;
1272 vectorDist.template getLastProp<VELOCITY_PREV>()[2] = 0.0;
1367 vectorDist.addComputationCosts(md);
1368 vectorDist.getDecomposition().decompose();
1373 vectorDist.ghost_get<TYPE,RHO,PRESSURE,VELOCITY>();
1375 auto NN = vectorDist.getCellList(2*H);
1412 vectorDist.addComputationCosts(md);
1413 vectorDist.getDecomposition().decompose();
1416 std::cout <<
"REBALANCED " << std::endl;
1422 EqState(vectorDist);
1424 double max_visc = 0.0;
1426 vectorDist.ghost_get<TYPE,RHO,PRESSURE,VELOCITY>();
1429 calc_forces(vectorDist,NN,max_visc);
1436 double dt = calc_deltaT(vectorDist,max_visc);
1441 verlet_int(vectorDist,dt);
1444 euler_int(vectorDist,dt);
1454 vectorDist.ghost_get<TYPE,RHO,PRESSURE,VELOCITY>();
1455 vectorDist.updateCellList(NN);
1458 sensor_pressure(vectorDist,NN,press_t,probes);
1460 vectorDist.write_frame(
"Geometry",write);
1464 {std::cout <<
"TIME: " << t <<
" write " << it_time.
getwct() <<
" " << v_cl.
getProcessUnitID() <<
" " << cnt <<
" Max visc: " << max_visc << std::endl;}
1469 {std::cout <<
"TIME: " << t <<
" " << it_time.
getwct() <<
" " << v_cl.
getProcessUnitID() <<
" " << cnt <<
" Max visc: " << max_visc << std::endl;}
This class represent an N-dimensional box.
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Class for FAST cell list implementation.
This class define the domain decomposition interface.
static PointIteratorSkin< dim, T, typename vd_type::Decomposition_type > DrawSkin(vd_type &vd, size_t(&sz)[dim], Box< dim, T > &domain, Box< dim, T > &sub_A, Box< dim, T > &sub_B)
Draw particles in a box B excluding the area of a second box A (B - A)
static PointIterator< dim, T, typename vd_type::Decomposition_type > DrawBox(vd_type &vd, size_t(&sz)[dim], Box< dim, T > &domain, Box< dim, T > &sub)
Draw particles in a box.
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
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.
void max(T &num)
Get the maximum number across all processors (or reduction with infinity norm)
Implementation of VCluster class.
Sparse Matrix implementation stub object when OpenFPM is compiled with no linear algebra support.
Class for cpu time benchmarking.
double getwct()
Return the elapsed real time.
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.
auto getPos(vect_dist_key_dx vec_key) -> decltype(vPos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
void remove(std::set< size_t > &keys)
Remove a set of elements from the distributed vector.
vector_dist_iterator getDomainIterator() const
Get an iterator that traverse the particles in the domain.
Model for Dynamic load balancing.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...