main implementing the time loop.
69 {
70
71 cdf::timer::timer_t timer;
72
73
74 constexpr auto filename = "velocity.json";
75
76 nlohmann::json j;
77 std::ifstream inbuf (filename);
78
79
80 #ifdef USE_THRUST
81 inbuf >> j;
83 std::unique_ptr<quadgrid_t<vector_t<real_t>>> qg;
84 std::unique_ptr<particles_t> p;
85 qg = std::make_unique<quadgrid_t<vector_t<real_t>>> (j["grid_properties"]);
86 p = std::make_unique<particles_t> (j, *qg);
87
88 p->build_mass();
89 p->init_particle_mesh();
90
91 std::map<std::string, vector_t<real_t>> vars=
92 j["grid_vars"].get<std::map<std::string, vector_t<real_t>>> ();
93
94
95 p->memcpy_host_to_device();
96
97 for (const auto & g : vars)
98 p->device_grid_vars[g.first] = g.second;
99
100 inbuf.close ();
101
102
103
104 stepper state (thrust::raw_pointer_cast(p->device_x.data()), thrust::raw_pointer_cast(p->device_y.data()), thrust::raw_pointer_cast(p->device_dprops[
"VX"].data()), thrust::raw_pointer_cast(p->device_dprops[
"VY"].data()), 1., 1.e-5);
105
106
107 thrust::counting_iterator<idx_t> first_p(0), last_p(p -> num_particles);
108
109 #else
110 inbuf >> j;
111
112
114
115
116
118
119
120 p.build_mass ();
121
122
123 std::map<std::string, vector_t<real_t>> vars=
124 j["grid_vars"].get<std::map<std::string, vector_t<real_t>>> ();
125
126 inbuf.close ();
127
128
129
130
131
132
133
134
135
136 stepper state (p.x.data(), p.y.data(), p.dprops[
"VX"].data(), p.dprops[
"VY"].data(), 1., 1.e-5);
137
138
139
140 p.init_particle_mesh ();
141
142 #endif
143
144
145
146 for (int it = 0; it < 1000; ++it) {
147
148 #ifdef USE_THRUST
149 thrust::fill(p->device_dprops["VX"].begin (), p->device_dprops["VX"].end (), 0.0);
150 thrust::fill(p->device_dprops["VX"].begin (), p->device_dprops["VY"].end (), 0.0);
151 thrust::fill(p->device_grid_vars["rho"].begin (), p->device_grid_vars["rho"].end (), 0.0);
152 #else
153
154 std::fill(p.dprops["VX"].begin (), p.dprops["VX"].end (), 0.0);
155 std::fill(p.dprops["VY"].begin (), p.dprops["VY"].end (), 0.0);
156 std::fill(vars["rho"].begin (), vars["rho"].end (), 0.0);
157 #endif
158
159
160 timer.tic("g2p");
161 #ifdef USE_THRUST
162 p->g2p(p->device_grid_vars, {"vx", "vy"}, {"VX", "VY"});
163 #else
164 p.g2p (vars, {"vx", "vy"}, {"VX", "VY"});
165 #endif
166
167 timer.toc("g2p");
168
169
170 timer.tic("move partcles");
171
172
173
174
175
176
177
178 #ifdef USE_THRUST
179 thrust::for_each(thrust::device, first_p, last_p, state);
180 #else
181
182 range rng (0, p.num_particles);
183 std::for_each (rng.begin (), rng.end (), state);
184 #endif
185
186
187 timer.toc("move partcles");
188
189
190
191 timer.tic("init_particle_mesh");
192 #ifdef USE_THRUST
193 p->update_ptcl_to_grd<particles_t::update_ptcl_to_grd_device>();
194 #else
196 #endif
197
198 timer.toc("init_particle_mesh");
199
200
201
202 timer.tic("p2g");
203 #ifdef USE_THRUST
204 p->p2g (p->device_grid_vars, {"M"}, {"rho"}, true);
205 #else
206 p.p2g (vars, {"M"}, {"rho"}, true);
207 #endif
208
209 timer.toc("p2g");
210
211
212 if (it % 50 == 0) {
213 #ifdef USE_THRUST
214 p->memcpy_device_to_host();
215
216 thrust::copy (p->device_grid_vars["rho"].cbegin(), p->device_grid_vars["rho"].cend(), vars.at("rho").begin());
217
218
219 const std::string ofilename = "particle";
220 const std::string ofileext = ".csv";
221 const std::string numfile = std::string(".") + std::to_string(it);
222
223 std::ofstream outbuf (ofilename + numfile + ofileext);
225
226 outbuf.close ();
227
228
229 const std::string gfilename = std::string("grid.") + std::to_string(it) + std::string(".vts");
230 qg->vtk_export (gfilename.c_str(), vars);
231 #else
232
233 const std::string ofilename = "particle";
234 const std::string ofileext = ".csv";
235 const std::string numfile = std::string(".") + std::to_string(it);
236
237 std::ofstream outbuf (ofilename + numfile + ofileext);
239
240 outbuf.close ();
241
242
243 const std::string gfilename = std::string("grid.") + std::to_string(it) + std::string(".vts");
244 qg.vtk_export (gfilename.c_str(), vars);
245 #endif
246
247 }
248 }
249
250
251 timer.print_report();
252 return 0;
253}
Functor class for moving particles.
Class to represent particles embedded in a grid.
quadgrid_t< vector_t< real_t > >::idx_t idx_t
datatype for indexing into vectors of properties