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" 
   30 constexpr 
int velocity = 0;
 
   31 constexpr 
int force = 1;
 
   65 void calc_forces(
vector_dist<3,
double, 
aggregate<
double[3],
double[3]> > & vd, 
VerletList<3, 
double, 
Mem_fast<>, 
shift<3, double> > & NN, 
double sigma12, 
double sigma6, 
double r_cut)
 
   70     auto it2 = vd.getDomainIterator();
 
   82         vd.template getProp<force>(p)[0] = 0.0;
 
   83         vd.template getProp<force>(p)[1] = 0.0;
 
   84         vd.template getProp<force>(p)[2] = 0.0;
 
   89         auto Np = NN.template getNNIterator<NO_CHECK>(p.getKey());
 
  100             if (q == p.getKey())    {++Np; 
continue;};
 
  109             double rn = norm2(r);
 
  111             if (rn > r_cut * r_cut) {++Np;
continue;}
 
  114             Point<3,double> f = 24.0*(2.0 *sigma12 / (rn*rn*rn*rn*rn*rn*rn) -  sigma6 / (rn*rn*rn*rn)) * r;
 
  117             vd.template getProp<force>(p)[0] += f.
get(0);
 
  118             vd.template getProp<force>(p)[1] += f.
get(1);
 
  119             vd.template getProp<force>(p)[2] += f.
get(2);
 
  153 double calc_energy(
vector_dist<3,
double, 
aggregate<
double[3],
double[3]> > & vd, 
VerletList<3, 
double, 
Mem_fast<>, 
shift<3, double> > & NN, 
double sigma12, 
double sigma6, 
double r_cut)
 
  157     double rc = r_cut*r_cut;
 
  158     double shift = 2.0 * ( sigma12 / (rc*rc*rc*rc*rc*rc) - sigma6 / ( rc*rc*rc) );
 
  161     auto it2 = vd.getDomainIterator();
 
  173         auto Np = NN.template getNNIterator<NO_CHECK>(p.getKey());
 
  182             if (q == p.getKey())    {++Np; 
continue;};
 
  188             double rn = norm2(xp - xq);
 
  190             if (rn >= r_cut*r_cut)
 
  194             E += 2.0 * ( sigma12 / (rn*rn*rn*rn*rn*rn) - sigma6 / ( rn*rn*rn) ) - shift;
 
  201         E +=   (vd.template getProp<velocity>(p)[0]*vd.template getProp<velocity>(p)[0] +
 
  202                 vd.template getProp<velocity>(p)[1]*vd.template getProp<velocity>(p)[1] +
 
  203                 vd.template getProp<velocity>(p)[2]*vd.template getProp<velocity>(p)[2]) / 2;
 
  215 int main(
int argc, 
char* argv[])
 
  266     double r_cut = 3.0*sigma;
 
  267     double r_gskin = 1.3*r_cut;
 
  268     double sigma12 = pow(sigma,12);
 
  269     double sigma6 = pow(sigma,6);
 
  274     openfpm_init(&argc,&argv);
 
  275     Vcluster & v_cl = create_vcluster();
 
  278     size_t sz[3] = {10,10,10};
 
  284     size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
 
  291     auto it = vd.getGridIterator(sz);
 
  299         vd.getLastPos()[0] = 
key.get(0) * it.getSpacing(0);
 
  300         vd.getLastPos()[1] = 
key.get(1) * it.getSpacing(1);
 
  301         vd.getLastPos()[2] = 
key.get(2) * it.getSpacing(2);
 
  303         vd.template getLastProp<velocity>()[0] = 0.0;
 
  304         vd.template getLastProp<velocity>()[1] = 0.0;
 
  305         vd.template getLastProp<velocity>()[2] = 0.0;
 
  307         vd.template getLastProp<force>()[0] = 0.0;
 
  308         vd.template getLastProp<force>()[1] = 0.0;
 
  309         vd.template getLastProp<force>()[2] = 0.0;
 
  320     auto NN = vd.getVerlet(r_gskin);
 
  325     calc_forces(vd,NN,sigma12,sigma6,r_cut);
 
  326     unsigned long int f = 0;
 
  329     double max_disp = 0.0;
 
  332     for (
size_t i = 0; i < 10000 ; i++)
 
  335         auto it3 = vd.getDomainIterator();
 
  337         double max_displ = 0.0;
 
  345             vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
 
  346             vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
 
  347             vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];
 
  349             Point<3,double> disp({vd.template getProp<velocity>(p)[0]*dt,vd.template getProp<velocity>(p)[1]*dt,vd.template getProp<velocity>(p)[2]*dt});
 
  352             vd.getPos(p)[0] += disp.get(0);
 
  353             vd.getPos(p)[1] += disp.get(1);
 
  354             vd.getPos(p)[2] += disp.get(2);
 
  356             if (disp.norm() > max_displ)
 
  357                 max_displ = disp.norm();
 
  362         if (max_disp < max_displ)
 
  363             max_disp = max_displ;
 
  371             vd.template ghost_get<>();
 
  373             vd.updateVerlet(NN,r_gskin);
 
  377             vd.template ghost_get<>(SKIP_LABELLING);
 
  385         calc_forces(vd,NN,sigma12,sigma6,r_cut);
 
  388         auto it4 = vd.getDomainIterator();
 
  395             vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
 
  396             vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
 
  397             vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];
 
  407             vd.write(
"particles_",f);
 
  410             vd.ghost_get<>(SKIP_LABELLING);
 
  413             double energy = calc_energy(vd,NN,sigma12,sigma6,r_cut);
 
  414             auto & vcl = create_vcluster();
 
  425             if (vcl.getProcessUnitID() == 0)
 
  426                 std::cout << 
"Energy: " << energy << 
"   " << max_disp << 
"  " << std::endl;
 
  435     std::cout << 
"Time: " << tsim.
getwct()  << std::endl;
 
  443     options.
title = std::string(
"Energy with time");
 
  446     options.
yAxis = std::string(
"Energy");
 
  449     options.
xAxis = std::string(
"iteration");
 
  462     cg.
write(
"gc_plot2_out.html");
 
void AddLinesGraph(openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
Add a simple lines graph. 
 
Class for Verlet list implementation. 
 
std::string title
Title of the chart. 
 
This class implement the point shape in an N-dimensional space. 
 
double getwct()
Return the elapsed real time. 
 
Implementation of VCluster class. 
 
std::string yAxis
Y axis name. 
 
Small class to produce graph with Google chart in HTML. 
 
void start()
Start the timer. 
 
const T & get(size_t i) const 
Get coordinate. 
 
size_t lineWidth
Width of the line. 
 
This class is a trick to indicate the compiler a specific specialization pattern. ...
 
void write(std::string file)
It write the graphs on file in html format using Google charts. 
 
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
 
Implementation of 1-D std::vector like structure. 
 
std::string xAxis
X axis name. 
 
Class for cpu time benchmarking. 
 
void stop()
Stop the timer.