2 #include "Vector/vector_dist.hpp"
3 #include "Decomposition/CartDecomposition.hpp"
4 #include "data_type/aggregate.hpp"
5 #include "Plot/GoogleChart.hpp"
6 #include "Plot/util.hpp"
43 constexpr
int velocity = 0;
44 constexpr
int force = 1;
48 template<
typename CellList>
void calc_forces(
vector_dist<3,
double,
aggregate<
double[3],
double[3]> > & vd,
CellList & NN,
double sigma12,
double sigma6)
55 vd.updateCellList(NN);
74 vd.template getProp<force>(p)[0] = 0.0;
75 vd.template getProp<force>(p)[1] = 0.0;
76 vd.template getProp<force>(p)[2] = 0.0;
79 auto Np = NN.getNNIteratorBox(NN.getCell(vd.getPos(p)));
88 if (q == p) {++Np;
continue;};
100 Point<3,double> f = 24.0*(2.0 *sigma12 / (rn*rn*rn*rn*rn*rn*rn) - sigma6 / (rn*rn*rn*rn)) * r;
103 vd.template getProp<force>(p)[0] += f.get(0);
104 vd.template getProp<force>(p)[1] += f.get(1);
105 vd.template getProp<force>(p)[2] += f.get(2);
143 template<
typename CellList>
double calc_energy(
vector_dist<3,
double,
aggregate<
double[3],
double[3]> > & vd,
CellList & NN,
double sigma12,
double sigma6)
148 vd.updateCellList(NN);
163 vd.template getProp<force>(p)[0] = 0.0;
164 vd.template getProp<force>(p)[1] = 0.0;
165 vd.template getProp<force>(p)[2] = 0.0;
168 auto Np = NN.getNNIteratorBox(NN.getCell(vd.getPos(p)));
177 if (q == p) {++Np;
continue;};
183 double rn = norm2(xp - xq);
186 E += 4.0 * ( sigma12 / (rn*rn*rn*rn*rn*rn) - sigma6 / ( rn*rn*rn) );
193 E += (vd.template getProp<velocity>(p)[0]*vd.template getProp<velocity>(p)[0] +
194 vd.template getProp<velocity>(p)[1]*vd.template getProp<velocity>(p)[1] +
195 vd.template getProp<velocity>(p)[2]*vd.template getProp<velocity>(p)[2]) / 2;
208 int main(
int argc,
char* argv[])
230 double sigma = r_cut/3.0;
231 double sigma12 = pow(sigma,12);
232 double sigma6 = pow(sigma,6);
237 openfpm_init(&argc,&argv);
241 size_t sz[3] = {40,40,40};
247 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
271 auto it = vd.getGridIterator(sz);
279 vd.getLastPos()[0] = key.get(0) * it.getSpacing(0);
280 vd.getLastPos()[1] = key.get(1) * it.getSpacing(1);
281 vd.getLastPos()[2] = key.get(2) * it.getSpacing(2);
283 vd.template getLastProp<velocity>()[0] = 0.0;
284 vd.template getLastProp<velocity>()[1] = 0.0;
285 vd.template getLastProp<velocity>()[2] = 0.0;
287 vd.template getLastProp<force>()[0] = 0.0;
288 vd.template getLastProp<force>()[1] = 0.0;
289 vd.template getLastProp<force>()[2] = 0.0;
416 auto NN = vd.getCellList_hilb(r_cut);
419 calc_forces(vd,NN,sigma12,sigma6);
420 unsigned long int f = 0;
426 size_t Nstep = 30000;
432 for (
size_t i = 0; i < Nstep ; i++)
435 auto it3 = vd.getDomainIterator();
443 vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
444 vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
445 vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];
448 vd.getPos(p)[0] += vd.template getProp<velocity>(p)[0]*dt;
449 vd.getPos(p)[1] += vd.template getProp<velocity>(p)[1]*dt;
450 vd.getPos(p)[2] += vd.template getProp<velocity>(p)[2]*dt;
457 vd.template ghost_get<>();
464 calc_forces(vd,NN,sigma12,sigma6);
474 auto it4 = vd.getDomainIterator();
481 vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
482 vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
483 vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];
493 vd.write(
"particles_",f);
499 double energy = calc_energy(vd,NN,sigma12,sigma6);
500 auto & vcl = create_vcluster();
506 if (vcl.getProcessUnitID() == 0)
507 std::cout << std::endl <<
"Energy: " << energy << std::endl;
514 std::cout <<
"Performance: " << time2.
getwct() << std::endl;
539 options.
title = std::string(
"Force calculation time");
542 options.
yAxis = std::string(
"Time");
545 options.
xAxis = std::string(
"iteration");
558 cg.
write(
"gc_plot2_out.html");
This class represent an N-dimensional box.
Class for FAST cell list implementation.
CellParticleIterator getCellParticleIterator()
return the celllist iterator (across cells)
Small class to produce graph with Google chart in HTML.
void write(std::string file)
It write the graphs on file in html format using Google charts.
void AddLinesGraph(openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
Add a simple lines graph.
This class implement the point shape in an N-dimensional space.
Implementation of VCluster class.
Implementation of 1-D std::vector like structure.
Class for cpu time benchmarking.
void stop()
Stop the timer.
void start()
Start the timer.
double getwct()
Return the elapsed real time.
std::string xAxis
X axis name.
size_t lineWidth
Width of the line.
std::string title
Title of the chart.
std::string yAxis
Y axis name.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...