71 cdf::timer::timer_t timer;
74 constexpr auto filename =
"velocity.json";
77 std::ifstream inbuf (filename);
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);
89 p->init_particle_mesh();
91 std::map<std::string, vector_t<real_t>> vars=
92 j[
"grid_vars"].get<std::map<std::string, vector_t<real_t>>> ();
95 p->memcpy_host_to_device();
97 for (
const auto & g : vars)
98 p->device_grid_vars[g.first] = g.second;
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);
107 thrust::counting_iterator<idx_t> first_p(0), last_p(p -> num_particles);
123 std::map<std::string, vector_t<real_t>> vars=
124 j[
"grid_vars"].get<std::map<std::string, vector_t<real_t>>> ();
136 stepper state (p.x.data(), p.y.data(), p.dprops[
"VX"].data(), p.dprops[
"VY"].data(), 1., 1.e-5);
140 p.init_particle_mesh ();
146 for (
int it = 0; it < 1000; ++it) {
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);
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);
162 p->g2p(p->device_grid_vars, {
"vx",
"vy"}, {
"VX",
"VY"});
164 p.g2p (vars, {
"vx",
"vy"}, {
"VX",
"VY"});
170 timer.tic(
"move partcles");
179 thrust::for_each(thrust::device, first_p, last_p, state);
182 range rng (0, p.num_particles);
183 std::for_each (rng.
begin (), rng.
end (), state);
187 timer.toc(
"move partcles");
191 timer.tic(
"init_particle_mesh");
193 p->update_ptcl_to_grd<particles_t::update_ptcl_to_grd_device>();
198 timer.toc(
"init_particle_mesh");
204 p->p2g (p->device_grid_vars, {
"M"}, {
"rho"},
true);
206 p.p2g (vars, {
"M"}, {
"rho"},
true);
214 p->memcpy_device_to_host();
216 thrust::copy (p->device_grid_vars[
"rho"].cbegin(), p->device_grid_vars[
"rho"].cend(), vars.at(
"rho").begin());
219 const std::string ofilename =
"particle";
220 const std::string ofileext =
".csv";
221 const std::string numfile = std::string(
".") + std::to_string(it);
223 std::ofstream outbuf (ofilename + numfile + ofileext);
229 const std::string gfilename = std::string(
"grid.") + std::to_string(it) + std::string(
".vts");
230 qg->vtk_export (gfilename.c_str(), vars);
233 const std::string ofilename =
"particle";
234 const std::string ofileext =
".csv";
235 const std::string numfile = std::string(
".") + std::to_string(it);
237 std::ofstream outbuf (ofilename + numfile + ofileext);
243 const std::string gfilename = std::string(
"grid.") + std::to_string(it) + std::string(
".vts");
244 qg.vtk_export (gfilename.c_str(), vars);
251 timer.print_report();
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