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 void set_rhosum( double rhosum ); 00325 00328 const ParticleStatistics &get_statistics( void ) const; 00329 00330 /* ************************************** * 00331 * Information and queries * 00332 * ************************************** */ 00333 00336 geom_mode_e geom_mode() const; 00337 00340 size_t size( void ) const; 00341 00344 virtual ParticleBase &particle( uint32_t i ) = 0; 00345 00348 virtual const ParticleBase &particle( uint32_t i ) const = 0; 00349 00352 double traj_length( uint32_t i ) const; 00353 00356 size_t traj_size( uint32_t i ) const; 00357 00360 virtual const ParticlePBase &trajectory_point( uint32_t i, uint32_t j ) const = 0; 00361 00364 void trajectory_point( double &t, Vec3D &loc, Vec3D &vel, uint32_t i, uint32_t j ) const; 00365 00369 void trajectories_at_plane( TrajectoryDiagnosticData &tdata, 00370 coordinate_axis_e axis, 00371 double val, 00372 const std::vector<trajectory_diagnostic_e> &diagnostics ) const; 00373 00378 void build_trajectory_density_field( ScalarField &tdens ) const; 00379 00380 /* ************************************** * 00381 * Particle and trajectory clearing * 00382 * ************************************** */ 00383 00389 void clear( void ); 00390 00396 void clear_trajectories( void ); 00397 00403 void clear_trajectory( size_t a ); 00404 00405 /* ************************************** * 00406 * Particle definition * 00407 * ************************************** */ 00408 00411 void reserve( size_t size ); 00412 00413 /* ************************************** * 00414 * Particle iterators * 00415 * ************************************** */ 00416 00424 void iterate_trajectories( ScalarField &scharge, const VectorField &efield, 00425 const VectorField &bfield, const Geometry &g ); 00426 00433 void step_particles( ScalarField &scharge, const VectorField &efield, 00434 const VectorField &bfield, const Geometry &g, double dt ); 00435 00436 /* ************************************** * 00437 * Debugging, plotting and saving * 00438 * ************************************** */ 00439 00442 virtual void save( const std::string &filename ) const = 0; 00443 00446 virtual void save( std::ostream &s ) const = 0; 00447 00450 virtual void debug_print( std::ostream &os ) const = 0; 00451 }; 00452 00453 00465 class ParticleDataBase2D : public ParticleDataBase { 00466 00467 class ParticleDataBase2DImp *_imp; 00468 00469 public: 00470 00471 /* ************************************** * 00472 * Constructors and destructor * 00473 * ************************************** */ 00474 00477 ParticleDataBase2D(); 00478 00481 ParticleDataBase2D( const ParticleDataBase2D &pdb ); 00482 00485 ParticleDataBase2D( std::istream &s ); 00486 00489 ~ParticleDataBase2D(); 00490 00493 const ParticleDataBase2D &operator=( const ParticleDataBase2D &pdb ); 00494 00495 /* ************************************** * 00496 * Information and queries * 00497 * ************************************** */ 00498 00501 virtual Particle2D &particle( uint32_t i ); 00502 00505 virtual const Particle2D &particle( uint32_t i ) const; 00506 00509 virtual const ParticleP2D &trajectory_point( uint32_t i, uint32_t j ) const; 00510 00511 using ParticleDataBase::trajectory_point; 00512 00513 /* ************************************** * 00514 * Particle definition * 00515 * ************************************** */ 00516 00528 void add_particle( double IQ, double q, double m, const ParticleP2D &x ); 00529 00534 void add_particle( const Particle2D &p ); 00535 00536 /* ************************************** * 00537 * Particle beam definition * 00538 * ************************************** */ 00539 00559 void add_2d_beam_with_energy( uint32_t N, double J, double q, double m, 00560 double E, double Tp, double Tt, 00561 double x1, double y1, double x2, double y2 ); 00562 00578 void add_2d_beam_with_velocity( uint32_t N, double J, double q, double m, 00579 double v, double dvp, double dvt, 00580 double x1, double y1, double x2, double y2 ); 00581 00598 void add_2d_KV_beam_with_emittance( uint32_t N, double I, double q, double m, 00599 double a, double b, double e, 00600 double Ex, double x0, double y0 ); 00601 00618 void add_2d_gaussian_beam_with_emittance( uint32_t N, double I, double q, double m, 00619 double a, double b, double e, 00620 double Ex, double x0, double y0 ); 00621 00622 /* ************************************** * 00623 * Debugging, plotting and saving * 00624 * ************************************** */ 00625 00628 virtual void save( const std::string &filename ) const; 00629 00632 virtual void save( std::ostream &s ) const; 00633 00636 virtual void debug_print( std::ostream &os ) const; 00637 }; 00638 00639 00640 00641 00653 class ParticleDataBaseCyl : public ParticleDataBase { 00654 00655 class ParticleDataBaseCylImp *_imp; 00656 00657 public: 00658 00659 /* ************************************** * 00660 * Constructors and destructor * 00661 * ************************************** */ 00662 00665 ParticleDataBaseCyl(); 00666 00669 ParticleDataBaseCyl( const ParticleDataBaseCyl &pdb ); 00670 00673 ParticleDataBaseCyl( std::istream &s ); 00674 00677 ~ParticleDataBaseCyl(); 00678 00681 const ParticleDataBaseCyl &operator=( const ParticleDataBaseCyl &pdb ); 00682 00683 /* ************************************** * 00684 * Information and queries * 00685 * ************************************** */ 00686 00689 virtual ParticleCyl &particle( uint32_t i ); 00690 00693 virtual const ParticleCyl &particle( uint32_t i ) const; 00694 00697 virtual const ParticlePCyl &trajectory_point( uint32_t i, uint32_t j ) const; 00698 00699 using ParticleDataBase::trajectory_point; 00700 00701 /* ************************************** * 00702 * Particle definition * 00703 * ************************************** */ 00704 00716 void add_particle( double IQ, double q, double m, const ParticlePCyl &x ); 00717 00722 void add_particle( const ParticleCyl &p ); 00723 00724 /* ************************************** * 00725 * Particle beam definition * 00726 * ************************************** */ 00727 00747 void add_2d_beam_with_energy( uint32_t N, double J, double q, double m, 00748 double E, double Tp, double Tt, 00749 double x1, double y1, double x2, double y2 ); 00750 00766 void add_2d_beam_with_velocity( uint32_t N, double J, double q, double m, 00767 double v, double dvp, double dvt, 00768 double x1, double y1, double x2, double y2 ); 00769 00772 void add_2d_full_gaussian_beam( uint32_t N, double I, double q, double m, 00773 double Ex, double Tp, double Tt, 00774 double x0, double dr ); 00775 00794 void add_2d_gaussian_beam_with_emittance( uint32_t N, double I, double q, double m, 00795 double a, double b, double e, 00796 double Ex, double x0 ); 00797 00798 /* ************************************** * 00799 * Debugging, plotting and saving * 00800 * ************************************** */ 00801 00804 virtual void save( const std::string &filename ) const; 00805 00808 virtual void save( std::ostream &s ) const; 00809 00812 virtual void debug_print( std::ostream &os ) const; 00813 }; 00814 00815 00816 00828 class ParticleDataBase3D : public ParticleDataBase { 00829 00830 class ParticleDataBase3DImp *_imp; 00831 00832 public: 00833 00834 /* ************************************** * 00835 * Constructors and destructor * 00836 * ************************************** */ 00837 00840 ParticleDataBase3D(); 00841 00844 ParticleDataBase3D( const ParticleDataBase3D &pdb ); 00845 00848 ParticleDataBase3D( std::istream &s ); 00849 00852 ~ParticleDataBase3D(); 00853 00856 const ParticleDataBase3D &operator=( const ParticleDataBase3D &pdb ); 00857 00858 /* ************************************** * 00859 * Information and queries * 00860 * ************************************** */ 00861 00864 virtual Particle3D &particle( uint32_t i ); 00865 00868 virtual const Particle3D &particle( uint32_t i ) const; 00869 00872 virtual const ParticleP3D &trajectory_point( uint32_t i, uint32_t j ) const; 00873 00874 using ParticleDataBase::trajectory_point; 00875 00876 /* ************************************** * 00877 * Particle definition * 00878 * ************************************** */ 00879 00891 void add_particle( double IQ, double q, double m, const ParticleP3D &x ); 00892 00897 void add_particle( const Particle3D &p ); 00898 00899 /* ************************************** * 00900 * Particle beam definition * 00901 * ************************************** */ 00902 00926 void add_cylindrical_beam_with_energy( uint32_t N, double J, double q, double m, 00927 double E, double Tp, double Tt, Vec3D c, 00928 Vec3D dir1, Vec3D dir2, double r ); 00929 00952 void add_cylindrical_beam_with_velocity( uint32_t N, double J, double q, double m, 00953 double v, double dvp, double dvt, Vec3D c, 00954 Vec3D dir1, Vec3D dir2, double r ); 00955 00964 void add_rectangular_beam_with_energy( uint32_t N, double J, double q, double m, 00965 double E, double Tp, double Tt, Vec3D c, 00966 Vec3D dir1, Vec3D dir2, double size1, double size2 ); 00967 00976 void add_rectangular_beam_with_velocity( uint32_t N, double J, double q, double m, 00977 double v, double dvp, double dvt, Vec3D c, 00978 Vec3D dir1, Vec3D dir2, double size1, double size2 ); 00979 00980 00998 void add_3d_KV_beam_with_emittance( uint32_t N, double I, double q, double m, 00999 double ay, double by, double ey, 01000 double az, double bz, double ez, 01001 double Ex, double x0, double y0, double z0 ); 01002 01021 void add_3d_gaussian_beam_with_emittance( uint32_t N, double I, double q, double m, 01022 double E0, 01023 double a1, double b1, double e1, 01024 double a2, double b2, double e2, 01025 Vec3D c, Vec3D dir1, Vec3D dir2 ); 01026 01027 01028 /* ************************************** * 01029 * Information and queries * 01030 * ************************************** */ 01031 01032 01050 void trajectories_at_free_plane( TrajectoryDiagnosticData &tdata, 01051 const Vec3D &c, const Vec3D &o, const Vec3D &p, 01052 const std::vector<trajectory_diagnostic_e> &diagnostics ) const; 01053 01054 01076 void export_path_manager_data( std::string filename, 01077 double ref_E, double ref_q, double ref_m, 01078 const Vec3D &c, const Vec3D &o, const Vec3D &p ) const; 01079 01080 /* ************************************** * 01081 * Debugging, plotting and saving * 01082 * ************************************** */ 01083 01086 virtual void save( const std::string &filename ) const; 01087 01090 virtual void save( std::ostream &s ) const; 01091 01094 virtual void debug_print( std::ostream &os ) const; 01095 }; 01096 01097 #endif 01098