14using assignment_t = std::function <
double& (
double&,
const double&)>;
43 std::vector<double>
x;
44 std::vector<double>
y;
47 std::map<std::string, std::vector<idx_t>>
iprops;
50 std::map<std::string, std::vector<double>>
dprops;
52 std::vector<double>
M;
76 default_x_generator ();
84 default_y_generator ();
90 template<output_format fmt>
92 print (std::ostream & os)
const {
93 os <<
"output format not implementd" << std::endl;
112 j[
"dprops"].get_to<std::map<std::string, std::vector<double>>> (
dprops);
113 j[
"iprops"].get_to<std::map<std::string, std::vector<int>>> (iprops);
114 j[
"x"].get_to<std::vector<double>> (
x);
115 j[
"y"].get_to<std::vector<double>> (
y);
128 const std::vector<std::string>& dpropnames,
129 const quadgrid_t<std::vector<double>>& grid_);
143 const std::vector<std::string>& dpropnames,
145 const std::vector<double> & xv,
146 const std::vector<double> & yv);
160 const std::vector<std::string>& dpropnames,
162 std::function<
double ()> xgen,
163 std::function<
double ()> ygen);
173 init_props (
const std::vector<std::string>& ipropnames,
174 const std::vector<std::string>& dpropnames);
184 std::vector<idx_t> vin{};
186 if (fun (
x[i],
y[i])) {
191 for (
auto &dprop :
dprops) {
192 for (
auto id = vin.rbegin ();
id != vin.rend (); ++
id) {
193 dprop.second.erase (dprop.second.begin () + (*
id));
197 for (
auto &iprop : iprops) {
198 for (
auto id = vin.rbegin ();
id != vin.rend (); ++
id) {
199 iprop.second.erase (iprop.second.begin () + (*
id));
203 for (
auto id = vin.rbegin ();
id != vin.rend (); ++
id) {
204 x.erase (
x.begin () + (*
id));
205 y.erase (
y.begin () + (*
id));
215 init_particle_mesh ();
222 init_particle_positions (std::function<
double ()> xgentr,
223 std::function<
double ()> ygentr);
235 return dprops.at (name) [ii];
240 dp (
const std::string & name,
idx_t ii)
const {
241 return dprops.at (name) [ii];
247 return iprops.at (name) [ii];
252 ip (
const std::string & name,
idx_t ii)
const {
253 return iprops.at (name) [ii];
258 getkey(std::map<std::string, std::vector<double>>
const &varnames,
260 return std::next (varnames.begin (), ivar)->first;
265 getkey(std::vector<std::string>
const &varnames,
267 return varnames[ivar];
272 getkey(std::initializer_list<const char *>
const &varnames,
274 return *(std::next (varnames.begin (), ivar));
283 p2g (std::map<std::string, std::vector<double>> & vars,
284 bool apply_mass =
false)
const {
285 p2g (vars, vars, vars, apply_mass);
294 template<
typename GT,
typename PT>
296 p2g (std::map<std::string, std::vector<double>> & vars,
297 PT
const & pvarnames,
298 GT
const & gvarnames,
299 bool apply_mass =
false,
302 template<
typename str>
304 p2g (std::map<std::string, std::vector<double>> & vars,
305 std::initializer_list<str>
const & pvarnames,
306 std::initializer_list<str>
const & gvarnames,
307 bool apply_mass =
false,
310 template<
typename GT,
typename PT>
312 p2gd (std::map<std::string, std::vector<double>> & vars,
313 PT
const & pxvarnames,
314 PT
const & pyvarnames,
315 std::string
const &area,
316 GT
const & gvarnames,
317 bool apply_mass =
false,
320 template<
typename str>
322 p2gd (std::map<std::string, std::vector<double>> & vars,
323 std::initializer_list<str>
const & pxvarnames,
324 std::initializer_list<str>
const & pyvarnames,
325 std::string
const & area,
326 std::initializer_list<str>
const & gvarnames,
327 bool apply_mass =
false,
331 g2p (
const std::map<std::string, std::vector<double>>& vars,
333 g2p (vars, vars, vars, apply_mass, OP);
336 template<
typename str>
338 g2p (
const std::map<std::string, std::vector<double>>& vars,
339 std::initializer_list<str>
const & gvarnames,
340 std::initializer_list<str>
const & pvarnames,
341 bool apply_mass =
false,
344 template<
typename GT,
typename PT>
346 g2p (
const std::map<std::string, std::vector<double>>& vars,
347 GT
const & gvarnames,
348 PT
const & pvarnames,
349 bool apply_mass =
false,
352 template<
typename GT,
typename PT>
354 g2pd (
const std::map<std::string, std::vector<double>>& vars,
355 GT
const & gvarnames,
356 PT
const & pxvarnames,
357 PT
const & pyvarnames,
358 bool apply_mass =
false,
361 template<
typename str>
363 g2pd (
const std::map<std::string, std::vector<double>>& vars,
364 std::initializer_list<str>
const & gvarnames,
365 std::initializer_list<str>
const &pxvarnames,
366 std::initializer_list<str>
const & pyvarnames,
367 bool apply_mass =
false,
quadgrid_t< std::vector< double > >::idx_t idx_t
Definition: check_shg.cpp:7
Definition: quadgrid_cpp.h:15
Definition: particles.cpp:8
assignment_t TIMES_EQ
Definition: particles.cpp:11
assignment_t EQ
Definition: particles.cpp:9
assignment_t PLUS_EQ
Definition: particles.cpp:10
void to_json(nlohmann::json &j, const particles_t &p)
Adaptor to allow implicit conversion from particles_t to json.
Definition: particles.cpp:242
std::function< double &(double &, const double &)> assignment_t
datatype for assignment operators
Definition: particles.h:14
Class to represent particles embedded in a grid.
Definition: particles.h:37
const idx_t & ip(const std::string &name, idx_t ii) const
shortcut for iprops.at (name) [ii]
Definition: particles.h:252
void g2p(const std::map< std::string, std::vector< double > > &vars, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ)
Definition: particles.h:331
idx_t & ip(const std::string &name, idx_t ii)
shortcut for iprops.at (name) [ii]
Definition: particles.h:246
std::map< idx_t, std::vector< idx_t > > grd_to_ptcl
grid/particles connectivity.
Definition: particles.h:53
std::map< std::string, std::vector< idx_t > > iprops
integer type quantities associated with the particles.
Definition: particles.h:47
particles_t(idx_t n, const quadgrid_t< std::vector< double > > &grid_)
Simplest form of constructor.
Definition: particles.h:101
double & dp(const std::string &name, idx_t ii)
shortcut for dprops.at (name) [ii]
Definition: particles.h:234
idx_t num_particles
number of particles.
Definition: particles.h:42
const quadgrid_t< std::vector< double > > & grid
refernce to a grid object.
Definition: particles.h:54
output_format
Enumeration of available output format.
Definition: particles.h:58
static const char * getkey(std::initializer_list< const char * > const &varnames, std::size_t ivar)
Definition: particles.h:272
static const std::string & getkey(std::map< std::string, std::vector< double > > const &varnames, std::size_t ivar)
Definition: particles.h:258
void print(std::ostream &os) const
Template for export function.
Definition: particles.h:92
std::map< std::string, std::vector< double > > dprops
double type quantities associated with the particles.
Definition: particles.h:50
void remove_in_region(std::function< bool(double, double)> fun)
Erase particcles based on coordinates.
Definition: particles.h:183
const double & dp(const std::string &name, idx_t ii) const
shortcut for dprops.at (name) [ii]
Definition: particles.h:240
std::vector< double > x
x coordinate of particle positions.
Definition: particles.h:43
quadgrid_t< std::vector< double > >::idx_t idx_t
datatype for indexing into vectors of properties
Definition: particles.h:40
particles_t(const nlohmann::json &j, const quadgrid_t< std::vector< double > > &grid_)
Ctor to import data from json.
Definition: particles.h:108
std::vector< double > y
y coordinate of particle positions.
Definition: particles.h:44
static const std::string & getkey(std::vector< std::string > const &varnames, std::size_t ivar)
Definition: particles.h:265
std::vector< double > M
Mass matrix to be used for transfers if required.
Definition: particles.h:52
void p2g(std::map< std::string, std::vector< double > > &vars, bool apply_mass=false) const
Map particle variables to the grid.
Definition: particles.h:283