|
quadgrid 0.1
simple cartesian quad grid with particles for c++/octave
|
Class to represent particles embedded in a grid. More...
#include <particles.h>
Classes | |
| class | update_ptcl_to_grd_host |
Public Types | |
| enum class | output_format : idx_t { csv = 0 , octave_ascii = 1 , json = 2 } |
| Enumeration of available output format. More... | |
| enum class | cell_color : idx_t { red = 0 , green = 1 , blue = 2 , black = 3 , all_colors = 4 } |
| Enumeration of cell colors. More... | |
| using | idx_t = quadgrid_t<vector_t<real_t>>::idx_t |
| datatype for indexing into vectors of properties | |
Public Member Functions | |
| real_t | default_x_generator () |
| The default generator function used to set up x-coordinates of particle positions if none is is specified. | |
| real_t | default_y_generator () |
| The default generator function used to set up y-coordinates of particle positions if none is is specified. | |
| template<output_format fmt> | |
| void | print (std::ostream &os) const |
| Template for export function. | |
| particles_t (idx_t n, const quadgrid_t< vector_t< real_t > > &grid_) | |
| Simplest form of constructor. | |
| particles_t (const nlohmann::json &j, const quadgrid_t< vector_t< real_t > > &grid_) | |
| Ctor to import data from json. | |
| particles_t (idx_t n, const vector_t< std::string > &ipropnames, const vector_t< std::string > &dpropnames, const quadgrid_t< vector_t< real_t > > &grid_) | |
| Constructor with default position generators. | |
| particles_t (idx_t n, const vector_t< std::string > &ipropnames, const vector_t< std::string > &dpropnames, const quadgrid_t< vector_t< real_t > > &grid_, const vector_t< real_t > &xv, const vector_t< real_t > &yv) | |
| Constructor with custom position vectors. | |
| particles_t (idx_t n, const vector_t< std::string > &ipropnames, const vector_t< std::string > &dpropnames, const quadgrid_t< vector_t< real_t > > &grid_, std::function< real_t()> xgen, std::function< real_t()> ygen) | |
| Constructor with custom position generators. | |
| void | init_props (const vector_t< std::string > &ipropnames, const vector_t< std::string > &dpropnames) |
| Initialize particle properties. | |
| void | remove_in_region (std::function< bool(real_t, real_t)> fun) |
| Erase particcles based on coordinates. | |
| void | memcpy_host_to_device () |
| Copy Host To Device. | |
| void | memcpy_device_to_host () |
| Copy Device To Host. | |
| void | init_particle_mesh () |
| Build grid/particles connectivity. | |
| template<class backend> | |
| void | update_ptcl_to_grd () |
| Updates theptcl_to_grd map only, without changing. | |
| void | mark_by_cell_color () |
| Mark particles by cell color. | |
| void | reorder (vector_t< idx_t > &) |
| Reorder coordinates an properties according to the ordering vvector. | |
| void | init_particle_positions (std::function< real_t()> xgentr, std::function< real_t()> ygentr) |
| Initialize particle positions with generator functions. | |
| void | build_mass () |
| Construct a mass matrix. | |
| real_t & | dp (const std::string &name, idx_t ii) |
| shortcut for dprops.at (name) [ii] | |
| const real_t & | dp (const std::string &name, idx_t ii) const |
| shortcut for dprops.at (name) [ii] | |
| idx_t & | ip (const std::string &name, idx_t ii) |
| shortcut for iprops.at (name) [ii] | |
| const idx_t & | ip (const std::string &name, idx_t ii) const |
| shortcut for iprops.at (name) [ii] | |
| void | p2g (std::map< std::string, device_vector_t< real_t > > &vars, bool apply_mass=false) |
| Map particle variables to the grid. | |
| template<typename GT, typename PT> | |
| void | p2g (std::map< std::string, device_vector_t< real_t > > &vars, PT const &pvarnames, GT const &gvarnames, bool apply_mass=false) |
| Map particle variables to the grid. | |
| template<typename str> | |
| void | p2g (std::map< std::string, device_vector_t< real_t > > &vars, std::initializer_list< str > const &pvarnames, std::initializer_list< str > const &gvarnames, bool apply_mass=false) |
| template<typename UnaryFunction> | |
| void | p2g (std::map< std::string, device_vector_t< real_t > > &vars, UnaryFunction helper) |
| template<typename GT, typename PT> | |
| void | p2g_print (std::map< std::string, vector_t< real_t > > &vars, PT const &pvarnames, GT const &gvarnames, bool apply_mass=false) const |
| template<typename str> | |
| void | p2g_print (std::map< std::string, vector_t< real_t > > &vars, std::initializer_list< str > const &pvarnames, std::initializer_list< str > const &gvarnames, bool apply_mass=false) const |
| template<typename GT, typename PT> | |
| 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) |
| template<typename str> | |
| void | p2gd (std::map< std::string, device_vector_t< real_t > > &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) |
| template<typename UnaryFunction> | |
| void | p2gd (std::map< std::string, device_vector_t< real_t > > &vars, UnaryFunction helper) |
| void | g2p (const std::map< std::string, device_vector_t< real_t > > &vars, bool apply_mass=false) |
| template<typename str> | |
| void | g2p (const std::map< std::string, device_vector_t< real_t > > &vars, std::initializer_list< str > const &gvarnames, std::initializer_list< str > const &pvarnames, bool apply_mass=false) |
| template<typename GT, typename PT> | |
| void | g2p (const std::map< std::string, device_vector_t< real_t > > &vars, GT const &gvarnames, PT const &pvarnames, bool apply_mass=false) |
| template<typename UnaryFunction> | |
| void | g2p (std::map< std::string, device_vector_t< real_t > > &vars, UnaryFunction helper) |
| template<typename GT, typename PT> | |
| 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) |
| template<typename str> | |
| void | g2pd (const std::map< std::string, device_vector_t< real_t > > &vars, std::initializer_list< str > const &gvarnames, std::initializer_list< str > const &pxvarnames, std::initializer_list< str > const &pyvarnames, bool apply_mass=false) |
| template<typename UnaryFunction> | |
| void | g2pd (std::map< std::string, device_vector_t< real_t > > &vars, UnaryFunction helper) |
Static Public Member Functions | |
| static const std::string & | getkey (std::map< std::string, device_vector_t< real_t > > const &varnames, std::size_t ivar) |
| static const std::string & | getkey (vector_t< 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. | |
| vector_t< real_t > | x |
| x coordinate of particle positions. | |
| vector_t< real_t > | y |
| y coordinate of particle positions. | |
| std::map< std::string, vector_t< idx_t > > | iprops |
| integer type quantities associated with the particles. | |
| std::map< std::string, vector_t< real_t > > | dprops |
| double type quantities associated with the particles. | |
| 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< idx_t > | ptcl_to_grd |
| particles->grid connectivity. | |
| vector_t< idx_t > | ptcl_grd_color |
| color of particle's cell. | |
| const quadgrid_t< vector_t< real_t > > & | grid |
| refernce to a grid object. | |
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 ()
Definition at line 28 of file particles.h.
| using particles_t::idx_t = quadgrid_t<vector_t<real_t>>::idx_t |
datatype for indexing into vectors of properties
Definition at line 32 of file particles.h.
|
strong |
Enumeration of cell colors.
| Enumerator | |
|---|---|
| red | |
| green | |
| blue | |
| black | |
| all_colors | |
Definition at line 77 of file particles.h.
|
strong |
Enumeration of available output format.
Definition at line 63 of file particles.h.
|
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. |
Definition at line 118 of file particles.h.
|
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.
Definition at line 125 of file particles.h.
| particles_t::particles_t | ( | idx_t | n, |
| const vector_t< std::string > & | ipropnames, | ||
| const vector_t< std::string > & | dpropnames, | ||
| const quadgrid_t< vector_t< real_t > > & | 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. |
Definition at line 27 of file particles.cpp.
| particles_t::particles_t | ( | idx_t | n, |
| const vector_t< std::string > & | ipropnames, | ||
| const vector_t< std::string > & | dpropnames, | ||
| const quadgrid_t< vector_t< real_t > > & | grid_, | ||
| const vector_t< real_t > & | xv, | ||
| const vector_t< real_t > & | 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. |
Definition at line 46 of file particles.cpp.
| particles_t::particles_t | ( | idx_t | n, |
| const vector_t< std::string > & | ipropnames, | ||
| const vector_t< std::string > & | dpropnames, | ||
| const quadgrid_t< vector_t< real_t > > & | grid_, | ||
| std::function< real_t()> | xgen, | ||
| std::function< real_t()> | 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. |
Definition at line 63 of file particles.cpp.
| 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
Definition at line 208 of file particles.cpp.
| real_t 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.
Definition at line 12 of file particles.cpp.
| real_t 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.
Definition at line 20 of file particles.cpp.
shortcut for dprops.at (name) [ii]
Definition at line 282 of file particles.h.
shortcut for dprops.at (name) [ii]
Definition at line 288 of file particles.h.
|
inline |
Definition at line 401 of file particles.h.
| void particles_t::g2p | ( | const std::map< std::string, device_vector_t< real_t > > & | vars, |
| GT const & | gvarnames, | ||
| PT const & | pvarnames, | ||
| bool | apply_mass = false ) |
Definition at line 324 of file particles_imp.h.
| void particles_t::g2p | ( | const std::map< std::string, device_vector_t< real_t > > & | vars, |
| std::initializer_list< str > const & | gvarnames, | ||
| std::initializer_list< str > const & | pvarnames, | ||
| bool | apply_mass = false ) |
Definition at line 266 of file particles_imp.h.
| void particles_t::g2p | ( | std::map< std::string, device_vector_t< real_t > > & | vars, |
| UnaryFunction | helper ) |
Definition at line 361 of file particles_imp.h.
| void particles_t::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 ) |
Definition at line 446 of file particles_imp.h.
| void particles_t::g2pd | ( | const std::map< std::string, device_vector_t< real_t > > & | vars, |
| std::initializer_list< str > const & | gvarnames, | ||
| std::initializer_list< str > const & | pxvarnames, | ||
| std::initializer_list< str > const & | pyvarnames, | ||
| bool | apply_mass = false ) |
Definition at line 380 of file particles_imp.h.
| void particles_t::g2pd | ( | std::map< std::string, device_vector_t< real_t > > & | vars, |
| UnaryFunction | helper ) |
Definition at line 508 of file particles_imp.h.
|
inlinestatic |
Definition at line 320 of file particles.h.
|
inlinestatic |
Definition at line 306 of file particles.h.
|
inlinestatic |
Definition at line 313 of file particles.h.
| void particles_t::init_particle_mesh | ( | ) |
Build grid/particles connectivity.
Builds/updates the grd_to_ptcl and ptcl_to_grd maps. Must be used whenever particles cross cell boundaries.
Definition at line 131 of file particles.cpp.
| void particles_t::init_particle_positions | ( | std::function< real_t()> | xgentr, |
| std::function< real_t()> | ygentr ) |
Initialize particle positions with generator functions.
Invoked automatically if the generators are passed to the CTOR, must be invoked manually otherwise.
Definition at line 194 of file particles.cpp.
| void particles_t::init_props | ( | const vector_t< std::string > & | ipropnames, |
| const vector_t< 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. |
Definition at line 81 of file particles.cpp.
shortcut for iprops.at (name) [ii]
Definition at line 294 of file particles.h.
shortcut for iprops.at (name) [ii]
Definition at line 300 of file particles.h.
| void particles_t::mark_by_cell_color | ( | ) |
Mark particles by cell color.
| void particles_t::memcpy_device_to_host | ( | ) |
Copy Device To Host.
| void particles_t::memcpy_host_to_device | ( | ) |
Copy Host To Device.
|
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.
Definition at line 331 of file particles.h.
| void particles_t::p2g | ( | std::map< std::string, device_vector_t< real_t > > & | vars, |
| PT const & | pvarnames, | ||
| GT const & | gvarnames, | ||
| bool | apply_mass = false ) |
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.
Definition at line 65 of file particles_imp.h.
| void particles_t::p2g | ( | std::map< std::string, device_vector_t< real_t > > & | vars, |
| std::initializer_list< str > const & | pvarnames, | ||
| std::initializer_list< str > const & | gvarnames, | ||
| bool | apply_mass = false ) |
Definition at line 7 of file particles_imp.h.
| void particles_t::p2g | ( | std::map< std::string, device_vector_t< real_t > > & | vars, |
| UnaryFunction | helper ) |
Definition at line 102 of file particles_imp.h.
| void particles_t::p2g_print | ( | std::map< std::string, vector_t< real_t > > & | vars, |
| PT const & | pvarnames, | ||
| GT const & | gvarnames, | ||
| bool | apply_mass = false ) const |
Definition at line 580 of file particles_imp.h.
| void particles_t::p2g_print | ( | std::map< std::string, vector_t< real_t > > & | vars, |
| std::initializer_list< str > const & | pvarnames, | ||
| std::initializer_list< str > const & | gvarnames, | ||
| bool | apply_mass = false ) const |
Definition at line 568 of file particles_imp.h.
| void particles_t::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 ) |
Definition at line 185 of file particles_imp.h.
| void particles_t::p2gd | ( | std::map< std::string, device_vector_t< real_t > > & | 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 ) |
Definition at line 120 of file particles_imp.h.
| void particles_t::p2gd | ( | std::map< std::string, device_vector_t< real_t > > & | vars, |
| UnaryFunction | helper ) |
Definition at line 248 of file particles_imp.h.
|
inline |
Template for export function.
If a format is not specified, just outputs an error message.
Definition at line 109 of file particles.h.
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.
Definition at line 200 of file particles.h.
Reorder coordinates an properties according to the ordering vvector.
Definition at line 335 of file particles.cpp.
| void particles_t::update_ptcl_to_grd | ( | ) |
Updates theptcl_to_grd map only, without changing.
Definition at line 561 of file particles_imp.h.
double type quantities associated with the particles.
Definition at line 42 of file particles.h.
grid->particles connectivity.
Definition at line 45 of file particles.h.
| const quadgrid_t<vector_t<real_t> >& particles_t::grid |
refernce to a grid object.
Definition at line 48 of file particles.h.
integer type quantities associated with the particles.
Definition at line 39 of file particles.h.
Mass matrix to be used for transfers if required.
Definition at line 44 of file particles.h.
| idx_t particles_t::num_particles |
number of particles.
Definition at line 34 of file particles.h.
color of particle's cell.
Definition at line 47 of file particles.h.
particles->grid connectivity.
Definition at line 46 of file particles.h.
x coordinate of particle positions.
Definition at line 35 of file particles.h.
y coordinate of particle positions.
Definition at line 36 of file particles.h.