particledatabase.hpp
Go to the documentation of this file.
00001 00005 /* Copyright (c) 2005-2011 Taneli Kalvas. All rights reserved. 00006 * 00007 * You can redistribute this software and/or modify it under the terms 00008 * of the GNU General Public License as published by the Free Software 00009 * Foundation; either version 2 of the License, or (at your option) 00010 * any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this library (file "COPYING" included in the package); 00019 * if not, write to the Free Software Foundation, Inc., 51 Franklin 00020 * Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 * 00022 * If you have questions about your rights to use or distribute this 00023 * software, please contact Berkeley Lab's Technology Transfer 00024 * Department at TTD@lbl.gov. Other questions, comments and bug 00025 * reports should be sent directly to the author via email at 00026 * taneli.kalvas@jyu.fi. 00027 * 00028 * NOTICE. This software was developed under partial funding from the 00029 * U.S. Department of Energy. As such, the U.S. Government has been 00030 * granted for itself and others acting on its behalf a paid-up, 00031 * nonexclusive, irrevocable, worldwide license in the Software to 00032 * reproduce, prepare derivative works, and perform publicly and 00033 * display publicly. Beginning five (5) years after the date 00034 * permission to assert copyright is obtained from the U.S. Department 00035 * of Energy, and subject to any subsequent five (5) year renewals, 00036 * the U.S. Government is granted for itself and others acting on its 00037 * behalf a paid-up, nonexclusive, irrevocable, worldwide license in 00038 * the Software to reproduce, prepare derivative works, distribute 00039 * copies to the public, perform publicly and display publicly, and to 00040 * permit others to do so. 00041 */ 00042 00043 #ifndef PARTICLEDATABASE_HPP 00044 #define PARTICLEDATABASE_HPP 1 00045 00046 00047 #include "scalarfield.hpp" 00048 #include "vectorfield.hpp" 00049 #include "particles.hpp" 00050 #include "trajectorydiagnostics.hpp" 00051 #include "particlestatistics.hpp" 00052 #include "constants.hpp" 00053 00054 00057 class TrajectoryHandlerCallback { 00058 public: 00059 00062 virtual ~TrajectoryHandlerCallback() {} 00063 00064 virtual void operator()( ParticleBase *particle, ParticlePBase *xcur, ParticlePBase *xend ) const = 0; 00065 00066 }; 00067 00068 00071 class TrajectoryEndCallback { 00072 public: 00073 00076 virtual ~TrajectoryEndCallback() {} 00077 00080 virtual void operator()( ParticleBase *particle, class ParticleDataBase *pdb ) const = 0; 00081 00082 }; 00083 00084 00094 class PPlasmaBfieldSuppression : public CallbackFunctorD_V { 00095 00096 double _phi; 00097 const ScalarField &_epot; 00099 public: 00100 00103 PPlasmaBfieldSuppression( const ScalarField &epot, double phi ) 00104 : _phi(phi), _epot(epot) {} 00105 00108 ~PPlasmaBfieldSuppression() {} 00109 00112 virtual double operator()( const Vec3D &x ) const { 00113 if( _epot( x ) > _phi ) 00114 return( 0.0 ); 00115 return( 1.0 ); 00116 } 00117 }; 00118 00119 00129 class NPlasmaBfieldSuppression : public CallbackFunctorD_V { 00130 00131 double _phi; 00132 const ScalarField &_epot; 00134 public: 00135 00138 NPlasmaBfieldSuppression( const ScalarField &epot, double phi ) 00139 : _phi(phi), _epot(epot) {} 00140 00143 ~NPlasmaBfieldSuppression() {} 00144 00147 virtual double operator()( const Vec3D &x ) const { 00148 if( _epot( x ) < _phi ) 00149 return( 0.0 ); 00150 return( 1.0 ); 00151 } 00152 }; 00153 00154 00155 /* ******************************************************************************************* * 00156 * ParticleDataBase classes * 00157 * ******************************************************************************************* */ 00158 00159 00167 class ParticleDataBase { 00168 00169 class ParticleDataBaseImp *_imp; 00170 00171 protected: 00172 00173 /* ************************************** * 00174 * Constructors * 00175 * ************************************** */ 00176 00179 ParticleDataBase(); 00180 00183 ParticleDataBase( const ParticleDataBase &pdb ); 00184 00187 const ParticleDataBase &operator=( const ParticleDataBase &pdb ); 00188 00193 void set_implementation_pointer( class ParticleDataBaseImp *imp ); 00194 00195 public: 00196 00197 /* ************************************** * 00198 * Destructor * 00199 * ************************************** */ 00200 00203 virtual ~ParticleDataBase(); 00204 00205 /* ****************************************** * 00206 * Particle iteration settings and statictics * 00207 * ****************************************** */ 00208 00214 void set_thread_count( uint32_t threadcount ) {} 00215 00221 void set_accuracy( double epsabs, double epsrel ); 00222 00232 void set_bfield_suppression( const CallbackFunctorD_V *functor ); 00233 00236 void set_trajectory_handler_callback( const TrajectoryHandlerCallback *thand_cb ); 00237 00240 void set_trajectory_end_callback( const TrajectoryEndCallback *tend_cb ); 00241 00246 void set_polyint( bool polyint ); 00247 00253 bool get_polyint( void ) const; 00254 00259 void set_max_steps( uint32_t maxsteps ); 00260 00265 void set_max_time( double maxt ); 00266 00275 void set_save_trajectories( uint32_t div ); 00276 00283 uint32_t get_save_trajectories( void ) const; 00284 00293 void set_mirror( const bool mirror[6] ); 00294 00301 void get_mirror( bool mirror[6] ) const; 00302 00305 int get_iteration_number( void ) const; 00306 00320 double get_rhosum( void ) const; 00321 00324 const ParticleStatistics &get_statistics( void ) const; 00325 00326 /* ************************************** * 00327 * Information and queries * 00328 * ************************************** */ 00329 00332 geom_mode_e geom_mode() const; 00333 00336 size_t size( void ) const; 00337 00340 virtual ParticleBase &particle( uint32_t i ) = 0; 00341 00344 virtual const ParticleBase &particle( uint32_t i ) const = 0; 00345 00348 double traj_length( uint32_t i ) const; 00349 00352 size_t traj_size( uint32_t i ) const; 00353 00356 virtual const ParticlePBase &trajectory_point( uint32_t i, uint32_t j ) const = 0; 00357 00360 void trajectory_point( double &t, Vec3D &loc, Vec3D &vel, uint32_t i, uint32_t j ) const; 00361 00365 void trajectories_at_plane( TrajectoryDiagnosticData &tdata, 00366 coordinate_axis_e axis, 00367 double val, 00368 const std::vector<trajectory_diagnostic_e> &diagnostics ) const; 00369 00374 void build_trajectory_density_field( ScalarField &tdens ) const; 00375 00376 /* ************************************** * 00377 * Particle and trajectory clearing * 00378 * ************************************** */ 00379 00385 void clear( void ); 00386 00392 void clear_trajectories( void ); 00393 00399 void clear_trajectory( size_t a ); 00400 00401 /* ************************************** * 00402 * Particle definition * 00403 * ************************************** */ 00404 00407 void reserve( size_t size ); 00408 00409 /* ************************************** * 00410 * Particle iterators * 00411 * ************************************** */ 00412 00420 void iterate_trajectories( ScalarField &scharge, const VectorField &efield, 00421 const VectorField &bfield, const Geometry &g ); 00422 00429 void step_particles( ScalarField &scharge, const VectorField &efield, 00430 const VectorField &bfield, const Geometry &g, double dt ); 00431 00432 /* ************************************** * 00433 * Debugging, plotting and saving * 00434 * ************************************** */ 00435 00438 virtual void save( const std::string &filename ) const = 0; 00439 00442 virtual void save( std::ostream &s ) const = 0; 00443 00446 virtual void debug_print( std::ostream &os ) const = 0; 00447 }; 00448 00449 00461 class ParticleDataBase2D : public ParticleDataBase { 00462 00463 class ParticleDataBase2DImp *_imp; 00464 00465 public: 00466 00467 /* ************************************** * 00468 * Constructors and destructor * 00469 * ************************************** */ 00470 00473 ParticleDataBase2D(); 00474 00477 ParticleDataBase2D( const ParticleDataBase2D &pdb ); 00478 00481 ParticleDataBase2D( std::istream &s ); 00482 00485 ~ParticleDataBase2D(); 00486 00489 const ParticleDataBase2D &operator=( const ParticleDataBase2D &pdb ); 00490 00491 /* ************************************** * 00492 * Information and queries * 00493 * ************************************** */ 00494 00497 virtual Particle2D &particle( uint32_t i ); 00498 00501 virtual const Particle2D &particle( uint32_t i ) const; 00502 00505 virtual const ParticleP2D &trajectory_point( uint32_t i, uint32_t j ) const; 00506 00507 using ParticleDataBase::trajectory_point; 00508 00509 /* ************************************** * 00510 * Particle definition * 00511 * ************************************** */ 00512 00524 void add_particle( double IQ, double q, double m, const ParticleP2D &x ); 00525 00530 void add_particle( const Particle2D &p ); 00531 00532 /* ************************************** * 00533 * Particle beam definition * 00534 * ************************************** */ 00535 00555 void add_2d_beam_with_energy( uint32_t N, double J, double q, double m, 00556 double E, double Tp, double Tt, 00557 double x1, double y1, double x2, double y2 ); 00558 00574 void add_2d_beam_with_velocity( uint32_t N, double J, double q, double m, 00575 double v, double dvp, double dvt, 00576 double x1, double y1, double x2, double y2 ); 00577 00594 void add_2d_KV_beam_with_emittance( uint32_t N, double I, double q, double m, 00595 double a, double b, double e, 00596 double Ex, double x0, double y0 ); 00597 00614 void add_2d_gaussian_beam_with_emittance( uint32_t N, double I, double q, double m, 00615 double a, double b, double e, 00616 double Ex, double x0, double y0 ); 00617 00618 /* ************************************** * 00619 * Debugging, plotting and saving * 00620 * ************************************** */ 00621 00624 virtual void save( const std::string &filename ) const; 00625 00628 virtual void save( std::ostream &s ) const; 00629 00632 virtual void debug_print( std::ostream &os ) const; 00633 }; 00634 00635 00636 00637 00649 class ParticleDataBaseCyl : public ParticleDataBase { 00650 00651 class ParticleDataBaseCylImp *_imp; 00652 00653 public: 00654 00655 /* ************************************** * 00656 * Constructors and destructor * 00657 * ************************************** */ 00658 00661 ParticleDataBaseCyl(); 00662 00665 ParticleDataBaseCyl( const ParticleDataBaseCyl &pdb ); 00666 00669 ParticleDataBaseCyl( std::istream &s ); 00670 00673 ~ParticleDataBaseCyl(); 00674 00677 const ParticleDataBaseCyl &operator=( const ParticleDataBaseCyl &pdb ); 00678 00679 /* ************************************** * 00680 * Information and queries * 00681 * ************************************** */ 00682 00685 virtual ParticleCyl &particle( uint32_t i ); 00686 00689 virtual const ParticleCyl &particle( uint32_t i ) const; 00690 00693 virtual const ParticlePCyl &trajectory_point( uint32_t i, uint32_t j ) const; 00694 00695 using ParticleDataBase::trajectory_point; 00696 00697 /* ************************************** * 00698 * Particle definition * 00699 * ************************************** */ 00700 00712 void add_particle( double IQ, double q, double m, const ParticlePCyl &x ); 00713 00718 void add_particle( const ParticleCyl &p ); 00719 00720 /* ************************************** * 00721 * Particle beam definition * 00722 * ************************************** */ 00723 00743 void add_2d_beam_with_energy( uint32_t N, double J, double q, double m, 00744 double E, double Tp, double Tt, 00745 double x1, double y1, double x2, double y2 ); 00746 00762 void add_2d_beam_with_velocity( uint32_t N, double J, double q, double m, 00763 double v, double dvp, double dvt, 00764 double x1, double y1, double x2, double y2 ); 00765 00768 void add_2d_full_gaussian_beam( uint32_t N, double I, double q, double m, 00769 double Ex, double Tp, double Tt, 00770 double x0, double dr ); 00771 00790 void add_2d_gaussian_beam_with_emittance( uint32_t N, double I, double q, double m, 00791 double a, double b, double e, 00792 double Ex, double x0 ); 00793 00794 /* ************************************** * 00795 * Debugging, plotting and saving * 00796 * ************************************** */ 00797 00800 virtual void save( const std::string &filename ) const; 00801 00804 virtual void save( std::ostream &s ) const; 00805 00808 virtual void debug_print( std::ostream &os ) const; 00809 }; 00810 00811 00812 00824 class ParticleDataBase3D : public ParticleDataBase { 00825 00826 class ParticleDataBase3DImp *_imp; 00827 00828 public: 00829 00830 /* ************************************** * 00831 * Constructors and destructor * 00832 * ************************************** */ 00833 00836 ParticleDataBase3D(); 00837 00840 ParticleDataBase3D( const ParticleDataBase3D &pdb ); 00841 00844 ParticleDataBase3D( std::istream &s ); 00845 00848 ~ParticleDataBase3D(); 00849 00852 const ParticleDataBase3D &operator=( const ParticleDataBase3D &pdb ); 00853 00854 /* ************************************** * 00855 * Information and queries * 00856 * ************************************** */ 00857 00860 virtual Particle3D &particle( uint32_t i ); 00861 00864 virtual const Particle3D &particle( uint32_t i ) const; 00865 00868 virtual const ParticleP3D &trajectory_point( uint32_t i, uint32_t j ) const; 00869 00870 using ParticleDataBase::trajectory_point; 00871 00872 /* ************************************** * 00873 * Particle definition * 00874 * ************************************** */ 00875 00887 void add_particle( double IQ, double q, double m, const ParticleP3D &x ); 00888 00893 void add_particle( const Particle3D &p ); 00894 00895 /* ************************************** * 00896 * Particle beam definition * 00897 * ************************************** */ 00898 00922 void add_cylindrical_beam_with_energy( uint32_t N, double J, double q, double m, 00923 double E, double Tp, double Tt, Vec3D c, 00924 Vec3D dir1, Vec3D dir2, double r ); 00925 00948 void add_cylindrical_beam_with_velocity( uint32_t N, double J, double q, double m, 00949 double v, double dvp, double dvt, Vec3D c, 00950 Vec3D dir1, Vec3D dir2, double r ); 00951 00960 void add_rectangular_beam_with_energy( uint32_t N, double J, double q, double m, 00961 double E, double Tp, double Tt, Vec3D c, 00962 Vec3D dir1, Vec3D dir2, double size1, double size2 ); 00963 00972 void add_rectangular_beam_with_velocity( uint32_t N, double J, double q, double m, 00973 double v, double dvp, double dvt, Vec3D c, 00974 Vec3D dir1, Vec3D dir2, double size1, double size2 ); 00975 00976 00994 void add_3d_KV_beam_with_emittance( uint32_t N, double I, double q, double m, 00995 double ay, double by, double ey, 00996 double az, double bz, double ez, 00997 double Ex, double x0, double y0, double z0 ); 00998 01016 void add_3d_gaussian_beam_with_emittance( uint32_t N, double I, double q, double m, 01017 double ay, double by, double ey, 01018 double az, double bz, double ez, 01019 double Ex, double x0, double y0, double z0 ); 01020 01021 01022 /* ************************************** * 01023 * Information and queries * 01024 * ************************************** */ 01025 01026 01044 void trajectories_at_free_plane( TrajectoryDiagnosticData &tdata, 01045 const Vec3D &c, const Vec3D &o, const Vec3D &p, 01046 const std::vector<trajectory_diagnostic_e> &diagnostics ) const; 01047 01048 01070 void export_path_manager_data( std::string filename, 01071 double ref_E, double ref_q, double ref_m, 01072 const Vec3D &c, const Vec3D &o, const Vec3D &p ) const; 01073 01074 /* ************************************** * 01075 * Debugging, plotting and saving * 01076 * ************************************** */ 01077 01080 virtual void save( const std::string &filename ) const; 01081 01084 virtual void save( std::ostream &s ) const; 01085 01088 virtual void debug_print( std::ostream &os ) const; 01089 }; 01090 01091 #endif