8 #include "Vector/vector_dist.hpp"
9 #include "Plot/GoogleChart.hpp"
10 #include "Plot/util.hpp"
35 constexpr
int velocity = 0;
36 constexpr
int force = 1;
59 template<
typename CellList>
void calc_forces(
vector_dist<3,
double,
aggregate<
double[3],
double[3]> > & vd,
CellList & NN,
double sigma12,
double sigma6,
double r_cut2)
79 vd.updateCellList(NN);
101 auto it2 = vd.getDomainIterator();
113 vd.template getProp<force>(p)[0] = 0.0;
114 vd.template getProp<force>(p)[1] = 0.0;
115 vd.template getProp<force>(p)[2] = 0.0;
118 auto Np = NN.getNNIteratorBox(NN.getCell(vd.getPos(p)));
127 if (q == p.getKey()) {++Np;
continue;};
136 double rn = norm2(r);
142 Point<3,double> f = 24.0*(2.0 *sigma12 / (rn*rn*rn*rn*rn*rn*rn) - sigma6 / (rn*rn*rn*rn)) * r;
145 vd.template getProp<force>(p)[0] += f.get(0);
146 vd.template getProp<force>(p)[1] += f.get(1);
147 vd.template getProp<force>(p)[2] += f.get(2);
179 template<
typename CellList>
double calc_energy(
vector_dist<3,
double,
aggregate<
double[3],
double[3]> > & vd,
CellList & NN,
double sigma12,
double sigma6,
double r_cut2)
182 double shift = 2.0 * ( sigma12 / (rc*rc*rc*rc*rc*rc) - sigma6 / ( rc*rc*rc) );
223 auto it2 = vd.getDomainIterator();
235 auto Np = NN.getNNIteratorBox(NN.getCell(vd.getPos(p)));
244 if (q == p.getKey()) {++Np;
continue;};
250 double rn = norm2(xp - xq);
256 E += 2.0 * ( sigma12 / (rn*rn*rn*rn*rn*rn) - sigma6 / ( rn*rn*rn) ) -
shift;
263 E += (vd.template getProp<velocity>(p)[0]*vd.template getProp<velocity>(p)[0] +
264 vd.template getProp<velocity>(p)[1]*vd.template getProp<velocity>(p)[1] +
265 vd.template getProp<velocity>(p)[2]*vd.template getProp<velocity>(p)[2]) / 2;
281 int main(
int argc,
char* argv[])
302 openfpm_init(&argc,&argv);
304 auto & v_cl = create_vcluster();
306 double r_cut = 3.0*sigma;
309 size_t sz[3] = {50,50,50};
315 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
321 double sigma12 = pow(sigma,12);
322 double sigma6 = pow(sigma,6);
364 if (v_cl.rank() == 0) {
366 auto it = vd.getGridIterator(sz);
378 vd.getLastPos()[0] = key.get(0) * it.getSpacing(0);
379 vd.getLastPos()[1] = key.get(1) * it.getSpacing(1);
380 vd.getLastPos()[2] = key.get(2) * it.getSpacing(2);
383 vd.template getLastProp<velocity>()[0] = 0.0;
384 vd.template getLastProp<velocity>()[1] = 0.0;
385 vd.template getLastProp<velocity>()[2] = 0.0;
387 vd.template getLastProp<force>()[0] = 0.0;
388 vd.template getLastProp<force>()[1] = 0.0;
389 vd.template getLastProp<force>()[2] = 0.0;
394 std::cerr <<
"size local 1 " << vd.size_local() << std::endl;
396 vd.addComputationCosts();
397 vd.getDecomposition().decompose();
401 std::cerr <<
"size local 2 " << vd.size_local() << std::endl;
455 calc_forces(vd,NN,sigma12,sigma6,r_cut*r_cut);
456 unsigned long int f = 0;
459 for (
size_t i = 0; i < 10000 ; i++)
462 auto it3 = vd.getDomainIterator();
470 vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
471 vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
472 vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];
475 vd.getPos(p)[0] += vd.template getProp<velocity>(p)[0]*dt;
476 vd.getPos(p)[1] += vd.template getProp<velocity>(p)[1]*dt;
477 vd.getPos(p)[2] += vd.template getProp<velocity>(p)[2]*dt;
484 vd.template ghost_get<>();
487 calc_forces(vd,NN,sigma12,sigma6,r_cut*r_cut);
490 auto it4 = vd.getDomainIterator();
497 vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
498 vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
499 vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];
509 vd.write_frame(
"particles_",f);
515 double energy = calc_energy(vd,NN,sigma12,sigma6,r_cut*r_cut);
516 auto & vcl = create_vcluster();
526 if (vcl.getProcessUnitID() == 0)
527 std::cout <<
"Energy: " << energy << std::endl;
536 std::cout <<
"Time: " << tsim.
getwct() << std::endl;
559 options.
title = std::string(
"Energy with time");
562 options.
yAxis = std::string(
"Energy");
565 options.
xAxis = std::string(
"iteration");
571 options.
width = 1280;
577 options.
more = GC_ZOOM;
587 cg.
write(
"gc_plot2_out.html");