1#include "Vector/vector_dist.hpp"
2#include "Decomposition/CartDecomposition.hpp"
3#include "data_type/aggregate.hpp"
4#include "Plot/GoogleChart.hpp"
5#include "Plot/util.hpp"
14typedef float real_number;
16constexpr int velocity = 0;
17constexpr int force = 1;
20template<
typename VerletList>
21void calc_forces(
vector_dist<3,real_number,
aggregate<real_number[3],real_number[3]> > & vd,
VerletList & NN, real_number sigma12, real_number sigma6, real_number r_cut)
25 auto itg = vd.getDomainAndGhostIterator();
32 vd.getProp<force>(p)[0] = 0.0;
33 vd.getProp<force>(p)[1] = 0.0;
34 vd.getProp<force>(p)[2] = 0.0;
42 auto it2 = vd.getParticleIteratorCRS(NN);
57 auto Np = NN.template getNNIterator<NO_CHECK>(p);
66 if (q == p) {++Np;
continue;};
75 real_number rn = norm2(r);
77 if (rn > r_cut * r_cut) {++Np;
continue;}
80 Point<3,real_number> f = 24.0*(2.0 *sigma12 / (rn*rn*rn*rn*rn*rn*rn) - sigma6 / (rn*rn*rn*rn)) * r;
83 vd.template getProp<force>(p)[0] += f.get(0);
84 vd.template getProp<force>(p)[1] += f.get(1);
85 vd.template getProp<force>(p)[2] += f.get(2);
90 vd.template getProp<force>(q)[0] -= f.get(0);
91 vd.template getProp<force>(q)[1] -= f.get(1);
92 vd.template getProp<force>(q)[2] -= f.get(2);
105 vd.ghost_put<
add_,force>();
109template<
typename VerletList>
110real_number calc_energy(
vector_dist<3,real_number,
aggregate<real_number[3],real_number[3]> > & vd,
VerletList & NN, real_number sigma12, real_number sigma6, real_number r_cut)
114 real_number rc = r_cut*r_cut;
115 real_number
shift = 4.0 * ( sigma12 / (rc*rc*rc*rc*rc*rc) - sigma6 / ( rc*rc*rc) );
118 auto it2 = vd.getParticleIteratorCRS(NN);
130 auto Np = NN.template getNNIterator<NO_CHECK>(p);
141 if (q == p) {++Np;
continue;};
147 real_number rn = norm2(xp - xq);
149 if (rn >= r_cut*r_cut) {++Np;
continue;}
152 E += 4.0 * ( sigma12 / (rn*rn*rn*rn*rn*rn) - sigma6 / ( rn*rn*rn) ) -
shift;
162 if (p < vd.size_local())
165 E += (vd.template getProp<velocity>(p)[0]*vd.template getProp<velocity>(p)[0] +
166 vd.template getProp<velocity>(p)[1]*vd.template getProp<velocity>(p)[1] +
167 vd.template getProp<velocity>(p)[2]*vd.template getProp<velocity>(p)[2]) / 2;
178int main(
int argc,
char* argv[])
180 real_number dt = 0.00005;
181 real_number sigma = 0.01;
182 real_number r_cut = 3.0*sigma;
183 real_number r_gskin = 1.3*r_cut;
184 real_number sigma12 = pow(sigma,12);
185 real_number sigma6 = pow(sigma,6);
190 openfpm_init(&argc,&argv);
194 size_t sz[3] = {100,100,100};
200 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
211 size_t start = vd.accum();
213 auto it = vd.getGridIterator(sz);
221 vd.getLastPos()[0] = key.get(0) * it.getSpacing(0);
222 vd.getLastPos()[1] = key.get(1) * it.getSpacing(1);
223 vd.getLastPos()[2] = key.get(2) * it.getSpacing(2);
225 vd.template getLastProp<velocity>()[0] = 0.0;
226 vd.template getLastProp<velocity>()[1] = 0.0;
227 vd.template getLastProp<velocity>()[2] = 0.0;
229 vd.template getLastProp<force>()[0] = 0.0;
230 vd.template getLastProp<force>()[1] = 0.0;
231 vd.template getLastProp<force>()[2] = 0.0;
244 auto NN = vd.getVerletCrs(r_gskin);;
247 calc_forces(vd,NN,sigma12,sigma6,r_cut);
248 unsigned long int f = 0;
251 real_number max_disp = 0.0;
254 for (
size_t i = 0; i < nstep ; i++)
257 auto it3 = vd.getDomainIterator();
259 real_number max_displ = 0.0;
267 vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
268 vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
269 vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];
271 Point<3,real_number> disp({vd.template getProp<velocity>(p)[0]*dt,vd.template getProp<velocity>(p)[1]*dt,vd.template getProp<velocity>(p)[2]*dt});
274 vd.getPos(p)[0] += disp.
get(0);
275 vd.getPos(p)[1] += disp.get(1);
276 vd.getPos(p)[2] += disp.get(2);
278 if (disp.norm() > max_displ)
279 max_displ = disp.norm();
284 if (max_disp < max_displ)
285 max_disp = max_displ;
291 vd.template ghost_get<>();
293 vd.updateVerlet(NN,r_gskin,VL_CRS_SYMMETRIC);
297 vd.template ghost_get<>(SKIP_LABELLING);
303 calc_forces(vd,NN,sigma12,sigma6,r_cut);
306 auto it4 = vd.getDomainIterator();
313 vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
314 vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
315 vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];
325 vd.write(
"particles_",f);
332 real_number energy = calc_energy(vd,NN,sigma12,sigma6,r_cut);
333 auto & vcl = create_vcluster();
344 if (vcl.getProcessUnitID() == 0)
345 std::cout <<
"Energy: " << energy <<
" " << max_disp <<
" " << std::endl;
354 std::cout <<
"Time: " << tsim.
getwct() << std::endl;
360 options.
title = std::string(
"Energy with time");
363 options.
yAxis = std::string(
"Energy");
366 options.
xAxis = std::string(
"iteration");
379 cg.
write(
"gc_plot2_out.html");
This class represent an N-dimensional box.
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.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Implementation of VCluster class.
Class for Verlet list implementation.
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.
This structure define the operation add to use with copy general.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...