9 std::initializer_list<str>
const & pvarnames,
10 std::initializer_list<str>
const & gvarnames,
12 using strlist = std::initializer_list<str>
const &;
14 (vars, pvarnames, gvarnames, apply_mass);
17template<
typename GVAR_t,
typename PVAR_t,
typename P2C_t>
37 GVAR_t gvar_,
const P2C_t ptcl_to_grd_,
const idx_t nrows_,
38 const real_t hx_,
const real_t hy_,
const PVAR_t dprop_,
bool apply_mass_)
39 :
x(x_),
y(y_),
M(M_),
gvar(gvar_),
52 for (
idx_t inode = 0; inode < 4; ++inode) {
54 qgt::shp (xx, yy, inode, c, r,
hx,
hy);
63template<
typename GT,
typename PT>
76 for (std::size_t ivar = 0; ivar < std::size(gvarnames); ++ivar) {
79 auto & device_gvar = device_grid_vars[
getkey(gvarnames, ivar)];
80 auto const & device_dprop = device_dprops.at(
getkey(pvarnames, ivar));
81 thrust::counting_iterator<idx_t> first_p(0), last_p(
this ->
num_particles);
82 p2g_helper_t helper(device_x.cbegin(), device_y.cbegin(), thrust::raw_pointer_cast(device_grid_M.data()),
83 thrust::raw_pointer_cast(device_gvar.data()), device_ptcl_to_grd.cbegin(),
grid.
num_rows(),
grid.
hx(),
84 grid.
hy(), device_dprop.cbegin(), apply_mass);
86 auto & gvar = vars[
getkey(gvarnames, ivar)];
87 auto const & dprop =
dprops.at (
getkey(pvarnames, ivar));
100template<
typename UnaryFunction>
104 UnaryFunction helper){
107 thrust::counting_iterator<idx_t> first_p(0), last_p(
this ->
num_particles);
118template<
typename str>
122 std::initializer_list<str>
const & pxvarnames,
123 std::initializer_list<str>
const & pyvarnames,
124 std::string
const &area,
125 std::initializer_list<str>
const & gvarnames,
127 using strlist = std::initializer_list<str>
const &;
129 (vars, pxvarnames, pyvarnames, area, gvarnames, apply_mass);
132template<
typename GVAR_t,
typename PVAR_t,
typename P2C_t,
typename DPROPX_t,
typename DPROPY_t,
typename DPROPAREA_t>
154 GVAR_t gvar_,
const P2C_t ptcl_to_grd_,
const idx_t nrows_,
155 const real_t hx_,
const real_t hy_,
const DPROPX_t dpropx_,
const DPROPY_t dpropy_,
const DPROPAREA_t dproparea_,
bool apply_mass_)
156 :
x(x_),
y(y_),
M(M_),
gvar(gvar_),
164 real_t Nx = 0.0, Ny = 0.0;
169 for (
idx_t inode = 0; inode < 4; ++inode) {
170 Nx =
apply_mass ? qgt::shg (xx, yy, 0, inode, c, r,
hx,
hy) /
M[qgt::gt(inode, c, r,
nrows)] :
171 qgt::shg (xx, yy, 0, inode, c, r,
hx,
hy);
172 Ny =
apply_mass ? qgt::shg (xx, yy, 1, inode, c, r,
hx,
hy) /
M[qgt::gt(inode, c, r,
nrows)] :
173 qgt::shg (xx, yy, 1, inode, c, r,
hx,
hy);
183template<
typename GT,
typename PT>
187 PT
const & pxvarnames,
188 PT
const & pyvarnames,
189 std::string
const &area,
190 GT
const & gvarnames,
196 for (std::size_t ivar = 0; ivar < std::size (gvarnames); ++ivar) {
199 auto & device_gvar = device_grid_vars[
getkey(gvarnames, ivar)];
200 auto const & device_dpropx = device_dprops.at (
getkey(pxvarnames, ivar));
201 auto const & device_dpropy = device_dprops.at (
getkey(pyvarnames, ivar));
202 auto const & device_dproparea = device_dprops.at (area);
204 thrust::counting_iterator<idx_t> first_p(0), last_p(
this ->
num_particles);
206 p2gd_helper_t helper(device_x.cbegin(), device_y.cbegin(), thrust::raw_pointer_cast(device_grid_M.data()),
207 thrust::raw_pointer_cast(device_gvar.data()), device_ptcl_to_grd.cbegin(),
grid.
num_rows(),
grid.
hx(),
208 grid.
hy(), device_dpropx.cbegin(), device_dpropy.cbegin(), device_dproparea.cbegin(), apply_mass);
211 auto & gvar = vars[
getkey(gvarnames, ivar)];
212 auto const & dpropx =
dprops.at (
getkey(pxvarnames, ivar));
213 auto const & dpropy =
dprops.at (
getkey(pyvarnames, ivar));
214 auto const & dproparea =
dprops.at (area);
219 dpropx.begin(), dpropy.begin(), dproparea.begin(), apply_mass);
222 algorithm_namespace::for_each(first_p, last_p, helper);
246template<
typename UnaryFunction>
250 UnaryFunction helper){
253 thrust::counting_iterator<idx_t> first_p(0), last_p(
this ->
num_particles);
264template<
typename str>
268 std::initializer_list<str>
const & gvarnames,
269 std::initializer_list<str>
const & pvarnames,
271 using strlist = std::initializer_list<str>
const &;
273 pvarnames, apply_mass);
278template<
typename GVAR_t,
typename PVAR_t,
typename P2C_t,
typename GRIDM_t>
297 const GVAR_t gvar_,
const P2C_t ptcl_to_grd_,
const idx_t nrows_,
298 const real_t hx_,
const real_t hy_, PVAR_t dprop_,
bool apply_mass_)
299 :
x(x_),
y(y_),
M(M_),
gvar(gvar_),
313 for (
idx_t inode = 0; inode < 4; ++inode) {
315 qgt::shp (xx, yy, inode, c, r,
hx,
hy);
322template<
typename GT,
typename PT>
326 GT
const & gvarnames,
327 PT
const & pvarnames,
334 for (std::size_t ivar = 0; ivar < std::size (gvarnames); ++ivar) {
337 auto & device_dprop = device_dprops.at(
getkey(pvarnames, ivar));
338 auto const & device_gvar = device_grid_vars[
getkey(gvarnames, ivar)];
339 thrust::counting_iterator<idx_t> first_p(0), last_p(
this ->
num_particles);
340 g2p_helper_t helper(thrust::raw_pointer_cast(device_x.data()), thrust::raw_pointer_cast(device_y.data()), device_grid_M.cbegin(), device_gvar.cbegin(),
341 device_ptcl_to_grd.cbegin(),
grid.
num_rows (),
grid.
hx (),
grid.
hy (), thrust::raw_pointer_cast(device_dprop.data()), apply_mass);
344 auto const & gvar = vars.at (
getkey (gvarnames, ivar));
350 dprop.begin (), apply_mass);
359template<
typename UnaryFunction>
363 UnaryFunction helper){
366 thrust::counting_iterator<idx_t> first_p(0), last_p(
this ->
num_particles);
378template<
typename str>
382 std::initializer_list<str>
const & gvarnames,
383 std::initializer_list<str>
const & pxvarnames,
384 std::initializer_list<str>
const & pyvarnames,
386 using strlist = std::initializer_list<str>
const &;
388 pyvarnames, apply_mass);
393template<
typename GVAR_t,
typename PVAR_t,
typename P2C_t,
typename GRIDM_t>
413 const GVAR_t gvar_,
const P2C_t ptcl_to_grd_,
const idx_t nrows_,
414 const real_t hx_,
const real_t hy_, PVAR_t dpropx_, PVAR_t dpropy_,
416 :
x(x_),
y(y_),
M(M_),
gvar(gvar_),
424 real_t Nx = 0.0, Ny = 0.0;
430 for (
idx_t inode = 0; inode < 4; ++inode) {
432 qgt::shg (xx, yy, 0, inode, c, r,
hx,
hy) *
M[qgt::gt(inode, c, r,
nrows)] :
433 qgt::shg (xx, yy, 0, inode, c, r,
hx,
hy);
435 qgt::shg (xx, yy, 1, inode, c, r,
hx,
hy) *
M[qgt::gt(inode, c, r,
nrows)] :
436 qgt::shg (xx, yy, 1, inode, c, r,
hx,
hy);
444template<
typename GT,
typename PT>
448 GT
const & gvarnames,
449 PT
const & pxvarnames,
450 PT
const & pyvarnames,
456 for (std::size_t ivar = 0; ivar < std::size (gvarnames); ++ivar) {
478 auto const & device_gvar = device_grid_vars.at (
getkey (gvarnames, ivar));
479 auto & device_dpropx = device_dprops.at (
getkey (pxvarnames, ivar));
480 auto & device_dpropy = device_dprops.at (
getkey (pyvarnames, ivar));
481 thrust::counting_iterator<idx_t> first_p(0), last_p(
this ->
num_particles);
482 g2pd_helper_t helper(thrust::raw_pointer_cast(device_x.data()), thrust::raw_pointer_cast(device_y.data()), device_grid_M.cbegin(), device_gvar.cbegin(),
483 device_ptcl_to_grd.cbegin(),
grid.
num_rows (),
grid.
hx (),
grid.
hy (), thrust::raw_pointer_cast(device_dpropx.data()),
484 thrust::raw_pointer_cast(device_dpropy.data()), apply_mass);
487 auto const & gvar = vars.at (
getkey (gvarnames, ivar));
496 dpropx.begin (), dpropy.begin (), apply_mass);
499 algorithm_namespace::for_each(first_p, last_p, helper);
506template<
typename UnaryFunction>
510 UnaryFunction helper){
513 thrust::counting_iterator<idx_t> first_p(0), last_p(
this ->
num_particles);
528particles_t::update_ptcl_to_grd_device{
535 ptcl_to_grd_update_t p2gu (thrust::raw_pointer_cast(p.device_ptcl_to_grd.data ()), thrust::raw_pointer_cast(p.device_x.data ()),
538 thrust::counting_iterator<idx_t> first_p(0), last_p(p.
num_particles);
555 std::for_each(rng.
begin(), rng.
end(), p2gu);}
559template<
class backend>
562 backend::update(*
this);
566template<
typename str>
570 std::initializer_list<str>
const & pvarnames,
571 std::initializer_list<str>
const & gvarnames,
572 bool apply_mass)
const {
573 using strlist = std::initializer_list<str>
const &;
575 (vars, pvarnames, gvarnames, apply_mass);
578template<
typename GT,
typename PT>
582 PT
const & pvarnames,
583 GT
const & gvarnames,
584 bool apply_mass)
const {
587 double N = 0.0, xx = 0.0, yy = 0.0;
590 for (std::size_t ivar = 0; ivar < std::size(gvarnames); ++ivar) {
591 auto & gvar = vars[
getkey(gvarnames, ivar)];
592 auto const & dprop =
dprops.at (
getkey(pvarnames, ivar));
598 for (
idx_t inode = 0; inode < 4; ++inode) {
599 N = icell.shp(xx, yy, inode) * dprop[
ip];
600 gvar[icell.gt(inode)] += N;
606 for (std::size_t ivar = 0; ivar < std::size (gvarnames); ++ivar)
607 for (
idx_t ii = 0; ii <
M.size (); ++ii) {
608 vars[
getkey(gvarnames, ivar)][ii] /=
M[ii];
615(std::ostream & os)
const;
620(std::ostream & os)
const;
625(std::ostream & os)
const;
void atomicAdd(T *x, const T y)
Template class for the implementation of the g2p method.
g2p_helper_t(const PVAR_t x_, const PVAR_t y_, GRIDM_t M_, const GVAR_t gvar_, const P2C_t ptcl_to_grd_, const idx_t nrows_, const real_t hx_, const real_t hy_, PVAR_t dprop_, bool apply_mass_)
Template class for the implementation g2pd method.
g2pd_helper_t(const PVAR_t x_, const PVAR_t y_, const GRIDM_t M_, const GVAR_t gvar_, const P2C_t ptcl_to_grd_, const idx_t nrows_, const real_t hx_, const real_t hy_, PVAR_t dpropx_, PVAR_t dpropy_, bool apply_mass_)
p2g_helper_t(const PVAR_t x_, const PVAR_t y_, GVAR_t M_, GVAR_t gvar_, const P2C_t ptcl_to_grd_, const idx_t nrows_, const real_t hx_, const real_t hy_, const PVAR_t dprop_, bool apply_mass_)
p2gd_helper_t(const PVAR_t x_, const PVAR_t y_, const GVAR_t M_, GVAR_t gvar_, const P2C_t ptcl_to_grd_, const idx_t nrows_, const real_t hx_, const real_t hy_, const DPROPX_t dpropx_, const DPROPY_t dpropy_, const DPROPAREA_t dproparea_, bool apply_mass_)
const DPROPAREA_t dproparea
static void update(particles_t &p)
Template class for the update of ptcl_to_grd mapping.
#define device_exec_policy
Class to represent particles embedded in a grid.
void p2g(std::map< std::string, device_vector_t< real_t > > &vars, bool apply_mass=false)
Map particle variables to the grid.
void g2pd(const std::map< std::string, device_vector_t< real_t > > &vars, GT const &gvarnames, PT const &pxvarnames, PT const &pyvarnames, bool apply_mass=false)
idx_t & ip(const std::string &name, idx_t ii)
shortcut for iprops.at (name) [ii]
void p2g_print(std::map< std::string, vector_t< real_t > > &vars, PT const &pvarnames, GT const &gvarnames, bool apply_mass=false) const
void g2p(const std::map< std::string, device_vector_t< real_t > > &vars, bool apply_mass=false)
idx_t num_particles
number of particles.
vector_t< idx_t > ptcl_to_grd
particles->grid connectivity.
quadgrid_t< vector_t< real_t > >::idx_t idx_t
datatype for indexing into vectors of properties
void print(std::ostream &os) const
Template for export function.
vector_t< real_t > M
Mass matrix to be used for transfers if required.
vector_t< real_t > x
x coordinate of particle positions.
const quadgrid_t< vector_t< real_t > > & grid
refernce to a grid object.
std::map< std::string, vector_t< real_t > > dprops
double type quantities associated with the particles.
vector_t< real_t > y
y coordinate of particle positions.
particles_t(idx_t n, const quadgrid_t< vector_t< real_t > > &grid_)
Simplest form of constructor.
void p2gd(std::map< std::string, device_vector_t< real_t > > &vars, PT const &pxvarnames, PT const &pyvarnames, std::string const &area, GT const &gvarnames, bool apply_mass=false)
static const std::string & getkey(std::map< std::string, device_vector_t< real_t > > const &varnames, std::size_t ivar)
void update_ptcl_to_grd()
Updates theptcl_to_grd map only, without changing.