Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.5new_solver
   Version 1.0.5dev
      Class Index
      File List
   Version 1.0.5b
   Version 1.0.4dev
   Version 1.0.4
Publications


Hosted by Get Ion Beam Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads

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 
00244     void set_relativistic( bool enable );
00245 
00250     void set_polyint( bool polyint );
00251     
00257     bool get_polyint( void ) const;
00258     
00263     void set_max_steps( uint32_t maxsteps );
00264 
00269     void set_max_time( double maxt );
00270 
00279     void set_save_trajectories( uint32_t div );
00280 
00287     uint32_t get_save_trajectories( void ) const;
00288 
00297     void set_mirror( const bool mirror[6] );
00298 
00305     void get_mirror( bool mirror[6] ) const;
00306 
00309     int get_iteration_number( void ) const;
00310 
00324     double get_rhosum( void ) const;
00325 
00328     void set_rhosum( double rhosum );
00329 
00332     const ParticleStatistics &get_statistics( void ) const;
00333 
00334 /* ************************************** *
00335  * Information and queries                *
00336  * ************************************** */
00337 
00340     geom_mode_e geom_mode() const;
00341 
00344     size_t size( void ) const;
00345 
00348     virtual ParticleBase &particle( uint32_t i ) = 0;
00349 
00352     virtual const ParticleBase &particle( uint32_t i ) const = 0;
00353 
00356     double traj_length( uint32_t i ) const;
00357     
00360     size_t traj_size( uint32_t i ) const;
00361     
00364     virtual const ParticlePBase &trajectory_point( uint32_t i, uint32_t j ) const = 0;
00365 
00368     void trajectory_point( double &t, Vec3D &loc, Vec3D &vel, uint32_t i, uint32_t j ) const;
00369 
00373     void trajectories_at_plane( TrajectoryDiagnosticData &tdata, 
00374                                 coordinate_axis_e axis,
00375                                 double val,
00376                                 const std::vector<trajectory_diagnostic_e> &diagnostics ) const;
00377 
00382     void build_trajectory_density_field( ScalarField &tdens ) const;
00383 
00384 /* ************************************** *
00385  * Particle and trajectory clearing       *
00386  * ************************************** */
00387 
00393     void clear( void );
00394 
00400     void clear_trajectories( void );
00401 
00407     void clear_trajectory( size_t a );
00408 
00409 /* ************************************** *
00410  * Particle definition                    *
00411  * ************************************** */
00412 
00415     void reserve( size_t size );
00416 
00417 /* ************************************** *
00418  * Particle iterators                     *
00419  * ************************************** */
00420 
00434     void iterate_trajectories( ScalarField &scharge, const VectorField &efield, 
00435                                const VectorField &bfield, const Geometry &geom );
00436 
00443     void step_particles( ScalarField &scharge, const VectorField &efield, 
00444                          const VectorField &bfield, const Geometry &geom, double dt );
00445 
00446 /* ************************************** *
00447  * Debugging, plotting and saving         *
00448  * ************************************** */
00449 
00452     virtual void save( const std::string &filename ) const = 0;
00453 
00456     virtual void save( std::ostream &s ) const = 0;
00457 
00460     virtual void debug_print( std::ostream &os ) const = 0;
00461 };
00462 
00463 
00475 class ParticleDataBase2D : public ParticleDataBase {
00476 
00477     class ParticleDataBase2DImp *_imp;
00478 
00479 public:
00480 
00481 /* ************************************** *
00482  * Constructors and destructor            *
00483  * ************************************** */
00484 
00487     ParticleDataBase2D();
00488 
00491     ParticleDataBase2D( const ParticleDataBase2D &pdb );
00492 
00495     ParticleDataBase2D( std::istream &s );
00496 
00499     ~ParticleDataBase2D();
00500 
00503     const ParticleDataBase2D &operator=( const ParticleDataBase2D &pdb );
00504     
00505 /* ************************************** *
00506  * Information and queries                *
00507  * ************************************** */
00508 
00511     virtual Particle2D &particle( uint32_t i );
00512 
00515     virtual const Particle2D &particle( uint32_t i ) const;
00516     
00519     virtual const ParticleP2D &trajectory_point( uint32_t i, uint32_t j ) const;
00520 
00521     using ParticleDataBase::trajectory_point;
00522 
00523 /* ************************************** *
00524  * Particle definition                    *
00525  * ************************************** */
00526 
00538     void add_particle( double IQ, double q, double m, const ParticleP2D &x );
00539 
00544     void add_particle( const Particle2D &p );
00545 
00546 /* ************************************** *
00547  * Particle beam definition               *
00548  * ************************************** */
00549 
00569     void add_2d_beam_with_energy( uint32_t N, double J, double q, double m, 
00570                                   double E, double Tp, double Tt, 
00571                                   double x1, double y1, double x2, double y2 );
00572 
00588     void add_2d_beam_with_velocity( uint32_t N, double J, double q, double m, 
00589                                     double v, double dvp, double dvt, 
00590                                     double x1, double y1, double x2, double y2 );
00591 
00608     void add_2d_KV_beam_with_emittance( uint32_t N, double I, double q, double m,
00609                                         double a, double b, double e,
00610                                         double Ex, double x0, double y0 );
00611 
00628     void add_2d_gaussian_beam_with_emittance( uint32_t N, double I, double q, double m,
00629                                               double a, double b, double e,
00630                                               double Ex, double x0, double y0 );
00631 
00632 /* ************************************** *
00633  * Debugging, plotting and saving         *
00634  * ************************************** */
00635 
00638     virtual void save( const std::string &filename ) const;
00639 
00642     virtual void save( std::ostream &s ) const;
00643 
00646     virtual void debug_print( std::ostream &os ) const;
00647 };
00648 
00649 
00650 
00651 
00663 class ParticleDataBaseCyl : public ParticleDataBase {
00664 
00665     class ParticleDataBaseCylImp *_imp;
00666 
00667 public:
00668 
00669 /* ************************************** *
00670  * Constructors and destructor            *
00671  * ************************************** */
00672 
00675     ParticleDataBaseCyl();
00676 
00679     ParticleDataBaseCyl( const ParticleDataBaseCyl &pdb );
00680 
00683     ParticleDataBaseCyl( std::istream &s );
00684 
00687     ~ParticleDataBaseCyl();
00688 
00691     const ParticleDataBaseCyl &operator=( const ParticleDataBaseCyl &pdb );
00692 
00693 /* ************************************** *
00694  * Information and queries                *
00695  * ************************************** */
00696 
00699     virtual ParticleCyl &particle( uint32_t i );
00700 
00703     virtual const ParticleCyl &particle( uint32_t i ) const;
00704     
00707     virtual const ParticlePCyl &trajectory_point( uint32_t i, uint32_t j ) const;
00708 
00709     using ParticleDataBase::trajectory_point;
00710 
00711 /* ************************************** *
00712  * Particle definition                    *
00713  * ************************************** */
00714 
00726     void add_particle( double IQ, double q, double m, const ParticlePCyl &x );
00727 
00732     void add_particle( const ParticleCyl &p );
00733 
00734 /* ************************************** *
00735  * Particle beam definition               *
00736  * ************************************** */
00737 
00757     void add_2d_beam_with_energy( uint32_t N, double J, double q, double m, 
00758                                   double E, double Tp, double Tt, 
00759                                   double x1, double y1, double x2, double y2 );
00760 
00776     void add_2d_beam_with_velocity( uint32_t N, double J, double q, double m, 
00777                                     double v, double dvp, double dvt, 
00778                                     double x1, double y1, double x2, double y2 );
00779 
00782     void add_2d_full_gaussian_beam( uint32_t N, double I, double q, double m,
00783                                     double Ex, double Tp, double Tt, 
00784                                     double x0, double dr );
00785 
00804     void add_2d_gaussian_beam_with_emittance( uint32_t N, double I, double q, double m,
00805                                               double a, double b, double e,
00806                                               double Ex, double x0 );
00807 
00808 /* ************************************** *
00809  * Debugging, plotting and saving         *
00810  * ************************************** */
00811 
00814     virtual void save( const std::string &filename ) const;
00815 
00818     virtual void save( std::ostream &s ) const;
00819 
00822     virtual void debug_print( std::ostream &os ) const;
00823 };
00824 
00825 
00826 
00838 class ParticleDataBase3D : public ParticleDataBase {
00839 
00840     class ParticleDataBase3DImp *_imp;
00841 
00842 public:
00843 
00844 /* ************************************** *
00845  * Constructors and destructor            *
00846  * ************************************** */
00847 
00850     ParticleDataBase3D();
00851 
00854     ParticleDataBase3D( const ParticleDataBase3D &pdb );
00855 
00858     ParticleDataBase3D( std::istream &s );
00859 
00862     ~ParticleDataBase3D();
00863 
00866     const ParticleDataBase3D &operator=( const ParticleDataBase3D &pdb );
00867 
00868 /* ************************************** *
00869  * Information and queries                *
00870  * ************************************** */
00871 
00874     virtual Particle3D &particle( uint32_t i );
00875 
00878     virtual const Particle3D &particle( uint32_t i ) const;
00879     
00882     virtual const ParticleP3D &trajectory_point( uint32_t i, uint32_t j ) const;
00883 
00884     using ParticleDataBase::trajectory_point;
00885 
00886 /* ************************************** *
00887  * Particle definition                    *
00888  * ************************************** */
00889 
00901     void add_particle( double IQ, double q, double m, const ParticleP3D &x );
00902 
00907     void add_particle( const Particle3D &p );
00908 
00909 /* ************************************** *
00910  * Particle beam definition               *
00911  * ************************************** */
00912 
00936     void add_cylindrical_beam_with_energy( uint32_t N, double J, double q, double m, 
00937                                            double E, double Tp, double Tt, Vec3D c, 
00938                                            Vec3D dir1, Vec3D dir2, double r );
00939 
00962     void add_cylindrical_beam_with_velocity( uint32_t N, double J, double q, double m, 
00963                                              double v, double dvp, double dvt, Vec3D c, 
00964                                              Vec3D dir1, Vec3D dir2, double r );
00965 
00974     void add_rectangular_beam_with_energy( uint32_t N, double J, double q, double m, 
00975                                            double E, double Tp, double Tt, Vec3D c, 
00976                                            Vec3D dir1, Vec3D dir2, double size1, double size2 );
00977 
00986     void add_rectangular_beam_with_velocity( uint32_t N, double J, double q, double m, 
00987                                              double v, double dvp, double dvt, Vec3D c, 
00988                                              Vec3D dir1, Vec3D dir2, double size1, double size2 );
00989 
00990 
01008     void add_3d_KV_beam_with_emittance( uint32_t N, double I, double q, double m,
01009                                         double ay, double by, double ey,
01010                                         double az, double bz, double ez,
01011                                         double Ex, double x0, double y0, double z0 );
01012 
01031     void add_3d_gaussian_beam_with_emittance( uint32_t N, double I, double q, double m,
01032                                               double E0, 
01033                                               double a1, double b1, double e1,
01034                                               double a2, double b2, double e2,
01035                                               Vec3D c, Vec3D dir1, Vec3D dir2 );
01036 
01037 
01038 /* ************************************** *
01039  * Information and queries                *
01040  * ************************************** */
01041 
01042 
01060     void trajectories_at_free_plane( TrajectoryDiagnosticData &tdata, 
01061                                      const Vec3D &c, const Vec3D &o, const Vec3D &p,
01062                                      const std::vector<trajectory_diagnostic_e> &diagnostics ) const;
01063 
01064 
01086     void export_path_manager_data( std::string filename, 
01087                                    double ref_E, double ref_q, double ref_m, 
01088                                    const Vec3D &c, const Vec3D &o, const Vec3D &p ) const;
01089 
01090 /* ************************************** *
01091  * Debugging, plotting and saving         *
01092  * ************************************** */
01093 
01096     virtual void save( const std::string &filename ) const;
01097 
01100     virtual void save( std::ostream &s ) const;
01101 
01104     virtual void debug_print( std::ostream &os ) const;
01105 };
01106 
01107 #endif
01108 


Reference manual for Ion Beam Simulator 1.0.5dev
Generated by Doxygen 1.7.1 on Mon Feb 6 2012 15:07:16.