quadgrid 0.1
simple cartesian quad grid with particles for c++/octave
Loading...
Searching...
No Matches
particles.cpp File Reference
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <random>
#include <counter.h>
#include <quadgrid_cpp.h>
#include <particles.h>
#include <quadgrid_config.h>

Go to the source code of this file.

Functions

template<>
void particles_t::print< particles_t::output_format::json > (std::ostream &os) const
template<>
void particles_t::print< particles_t::output_format::csv > (std::ostream &os) const
template<>
void particles_t::print< particles_t::output_format::octave_ascii > (std::ostream &os) const
void to_json (nlohmann::json &j, const particles_t &p)
 Adaptor to allow implicit conversion from particles_t to json.

Function Documentation

◆ particles_t::print< particles_t::output_format::csv >()

template<>
void particles_t::print< particles_t::output_format::csv > ( std::ostream & os) const

Definition at line 228 of file particles.cpp.

229 {
230
231 os << "\"x\", " << "\"y\"";
232
233 for (auto const & ii : dprops)
234 os << ", \"" << ii.first << "\"";
235
236 for (auto const & ii : iprops)
237 os << ", \"" << ii.first << "\"";
238
239 os << std::endl;
240
241
242 for (idx_t jj = 0; jj < x.size (); ++jj) {
243
244 os << x[jj] << ", " << y[jj];
245
246 for (auto const & ii : dprops)
247 os << ", " << std::setprecision (16) << ii.second[jj];
248
249 for (auto const & ii : iprops)
250 os << ", " << ii.second[jj];
251
252 os << std::endl;
253 }
254}

◆ particles_t::print< particles_t::output_format::json >()

template<>
void particles_t::print< particles_t::output_format::json > ( std::ostream & os) const

Definition at line 221 of file particles.cpp.

222 {
223 nlohmann::json j = *this;
224 os << j;
225}

◆ particles_t::print< particles_t::output_format::octave_ascii >()

template<>
void particles_t::print< particles_t::output_format::octave_ascii > ( std::ostream & os) const

Definition at line 257 of file particles.cpp.

259 {
260
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 << " ";
267 }
268 os << std::endl;
269
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 << " ";
276 }
277 os << std::endl;
278
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;
284
285
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 << " ";
293 }
294 os << std::endl;
295 }
296 os << std::endl;
297
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;
303
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) {
310 os << kk << " ";
311 }
312 os << std::endl;
313 }
314 os << std::endl;
315}

◆ to_json()

void to_json ( nlohmann::json & j,
const particles_t & p )

Adaptor to allow implicit conversion from particles_t to json.

Definition at line 318 of file particles.cpp.

318 {
319 j = nlohmann::json{
320 {"num_particles", p.num_particles},
321 {"x", p.x},
322 {"y", p.y},
323 {"dprops", p.dprops},
324 {"iprops", p.iprops},
325 {"grid_properties",
326 {{"nx", p.grid.num_cols ()},
327 {"ny", p.grid.num_rows ()},
328 {"hx", p.grid.hx ()},
329 {"hy", p.grid.hy ()}}
330 }
331 };
332}
real_t hy() const
idx_t num_cols() const
idx_t num_rows() const
real_t hx() const
idx_t num_particles
number of particles.
Definition particles.h:34
std::map< std::string, vector_t< idx_t > > iprops
integer type quantities associated with the particles.
Definition particles.h:39
vector_t< real_t > x
x coordinate of particle positions.
Definition particles.h:35
const quadgrid_t< vector_t< real_t > > & grid
refernce to a grid object.
Definition particles.h:48
std::map< std::string, vector_t< real_t > > dprops
double type quantities associated with the particles.
Definition particles.h:42
vector_t< real_t > y
y coordinate of particle positions.
Definition particles.h:36