OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
main_expr.cpp
1 #include "Vector/vector_dist.hpp"
2 #include "Plot/GoogleChart.hpp"
3 #include "Operators/Vector/vector_dist_operators.hpp"
4 
5 constexpr int velocity = 0;
6 constexpr int force = 1;
7 
8 struct ln_potential
9 {
10  double sigma12,sigma6;
11 
12  ln_potential(double sigma12_, double sigma6_) {sigma12 = sigma12_, sigma6 = sigma6_;}
13 
14  Point<2,double> value(const Point<3,double> & xp, const Point<3,double> xq)
15  {
16  double rn = norm2(xp - xq);
17 
18  Point<2,double> E({4.0 * ( sigma12 / (rn*rn*rn*rn*rn*rn) - sigma6 / ( rn*rn*rn) ),
19  0.0});
20 
21  return E;
22  }
23 };
24 
25 struct ln_force
26 {
27  double sigma12,sigma6;
28 
29  ln_force(double sigma12_, double sigma6_) {sigma12 = sigma12_; sigma6 = sigma6_;}
30 
31  Point<3,double> value(const Point<3,double> & xp, const Point<3,double> xq)
32  {
33  Point<3,double> r = xp - xq;
34  double rn = norm2(r);
35 
36  return 24.0*(2.0 * sigma12 / (rn*rn*rn*rn*rn*rn*rn) - sigma6 / (rn*rn*rn*rn)) * r;
37  }
38 };
39 
40 int main(int argc, char* argv[])
41 {
42  double dt = 0.0005, sigma = 0.1, r_cut = 0.3;
43 
44  double sigma6 = pow(sigma,6), sigma12 = pow(sigma,12);
45 
48 
49 
50  openfpm_init(&argc,&argv);
51  Vcluster & vcl = create_vcluster();
52 
53  size_t sz[3] = {10,10,10};
54  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
55  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
56  Ghost<3,float> ghost(r_cut);
57 
58  ln_force lf(sigma12,sigma6);
59  ln_potential lp(sigma12,sigma6);
60 
62 
63  auto v_force = getV<force>(vd);
64  auto v_velocity = getV<velocity>(vd);
65  auto v_pos = getV<PROP_POS>(vd);
66 
67  auto it = vd.getGridIterator(sz);
68 
69  while (it.isNext())
70  {
71  vd.add();
72 
73  auto key = it.get();
74 
75  vd.getLastPos()[0] = key.get(0) * it.getSpacing(0);
76  vd.getLastPos()[1] = key.get(1) * it.getSpacing(1);
77  vd.getLastPos()[2] = key.get(2) * it.getSpacing(2);
78 
79  ++it;
80  }
81 
82  v_force = 0;
83  v_velocity = 0;
84 
85  auto NN = vd.getCellList(r_cut);
86 
87  vd.updateCellList(NN);
88  v_force = applyKernel_in_sim(vd,NN,lf);
89  unsigned long int f = 0;
90 
91  // MD time stepping
92  for (size_t i = 0; i < 10000 ; i++)
93  {
94  assign(v_velocity, v_velocity + 0.5*dt*v_force,
95  v_pos, v_pos + v_velocity*dt);
96 
97  vd.map();
98  vd.template ghost_get<>();
99 
100  // calculate forces or a(tn + 1) Step 2
101  vd.updateCellList(NN);
102  v_force = applyKernel_in_sim(vd,NN,lf);
103 
104  v_velocity = v_velocity + 0.5*dt*v_force;
105 
106  if (i % 100 == 0)
107  {
108  vd.deleteGhost();
109  vd.write("particles_",f);
110  vd.ghost_get<>();
111 
112  Point<2,double> E = rsum(applyKernel_in_sim(vd,NN,lp) + (v_velocity * v_velocity)/2.0,vd).get();
113 
114  vcl.sum(E.get(0));vcl.sum(E.get(1));
115  vcl.execute();
116 
117  // we save the energy calculated at time step i c contain the time-step y contain the energy
118  x.add(i);
119  y.add({E.get(0),E.get(1),E.get(0) - E.get(1)});
120 
121  if (vcl.getProcessUnitID() == 0)
122  std::cout << "Energy Total: " << E.get(0) << " Kinetic: " << E.get(1) << " Potential: " << E.get(0) - E.get(1) << std::endl;
123 
124  f++;
125  }
126  }
127 
128  GCoptions options;
129  options.title = std::string("Energy with time");
130  options.yAxis = std::string("Energy");
131  options.xAxis = std::string("iteration");
132  options.lineWidth = 1.0;
133 
134  GoogleChart cg;
135  cg.AddLinesGraph(x,y,options);
136  cg.write("gc_plot2_out.html");
137 
138  openfpm_finalize();
139 }
void sum(T &num)
Sum the numbers across all processors and get the result.
void AddLinesGraph(openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
Add a simple lines graph.
size_t getProcessUnitID()
Get the process unit id.
void execute()
Execute all the requests.
std::string title
Title of the chart.
Definition: GoogleChart.hpp:27
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
Definition: Ghost.hpp:39
Implementation of VCluster class.
Definition: VCluster.hpp:36
std::string yAxis
Y axis name.
Definition: GoogleChart.hpp:29
Small class to produce graph with Google chart in HTML.
const T & get(size_t i) const
Get coordinate.
Definition: Point.hpp:142
size_t lineWidth
Width of the line.
Definition: GoogleChart.hpp:55
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:201
void write(std::string file)
It write the graphs on file in html format using Google charts.
Distributed vector.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61
std::string xAxis
X axis name.
Definition: GoogleChart.hpp:31
Google chart options.
Definition: GoogleChart.hpp:24