167#include "Vector/vector_dist.hpp"
168#include "Draw/DrawParticles.hpp"
170int main(
int argc,
char* argv[])
173 openfpm_init(&argc,&argv);
179 double cutoff = 2 * R;
180 double skin = 0.1 * cutoff;
181 constexpr int max_contacts = 36;
182 constexpr int max_contacts_def = max_contacts * 3;
184 double Im = 2.0 * R * R * m / 5.0;
187 double gamma_n = 3401;
188 double gamma_t = 3401;
191 double t_stop = 0.001;
193 double t_stop = 16.0000;
204 constexpr int velocity = 0;
205 constexpr int force = 1;
206 constexpr int omega = 2;
207 constexpr int tau = 3;
208 constexpr int cpd = 4;
209 constexpr int cpi = 5;
210 constexpr int ncp = 6;
211 constexpr int tt = 7;
212 constexpr int gid = 8;
214 size_t bc[3] = {NON_PERIODIC,PERIODIC,NON_PERIODIC};
216 vector_dist<3,double,aggregate<Point<3,double>,
Point<3,double>,
Point<3,double>,
Point<3,double>,
217 double[max_contacts_def],
int[max_contacts],
218 int,
int,
int>> parts(0,domain,bc,g);
223 size_t sz[3] = {143,51,56};
230 while (sand_it.isNext())
236 parts.getLastPos()[0] = sand_it.get().get(0);
237 parts.getLastPos()[1] = sand_it.get().get(1);
238 parts.getLastPos()[2] = sand_it.get().get(2);
240 parts.getLastProp<velocity>()[0] = 0.0;
241 parts.getLastProp<velocity>()[1] = 0.0;
242 parts.getLastProp<velocity>()[2] = 0.0;
244 parts.getLastProp<omega>()[0] = 0.0;
245 parts.getLastProp<omega>()[1] = 0.0;
246 parts.getLastProp<omega>()[2] = 0.0;
248 parts.getLastProp<tau>()[0] = 0.0;
249 parts.getLastProp<tau>()[1] = 0.0;
250 parts.getLastProp<tau>()[2] = 0.0;
252 parts.getLastProp<force>()[0] = 0.0;
253 parts.getLastProp<force>()[1] = 0.0;
254 parts.getLastProp<force>()[2] = 0.0;
256 parts.getLastProp<ncp>() = 0;
258 parts.getLastProp<tt>() = 0;
268 while (base_it.isNext())
274 parts.getLastPos()[0] = base_it.get().get(0);
275 parts.getLastPos()[1] = base_it.get().get(1);
276 parts.getLastPos()[2] = base_it.get().get(2);
278 parts.getLastProp<tt>() = 1;
283 Box<3,double> wall_front({16.86,0.0,0.06},{16.98,5.9999,6.54});
288 while (wall_f_it.isNext())
294 parts.getLastPos()[0] = wall_f_it.get().get(0);
295 parts.getLastPos()[1] = wall_f_it.get().get(1);
296 parts.getLastPos()[2] = wall_f_it.get().get(2);
298 parts.getLastProp<tt>() = 1;
308 while (wall_b_it.isNext())
314 parts.getLastPos()[0] = wall_b_it.get().get(0);
315 parts.getLastPos()[1] = wall_b_it.get().get(1);
316 parts.getLastPos()[2] = wall_b_it.get().get(2);
318 parts.getLastProp<tt>() = 1;
327 parts.getDecomposition().decompose();
332 auto it_p = parts.getDomainIterator();
333 size_t accu = parts.accum();
335 while (it_p.isNext())
339 parts.getProp<
gid>(p) = accu;
350 auto nlist = parts.getVerlet<VERLETLIST_BAL(3,
double)>(cutoff + skin);
357 auto pit = parts.getDomainIterator();
368 if (parts.getProp<tt>(p) == 1) {++pit;
continue;}
370 parts.getProp<velocity>(p)[0] = parts.getProp<velocity>(p)[0] + parts.getProp<force>(p)[0]*dt;
371 parts.getProp<velocity>(p)[1] = parts.getProp<velocity>(p)[1] + parts.getProp<force>(p)[1]*dt;
372 parts.getProp<velocity>(p)[2] = parts.getProp<velocity>(p)[2] + parts.getProp<force>(p)[2]*dt;
374 double norm2 = parts.getProp<velocity>(p)[0]*parts.getProp<velocity>(p)[0] +
375 parts.getProp<velocity>(p)[1]*parts.getProp<velocity>(p)[1] +
376 parts.getProp<velocity>(p)[2]*parts.getProp<velocity>(p)[2];
380 parts.getPos(p)[0] = parts.getPos(p)[0] + parts.getProp<velocity>(p)[0]*dt;
381 parts.getPos(p)[1] = parts.getPos(p)[1] + parts.getProp<velocity>(p)[1]*dt;
382 parts.getPos(p)[2] = parts.getPos(p)[2] + parts.getProp<velocity>(p)[2]*dt;
384 if (parts.getPos(p)[0] < domain.getLow(0) || parts.getPos(p)[0] > domain.getHigh(0) ||
385 parts.getPos(p)[2] < domain.getLow(2) || parts.getPos(p)[2] > domain.getHigh(2) )
386 {parts.getProp<tt>(p) = 1;}
388 parts.getProp<omega>(p)[0] = parts.getProp<omega>(p)[0] + parts.getProp<tau>(p)[0]/Im*dt;
389 parts.getProp<omega>(p)[1] = parts.getProp<omega>(p)[1] + parts.getProp<tau>(p)[1]/Im*dt;
390 parts.getProp<omega>(p)[2] = parts.getProp<omega>(p)[2] + parts.getProp<tau>(p)[2]/Im*dt;
394 tot_sp += sqrt(max_vel)*dt;
402 if (tot_sp >= skin / 2.0)
410 if (v_cl.
rank() == 0)
411 {std::cout <<
"Redecomposing" << std::endl;}
414 parts.getDecomposition().redecompose(200);
418 if (v_cl.
rank() == 0)
419 {std::cout <<
"Reconstruct Verlet" << std::endl;}
421 parts.ghost_get<velocity,omega,
gid>();
422 parts.updateVerlet(nlist,cutoff+skin);
428 parts.ghost_get<velocity,omega,
gid>();
435 auto pit2 = parts.getDomainIterator();
437 while (pit2.isNext())
444 if (parts.getProp<tt>(p) == 1) {++pit2;
continue;}
450 int contact_ok[max_contacts];
451 for (
size_t i = 0; i < max_contacts ; i++) {contact_ok[i] = 0;}
453 auto NN = nlist.getNNIterator(p.getKey());
459 if (q == p.getKey()) {++NN;
continue;}
466 double r_s_pq2 = norm2(r_pq);
472 double delta_ij = 2.0*R - sqrt(r_s_pq2);
474 if (delta_ij < 0.0) {++NN;
continue;}
476 size_t cnt_end = parts.getProp<ncp>(p);
477 int this_contact = cnt_end;
479 for (
size_t k = 0 ; k < cnt_end ; k++)
481 if (parts.getProp<cpi>(p)[k] == parts.getProp<
gid>(q))
488 if (this_contact == cnt_end)
490 parts.getProp<ncp>(p) += 1;
491 this_contact = parts.getProp<ncp>(p) - 1;
493 cidx = 3 * this_contact;
495 if (this_contact >= max_contacts)
496 {std::cout <<
"Error reached maximum nunber of contacts points" << std::endl;}
498 parts.getProp<cpi>(p)[this_contact] = parts.getProp<
gid>(q);
500 parts.getProp<cpd>(p)[cidx] = 0.0;
501 parts.getProp<cpd>(p)[cidx + 1] = 0.0;
502 parts.getProp<cpd>(p)[cidx + 2] = 0.0;
507 cidx = 3 * this_contact;
516 v_cross.
get(0) = v_omega.
get(1) * n_ij.
get(2) - v_omega.
get(2) * n_ij.
get(1);
517 v_cross.
get(1) = v_omega.
get(2) * n_ij.
get(0) - v_omega.
get(0) * n_ij.
get(2);
518 v_cross.
get(2) = v_omega.
get(0) * n_ij.
get(1) - v_omega.
get(1) * n_ij.
get(0);
523 parts.getProp<cpd>(p)[cidx] += v_dtij.
get(0);
524 parts.getProp<cpd>(p)[cidx + 1] += v_dtij.
get(1);
525 parts.getProp<cpd>(p)[cidx + 2] += v_dtij.
get(2);
529 u_ij.
get(0) = parts.getProp<cpd>(p)[cidx];
530 u_ij.
get(1) = parts.getProp<cpd>(p)[cidx + 1];
531 u_ij.
get(2) = parts.getProp<cpd>(p)[cidx + 2];
533 Point<3,double> F_nij = sqrt(delta_ij/2/R) * (k_n*delta_ij*n_ij - gamma_n*m_eff*v_nij);
536 Point<3,double> F_tij = sqrt(delta_ij/2/R) * (-k_t*u_ij - gamma_t*m_eff*v_tij);
537 double F_tij_sq = norm2(F_tij);
538 double F_nij_sq = mu * mu * norm2(F_nij);
539 if (F_tij_sq > F_nij_sq)
541 F_tij = F_tij * (F_nij_sq / F_tij_sq);
543 parts.getProp<cpd>(p)[cidx] = -1.0 / k_t * (F_tij.
get(0) * sqrt(2*R/delta_ij) + gamma_t*m_eff*v_tij.
get(0));
544 parts.getProp<cpd>(p)[cidx+1] = -1.0 / k_t * (F_tij.
get(1) * sqrt(2*R/delta_ij) + gamma_t*m_eff*v_tij.
get(1));
545 parts.getProp<cpd>(p)[cidx+2] = -1.0 / k_t * (F_tij.
get(2) * sqrt(2*R/delta_ij) + gamma_t*m_eff*v_tij.
get(2));
550 dTau.
get(0) = dTau.get(0) - R * (n_ij.
get(1) * F_tij.get(2) - n_ij.
get(2) * F_tij.get(1));
551 dTau.get(1) = dTau.get(1) - R * (n_ij.
get(2) * F_tij.get(0) - n_ij.
get(0) * F_tij.get(2));
552 dTau.get(2) = dTau.get(2) - R * (n_ij.
get(0) * F_tij.get(1) - n_ij.
get(1) * F_tij.get(0));
554 contact_ok[this_contact] = 1;
559 int cnt_end = parts.getProp<ncp>(p);
561 for (
int iread = 0; iread < cnt_end ; iread++)
563 if (contact_ok[iread] == 1)
569 parts.getProp<cpd>(p)[j] = parts.getProp<cpd>(p)[k];
570 parts.getProp<cpd>(p)[j+1] = parts.getProp<cpd>(p)[k+1];
571 parts.getProp<cpd>(p)[j+2] = parts.getProp<cpd>(p)[k+2];
575 parts.getProp<ncp>(p) = i;
577 if (parts.getProp<tt>(p) == 0)
579 parts.getProp<force>(p).get(0) = m * 4.905 + dF_n.get(0) + dF_t.get(0);
580 parts.getProp<force>(p).get(1) = 0.0 + dF_n.get(1) + dF_t.get(1);
581 parts.getProp<force>(p).get(2) = m * -8.49570921 + dF_n.get(2) + dF_t.get(2);
583 parts.getProp<tau>(p) = dTau;
586 if (parts.getProp<tt>(p) == 1)
588 parts.getProp<force>(p) = 0;
589 parts.getProp<tau>(p) = 0;
597 if (v_cl.
rank() == 0)
598 {std::cout <<
"Time step" << std::endl;}
602 std::cout <<
"Write " << cnt << std::endl;
603 parts.write_frame(
"output",cnt);
This class represent an N-dimensional box.
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.
size_t rank()
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.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data