particledatabase.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2011 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 #ifndef PARTICLEDATABASE_HPP
44 #define PARTICLEDATABASE_HPP 1
45 
46 
47 #include "scalarfield.hpp"
48 #include "vectorfield.hpp"
49 #include "particles.hpp"
51 #include "particlestatistics.hpp"
52 #include "constants.hpp"
53 
54 
58 public:
59 
63 
64  virtual void operator()( ParticleBase *particle, ParticlePBase *xcur, ParticlePBase *xend ) const = 0;
65 
66 };
67 
68 
72 public:
73 
77 
80  virtual void operator()( ParticleBase *particle, class ParticleDataBase *pdb ) const = 0;
81 
82 };
83 
84 
95 
96  double _phi;
97  const ScalarField &_epot;
99 public:
100 
103  PPlasmaBfieldSuppression( const ScalarField &epot, double phi )
104  : _phi(phi), _epot(epot) {}
105 
109 
112  virtual double operator()( const Vec3D &x ) const {
113  if( _epot( x ) > _phi )
114  return( 0.0 );
115  return( 1.0 );
116  }
117 };
118 
119 
130 
131  double _phi;
132  const ScalarField &_epot;
134 public:
135 
138  NPlasmaBfieldSuppression( const ScalarField &epot, double phi )
139  : _phi(phi), _epot(epot) {}
140 
144 
147  virtual double operator()( const Vec3D &x ) const {
148  if( _epot( x ) < _phi )
149  return( 0.0 );
150  return( 1.0 );
151  }
152 };
153 
154 
155 /* ******************************************************************************************* *
156  * ParticleDataBase classes *
157  * ******************************************************************************************* */
158 
159 
168 
169  class ParticleDataBaseImp *_imp;
170 
171 protected:
172 
173 /* ************************************** *
174  * Constructors *
175  * ************************************** */
176 
180 
183  ParticleDataBase( const ParticleDataBase &pdb );
184 
187  const ParticleDataBase &operator=( const ParticleDataBase &pdb );
188 
193  void set_implementation_pointer( class ParticleDataBaseImp *imp );
194 
195 public:
196 
197 /* ************************************** *
198  * Destructor *
199  * ************************************** */
200 
203  virtual ~ParticleDataBase();
204 
205 /* ****************************************** *
206  * Particle iteration settings and statictics *
207  * ****************************************** */
208 
214  void set_thread_count( uint32_t threadcount ) {}
215 
221  void set_accuracy( double epsabs, double epsrel );
222 
232  void set_bfield_suppression( const CallbackFunctorD_V *functor );
233 
237 
240  void set_trajectory_end_callback( const TrajectoryEndCallback *tend_cb );
241 
246  void set_polyint( bool polyint );
247 
253  bool get_polyint( void ) const;
254 
259  void set_max_steps( uint32_t maxsteps );
260 
265  void set_max_time( double maxt );
266 
275  void set_save_trajectories( uint32_t div );
276 
283  uint32_t get_save_trajectories( void ) const;
284 
293  void set_mirror( const bool mirror[6] );
294 
301  void get_mirror( bool mirror[6] ) const;
302 
305  int get_iteration_number( void ) const;
306 
320  double get_rhosum( void ) const;
321 
324  void set_rhosum( double rhosum );
325 
328  const ParticleStatistics &get_statistics( void ) const;
329 
330 /* ************************************** *
331  * Information and queries *
332  * ************************************** */
333 
336  geom_mode_e geom_mode() const;
337 
340  size_t size( void ) const;
341 
344  virtual ParticleBase &particle( uint32_t i ) = 0;
345 
348  virtual const ParticleBase &particle( uint32_t i ) const = 0;
349 
352  double traj_length( uint32_t i ) const;
353 
356  size_t traj_size( uint32_t i ) const;
357 
360  virtual const ParticlePBase &trajectory_point( uint32_t i, uint32_t j ) const = 0;
361 
364  void trajectory_point( double &t, Vec3D &loc, Vec3D &vel, uint32_t i, uint32_t j ) const;
365 
370  coordinate_axis_e axis,
371  double val,
372  const std::vector<trajectory_diagnostic_e> &diagnostics ) const;
373 
378  void build_trajectory_density_field( ScalarField &tdens ) const;
379 
380 /* ************************************** *
381  * Particle and trajectory clearing *
382  * ************************************** */
383 
389  void clear( void );
390 
396  void clear_trajectories( void );
397 
403  void clear_trajectory( size_t a );
404 
405 /* ************************************** *
406  * Particle definition *
407  * ************************************** */
408 
411  void reserve( size_t size );
412 
413 /* ************************************** *
414  * Particle iterators *
415  * ************************************** */
416 
424  void iterate_trajectories( ScalarField &scharge, const VectorField &efield,
425  const VectorField &bfield, const Geometry &g );
426 
433  void step_particles( ScalarField &scharge, const VectorField &efield,
434  const VectorField &bfield, const Geometry &g, double dt );
435 
436 /* ************************************** *
437  * Debugging, plotting and saving *
438  * ************************************** */
439 
442  virtual void save( const std::string &filename ) const = 0;
443 
446  virtual void save( std::ostream &s ) const = 0;
447 
450  virtual void debug_print( std::ostream &os ) const = 0;
451 };
452 
453 
466 
467  class ParticleDataBase2DImp *_imp;
468 
469 public:
470 
471 /* ************************************** *
472  * Constructors and destructor *
473  * ************************************** */
474 
478 
482 
485  ParticleDataBase2D( std::istream &s );
486 
490 
493  const ParticleDataBase2D &operator=( const ParticleDataBase2D &pdb );
494 
495 /* ************************************** *
496  * Information and queries *
497  * ************************************** */
498 
501  virtual Particle2D &particle( uint32_t i );
502 
505  virtual const Particle2D &particle( uint32_t i ) const;
506 
509  virtual const ParticleP2D &trajectory_point( uint32_t i, uint32_t j ) const;
510 
512 
513 /* ************************************** *
514  * Particle definition *
515  * ************************************** */
516 
528  void add_particle( double IQ, double q, double m, const ParticleP2D &x );
529 
534  void add_particle( const Particle2D &p );
535 
536 /* ************************************** *
537  * Particle beam definition *
538  * ************************************** */
539 
559  void add_2d_beam_with_energy( uint32_t N, double J, double q, double m,
560  double E, double Tp, double Tt,
561  double x1, double y1, double x2, double y2 );
562 
578  void add_2d_beam_with_velocity( uint32_t N, double J, double q, double m,
579  double v, double dvp, double dvt,
580  double x1, double y1, double x2, double y2 );
581 
598  void add_2d_KV_beam_with_emittance( uint32_t N, double I, double q, double m,
599  double a, double b, double e,
600  double Ex, double x0, double y0 );
601 
618  void add_2d_gaussian_beam_with_emittance( uint32_t N, double I, double q, double m,
619  double a, double b, double e,
620  double Ex, double x0, double y0 );
621 
622 /* ************************************** *
623  * Debugging, plotting and saving *
624  * ************************************** */
625 
628  virtual void save( const std::string &filename ) const;
629 
632  virtual void save( std::ostream &s ) const;
633 
636  virtual void debug_print( std::ostream &os ) const;
637 };
638 
639 
640 
641 
654 
655  class ParticleDataBaseCylImp *_imp;
656 
657 public:
658 
659 /* ************************************** *
660  * Constructors and destructor *
661  * ************************************** */
662 
666 
670 
673  ParticleDataBaseCyl( std::istream &s );
674 
678 
682 
683 /* ************************************** *
684  * Information and queries *
685  * ************************************** */
686 
689  virtual ParticleCyl &particle( uint32_t i );
690 
693  virtual const ParticleCyl &particle( uint32_t i ) const;
694 
697  virtual const ParticlePCyl &trajectory_point( uint32_t i, uint32_t j ) const;
698 
700 
701 /* ************************************** *
702  * Particle definition *
703  * ************************************** */
704 
716  void add_particle( double IQ, double q, double m, const ParticlePCyl &x );
717 
722  void add_particle( const ParticleCyl &p );
723 
724 /* ************************************** *
725  * Particle beam definition *
726  * ************************************** */
727 
747  void add_2d_beam_with_energy( uint32_t N, double J, double q, double m,
748  double E, double Tp, double Tt,
749  double x1, double y1, double x2, double y2 );
750 
766  void add_2d_beam_with_velocity( uint32_t N, double J, double q, double m,
767  double v, double dvp, double dvt,
768  double x1, double y1, double x2, double y2 );
769 
772  void add_2d_full_gaussian_beam( uint32_t N, double I, double q, double m,
773  double Ex, double Tp, double Tt,
774  double x0, double dr );
775 
794  void add_2d_gaussian_beam_with_emittance( uint32_t N, double I, double q, double m,
795  double a, double b, double e,
796  double Ex, double x0 );
797 
798 /* ************************************** *
799  * Debugging, plotting and saving *
800  * ************************************** */
801 
804  virtual void save( const std::string &filename ) const;
805 
808  virtual void save( std::ostream &s ) const;
809 
812  virtual void debug_print( std::ostream &os ) const;
813 };
814 
815 
816 
829 
830  class ParticleDataBase3DImp *_imp;
831 
832 public:
833 
834 /* ************************************** *
835  * Constructors and destructor *
836  * ************************************** */
837 
841 
845 
848  ParticleDataBase3D( std::istream &s );
849 
853 
856  const ParticleDataBase3D &operator=( const ParticleDataBase3D &pdb );
857 
858 /* ************************************** *
859  * Information and queries *
860  * ************************************** */
861 
864  virtual Particle3D &particle( uint32_t i );
865 
868  virtual const Particle3D &particle( uint32_t i ) const;
869 
872  virtual const ParticleP3D &trajectory_point( uint32_t i, uint32_t j ) const;
873 
875 
876 /* ************************************** *
877  * Particle definition *
878  * ************************************** */
879 
891  void add_particle( double IQ, double q, double m, const ParticleP3D &x );
892 
897  void add_particle( const Particle3D &p );
898 
899 /* ************************************** *
900  * Particle beam definition *
901  * ************************************** */
902 
926  void add_cylindrical_beam_with_energy( uint32_t N, double J, double q, double m,
927  double E, double Tp, double Tt, Vec3D c,
928  Vec3D dir1, Vec3D dir2, double r );
929 
952  void add_cylindrical_beam_with_velocity( uint32_t N, double J, double q, double m,
953  double v, double dvp, double dvt, Vec3D c,
954  Vec3D dir1, Vec3D dir2, double r );
955 
964  void add_rectangular_beam_with_energy( uint32_t N, double J, double q, double m,
965  double E, double Tp, double Tt, Vec3D c,
966  Vec3D dir1, Vec3D dir2, double size1, double size2 );
967 
976  void add_rectangular_beam_with_velocity( uint32_t N, double J, double q, double m,
977  double v, double dvp, double dvt, Vec3D c,
978  Vec3D dir1, Vec3D dir2, double size1, double size2 );
979 
980 
998  void add_3d_KV_beam_with_emittance( uint32_t N, double I, double q, double m,
999  double ay, double by, double ey,
1000  double az, double bz, double ez,
1001  double Ex, double x0, double y0, double z0 );
1002 
1021  void add_3d_gaussian_beam_with_emittance( uint32_t N, double I, double q, double m,
1022  double E0,
1023  double a1, double b1, double e1,
1024  double a2, double b2, double e2,
1025  Vec3D c, Vec3D dir1, Vec3D dir2 );
1026 
1027 
1028 /* ************************************** *
1029  * Information and queries *
1030  * ************************************** */
1031 
1032 
1051  const Vec3D &c, const Vec3D &o, const Vec3D &p,
1052  const std::vector<trajectory_diagnostic_e> &diagnostics ) const;
1053 
1054 
1076  void export_path_manager_data( std::string filename,
1077  double ref_E, double ref_q, double ref_m,
1078  const Vec3D &c, const Vec3D &o, const Vec3D &p ) const;
1079 
1080 /* ************************************** *
1081  * Debugging, plotting and saving *
1082  * ************************************** */
1083 
1086  virtual void save( const std::string &filename ) const;
1087 
1090  virtual void save( std::ostream &s ) const;
1091 
1094  virtual void debug_print( std::ostream &os ) const;
1095 };
1096 
1097 #endif
1098