44 #define PARTICLES_HPP 1
49 #include <gsl/gsl_errno.h>
58 #define IBSIMU_DERIV_ERROR 201
111 ParticleP2D(
double t,
double x,
double vx,
double y,
double vy ) {
112 _x[0] = t; _x[1] = x; _x[2] = vx; _x[3] = y; _x[4] = vy;
131 static size_t dim() {
return(2); }
135 static size_t size() {
return(5); }
148 static int get_derivatives(
double t,
const double *x,
double *dxdt,
void *data );
158 int extrapolate = 0 );
164 static const std::string
IQ_unit() {
return(
"A/m" ); }
176 double speed() {
return( sqrt(_x[2]*_x[2] + _x[4]*_x[4]) ); }
196 res[0] = _x[0] + pp[0];
197 res[1] = _x[1] + pp[1];
198 res[2] = _x[2] + pp[2];
199 res[3] = _x[3] + pp[3];
200 res[4] = _x[4] + pp[4];
206 res[0] = _x[0] - pp[0];
207 res[1] = _x[1] - pp[1];
208 res[2] = _x[2] - pp[2];
209 res[3] = _x[3] - pp[3];
210 res[4] = _x[4] - pp[4];
226 void save( std::ostream &s )
const {
241 << std::setw(12) << pp(0) <<
", "
242 << std::setw(12) << pp(1) <<
", "
243 << std::setw(12) << pp(2) <<
", "
244 << std::setw(12) << pp(3) <<
", "
245 << std::setw(12) << pp(4) <<
")";
279 ParticlePCyl(
double t,
double x,
double vx,
double r,
double vr,
double w ) {
280 _x[0] = t; _x[1] = x; _x[2] = vx; _x[3] = r; _x[4] = vr; _x[5] = w;
300 static size_t dim() {
return(2); }
304 static size_t size() {
return(6); }
322 static int get_derivatives(
double t,
const double *x,
double *dxdt,
void *data );
332 int extrapolate = 0 );
338 static const std::string
IQ_unit() {
return(
"A" ); }
350 double speed() {
return( sqrt(_x[2]*_x[2] + _x[4]*_x[4] + _x[3]*_x[3]*_x[5]*_x[5]) ); }
370 res[0] = _x[0] + pp[0];
371 res[1] = _x[1] + pp[1];
372 res[2] = _x[2] + pp[2];
373 res[3] = _x[3] + pp[3];
374 res[4] = _x[4] + pp[4];
375 res[5] = _x[5] + pp[5];
381 res[0] = _x[0] - pp[0];
382 res[1] = _x[1] - pp[1];
383 res[2] = _x[2] - pp[2];
384 res[3] = _x[3] - pp[3];
385 res[4] = _x[4] - pp[4];
386 res[5] = _x[5] - pp[5];
403 void save( std::ostream &s )
const {
419 << std::setw(12) << pp(0) <<
", "
420 << std::setw(12) << pp(1) <<
", "
421 << std::setw(12) << pp(2) <<
", "
422 << std::setw(12) << pp(3) <<
", "
423 << std::setw(12) << pp(4) <<
", "
424 << std::setw(12) << pp(5) <<
")";
459 ParticleP3D(
double t,
double x,
double vx,
double y,
double vy,
double z,
double vz ) {
460 _x[0] = t; _x[1] = x; _x[2] = vx; _x[3] = y; _x[4] = vy; _x[5] = z; _x[6] = vz;
481 static size_t dim() {
return(3); }
485 static size_t size() {
return(7); }
500 static int get_derivatives(
double t,
const double *x,
double *dxdt,
void *data );
510 int extrapolate = 0 );
516 static const std::string
IQ_unit() {
return(
"A" ); }
528 double speed() {
return( sqrt(_x[2]*_x[2] + _x[4]*_x[4] + _x[6]*_x[6]) ); }
548 res[0] = _x[0] + pp[0];
549 res[1] = _x[1] + pp[1];
550 res[2] = _x[2] + pp[2];
551 res[3] = _x[3] + pp[3];
552 res[4] = _x[4] + pp[4];
553 res[5] = _x[5] + pp[5];
554 res[6] = _x[6] + pp[6];
560 res[0] = _x[0] - pp[0];
561 res[1] = _x[1] - pp[1];
562 res[2] = _x[2] - pp[2];
563 res[3] = _x[3] - pp[3];
564 res[4] = _x[4] - pp[4];
565 res[5] = _x[5] - pp[5];
566 res[6] = _x[6] - pp[6];
584 void save( std::ostream &s )
const {
601 << std::setw(12) << pp(0) <<
", "
602 << std::setw(12) << pp(1) <<
", "
603 << std::setw(12) << pp(2) <<
", "
604 << std::setw(12) << pp(3) <<
", "
605 << std::setw(12) << pp(4) <<
", "
606 << std::setw(12) << pp(5) <<
", "
607 << std::setw(12) << pp(6) <<
")";
691 double IQ()
const {
return(
_IQ ); }
695 double q()
const {
return(
_q ); }
699 double m()
const {
return(
_m ); }
707 void save( std::ostream &s )
const {
726 std::vector<PP> _trajectory;
748 _trajectory.reserve( N );
749 for( uint32_t a = 0; a < N; a++ )
750 _trajectory.push_back( PP( s ) );
784 PP &
x() {
return( _x ); }
788 const PP &
x()
const {
return( _x ); }
792 PP &
traj(
int i ) {
return( _trajectory[i] ); }
796 const PP &
traj(
int i )
const {
return( _trajectory[i] ); }
800 size_t traj_size(
void )
const {
return( _trajectory.size() ); }
816 void save( std::ostream &s )
const {
819 for( uint32_t a = 0; a < _trajectory.size(); a++ )
820 _trajectory[a].
save( s );
828 os <<
"**Particle\n";
831 os <<
"stat = PARTICLE_OK\n";
834 os <<
"stat = PARTICLE_OUT\n";
837 os <<
"stat = PARTICLE_COLL\n";
840 os <<
"stat = PARTICLE_BADDEF\n";
843 os <<
"stat = PARTICLE_TIME\n";
846 os <<
"stat = PARTICLE_NSTP\n";
849 os <<
"IQ = " <<
_IQ <<
"\n";
850 os <<
"q = " <<
_q <<
"\n";
851 os <<
"m = " <<
_m <<
"\n";
852 os <<
"x = " << _x <<
"\n";
853 os <<
"Trajectory:\n";
854 for( a = 0; a < _trajectory.size(); a++ )
855 os <<
"x[" << a <<
"] = " << _trajectory[a] <<
"\n";
Particle< ParticlePCyl > ParticleCyl
Particle class in Cylindrical symmetry.
Definition: particles.hpp:887
static const std::string IQ_unit()
Return string representation for unit of current.
Definition: particles.hpp:164
ParticlePCyl operator-(const ParticlePCyl &pp) const
Definition: particles.hpp:379
ParticlePCyl()
Default constuctor.
Definition: particles.hpp:275
Particle point class for cylindrical coordinates.
Definition: particles.hpp:267
const double & operator()(int i) const
Operator for pointing to coordinate data.
Definition: particles.hpp:366
static size_t dim()
Returns number of dimensions for geometry.
Definition: particles.hpp:300
void write_int32(std::ostream &os, int32_t value)
Write int32_t value into stream os.
const VectorField * _bfield
Magnetic field or NULL.
Definition: particles.hpp:903
static geom_mode_e geom_mode()
Returns geometry mode.
Definition: particles.hpp:127
void save(std::ostream &s) const
Saves data to stream.
Definition: particles.hpp:816
static geom_mode_e geom_mode()
Returns geometry mode.
Definition: particles.hpp:296
Vec3D velocity() const
Returns the velocity of particle point in Vec3D.
Definition: particles.hpp:346
Abstract base class for vector field.
Definition: vectorfield.hpp:53
static int trajectory_intersections_at_plane(std::vector< ParticlePCyl > &intsc, int crd, double val, const ParticlePCyl &x1, const ParticlePCyl &x2, int extrapolate=0)
Return the number of trajectory intersections with plane crd = val on the trajectory from x1 to x2...
Particle< ParticleP3D > Particle3D
Particle class in 3D.
Definition: particles.hpp:894
const CallbackFunctorD_V * _bsup_cb
B-field plasma suppression callback.
Definition: particles.hpp:906
PP & traj(int i)
Return reference to trajectory data.
Definition: particles.hpp:792
ParticleP2D operator-(const ParticleP2D &pp) const
Definition: particles.hpp:204
Vec3D location() const
Returns the location of particle point in Vec3D.
Definition: particles.hpp:168
static const std::string IQ_unit()
Return string representation for unit of current.
Definition: particles.hpp:338
Vec3D location() const
Returns the location of particle in Vec3D.
Definition: particles.hpp:776
double _m
Mass m [kg].
Definition: particles.hpp:654
ParticlePCyl operator*(double x) const
Definition: particles.hpp:390
ParticleP3D(std::istream &s)
Constructor for loading particle point from a file.
Definition: particles.hpp:465
double speed()
Returns speed of particle.
Definition: particles.hpp:176
static geom_mode_e geom_mode()
Returns geometry mode.
Definition: particles.hpp:477
ParticleBase(double IQ, double q, double m)
Definition: particles.hpp:656
static size_t dim()
Returns number of dimensions for geometry.
Definition: particles.hpp:131
Particle point class for 3D.
Definition: particles.hpp:447
Definition: particles.hpp:70
ParticleP2D operator*(double x) const
Definition: particles.hpp:214
const double & operator[](int i) const
Operator for pointing to coordinate data.
Definition: particles.hpp:184
const double & operator[](int i) const
Operator for pointing to coordinate data.
Definition: particles.hpp:358
double _IQ
Current or charge of particle.
Definition: particles.hpp:642
Particle(std::istream &s)
Constructor for loading particle from a file.
Definition: particles.hpp:744
Definition: particles.hpp:72
Temporary data bundle for particle iterators.
Definition: particles.hpp:900
const PP & traj(int i) const
Return const reference to trajectory data.
Definition: particles.hpp:796
double _q
Charge q [C].
Definition: particles.hpp:653
Particle point base class
Definition: particles.hpp:88
void set_bfield_suppression_callback(const CallbackFunctorD_V *bsup_cb)
Set B-field potential dependent suppression callback.
Definition: particles.hpp:915
geom_mode_e
Geometry mode enum.
Definition: types.hpp:59
void clear_trajectory(void)
Clears the particle trajectory.
Definition: particles.hpp:812
ParticleP2D operator*(double x, const ParticleP2D &pp)
Definition: particles.hpp:250
static size_t size()
Returns number of coordinates used for particle point.
Definition: particles.hpp:135
2D geometry
Definition: types.hpp:61
Three dimensional vectors.
particle_status_e
Particle status enum.
Definition: particles.hpp:68
ParticleP2D(std::istream &s)
Constructor for loading particle point from a file.
Definition: particles.hpp:117
Definition: particles.hpp:71
Vec3D location() const
Returns the location of particle point in Vec3D.
Definition: particles.hpp:520
Vec3D velocity() const
Returns the velocity of particle in Vec3D.
Definition: particles.hpp:780
const double & operator[](int i) const
Operator for pointing to coordinate data.
Definition: particles.hpp:536
ParticlePCyl(double t, double x, double vx, double r, double vr, double w)
Constructor for cylindrical particle point.
Definition: particles.hpp:279
void write_double(std::ostream &os, double value)
Write double value into stream os.
Particle base class
Definition: particles.hpp:637
const PP & x() const
Return const reference to coordinate data.
Definition: particles.hpp:788
static const std::string IQ_unit()
Return string representation for unit of current.
Definition: particles.hpp:516
size_t traj_size(void) const
Return number of trajectory points of particle.
Definition: particles.hpp:800
double & operator[](int i)
Operator for pointing to coordinate data.
Definition: particles.hpp:354
static int trajectory_intersections_at_plane(std::vector< ParticleP3D > &intsc, int crd, double val, const ParticleP3D &x1, const ParticleP3D &x2, int extrapolate=0)
Return the number of trajectory intersections with plane crd = val on the trajectory from x1 to x2...
Vec3D velocity() const
Returns the velocity of particle point in Vec3D.
Definition: particles.hpp:524
double & operator()(int i)
Operator for pointing to coordinate data.
Definition: particles.hpp:362
Vec3D velocity() const
Returns the velocity of particle point in Vec3D.
Definition: particles.hpp:172
Geometry defining class.
Definition: geometry.hpp:131
const double & operator[](int i) const
Operator for pointing to coordinate data.
Definition: particles.hpp:772
void save(std::ostream &s) const
Saves data to stream.
Definition: particles.hpp:707
static size_t dim()
Returns number of dimensions for geometry.
Definition: particles.hpp:481
ParticleP2D()
Default constuctor.
Definition: particles.hpp:107
ParticleBase(std::istream &s)
Constructor for loading particle from a file.
Definition: particles.hpp:667
void add_trajectory_point(const PP &x)
Add trajectory point to the end of the trajectory.
Definition: particles.hpp:804
particle_status_e _status
Status of particle.
Definition: particles.hpp:641
PP & x()
Return reference to coordinate data.
Definition: particles.hpp:784
Definition: callback.hpp:61
particle_status_e get_status()
Return particle status.
Definition: particles.hpp:680
std::ostream & operator<<(std::ostream &os, const ParticleP2D &pp)
Definition: particles.hpp:238
double & operator[](int i)
Operator for pointing to coordinate data.
Definition: particles.hpp:532
static int get_derivatives(double t, const double *x, double *dxdt, void *data)
Returns time derivatives dxdt of coordinates at time t and coordinates x = (x,vx,y,vy,z,vz) for one particle.
ParticleP3D(double t, double x, double vx, double y, double vy, double z, double vz)
Constructor for 3D particle point.
Definition: particles.hpp:459
const double & operator()(int i) const
Operator for pointing to coordinate data.
Definition: particles.hpp:544
ParticleP3D operator+(const ParticleP3D &pp) const
Definition: particles.hpp:546
double & operator()(int i)
Operator for pointing to coordinate data.
Definition: particles.hpp:540
static size_t size()
Returns number of coordinates used for particle point.
Definition: particles.hpp:304
double qm() const
Return charge per mass ratio (q/m) [C/kg].
Definition: particles.hpp:703
Definition: particles.hpp:69
void save(std::ostream &s) const
Saves data to stream.
Definition: particles.hpp:584
static int trajectory_intersections_at_plane(std::vector< ParticleP2D > &intsc, int crd, double val, const ParticleP2D &x1, const ParticleP2D &x2, int extrapolate=0)
Return the number of trajectory intersections with plane crd = val on the trajectory from x1 to x2...
ParticleP3D operator-(const ParticleP3D &pp) const
Definition: particles.hpp:558
Particle class in some geometry.
Definition: particles.hpp:724
Definition: particles.hpp:74
const VectorField * _efield
Electric field or NULL.
Definition: particles.hpp:902
Definition: particles.hpp:73
void set_status(particle_status_e status)
Set particle status.
Definition: particles.hpp:684
ScalarField * _scharge
Space charge field or NULL.
Definition: particles.hpp:901
~Particle()
Destructor.
Definition: particles.hpp:756
Particle point class for 2D.
Definition: particles.hpp:99
ParticleP2D(double t, double x, double vx, double y, double vy)
Constructor for 2D particle point.
Definition: particles.hpp:111
ParticlePCyl(std::istream &s)
Constructor for loading particle point from a file.
Definition: particles.hpp:285
static int get_derivatives(double t, const double *x, double *dxdt, void *data)
Returns time derivatives dxdt of coordinates at time t and coordinates x = (x,vx,r,vr,w) for one particle.
ParticleP3D operator*(double x) const
Definition: particles.hpp:570
int32_t read_int32(std::istream &is)
Read int32_t from stream is.
Particle< ParticleP2D > Particle2D
Particle class in 2D.
Definition: particles.hpp:880
General callback functors.
double _qm
Precalculated q/m.
Definition: particles.hpp:905
double & operator[](int i)
Operator for pointing to coordinate data.
Definition: particles.hpp:768
double IQ() const
Return current or charge carried by trajectory or particle cloud [A/C].
Definition: particles.hpp:691
Vec3D location() const
Returns the location of particle point in Vec3D.
Definition: particles.hpp:342
void save(std::ostream &s) const
Saves data to stream.
Definition: particles.hpp:226
double & operator[](int i)
Operator for pointing to coordinate data.
Definition: particles.hpp:180
ParticleP2D operator+(const ParticleP2D &pp) const
Definition: particles.hpp:194
double & operator()(int i)
Operator for pointing to coordinate data.
Definition: particles.hpp:760
const Geometry * _geom
Geometry.
Definition: particles.hpp:904
~ParticleBase()
Definition: particles.hpp:674
Cylindrically symmetric geometry.
Definition: types.hpp:62
Three dimensional vector.
Definition: vec3d.hpp:58
static size_t size()
Returns number of coordinates used for particle point.
Definition: particles.hpp:485
Particle(double IQ, double q, double m, const PP &x)
Constructor for particle.
Definition: particles.hpp:739
static int get_derivatives(double t, const double *x, double *dxdt, void *data)
Returns time derivatives dxdt of coordinates at time t and coordinates x = (x,vx,y,vy) for one particle.
double q() const
Return particle charge (q) [C].
Definition: particles.hpp:695
double & operator()(int i)
Operator for pointing to coordinate data.
Definition: particles.hpp:188
void copy_trajectory(const std::vector< PP > &traj)
Define trajectory by copying.
Definition: particles.hpp:808
const double & operator()(int i) const
Operator for pointing to coordinate data.
Definition: particles.hpp:764
const double & operator()(int i) const
Operator for pointing to coordinate data.
Definition: particles.hpp:192
ParticlePCyl operator+(const ParticlePCyl &pp) const
Definition: particles.hpp:368
double speed()
Returns speed of particle.
Definition: particles.hpp:350
void save(std::ostream &s) const
Saves data to stream.
Definition: particles.hpp:403
void debug_print(std::ostream &os) const
Print debugging information to os.
Definition: particles.hpp:826
double speed()
Returns speed of particle.
Definition: particles.hpp:528
3D geometry
Definition: types.hpp:63
ParticleP3D()
Default constuctor.
Definition: particles.hpp:455
double m() const
Return particle mass (m) [kg].
Definition: particles.hpp:699
Scalar field class.
Definition: scalarfield.hpp:70
double read_double(std::istream &is)
Readd double from stream is.
ParticleIteratorData(ScalarField *scharge, const VectorField *efield, const VectorField *bfield, const Geometry *geom)
Definition: particles.hpp:908