OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
main.cpp
1 
2 #include "util/cuda_launch.hpp"
3 #include "Grid/grid_dist_id.hpp"
4 #include "data_type/aggregate.hpp"
5 #include "timer.hpp"
6 
75 constexpr int U = 0;
76 constexpr int V = 1;
77 
78 constexpr int U_next = 2;
79 constexpr int V_next = 3;
80 
81 constexpr int x = 0;
82 constexpr int y = 1;
83 constexpr int z = 2;
84 
86 {
87  for (int i = 0 ; i < 10 ; i++)
88  {
89  timer t;
90  t.start();
91 
92  auto it = grid.getGridIterator();
93 
94  while (it.isNext())
95  {
96  // Get the local grid key
97  auto key = it.get_dist();
98 
99  // Old values U and V
100  grid.template insert<U>(key) = 1.0;
101 
102  ++it;
103  }
104 
105  t.stop();
106  std::cout << "Time populate: " << t.getwct() << std::endl;
107 
108  grid.clear();
109 
110  timer t2;
111  t2.start();
112 
113  auto it2 = grid.getGridIterator();
114 
115  while (it2.isNext())
116  {
117  // Get the local grid key
118  auto key = it2.get_dist();
119 
120  // Old values U and V
121  grid.template insert<U>(key) = 5.0;
122 
123  ++it2;
124  }
125 
126  t2.stop();
127  std::cout << "Time populate: " << t2.getwct() << std::endl;
128 
129  }
130 }
131 
132 
133 int main(int argc, char* argv[])
134 {
135  openfpm_init(&argc,&argv);
136 
137  // domain
138  Box<3,double> domain({0.0,0.0,0.0},{2.5,2.5,2.5});
139 
140  // grid size
141  size_t sz[3] = {256,256,256};
142 
143  // Define periodicity of the grid
144  periodicity<3> bc = {PERIODIC,PERIODIC,PERIODIC};
145 
146  // Ghost in grid unit
147  Ghost<3,long int> g(1);
148 
149  // deltaT
150  double deltaT = 0.25;
151 
152  // Diffusion constant for specie U
153  double du = 2*1e-5;
154 
155  // Diffusion constant for specie V
156  double dv = 1*1e-5;
157 
158  // Number of timesteps
159 #ifdef TEST_RUN
160  size_t timeSteps = 200;
161 #else
162  size_t timeSteps = 5000;
163 #endif
164 
165  // K and F (Physical constant in the equation)
166  double K = 0.053;
167  double F = 0.014;
168 
170 
172 
174 
175  // spacing of the grid on x and y
176  double spacing[3] = {grid.spacing(0),grid.spacing(1),grid.spacing(2)};
177 
178  init(grid,domain);
179 
180  // sync the ghost
181  size_t count = 0;
182  grid.template ghost_get<U,V>();
183 
184  // because we assume that spacing[x] == spacing[y] we use formula 2
185  // and we calculate the prefactor of Eq 2
186  double uFactor = deltaT * du/(spacing[x]*spacing[x]);
187  double vFactor = deltaT * dv/(spacing[x]*spacing[x]);
188 
189  timer tot_sim;
190  tot_sim.start();
191 
192  auto & v_cl = create_vcluster();
193 
194  tot_sim.stop();
195  std::cout << "Total simulation: " << tot_sim.getwct() << std::endl;
196 
197  grid.write("final");
198 
200 
212 
214  openfpm_finalize();
215 
217 
226 }
double getwct()
Return the elapsed real time.
Definition: timer.hpp:130
Definition: Ghost.hpp:39
It model an expression expr1 * expr2.
Definition: mul.hpp:119
This is a distributed grid.
void start()
Start the timer.
Definition: timer.hpp:90
This class represent an N-dimensional box.
Definition: Box.hpp:60
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:214
OutputIteratorT OffsetT ReductionOpT OuputT init
< [in] The initial value of the reduction
Boundary conditions.
Definition: common.hpp:21
Class for cpu time benchmarking.
Definition: timer.hpp:27
void stop()
Stop the timer.
Definition: timer.hpp:119
[v_transform metafunction]