quadgrid 0.1
simple cartesian quad grid with particles for c++/octave
particles_t Struct Reference

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_tip (const std::string &name, idx_t ii)
 shortcut for iprops.at (name) [ii] More...
 
const idx_tip (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...
 

Detailed Description

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 ()

Member Typedef Documentation

◆ idx_t

using particles_t::idx_t = quadgrid_t<std::vector<double> >::idx_t

datatype for indexing into vectors of properties

Member Enumeration Documentation

◆ output_format

enum class particles_t::output_format : idx_t
strong

Enumeration of available output format.

Enumerator
csv 

comma separated ascii file with headers, can be read by common spreadsheet apps or by Paraview or Octave.

octave_ascii 

GNU Octave ascii data format, can be loaded via the load command in GNU Octave.

json 

Constructor & Destructor Documentation

◆ particles_t() [1/5]

particles_t::particles_t ( idx_t  n,
const quadgrid_t< std::vector< double > > &  grid_ 
)
inline

Simplest form of constructor.

Particle positions are not assigned, they must be set manually later.

Parameters
nnumber of particles
grid_quadgrid_t object, sizes need to have been already set up.

◆ particles_t() [2/5]

particles_t::particles_t ( const nlohmann::json &  j,
const quadgrid_t< std::vector< double > > &  grid_ 
)
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() [3/5]

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.

Parameters
nnumber of particles
grid_quadgrid_t object, sizes need to have been already set up.
ipropnameskeys for entries in the particles_t::iprops map.
dpropnameskeys for entries in the particles_t::dprops map.

◆ particles_t() [4/5]

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.

Parameters
nnumber of particles
grid_quadgrid_t object, sizes need to have been already set up.
ipropnameskeys for entries in the particles_t::iprops map.
dpropnameskeys for entries in the particles_t::dprops map.
xvthe x-coordinates of new particles.
yvthe y-coordinates of new particles.

◆ particles_t() [5/5]

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.

Parameters
nnumber of particles
grid_quadgrid_t object, sizes need to have been already set up.
ipropnameskeys for entries in the particles_t::iprops map.
dpropnameskeys for entries in the particles_t::dprops map.
xgengenerator function for the x-coordinates of new particles.
ygengenerator function for the y-coordinates of new particles.

Member Function Documentation

◆ build_mass()

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

◆ default_x_generator()

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.

◆ default_y_generator()

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.

◆ dp() [1/2]

double & particles_t::dp ( const std::string &  name,
idx_t  ii 
)
inline

shortcut for dprops.at (name) [ii]

◆ dp() [2/2]

const double & particles_t::dp ( const std::string &  name,
idx_t  ii 
) const
inline

shortcut for dprops.at (name) [ii]

◆ g2p() [1/3]

void particles_t::g2p ( const std::map< std::string, std::vector< double > > &  vars,
bool  apply_mass = false,
assignment_t  OP = ASSIGNMENT_OPS::PLUS_EQ 
)
inline

◆ g2p() [2/3]

template<typename GT , typename PT >
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 
)

◆ g2p() [3/3]

template<typename str >
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 
)

◆ g2pd() [1/2]

template<typename GT , typename PT >
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 
)

◆ g2pd() [2/2]

template<typename str >
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 
)

◆ getkey() [1/3]

static const char * particles_t::getkey ( std::initializer_list< const char * > const &  varnames,
std::size_t  ivar 
)
inlinestatic

◆ getkey() [2/3]

static const std::string & particles_t::getkey ( std::map< std::string, std::vector< double > > const &  varnames,
std::size_t  ivar 
)
inlinestatic

◆ getkey() [3/3]

static const std::string & particles_t::getkey ( std::vector< std::string > const &  varnames,
std::size_t  ivar 
)
inlinestatic

◆ init_particle_mesh()

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.

◆ init_particle_positions()

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.

◆ init_props()

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.

Parameters
ipropnameskeys for entries in the particles_t::iprops map.
dpropnameskeys for entries in the particles_t::dprops map.

◆ ip() [1/2]

idx_t & particles_t::ip ( const std::string &  name,
idx_t  ii 
)
inline

shortcut for iprops.at (name) [ii]

◆ ip() [2/2]

const idx_t & particles_t::ip ( const std::string &  name,
idx_t  ii 
) const
inline

shortcut for iprops.at (name) [ii]

◆ p2g() [1/3]

void particles_t::p2g ( std::map< std::string, std::vector< double > > &  vars,
bool  apply_mass = false 
) const
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.

◆ p2g() [2/3]

template<typename GT , typename PT >
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.

◆ p2g() [3/3]

template<typename str >
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

◆ p2gd() [1/2]

template<typename GT , typename PT >
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

◆ p2gd() [2/2]

template<typename str >
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

◆ print()

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

Template for export function.

If a format is not specified, just outputs an error message.

◆ remove_in_region()

void particles_t::remove_in_region ( std::function< bool(double, double)>  fun)
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.

Member Data Documentation

◆ dprops

std::map<std::string, std::vector<double> > particles_t::dprops

double type quantities associated with the particles.

◆ grd_to_ptcl

std::map<idx_t, std::vector<idx_t> > particles_t::grd_to_ptcl

grid/particles connectivity.

◆ grid

const quadgrid_t<std::vector<double> >& particles_t::grid

refernce to a grid object.

◆ iprops

std::map<std::string, std::vector<idx_t> > particles_t::iprops

integer type quantities associated with the particles.

◆ M

std::vector<double> particles_t::M

Mass matrix to be used for transfers if required.

◆ num_particles

idx_t particles_t::num_particles

number of particles.

◆ x

std::vector<double> particles_t::x

x coordinate of particle positions.

◆ y

std::vector<double> particles_t::y

y coordinate of particle positions.


The documentation for this struct was generated from the following files: