13 static std::random_device rd;
14 static std::mt19937 gen (rd ());
15 static std::uniform_real_distribution<> dis (0.0, 1.0);
21 static std::random_device rd;
22 static std::mt19937 gen (rd ());
23 static std::uniform_real_distribution<> dis (0.0, 1.0);
68 std::function<
real_t ()> xgen,
69 std::function<
real_t ()> ygen
87 for (
idx_t ii = 0; ii < ipropnames.
size (); ++ii) {
91 for (
idx_t ii = 0; ii < dpropnames.
size (); ++ii) {
104 for (
const auto & p :
dprops)
105 device_dprops[p.first] = p.second;
107 for (
const auto & p :
iprops)
108 device_iprops[p.first] = p.second;
110 std::cout<<
"Memcpy Host to Device"<<std::endl;
116 thrust::copy (device_x.cbegin (), device_x.cend (),
x.begin ());
117 thrust::copy (device_y.cbegin (), device_y.cend (),
y.begin ());
118 thrust::copy (device_grid_M.cbegin (), device_grid_M.cend (),
M.begin ());
119 thrust::copy (device_ptcl_to_grd.cbegin(), device_ptcl_to_grd.cend(),
ptcl_to_grd.begin());
121 for (
const auto & p : device_dprops)
122 dprops[p.first] = p.second;
124 std::cout<<
"Memcpy Device to Host"<<std::endl;
132 static idx_t loop = 0;
136 igrid.second.clear ();
196 std::function<
real_t ()> xgentr,
197 std::function<
real_t ()> ygentr
202 std::generate (
x.begin (),
x.end (), xgentr);
203 std::generate (
y.begin (),
y.end (), ygentr);
213 inode < quadgrid_t<vector_t<real_t>>::cell_t::nodes_per_cell;
215 M[icell->gt (inode)] += (
grid.
hx () / 2.) * (
grid.
hy () / 2.);
223 nlohmann::json j = *
this;
231 os <<
"\"x\", " <<
"\"y\"";
233 for (
auto const & ii : dprops)
234 os <<
", \"" << ii.first <<
"\"";
236 for (
auto const & ii : iprops)
237 os <<
", \"" << ii.first <<
"\"";
242 for (
idx_t jj = 0; jj < x.
size (); ++jj) {
244 os << x[jj] <<
", " << y[jj];
246 for (
auto const & ii : dprops)
247 os <<
", " << std::setprecision (16) << ii.second[jj];
249 for (
auto const & ii : iprops)
250 os <<
", " << ii.second[jj];
259(std::ostream & os)
const {
261 os <<
"# name: x" << std::endl
262 <<
"# type: matrix" << std::endl
263 <<
"# rows: 1" << std::endl
264 <<
"# columns: " << x.size () << std::endl;
265 for (
auto const & kk : x) {
266 os << std::setprecision(16) << kk <<
" ";
270 os <<
"# name: y" << std::endl
271 <<
"# type: matrix" << std::endl
272 <<
"# rows: 1" << std::endl
273 <<
"# columns: " << y.size () << std::endl;
274 for (
auto const & kk : y) {
275 os << std::setprecision(16) << kk <<
" ";
279 os <<
"# name: dprops" << std::endl
280 <<
"# type: scalar struct" << std::endl
281 <<
"# ndims: 2" << std::endl
282 <<
"1 1" << std::endl
283 <<
"# length: " << dprops.size () << std::endl;
286 for (
auto const & ii : dprops) {
287 os <<
"# name: " << ii.first << std::endl
288 <<
"# type: matrix" << std::endl
289 <<
"# rows: 1" << std::endl
290 <<
"# columns: " << ii.second.size () << std::endl;
291 for (
auto const & kk : ii.second) {
292 os << std::setprecision(16) << kk <<
" ";
298 os <<
"# name: iprops" << std::endl
299 <<
"# type: scalar struct" << std::endl
300 <<
"# ndims: 2" << std::endl
301 <<
"1 1" << std::endl
302 <<
"# length: " << iprops.size () << std::endl;
304 for (
auto const & ii : iprops) {
305 os <<
"# name: " << ii.first << std::endl
306 <<
"# type: int64 matrix" << std::endl
307 <<
"# ndims: 2" << std::endl
308 <<
"1 " << ii.second.size () << std::endl;
309 for (
auto const & kk : ii.second) {
338 if (ii != ordering[ii]) {
340 for (
auto &dprop :
dprops) {
341 auto &col = dprop.second;
342 std::swap (col[ii], col[ordering[ii]]);
345 for (
auto &iprop :
iprops) {
346 auto &col = iprop.second;
347 std::swap (col[ii], col[ordering[ii]]);
350 std::swap (
x[ii],
x[ordering[ii]]);
351 std::swap (
y[ii],
y[ordering[ii]]);
353 for (
int jj = ii; jj < ordering.size (); ++jj) {
354 if (ordering[jj] == ii) {
355 ordering[jj] = ordering[ii];
idx_t num_global_nodes() const
HOST static DEVICE idx_t sub2gind(idx_t r, idx_t c, idx_t nr)
cell_iterator begin_cell_sweep()
cell_iterator end_cell_sweep()
static constexpr morton_code_t M[]
void to_json(nlohmann::json &j, const particles_t &p)
Adaptor to allow implicit conversion from particles_t to json.
Class to represent particles embedded in a grid.
void memcpy_host_to_device()
Copy Host To Device.
void init_particle_positions(std::function< real_t()> xgentr, std::function< real_t()> ygentr)
Initialize particle positions with generator functions.
idx_t num_particles
number of particles.
vector_t< idx_t > ptcl_to_grd
particles->grid connectivity.
void init_particle_mesh()
Build grid/particles connectivity.
std::map< std::string, vector_t< idx_t > > iprops
integer type quantities associated with the particles.
real_t default_x_generator()
The default generator function used to set up x-coordinates of particle positions if none is is speci...
void init_props(const vector_t< std::string > &ipropnames, const vector_t< std::string > &dpropnames)
Initialize particle properties.
quadgrid_t< vector_t< real_t > >::idx_t idx_t
datatype for indexing into vectors of properties
real_t default_y_generator()
The default generator function used to set up y-coordinates of particle positions if none is is speci...
void print(std::ostream &os) const
Template for export function.
vector_t< real_t > M
Mass matrix to be used for transfers if required.
std::map< idx_t, vector_t< idx_t > > grd_to_ptcl
grid->particles connectivity.
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.
void build_mass()
Construct a mass matrix.
void reorder(vector_t< idx_t > &)
Reorder coordinates an properties according to the ordering vvector.
particles_t(idx_t n, const quadgrid_t< vector_t< real_t > > &grid_)
Simplest form of constructor.
void memcpy_device_to_host()
Copy Device To Host.
void update_ptcl_to_grd()
Updates theptcl_to_grd map only, without changing.