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"
43constexpr int velocity = 0;
44constexpr int force = 1;
48template<
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);
60 auto it2 = NN.getIterator();
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.template getNNIterator<NO_CHECK>(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);
143template<
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);
151 auto it2 = NN.getIterator();
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.template getNNIterator<NO_CHECK>(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;
208int 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;
415 auto NN = vd.getCellList_hilb(r_cut);
418 calc_forces(vd,NN,sigma12,sigma6);
419 unsigned long int f = 0;
425 size_t Nstep = 30000;
431 for (
size_t i = 0; i < Nstep ; i++)
434 auto it3 = vd.getDomainIterator();
442 vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
443 vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
444 vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];
447 vd.getPos(p)[0] += vd.template getProp<velocity>(p)[0]*dt;
448 vd.getPos(p)[1] += vd.template getProp<velocity>(p)[1]*dt;
449 vd.getPos(p)[2] += vd.template getProp<velocity>(p)[2]*dt;
456 vd.template ghost_get<>();
463 calc_forces(vd,NN,sigma12,sigma6);
473 auto it4 = vd.getDomainIterator();
480 vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
481 vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
482 vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];
492 vd.write(
"particles_",f);
498 double energy = calc_energy(vd,NN,sigma12,sigma6);
499 auto & vcl = create_vcluster();
505 if (vcl.getProcessUnitID() == 0)
506 std::cout << std::endl <<
"Energy: " << energy << std::endl;
513 std::cout <<
"Performance: " << time2.
getwct() << std::endl;
538 options.
title = std::string(
"Force calculation time");
541 options.
yAxis = std::string(
"Time");
544 options.
xAxis = std::string(
"iteration");
557 cg.
write(
"gc_plot2_out.html");
This class represent an N-dimensional box.
Class for FAST cell list implementation.
auto get(size_t cell, size_t ele) -> decltype(this->Mem_type::get(cell, ele))
Get an element in the cell.
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...