OpenFPM  5.2.0
Project that contain the implementation of distributed structures
DCPSE_op_test_temporal.cpp
1 /*
2  * DCPSE_op_test_temporal.cpp
3  *
4  * Created on: Sep 15, 2020
5  * Author: i-bird
6  */
7 #include "config.h"
8 #ifdef HAVE_EIGEN
9 #ifdef HAVE_PETSC
10 
11 #ifndef DCPSE_OP_TEST_TEMPORAL_CPP_
12 #define DCPSE_OP_TEST_TEMPORAL_CPP_
13 
14 #define BOOST_TEST_DYN_LINK
15 
16 #include <boost/test/unit_test.hpp>
17 #include "Operators/Vector/vector_dist_operators.hpp"
18 #include "DCPSE/DCPSE_op/DCPSE_op.hpp"
19 
20 BOOST_AUTO_TEST_SUITE(temporal_test_suite)
21 
22  BOOST_AUTO_TEST_CASE(temporal_test)
23  {
24  size_t grd_sz = 12;
25  double boxsize = 10;
26  const size_t sz[3] = {grd_sz, grd_sz, grd_sz};
27  Box<3, double> box({0, 0, 0}, {boxsize, boxsize, boxsize});
28  size_t bc[3] = {NON_PERIODIC, NON_PERIODIC, NON_PERIODIC};
29  double Lx = box.getHigh(0);
30  double Ly = box.getHigh(1);
31  double Lz = box.getHigh(2);
32  double spacing = box.getHigh(0) / (sz[0] - 1);
33  double rCut = 3.9 * spacing;
34  double rCut2 = 3.9 * spacing;
35  int ord = 2;
36  int ord2 = 2;
37  double sampling_factor = 4.0;
38  double sampling_factor2 = 2.4;
39  Ghost<3, double> ghost(rCut);
40  auto &v_cl = create_vcluster();
41 
42  vector_dist<3, double, aggregate<double,VectorS<3, double>,double[3][3],double,VectorS<3,double>,double[3][3]> > Particles(0, box, bc, ghost);
43 
44  auto it = Particles.getGridIterator(sz);
45  while (it.isNext())
46  {
47  Particles.add();
48  auto key = it.get();
49  double x = key.get(0) * it.getSpacing(0);
50  Particles.getLastPos()[0] = x;
51  double y = key.get(1) * it.getSpacing(1);
52  Particles.getLastPos()[1] = y;
53  double z = key.get(2) * it.getSpacing(1);
54  Particles.getLastPos()[2] = z;
55  ++it;
56  }
57 
58  Particles.map();
59  Particles.ghost_get<0>();
60 
61  constexpr int x = 0;
62  constexpr int y = 1;
63  constexpr int z = 2;
64 
65 
66  constexpr int sScalar = 0;
67  constexpr int sVector = 1;
68  constexpr int sTensor = 2;
69  constexpr int dScalar = 3;
70  constexpr int dVector = 4;
71  constexpr int dTensor = 5;
72  auto Pos = getV<POS_PROP>(Particles);
73  auto sS = getV<sScalar>(Particles);
74  auto sV = getV<sVector>(Particles);
75  auto sT = getV<sTensor>(Particles);
76  auto dS = getV<dScalar>(Particles);
77  auto dV = getV<dVector>(Particles);
78  auto dT = getV<dTensor>(Particles);
79 
80  //Particles_subset.write("Pars");
81  auto verletList = Particles.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
82 
83  Derivative_x<decltype(verletList)> Dx(Particles, verletList, ord, rCut, support_options::RADIUS);
84  Derivative_x<decltype(verletList)> Bulk_Dx(Particles, verletList, ord, rCut, support_options::RADIUS);
85  texp_v<double> TVx,TdxVx;
88 
89 
90  auto it3 = Particles.getDomainIterator();
91 
92  sS = 5;
93  sV[0] = 1;
94  sV[1] = 2;
95  sV[2] = 3;
96  sT[0][0] = 1;
97  sT[0][1] = 2;
98  sT[0][2] = 3;
99  sT[1][0] = 4;
100  sT[1][1] = 5;
101  sT[1][2] = 6;
102  sT[2][0] = 7;
103  sT[2][1] = 8;
104  sT[2][2] = 9;
105  TVx=sS;
106  dS = TVx;
107 
108  {
109  auto it3 = Particles.getDomainIterator();
110 
111  bool match = true;
112  while (it3.isNext())
113  {
114  auto key = it3.get();
115 
116  match &= Particles.template getProp<sScalar>(key) == Particles.template getProp<dScalar>(key);
117 
118  ++it3;
119  }
120 
121  BOOST_REQUIRE_EQUAL(match,true);
122  }
123 
124 
125  TVx=sS*sS;
126  dS = TVx;
127 
128  {
129  auto it3 = Particles.getDomainIterator();
130 
131  bool match = true;
132  while (it3.isNext())
133  {
134  auto key = it3.get();
135 
136  match &= Particles.template getProp<sScalar>(key)*Particles.template getProp<sScalar>(key) == Particles.template getProp<dScalar>(key);
137 
138  ++it3;
139  }
140 
141  BOOST_REQUIRE_EQUAL(match,true);
142  }
143 
144  TVx=sV[0];
145  dS = TVx;
146 
147  {
148  auto it3 = Particles.getDomainIterator();
149 
150  bool match = true;
151  while (it3.isNext())
152  {
153  auto key = it3.get();
154 
155  match &= Particles.template getProp<sVector>(key)[0] == Particles.template getProp<dScalar>(key);
156 
157  ++it3;
158  }
159  BOOST_REQUIRE_EQUAL(match,true);
160  }
161 
162  TVx=sT[0][0];
163  dS = TVx;
164  {
165  auto it3 = Particles.getDomainIterator();
166 
167  bool match = true;
168  while (it3.isNext())
169  {
170  auto key = it3.get();
171 
172  match &= Particles.template getProp<sVector>(key)[0] == Particles.template getProp<dScalar>(key);
173 
174  ++it3;
175  }
176  BOOST_REQUIRE_EQUAL(match,true);
177  }
178 
179  TV=sV;
180  dV=TV;
181 
182  {
183  auto it3 = Particles.getDomainIterator();
184 
185  bool match = true;
186  while (it3.isNext())
187  {
188  auto key = it3.get();
189 
190  match &= Particles.template getProp<sVector>(key)[0] == Particles.template getProp<dVector>(key)[0];
191  match &= Particles.template getProp<sVector>(key)[1] == Particles.template getProp<dVector>(key)[1];
192  match &= Particles.template getProp<sVector>(key)[2] == Particles.template getProp<dVector>(key)[2];
193 
194  ++it3;
195  }
196  BOOST_REQUIRE_EQUAL(match,true);
197  }
198 
199  TV=0.5*sV+sV;
200  dV=TV;
201  //Pol_bulk = dPol + (0.5 * dt) * k1;
202  {
203  auto it3 = Particles.getDomainIterator();
204 
205  bool match = true;
206  while (it3.isNext())
207  {
208  auto key = it3.get();
209  double x1=Particles.template getProp<sVector>(key)[0];
210  double y1=Particles.template getProp<dVector>(key)[0];
211  double x2=Particles.template getProp<sVector>(key)[1];
212  double y2=Particles.template getProp<dVector>(key)[1];
213  double x3=Particles.template getProp<sVector>(key)[2];
214  double y3=Particles.template getProp<dVector>(key)[2];
215 
216  match &= 1.5*Particles.template getProp<sVector>(key)[0] == Particles.template getProp<dVector>(key)[0];
217  match &= 1.5*Particles.template getProp<sVector>(key)[1] == Particles.template getProp<dVector>(key)[1];
218  match &= 1.5*Particles.template getProp<sVector>(key)[2] == Particles.template getProp<dVector>(key)[2];
219 
220  ++it3;
221  }
222  BOOST_REQUIRE_EQUAL(match,true);
223  }
224 
225  TV=sV;
226  dV=pmul(TV,TV);
227  //Pol_bulk = dPol + (0.5 * dt) * k1;
228  {
229  auto it3 = Particles.getDomainIterator();
230 
231  bool match = true;
232  while (it3.isNext())
233  {
234  auto key = it3.get();
235  double x1=Particles.template getProp<sVector>(key)[0];
236  double y1=Particles.template getProp<dVector>(key)[0];
237  double x2=Particles.template getProp<sVector>(key)[1];
238  double y2=Particles.template getProp<dVector>(key)[1];
239  double x3=Particles.template getProp<sVector>(key)[2];
240  double y3=Particles.template getProp<dVector>(key)[2];
241 
242  match &= Particles.template getProp<sVector>(key)[0]*Particles.template getProp<sVector>(key)[0] == Particles.template getProp<dVector>(key)[0];
243  match &= Particles.template getProp<sVector>(key)[1]*Particles.template getProp<sVector>(key)[1] == Particles.template getProp<dVector>(key)[1];
244  match &= Particles.template getProp<sVector>(key)[2]*Particles.template getProp<sVector>(key)[2] == Particles.template getProp<dVector>(key)[2];
245 
246  ++it3;
247  }
248  //THERE IS A BUG HERE IT IS SUMMING THE VECTORS.
249  BOOST_REQUIRE_EQUAL(match,true);
250  }
251 
252 /*
253  TdxVx=Dx(sV[x]);
254  TT[0][0] = Dx(sV[x]);*/
255 
256  }
257 
258 BOOST_AUTO_TEST_SUITE_END()
259 
260 #endif /* DCPSE_OP_TEST_TEMPORAL_CPP_ */
261 #endif
262 #endif
This class represent an N-dimensional box.
Definition: Box.hpp:60
Definition: Ghost.hpp:40
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:28
Main class that encapsulate a vector properties operand to be used for expressions construction.
Distributed vector.