1#include "Vector/vector_dist.hpp"
2#include "Plot/GoogleChart.hpp"
3#include "Plot/util.hpp"
12typedef float real_number;
14constexpr int velocity = 0;
15constexpr int force = 1;
18template<
typename CellList>
void calc_forces(
vector_dist<3,real_number,
aggregate<real_number[3],real_number[3]> > & vd,
CellList & NN, real_number sigma12, real_number sigma6, real_number r_cut2)
20 vd.updateCellList(NN);
23 auto it2 = vd.getDomainIterator();
35 vd.template getProp<force>(p)[0] = 0.0;
36 vd.template getProp<force>(p)[1] = 0.0;
37 vd.template getProp<force>(p)[2] = 0.0;
40 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(vd.getPos(p)));
49 if (q == p.getKey()) {++Np;
continue;};
58 real_number rn = norm2(r);
64 Point<3,real_number> f = 24.0*(2.0 *sigma12 / (rn*rn*rn*rn*rn*rn*rn) - sigma6 / (rn*rn*rn*rn)) * r;
67 vd.template getProp<force>(p)[0] += f.get(0);
68 vd.template getProp<force>(p)[1] += f.get(1);
69 vd.template getProp<force>(p)[2] += f.get(2);
80template<
typename CellList> real_number calc_energy(
vector_dist<3,real_number,
aggregate<real_number[3],real_number[3]> > & vd,
CellList & NN, real_number sigma12, real_number sigma6, real_number r_cut2)
82 real_number rc = r_cut2;
83 real_number
shift = 2.0 * ( sigma12 / (rc*rc*rc*rc*rc*rc) - sigma6 / ( rc*rc*rc) );
88 auto it2 = vd.getDomainIterator();
100 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(vd.getPos(p)));
109 if (q == p.getKey()) {++Np;
continue;};
115 real_number rn = norm2(xp - xq);
121 E += 2.0 * ( sigma12 / (rn*rn*rn*rn*rn*rn) - sigma6 / ( rn*rn*rn) ) -
shift;
128 E += (vd.template getProp<velocity>(p)[0]*vd.template getProp<velocity>(p)[0] +
129 vd.template getProp<velocity>(p)[1]*vd.template getProp<velocity>(p)[1] +
130 vd.template getProp<velocity>(p)[2]*vd.template getProp<velocity>(p)[2]) / 2;
141int main(
int argc,
char* argv[])
143 openfpm_init(&argc,&argv);
145 real_number sigma = 0.01;
146 real_number r_cut = 3.0*sigma;
149 size_t sz[3] = {100,100,100};
155 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
160 real_number dt = 0.00005;
161 real_number sigma12 = pow(sigma,12);
162 real_number sigma6 = pow(sigma,6);
170 auto it = vd.getGridIterator(sz);
182 vd.getLastPos()[0] = key.get(0) * it.getSpacing(0);
183 vd.getLastPos()[1] = key.get(1) * it.getSpacing(1);
184 vd.getLastPos()[2] = key.get(2) * it.getSpacing(2);
187 vd.template getLastProp<velocity>()[0] = 0.0;
188 vd.template getLastProp<velocity>()[1] = 0.0;
189 vd.template getLastProp<velocity>()[2] = 0.0;
191 vd.template getLastProp<force>()[0] = 0.0;
192 vd.template getLastProp<force>()[1] = 0.0;
193 vd.template getLastProp<force>()[2] = 0.0;
207 auto NN = vd.getCellList(r_cut);
213 calc_forces(vd,NN,sigma12,sigma6,r_cut*r_cut);
214 unsigned long int f = 0;
217 for (
size_t i = 0; i < nstep ; i++)
223 auto it3 = vd.getDomainIterator();
231 vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
232 vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
233 vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];
236 vd.getPos(p)[0] += vd.template getProp<velocity>(p)[0]*dt;
237 vd.getPos(p)[1] += vd.template getProp<velocity>(p)[1]*dt;
238 vd.getPos(p)[2] += vd.template getProp<velocity>(p)[2]*dt;
245 vd.template ghost_get<>();
248 calc_forces(vd,NN,sigma12,sigma6,r_cut*r_cut);
252 auto it4 = vd.getDomainIterator();
259 vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
260 vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
261 vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];
271 vd.write(
"particles_",f);
277 real_number energy = calc_energy(vd,NN,sigma12,sigma6,r_cut*r_cut);
278 auto & vcl = create_vcluster();
288 if (vcl.getProcessUnitID() == 0)
289 std::cout <<
"Energy: " << energy << std::endl;
299 vd.reorder(5,reorder_opt::LINEAR);
304 std::cout <<
"Time: " << tsim.
getwct() << std::endl;
310 options.
title = std::string(
"Energy with time");
313 options.
yAxis = std::string(
"Energy");
316 options.
xAxis = std::string(
"iteration");
322 options.
width = 1280;
328 options.
more = GC_ZOOM;
338 cg.
write(
"gc_plot2_out.html");
This class represent an N-dimensional box.
Class for FAST cell list implementation.
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 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.
size_t width
width of the graph in pixels
size_t heigh
height of the graph in pixels
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...