quadgrid 0.1
simple cartesian quad grid with particles for c++/octave
|
Class to represent particles embedded in a grid. More...
#include <particles.h>
Public Types | |
enum class | output_format : idx_t { csv = 0 , octave_ascii = 1 , json = 2 } |
Enumeration of available output format. More... | |
using | idx_t = quadgrid_t< std::vector< double > >::idx_t |
datatype for indexing into vectors of properties More... | |
Public Member Functions | |
double | default_x_generator () |
The default generator function used to set up x-coordinates of particle positions if none is is specified. More... | |
double | default_y_generator () |
The default generator function used to set up y-coordinates of particle positions if none is is specified. More... | |
template<output_format fmt> | |
void | print (std::ostream &os) const |
Template for export function. More... | |
particles_t (idx_t n, const quadgrid_t< std::vector< double > > &grid_) | |
Simplest form of constructor. More... | |
particles_t (const nlohmann::json &j, const quadgrid_t< std::vector< double > > &grid_) | |
Ctor to import data from json. More... | |
particles_t (idx_t n, const std::vector< std::string > &ipropnames, const std::vector< std::string > &dpropnames, const quadgrid_t< std::vector< double > > &grid_) | |
Constructor with default position generators. More... | |
particles_t (idx_t n, const std::vector< std::string > &ipropnames, const std::vector< std::string > &dpropnames, const quadgrid_t< std::vector< double > > &grid_, const std::vector< double > &xv, const std::vector< double > &yv) | |
Constructor with custom position vectors. More... | |
particles_t (idx_t n, const std::vector< std::string > &ipropnames, const std::vector< std::string > &dpropnames, const quadgrid_t< std::vector< double > > &grid_, std::function< double()> xgen, std::function< double()> ygen) | |
Constructor with custom position generators. More... | |
void | init_props (const std::vector< std::string > &ipropnames, const std::vector< std::string > &dpropnames) |
Initialize particle properties. More... | |
void | remove_in_region (std::function< bool(double, double)> fun) |
Erase particcles based on coordinates. More... | |
void | init_particle_mesh () |
Build grid/particles connectivity. More... | |
void | init_particle_positions (std::function< double()> xgentr, std::function< double()> ygentr) |
Initialize particle positions with generator functions. More... | |
void | build_mass () |
Construct a mass matrix. More... | |
double & | dp (const std::string &name, idx_t ii) |
shortcut for dprops.at (name) [ii] More... | |
const double & | dp (const std::string &name, idx_t ii) const |
shortcut for dprops.at (name) [ii] More... | |
idx_t & | ip (const std::string &name, idx_t ii) |
shortcut for iprops.at (name) [ii] More... | |
const idx_t & | ip (const std::string &name, idx_t ii) const |
shortcut for iprops.at (name) [ii] More... | |
void | p2g (std::map< std::string, std::vector< double > > &vars, bool apply_mass=false) const |
Map particle variables to the grid. More... | |
template<typename GT , typename PT > | |
void | p2g (std::map< std::string, std::vector< double > > &vars, PT const &pvarnames, GT const &gvarnames, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ) const |
Map particle variables to the grid. More... | |
template<typename str > | |
void | p2g (std::map< std::string, std::vector< double > > &vars, std::initializer_list< str > const &pvarnames, std::initializer_list< str > const &gvarnames, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ) const |
template<typename GT , typename PT > | |
void | p2gd (std::map< std::string, std::vector< double > > &vars, PT const &pxvarnames, PT const &pyvarnames, std::string const &area, GT const &gvarnames, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ) const |
template<typename str > | |
void | p2gd (std::map< std::string, std::vector< double > > &vars, std::initializer_list< str > const &pxvarnames, std::initializer_list< str > const &pyvarnames, std::string const &area, std::initializer_list< str > const &gvarnames, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ) const |
void | g2p (const std::map< std::string, std::vector< double > > &vars, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ) |
template<typename str > | |
void | g2p (const std::map< std::string, std::vector< double > > &vars, std::initializer_list< str > const &gvarnames, std::initializer_list< str > const &pvarnames, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ) |
template<typename GT , typename PT > | |
void | g2p (const std::map< std::string, std::vector< double > > &vars, GT const &gvarnames, PT const &pvarnames, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ) |
template<typename GT , typename PT > | |
void | g2pd (const std::map< std::string, std::vector< double > > &vars, GT const &gvarnames, PT const &pxvarnames, PT const &pyvarnames, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ) |
template<typename str > | |
void | g2pd (const std::map< std::string, std::vector< double > > &vars, std::initializer_list< str > const &gvarnames, std::initializer_list< str > const &pxvarnames, std::initializer_list< str > const &pyvarnames, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ) |
Static Public Member Functions | |
static const std::string & | getkey (std::map< std::string, std::vector< double > > const &varnames, std::size_t ivar) |
static const std::string & | getkey (std::vector< std::string > const &varnames, std::size_t ivar) |
static const char * | getkey (std::initializer_list< const char * > const &varnames, std::size_t ivar) |
Public Attributes | |
idx_t | num_particles |
number of particles. More... | |
std::vector< double > | x |
x coordinate of particle positions. More... | |
std::vector< double > | y |
y coordinate of particle positions. More... | |
std::map< std::string, std::vector< idx_t > > | iprops |
integer type quantities associated with the particles. More... | |
std::map< std::string, std::vector< double > > | dprops |
double type quantities associated with the particles. More... | |
std::vector< double > | M |
Mass matrix to be used for transfers if required. More... | |
std::map< idx_t, std::vector< idx_t > > | grd_to_ptcl |
grid/particles connectivity. More... | |
const quadgrid_t< std::vector< double > > & | grid |
refernce to a grid object. More... | |
Class to represent particles embedded in a grid.
Offers methods for transfer of quantities from particles to grid or vice-versa (particles_t::p2g, g2p, p2gd
, g2pd
). Initial positions of the particles are chosen at random unless otherwise specified. To each particle a set one can associate a set of double
and one of int
which are stored in the std::map
variables dprops
and iprops
, respectively. Can compute a (lumped) mass matrix to be used in the transfer functions. If particles are moved, the connectivity must be updated invoking the method init_particle_mesh ()
using particles_t::idx_t = quadgrid_t<std::vector<double> >::idx_t |
datatype for indexing into vectors of properties
|
strong |
|
inline |
Simplest form of constructor.
Particle positions are not assigned, they must be set manually later.
n | number of particles |
grid_ | quadgrid_t object, sizes need to have been already set up. |
|
inline |
Ctor to import data from json.
Grid data may be stored in the same json
object but must be read separately before invoking this constructor.
particles_t::particles_t | ( | idx_t | n, |
const std::vector< std::string > & | ipropnames, | ||
const std::vector< std::string > & | dpropnames, | ||
const quadgrid_t< std::vector< double > > & | grid_ | ||
) |
Constructor with default position generators.
Distributes particles randomly over the grid.
n | number of particles |
grid_ | quadgrid_t object, sizes need to have been already set up. |
ipropnames | keys for entries in the particles_t::iprops map. |
dpropnames | keys for entries in the particles_t::dprops map. |
particles_t::particles_t | ( | idx_t | n, |
const std::vector< std::string > & | ipropnames, | ||
const std::vector< std::string > & | dpropnames, | ||
const quadgrid_t< std::vector< double > > & | grid_, | ||
const std::vector< double > & | xv, | ||
const std::vector< double > & | yv | ||
) |
Constructor with custom position vectors.
Distributes particles based on the given vectors xv
and yv
. The vectors are copied, and left unchangend they can be deleted to reclaim memory if needed.
n | number of particles |
grid_ | quadgrid_t object, sizes need to have been already set up. |
ipropnames | keys for entries in the particles_t::iprops map. |
dpropnames | keys for entries in the particles_t::dprops map. |
xv | the x-coordinates of new particles. |
yv | the y-coordinates of new particles. |
particles_t::particles_t | ( | idx_t | n, |
const std::vector< std::string > & | ipropnames, | ||
const std::vector< std::string > & | dpropnames, | ||
const quadgrid_t< std::vector< double > > & | grid_, | ||
std::function< double()> | xgen, | ||
std::function< double()> | ygen | ||
) |
Constructor with custom position generators.
Distributes particles based on the given generator functions xgen
and ygen
. Each call to these functions should return the x- and y-coordinate of a new particle.
n | number of particles |
grid_ | quadgrid_t object, sizes need to have been already set up. |
ipropnames | keys for entries in the particles_t::iprops map. |
dpropnames | keys for entries in the particles_t::dprops map. |
xgen | generator function for the x-coordinates of new particles. |
ygen | generator function for the y-coordinates of new particles. |
void particles_t::build_mass | ( | ) |
Construct a mass matrix.
Must be invoked manually before invoking any of the transfer methods with flag use_mass
set to true
double particles_t::default_x_generator | ( | ) |
The default generator function used to set up x-coordinates of particle positions if none is is specified.
Generates a uniform random distribution.
double particles_t::default_y_generator | ( | ) |
The default generator function used to set up y-coordinates of particle positions if none is is specified.
Generates a uniform random distribution.
|
inline |
shortcut for dprops.at (name) [ii]
|
inline |
shortcut for dprops.at (name) [ii]
|
inline |
void particles_t::g2p | ( | const std::map< std::string, std::vector< double > > & | vars, |
GT const & | gvarnames, | ||
PT const & | pvarnames, | ||
bool | apply_mass = false , |
||
assignment_t | OP = ASSIGNMENT_OPS::PLUS_EQ |
||
) |
void particles_t::g2p | ( | const std::map< std::string, std::vector< double > > & | vars, |
std::initializer_list< str > const & | gvarnames, | ||
std::initializer_list< str > const & | pvarnames, | ||
bool | apply_mass = false , |
||
assignment_t | OP = ASSIGNMENT_OPS::PLUS_EQ |
||
) |
void particles_t::g2pd | ( | const std::map< std::string, std::vector< double > > & | vars, |
GT const & | gvarnames, | ||
PT const & | pxvarnames, | ||
PT const & | pyvarnames, | ||
bool | apply_mass = false , |
||
assignment_t | OP = ASSIGNMENT_OPS::PLUS_EQ |
||
) |
void particles_t::g2pd | ( | const std::map< std::string, std::vector< double > > & | vars, |
std::initializer_list< str > const & | gvarnames, | ||
std::initializer_list< str > const & | pxvarnames, | ||
std::initializer_list< str > const & | pyvarnames, | ||
bool | apply_mass = false , |
||
assignment_t | OP = ASSIGNMENT_OPS::PLUS_EQ |
||
) |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
void particles_t::init_particle_mesh | ( | ) |
Build grid/particles connectivity.
Builds/updates the grd_to_ptcl
map. Must be used whenever particles cross cell boundaries.
void particles_t::init_particle_positions | ( | std::function< double()> | xgentr, |
std::function< double()> | ygentr | ||
) |
Initialize particle positions with generator functions.
Invoked automatically if the generators are passed to the CTOR, must be invoked manually otherwise.
void particles_t::init_props | ( | const std::vector< std::string > & | ipropnames, |
const std::vector< std::string > & | dpropnames | ||
) |
Initialize particle properties.
Allocates vectors to store particle properties, this is invoked automatically if the CTOR is invoked specifying property names, must be invoked manually otherwise.
ipropnames | keys for entries in the particles_t::iprops map. |
dpropnames | keys for entries in the particles_t::dprops map. |
shortcut for iprops.at (name) [ii]
shortcut for iprops.at (name) [ii]
|
inline |
Map particle variables to the grid.
Assume all fields of vars
are to be mapped, and use the same field names for particle and grid variables.
void particles_t::p2g | ( | std::map< std::string, std::vector< double > > & | vars, |
PT const & | pvarnames, | ||
GT const & | gvarnames, | ||
bool | apply_mass = false , |
||
assignment_t | OP = ASSIGNMENT_OPS::PLUS_EQ |
||
) | const |
Map particle variables to the grid.
Choose which quantities need to be mapped according to the strings in gvarnames
, and use the same field names for particle and grid variables.
void particles_t::p2g | ( | std::map< std::string, std::vector< double > > & | vars, |
std::initializer_list< str > const & | pvarnames, | ||
std::initializer_list< str > const & | gvarnames, | ||
bool | apply_mass = false , |
||
assignment_t | OP = ASSIGNMENT_OPS::PLUS_EQ |
||
) | const |
void particles_t::p2gd | ( | std::map< std::string, std::vector< double > > & | vars, |
PT const & | pxvarnames, | ||
PT const & | pyvarnames, | ||
std::string const & | area, | ||
GT const & | gvarnames, | ||
bool | apply_mass = false , |
||
assignment_t | OP = ASSIGNMENT_OPS::PLUS_EQ |
||
) | const |
void particles_t::p2gd | ( | std::map< std::string, std::vector< double > > & | vars, |
std::initializer_list< str > const & | pxvarnames, | ||
std::initializer_list< str > const & | pyvarnames, | ||
std::string const & | area, | ||
std::initializer_list< str > const & | gvarnames, | ||
bool | apply_mass = false , |
||
assignment_t | OP = ASSIGNMENT_OPS::PLUS_EQ |
||
) | const |
|
inline |
Template for export function.
If a format is not specified, just outputs an error message.
|
inline |
Erase particcles based on coordinates.
Given a function to decide whether a particle lies inside a region or not, remove all particles for which the function returns true, and also erase corresponding entries in dprops and iprops.
std::map<std::string, std::vector<double> > particles_t::dprops |
double
type quantities associated with the particles.
const quadgrid_t<std::vector<double> >& particles_t::grid |
refernce to a grid object.
std::map<std::string, std::vector<idx_t> > particles_t::iprops |
integer type quantities associated with the particles.
std::vector<double> particles_t::M |
Mass matrix to be used for transfers if required.
idx_t particles_t::num_particles |
number of particles.
std::vector<double> particles_t::x |
x coordinate of particle positions.
std::vector<double> particles_t::y |
y coordinate of particle positions.