OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
energy_force.hpp
1/*
2 * energy_force.hpp
3 *
4 * Created on: Aug 6, 2016
5 * Author: i-bird
6 */
7
8#ifndef EXAMPLE_VECTOR_4_REORDER_ENERGY_FORCE_HPP_
9#define EXAMPLE_VECTOR_4_REORDER_ENERGY_FORCE_HPP_
10
11constexpr int velocity = 0;
12constexpr int force = 1;
13
14
15template<typename CellList> void calc_forces(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, CellList & NN, double sigma12, double sigma6)
16{
17 // update the Cell-list
18 vd.updateCellList(NN);
19
20 // Get an iterator over particles
21 auto it2 = vd.getDomainIterator();
22
23 // For each particle p ...
24 while (it2.isNext())
25 {
26 // ... get the particle p
27 auto p = it2.get();
28
29 // Get the position xp of the particle
30 Point<3,double> xp = vd.getPos(p);
31
32 // Reset the forice counter
33 vd.template getProp<force>(p)[0] = 0.0;
34 vd.template getProp<force>(p)[1] = 0.0;
35 vd.template getProp<force>(p)[2] = 0.0;
36
37 // Get an iterator over the neighborhood particles of p
38 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(vd.getPos(p)));
39
40 // For each neighborhood particle ...
41 while (Np.isNext())
42 {
43 // ... q
44 auto q = Np.get();
45
46 // if (p == q) skip this particle
47 if (q == p.getKey()) {++Np; continue;};
48
49 // Get the position of p
50 Point<3,double> xq = vd.getPos(q);
51
52 // Get the distance between p and q
53 Point<3,double> r = xp - xq;
54
55 // take the norm of this vector
56 double rn = norm2(r);
57
58 // Calculate the force, using pow is slower
59 Point<3,double> f = 24.0*(2.0 *sigma12 / (rn*rn*rn*rn*rn*rn*rn) - sigma6 / (rn*rn*rn*rn)) * r;
60
61 // we sum the force produced by q on p
62 vd.template getProp<force>(p)[0] += f.get(0);
63 vd.template getProp<force>(p)[1] += f.get(1);
64 vd.template getProp<force>(p)[2] += f.get(2);
65
66 // Next neighborhood
67 ++Np;
68 }
69
70 // Next particle
71 ++it2;
72 }
73}
74
75
76template<typename CellList> double calc_energy(vector_dist<3,double, aggregate<double[3],double[3]> > & vd, CellList & NN, double sigma12, double sigma6)
77{
78 double E = 0.0;
79
80 // Update the cell-list
81 vd.updateCellList(NN);
82
83 // Get the iterator
84 auto it2 = vd.getDomainIterator();
85
86 // For each particle ...
87 while (it2.isNext())
88 {
89 // ... p
90 auto p = it2.get();
91
92 // Get the position of the particle p
93 Point<3,double> xp = vd.getPos(p);
94
95 // Reset the force
96 vd.template getProp<force>(p)[0] = 0.0;
97 vd.template getProp<force>(p)[1] = 0.0;
98 vd.template getProp<force>(p)[2] = 0.0;
99
100 // Get an iterator over the neighborhood of the particle p
101 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(vd.getPos(p)));
102
103 // For each neighborhood of the particle p
104 while (Np.isNext())
105 {
106 // Neighborhood particle q
107 auto q = Np.get();
108
109 // if p == q skip this particle
110 if (q == p.getKey()) {++Np; continue;};
111
112 // Get position of the particle q
113 Point<3,double> xq = vd.getPos(q);
114
115 // take the normalized direction
116 double rn = norm2(xp - xq);
117
118 // potential energy (using pow is slower)
119 E += 4.0 * ( sigma12 / (rn*rn*rn*rn*rn*rn) - sigma6 / ( rn*rn*rn) );
120
121 // Next neighborhood
122 ++Np;
123 }
124
125 // Kinetic energy of the particle given by its actual speed
126 E += (vd.template getProp<velocity>(p)[0]*vd.template getProp<velocity>(p)[0] +
127 vd.template getProp<velocity>(p)[1]*vd.template getProp<velocity>(p)[1] +
128 vd.template getProp<velocity>(p)[2]*vd.template getProp<velocity>(p)[2]) / 2;
129
130 // Next Particle
131 ++it2;
132 }
133
134 return E;
135}
136
137
138#endif /* EXAMPLE_VECTOR_4_REORDER_ENERGY_FORCE_HPP_ */
Class for FAST cell list implementation.
Definition CellList.hpp:357
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
Distributed vector.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...