HG-MD  1
MD.h
Go to the documentation of this file.
00001 #ifndef MD_H
00002 #define MD_H
00003 #define SIGN(x) (x>0?(1):(-1))
00004 #define MAX(x,y) (x>y?(x):(y))
00005 #define MIN(x,y) (x<y?(x):(y))
00006 
00007 #define UNUSED  __attribute__ ((__unused__))
00008 
00009 //This is a header with some extra standard maths function and constants that are required by the code
00010 #include "ExtendedMath.h"
00011 
00012 //The vector class contains a 3D vector class.
00013 #include "Vector.h"
00014 #include <string.h>
00015 //This class defines the particle handler
00016 #include "ParticleHandler.h"
00017 // This class defines walls and periodic walls
00018 #include "CWall.h"
00019 //This is the class that defines the std_save routines
00020 #include "STD_save.h"
00021 #include <time.h>
00022 
00023 //This is only used to change the file permission of the xball script create, at some point this code may be moved from this file to a different file.
00024 #include <sys/types.h>
00025 #include <sys/stat.h>
00026 
00027 #include "RNG.h"
00028 
00029 
00030 using namespace std;
00031 
00032 
00033 
00034 
00037 class MD : public STD_save {
00038 public:
00040         void constructor();
00041         
00042         MD()
00043         {
00044                 constructor();
00045                 #ifdef CONSTUCTOR_OUTPUT
00046                         cerr << "MD() finished"<<endl;
00047                 #endif
00048         }
00049         
00050         MD(STD_save& other) : STD_save(other) {
00051                 constructor();
00052                 #ifdef CONSTUCTOR_OUTPUT
00053                         cerr << "MD(STD_save& other) finished " << endl;
00054                 #endif          
00055         }
00056         
00058         virtual ~MD() {};
00059         
00060         void info(){print(cout);}
00061         
00063         void solve();
00064 
00066         void solve(unsigned int argc, char *argv[]) {
00067                 readArguments(argc, argv);
00068                 solve();
00069         };
00070 
00072         void solveWithMDCLR();
00073         
00075         Mdouble get_t(){return t;}
00077         void set_t(Mdouble new_t){t=new_t;}
00078         
00080         void set_NWall(int N){if (N>=0) {Walls.resize(N);} else {cerr << "Error in set_NWall" << endl; exit(-1);}}
00082         int get_NWall(){return Walls.size();}
00083         
00084         //~ ///Allows the number of Species to be changed
00085         //~ void set_NSpecies(int N){
00086                 //~ if (N>=0) {
00087                         //~ Species.resize(N); 
00088                         //~ for (int i=0; i<N; i++) {
00089                                 //~ Species[i].MixedSpecies.resize(i); 
00090                                 //~ cout << "S" << Species[i].MixedSpecies.size() << endl;
00091                         //~ }
00092                 //~ } else {cerr << "Error in set_NSpecies" << endl; exit(-1);}
00093         //~ }
00095         int get_NSpecies(){return Species.size();}
00096         
00098         vector<CWall>& get_Walls(void){return Walls;}
00100         CWall& get_Walls(int i){return Walls[i];}
00101         
00103         vector<CWallPeriodic>& get_WallsPeriodic(void){return WallsPeriodic;}
00105         CWallPeriodic& get_WallsPeriodic(int i){return WallsPeriodic[i];}
00106         
00108         vector<CSpecies>& get_Species(void){return Species;}
00110         CSpecies* get_Species(int i) {return &Species[i];}
00111         
00113         CSpecies* get_MixedSpecies(int i, int j) {
00114                 if (i>j) return &Species[i].MixedSpecies[j];
00115                 else return &Species[j].MixedSpecies[i];
00116         };
00118         void set_MixedSpecies(int i, int j, CSpecies& S) {
00119                 if (i>j) Species[i].MixedSpecies[j] = S;
00120                 else Species[j].MixedSpecies[i] = S;
00121         };
00122         
00124         void set_NWallPeriodic(int N){if (N>=0) {WallsPeriodic.resize(N);} else {cerr << "Error in set_NWallPeriodic" << endl; exit(-1);}}
00126         int get_NWallPeriodic(){return WallsPeriodic.size();}
00127         
00129         void set_tmax(Mdouble new_tmax){if (new_tmax>=0){tmax=new_tmax;} else { cerr << "Error in set_tmax" << endl; exit(-1); }}
00131         Mdouble get_tmax(){return tmax;}
00132         
00133 
00134         ParticleHandler& get_ParticleHandler() { return  particleHandler;}
00135 
00136         
00138         void set_savecount       (int new_){if (new_>0) {set_save_count_all(new_);}  else {cerr << "Error in set_savecount (set_savecount("<<new_<<"))"<< endl; exit(-1);}}
00139         void set_save_count_all  (int new_){if (new_>0) {save_count_data =new_;save_count_ene  =new_;save_count_stat =new_;save_count_fstat=new_;} else {cerr << "Error in set_save_count_all (set_save_count_all("<<new_<<"))"<< endl; exit(-1);}}
00140         void set_save_count_data (int new_){if (new_>0) {save_count_data =new_;} else {cerr << "Error in set_save_count_data, (set_save_count_data ("<<new_<<"))"<< endl; exit(-1);}}
00141         void set_save_count_ene  (int new_){if (new_>0) {save_count_ene  =new_;} else {cerr << "Error in set_save_count_ene, (set_save_count_ene  ("<<new_<<"))"<< endl; exit(-1);}}
00142         void set_save_count_stat (int new_){if (new_>0) {save_count_stat =new_;} else {cerr << "Error in set_save_count_stat, (set_save_count_stat ("<<new_<<"))"<< endl; exit(-1);}}
00143         void set_save_count_fstat(int new_){if (new_>0) {save_count_fstat=new_;} else {cerr << "Error in set_save_count_fstat, (set_save_count_fstat("<<new_<<"))"<< endl; exit(-1);}}
00145         int get_savecount  (){return get_save_count_data ();}
00146         int get_save_count (){return get_save_count_data ();}
00147         int get_save_count_data (){return save_count_data;}
00148         int get_save_count_ene  (){return save_count_ene;}
00149         int get_save_count_stat (){return save_count_stat;}
00150         int get_save_count_fstat(){return save_count_fstat;}
00151         
00153         void set_do_stat_always (bool new_) {do_stat_always=new_;}
00154         void set_number_of_saves      (Mdouble N){set_number_of_saves_all(N);}
00155         void set_number_of_saves_all  (Mdouble N){if (dt) {set_save_count_all((N>1)?((int)ceil(tmax/dt/(N-1.0))):1000000);} else {cerr << "Error in set_number_of_saves_all ; dt must be set"; exit(-1);} }
00156         void set_number_of_saves_data (Mdouble N){if (dt) {save_count_data  = (N>1)?((int)ceil(tmax/dt/(N-1.0))):1000000; } else {cerr << "Error in set_number_of_saves_data ; dt must be set"; exit(-1);} }
00157         void set_number_of_saves_ene  (Mdouble N){if (dt) {save_count_ene   = (N>1)?((int)ceil(tmax/dt/(N-1.0))):1000000; } else {cerr << "Error in set_number_of_saves_ene  ; dt must be set"; exit(-1);} }
00158         void set_number_of_saves_stat (Mdouble N){if (dt) {save_count_stat  = (N>1)?((int)ceil(tmax/dt/(N-1.0))):1000000; } else {cerr << "Error in set_number_of_saves_stat ; dt must be set"; exit(-1);} }
00159         void set_number_of_saves_fstat(Mdouble N){if (dt) {save_count_fstat = (N>1)?((int)ceil(tmax/dt/(N-1.0))):1000000; } else {cerr << "Error in set_number_of_saves_fstat; dt must be set"; exit(-1);} }
00160         
00162 
00164         void set_plastic_k1_k2max_kc_depth(Mdouble k1_, Mdouble k2max_, Mdouble kc_, Mdouble depth_, unsigned int indSpecies = 0)
00165         {if (indSpecies<Species.size()) {Species[indSpecies].set_plastic_k1_k2max_kc_depth(k1_, k2max_, kc_, depth_);} else {cerr << "Error in set_k: species does not exist"; exit(-1);} }             
00166         void set_k1(Mdouble new_, unsigned int indSpecies = 0) 
00167         {if (indSpecies<Species.size()) {Species[indSpecies].set_k1(new_);} else {cerr << "Error in set_k: species does not exist"; exit(-1);} }
00168         void set_k2max(Mdouble new_, unsigned int indSpecies = 0) 
00169         {if (indSpecies<Species.size()) {Species[indSpecies].set_k2max(new_);} else {cerr << "Error in set_k: species does not exist"; exit(-1);} }
00170         void set_kc(Mdouble new_, unsigned int indSpecies = 0) 
00171         {if (indSpecies<Species.size()) {Species[indSpecies].set_kc(new_);} else {cerr << "Error in set_k: species does not exist"; exit(-1);} }
00172         void set_depth(Mdouble new_, unsigned int indSpecies = 0) 
00173         {if (indSpecies<Species.size()) {Species[indSpecies].set_depth(new_);} else {cerr << "Error in set_k: species does not exist"; exit(-1);} }
00175         Mdouble get_k1(unsigned int indSpecies = 0) 
00176         {return Species[indSpecies].get_k1();}
00177         Mdouble get_k2max(unsigned int indSpecies = 0) 
00178         {return Species[indSpecies].get_k2max();}
00179         Mdouble get_kc(unsigned int indSpecies = 0) 
00180         {return Species[indSpecies].get_kc();}
00181         Mdouble get_depth(unsigned int indSpecies = 0) 
00182         {return Species[indSpecies].get_depth();}
00183         Mdouble get_plastic_dt(Mdouble mass, unsigned int indSpecies = 0)
00184         {return Species[indSpecies].get_plastic_dt(mass);}
00185         
00187         void set_k(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_k(new_);} else {cerr << "Error in set_k: species does not exist"; exit(-1);} }
00189         Mdouble get_k(int indSpecies = 0){return Species[indSpecies].get_k();}
00191         void set_kt(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_kt(new_);} else {cerr << "Error in set_kt: species does not exist"; exit(-1);}}
00193         Mdouble get_kt(int indSpecies = 0){return Species[indSpecies].get_kt();}
00195         void set_krolling(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_krolling(new_);} else {cerr << "Error in set_krolling: species does not exist"; exit(-1);}}
00197         Mdouble get_krolling(int indSpecies = 0){return Species[indSpecies].get_krolling();}
00199         void set_ktorsion(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_ktorsion(new_);} else {cerr << "Error in set_ktorsion: species does not exist"; exit(-1);}}
00201         Mdouble get_ktorsion(int indSpecies = 0){return Species[indSpecies].get_ktorsion();}
00203         void set_rho(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_rho(new_);} else {cerr << "Error in set_rho: species does not exist"; exit(-1);}}
00205         Mdouble get_rho(int indSpecies = 0){return Species[indSpecies].get_rho();}
00207         void set_dispt(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_dispt(new_);} else {cerr << "Error in set_dispt: species does not exist"; exit(-1);}}
00209         Mdouble get_dispt(unsigned int indSpecies = 0){return Species[indSpecies].get_dispt();}
00211         void set_disprolling(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_disprolling(new_);} else {cerr << "Error in set_disprolling: species does not exist"; exit(-1);}}
00213         Mdouble get_disprolling(unsigned int indSpecies = 0){return Species[indSpecies].get_disprolling();}
00215         void set_disptorsion(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_disptorsion(new_);} else {cerr << "Error in set_disptorsion: species does not exist"; exit(-1);}}
00217         Mdouble get_disptorsion(unsigned int indSpecies = 0){return Species[indSpecies].get_disptorsion();}
00218 
00220         void set_disp(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_dissipation(new_);} else {cerr << "Error in set_dissipation: species does not exist"; exit(-1);}}
00222         Mdouble get_disp(unsigned int indSpecies = 0){return Species[indSpecies].get_dissipation();}
00224         void set_dissipation(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_dissipation(new_);} else {cerr << "Error in set_dissipation: species does not exist"; exit(-1);}}
00226         Mdouble get_dissipation(unsigned int indSpecies = 0){return Species[indSpecies].get_dissipation();}
00228         void set_mu(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_mu(new_);} else {cerr << "Error in set_mu: species does not exist"; exit(-1);}}
00230         Mdouble get_mu(unsigned int indSpecies = 0){return Species[indSpecies].get_mu();}
00232         void set_murolling(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_murolling(new_);} else {cerr << "Error in set_murolling: species does not exist"; exit(-1);}}
00234         Mdouble get_murolling(unsigned int indSpecies = 0){return Species[indSpecies].get_murolling();}
00236         void set_mutorsion(Mdouble new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_mutorsion(new_);} else {cerr << "Error in set_mutorsion: species does not exist"; exit(-1);}}
00238         Mdouble get_mutorsion(unsigned int indSpecies = 0){return Species[indSpecies].get_mutorsion();}
00239 
00241         void set_dim_particle(int new_, unsigned int indSpecies = 0){if (indSpecies<Species.size()) {Species[indSpecies].set_dim_particle(new_);} else {cerr << "Error in set_dim_particle: species does not exist"; exit(-1);}}
00243         int get_dim_particle(unsigned int indSpecies = 0){return Species[indSpecies].get_dim_particle();}
00245         int get_save_data_data(){return save_data_data;}
00246         int get_save_data_ene(){return save_data_ene;}
00247         int get_save_data_fstat(){return save_data_fstat;}
00248         int get_save_data_stat(){return save_data_stat;}
00249         int get_do_stat_always(){return do_stat_always;}
00250         
00252         void set_k_and_restitution_coefficient(Mdouble k_, Mdouble eps, Mdouble mass, unsigned int indSpecies = 0){
00253                 if (indSpecies<Species.size()) {Species[indSpecies].set_k_and_restitution_coefficient(k_, eps, mass);} else {cerr << "Error in set_k_and_restitution_coefficient: species does not exist"; exit(-1);}
00254         }
00256         void set_collision_time_and_restitution_coefficient(Mdouble tc, Mdouble eps, Mdouble mass, unsigned int indSpecies = 0){
00257                 if (indSpecies<Species.size()) {Species[indSpecies].set_collision_time_and_restitution_coefficient(tc, eps, mass);} else {cerr << "Error in set_collision_time_and_restitution_coefficient: species does not exist"; exit(-1);}
00258         }
00259         
00263         void set_collision_time_and_restitution_coefficient(Mdouble tc, Mdouble eps, Mdouble mass1, Mdouble mass2,unsigned int indSpecies =0)
00264                 {
00265                                 if (indSpecies<Species.size()) {Species[indSpecies].set_collision_time_and_restitution_coefficient(tc, eps, mass1, mass2);} else {cerr << "Error in set_collision_time_and_restitution_coefficient: species does not exist"; exit(-1);}
00266                 }
00267 
00269         void set_collision_time_and_normal_and_tangential_restitution_coefficient(Mdouble tc, Mdouble eps, Mdouble beta, Mdouble mass1, Mdouble mass2,unsigned int indSpecies =0) {
00270                 if (indSpecies<Species.size()) {Species[indSpecies].set_collision_time_and_normal_and_tangential_restitution_coefficient(tc, eps, beta, mass1, mass2);} else {cerr << "Error in set_collision_time_and_restitution_coefficient: species does not exist"; exit(-1);}
00271         }
00272 
00274         void set_collision_time_and_normal_and_tangential_restitution_coefficient_nodispt(Mdouble tc, Mdouble eps, Mdouble beta, Mdouble mass1, Mdouble mass2, unsigned int indSpecies =0) {
00275                 if (indSpecies<Species.size()) {Species[indSpecies].set_collision_time_and_normal_and_tangential_restitution_coefficient_nodispt(tc, eps, beta, mass1, mass2);} else {cerr << "Error in set_collision_time_and_restitution_coefficient: species does not exist"; exit(-1);}
00276 
00277         }
00278 
00280         Mdouble get_collision_time(Mdouble mass, unsigned int indSpecies = 0){return Species[indSpecies].get_collision_time(mass);}
00282         Mdouble get_restitution_coefficient(Mdouble mass, unsigned int indSpecies = 0){return Species[indSpecies].get_restitution_coefficient(mass);}
00283         
00285         Mdouble get_xmin(){return xmin;}
00287         Mdouble get_xmax(){return xmax;}
00289         Mdouble get_ymin(){return ymin;}        
00291         Mdouble get_ymax(){return ymax;}
00293         Mdouble get_zmin(){return zmin;}        
00295         Mdouble get_zmax(){return zmax;}
00296         
00298 
00299         void set_xmin(Mdouble new_xmin){if (new_xmin<=xmax){xmin=new_xmin;} else { cerr << "Error in set_xmin(" << new_xmin << "): xmax=" << xmax << endl; exit(-1); }}
00300 
00301         void set_ymin(Mdouble new_ymin){if (new_ymin<=ymax){ymin=new_ymin;} else { cerr << "Error in set_ymin(" << new_ymin << "): ymax=" << ymax << endl; exit(-1); }}
00302 
00304 
00305         void set_zmin(Mdouble new_zmin){if (new_zmin<=zmax){zmin=new_zmin;} else { cerr << "Error in set_zmin(" << new_zmin << "): zmax=" << zmax << endl; exit(-1); }}
00306 
00308 
00309         void set_xmax(Mdouble new_xmax){if (new_xmax>=xmin){xmax=new_xmax;} else { cerr << "Error in set_xmax(" << new_xmax << "): xmin=" << xmin << endl; exit(-1); }}
00311 
00312         void set_ymax(Mdouble new_ymax){if (new_ymax>ymin){ymax=new_ymax;} else { cerr << "Error in set_ymax(" << new_ymax << "): ymin=" << ymin << endl; exit(-1); }}
00314 
00315         void set_zmax(Mdouble new_zmax){if (new_zmax>ymin){zmax=new_zmax;} else { cerr << "Error in set_zmax(" << new_zmax << "): zmin=" << zmin << endl; exit(-1); }}
00316         
00318         void set_dt(Mdouble new_dt){if (dt>=0.0){dt=new_dt;} else { cerr << "Error in set_dt" << endl; exit(-1); }}
00320         Mdouble get_dt(){return dt;}
00321         
00323         void set_name(const char* name){problem_name.str(""); problem_name << name;}
00324         
00326         void set_xballs_colour_mode(int new_cmode){xballs_cmode=new_cmode;}
00327         void set_xballs_cmode(int new_cmode){xballs_cmode=new_cmode;}
00328         int get_xballs_cmode(){return xballs_cmode;}
00329         
00331         void set_xballs_vector_scale(double new_vscale){xballs_vscale=new_vscale;}
00332         double get_xballs_vscale(){return xballs_vscale;}
00333         
00335         void set_xballs_additional_arguments(string new_){xballs_additional_arguments=new_.c_str();}
00336         string get_xballs_additional_arguments(){return xballs_additional_arguments;}
00337         
00339         void set_xballs_scale(Mdouble new_scale){xballs_scale=new_scale;}
00340         double get_xballs_scale(){return xballs_scale;}
00341         
00343         void set_gravity(Vec3D new_gravity){gravity = new_gravity;}
00345         Vec3D get_gravity(){return gravity;}
00346         
00348         void set_dim(int new_dim){ if (new_dim>=1 && new_dim<=3) dim = new_dim; else { cerr << "Error in set_dim" << endl; exit(-1); }}
00350         int get_dim(){return dim;}
00351         
00353         int get_restart_version(){return restart_version;}
00355         void set_restart_version(int new_){restart_version=new_;}
00356         
00358         bool get_restarted(){return restarted;}
00360 
00362         Mdouble get_max_radius(){return max_radius;}
00363         
00364         void set_restarted(bool new_){
00365                 restarted=new_;
00366                 set_append(new_);
00367         }
00368 
00370         bool get_append(){return append;}
00372         void set_append(bool new_){append=new_;}
00373 
00374 
00376         Mdouble get_ene_ela(){return ene_ela;}
00378         void set_ene_ela(Mdouble new_){ene_ela=new_;}
00380         void add_ene_ela(Mdouble new_){ene_ela+=new_;}
00381 
00382         //access function to MD::Hertzian
00383         bool get_Hertzian(){return Hertzian;}
00384         void set_Hertzian(bool new_){Hertzian=new_;
00385                 if (Hertzian) cout << "Hertzian law activated" << endl;
00386                 else cout << "Hertzian law deactivated" << endl;
00387         }
00388 
00390         void Remove_Particle(int IP);
00391         
00393         // Some statistical output that might be of interest when setting particles' parameters
00394         
00395         Mdouble get_Mass_from_Radius(Mdouble radius, int indSpecies=0) {
00396                 Particle P;
00397                 P.set_Radius(radius);
00398                 P.set_IndSpecies(indSpecies);
00399                 P.compute_particle_mass(Species);
00400                 return P.get_Mass();
00401         }
00402         
00404         Mdouble get_maximum_velocity(Particle &P){return Species[P.get_IndSpecies()].get_maximum_velocity(P.get_Radius(),P.get_Mass());}
00405         
00406         virtual Particle* get_SmallestParticle() {return particleHandler.get_SmallestParticle();}
00407         virtual Particle* get_LargestParticle() {return particleHandler.get_LargestParticle();}
00408         virtual void removeParticle(int iP)
00409         {
00410                 HGRID_RemoveParticleFromHgrid(particleHandler.get_Particle(iP));
00411                 particleHandler.removeParticle(iP);
00412         }
00413         
00416         Mdouble get_maximum_velocity(){
00417                 Particle *P = get_SmallestParticle();
00418                 return P->get_Radius() * sqrt(Species[P->get_IndSpecies()].k/(.5*P->get_Mass()));
00419         }
00420         
00422         void set_dt_by_mass(Mdouble mass){dt = .02 * get_collision_time(mass);}
00423         
00425         void set_dt(Particle &P){
00426                 Mdouble mass = P.get_Mass(); 
00427                 dt = .02 * get_collision_time(mass);
00428                 if (Species[P.get_IndSpecies()].dispt) { dt = min(dt,0.125*mass/Species[P.get_IndSpecies()].dispt); cerr << "Warning: dispt is large, dt had to be lowered"; }
00429         }
00430         
00432         void set_dt(){
00435                 setup_particles_initial_conditions();
00436                 for (unsigned int i=0;i<particleHandler.get_NumberOfParticles();i++) particleHandler.get_Particle(i)->compute_particle_mass(Species);
00437                 set_dt(get_SmallestParticle()[0]);
00438         }
00439         
00442         virtual void setup_particles_initial_conditions();
00443         
00445         virtual void create_xballs_script();
00446 
00448         virtual double getInfo(Particle& P UNUSED) {return 0;}
00449         
00451         virtual void save_restart_data ();
00452         
00454         int load_restart_data ();
00455         int load_restart_data (string filename);
00456         
00458         void statistics_from_restart_data(const char* name);
00459         
00461         virtual void write(std::ostream& os);
00463         virtual void read(std::istream& is);
00465         virtual void write_v1(std::ostream& os);
00467         virtual void read_v1(std::istream& is);
00468         virtual void read_v2(std::istream& is);
00469         
00471         bool load_from_data_file (const char* filename, unsigned int format=0);
00473         bool load_par_ini_file (const char* filename);
00474         bool read_next_from_data_file (unsigned int format=0); 
00475         int read_dim_from_data_file ();
00476         bool find_next_data_file (Mdouble tmin, bool verbose=true);
00477 
00478         
00480 
00481         virtual void print(std::ostream& os, bool print_all=false);
00482         
00483         friend inline std::ostream& operator<<(std::ostream& os, MD &md) {
00484                 md.print(os);
00485                 return os;
00486         }
00487         
00488         void add_Species(CSpecies& S);
00489         
00490         void add_Species(void) { add_Species(Species[0]); };
00491                 
00492         void set_format(int new_) {format = new_;};
00493         
00494         int readArguments(unsigned int argc, char *argv[]);
00495 
00496         virtual int readNextArgument(unsigned int& i, unsigned int argc, char *argv[]);
00497         
00498         //This is a random generator, often used by the initial conditions etc...
00499         RNG random;
00500 
00501 //functions that should only be used in the class definitions 
00502 protected:
00503         
00505         virtual void compute_all_forces();
00506 
00508         virtual void compute_internal_forces(Particle* i);
00509 
00511         virtual void compute_internal_forces(Particle* P1, Particle* P2);
00512         
00514         void compute_plastic_internal_forces(Particle* P1, Particle* P2);
00515         
00517         virtual void compute_external_forces(Particle* PI);
00518         
00520         virtual void compute_walls(Particle* PI);
00521         
00523         virtual void actions_before_time_loop(){
00525                 //automatically sets dt if dt is not specified by the user
00526                 if (!dt) set_dt(); 
00527         };
00528         
00530         virtual void HGRID_actions_before_time_loop(){};
00531         
00533         virtual void HGRID_actions_before_time_step(){};
00534         
00536         virtual void HGRID_InsertParticleToHgrid(Particle *obj UNUSED){};
00537         virtual void HGRID_UpdateParticleInHgrid(Particle *obj UNUSED){};
00538         virtual void HGRID_RemoveParticleFromHgrid(Particle *obj UNUSED){};
00539         virtual bool get_HGRID_UpdateEachTimeStep(){return true;};
00540         
00542         virtual void actions_before_time_step(){};
00543         
00545         virtual void actions_after_solve(){};
00546 
00548         virtual void actions_after_time_step(){};       
00549         
00551         virtual void output_xballs_data();
00552         virtual void output_xballs_data_particle(int i);
00553         
00555         virtual void start_ene();
00556         virtual void fstat_header();
00557         virtual void output_ene();
00558         
00560         virtual void initialize_statistics(){};
00561         virtual void output_statistics(){};
00562         virtual void gather_statistics_collision(int index1 UNUSED,int index2 UNUSED, Vec3D Contact UNUSED, Mdouble delta UNUSED, Mdouble ctheta UNUSED, Mdouble fdotn UNUSED, Mdouble fdott UNUSED, Vec3D P1_P2_normal_ UNUSED, Vec3D P1_P2_tangential UNUSED){};
00563         virtual void process_statistics(bool usethese UNUSED){};
00564         virtual void finish_statistics(){};
00565         virtual void set_initial_pressures_for_pressure_controlled_walls(){};   
00566         
00568         virtual void do_integration_before_force_computation(Particle* pI);
00569         
00570         virtual void HGRID_update_move(Particle*, Mdouble){};
00571         virtual void HGRID_actions_before_integration(){};
00572         virtual void HGRID_actions_after_integration(){};
00573         
00575         virtual void do_integration_after_force_computation(Particle* pI);
00576         
00578         virtual void InitBroadPhase(){};
00579         
00581         virtual void broad_phase(Particle* i)
00582         {
00583                 for (vector<Particle*>::iterator it = particleHandler.begin(); (*it)!=i; ++it)
00584                 {
00585                         compute_internal_forces(i,*it);
00586                 }
00587         }
00588         
00589         void set_FixedParticles(unsigned int n){for (unsigned int i=0; i<std::min((unsigned int)particleHandler.get_NumberOfParticles(),n); i++) particleHandler.get_Particle(i)->fixParticle();}
00590         
00591         void initialize_tangential_springs();
00592                 
00594         void compute_particle_masses() {for (unsigned int i=0;i<particleHandler.get_NumberOfParticles();i++) particleHandler.get_Particle(i)->compute_particle_mass(Species);}
00595         
00597         virtual void cout_time() {
00598                 cout << "\rt=" << setprecision(3) <<fixed<< left << setw(6) << t 
00599                         << ", tmax=" << setprecision(3) << left << setw(6) << tmax << " \r";
00600                 cout.flush();
00601         }
00602         
00603         virtual bool continue_solve() {return true;}
00604         
00606         void reset_DeltaMax(){for (vector<Particle*>::iterator it = particleHandler.begin(); it!=particleHandler.end(); ++it) (*it)->get_DeltaMaxs().resize(0);}
00608         void reset_TangentialSprings(){for (vector<Particle*>::iterator it = particleHandler.begin(); it!=particleHandler.end(); ++it) (*it)->get_TangentialSprings().resize(0);}
00609 
00610 
00612         //virtual int Check_and_Duplicate_Periodic_Particle(int i, int nWallPeriodic);
00613 
00616         //vector<Particle> Particles;
00617         
00620         vector<CWall> Walls;
00621         vector<CWallPeriodic> WallsPeriodic;
00622 
00624         vector<CSpecies> Species;
00625 
00626 private:
00627 
00629         int dim;
00630 
00632         Vec3D gravity; 
00633         
00634         Mdouble max_radius;
00635         
00637         Mdouble xmin,xmax,ymin,ymax,zmin,zmax;
00638         
00640         Mdouble dt;
00641         Mdouble tmax;
00642         
00644         int save_count_data; //<determines how many time steps are skipped before the next data file is written
00645         int save_count_ene;  //<determines how many time steps are skipped before the next ene file is written
00646         int save_count_stat; //<determines how many time steps are skipped before the next fstat file is written
00647         int save_count_fstat;//<determines how many time steps are skipped before the next stat file is written
00648         bool save_data_data;//<determines if the current timestep is written into the data file
00649         bool save_data_ene;//<determines if the current timestep is written into the ene file
00650         bool save_data_fstat;//<determines if the current timestep is written into the fstat file
00651         bool save_data_stat;//<determines if the current timestep is written into the stat file
00652         bool do_stat_always;
00653         
00654 
00656         Mdouble t;
00657 
00659         Mdouble ene_ela; //<stores the potential energy in the elastic springs (global, because it has to be calculated in the force loop
00660 
00661         
00662         //This is the private data that is only used by the xballs output
00663 
00664         int xballs_cmode; //< sets the xballs argument cmode (see xballs.txt)
00665         Mdouble xballs_vscale; //< sets the xballs argument vscale (see xballs.txt)
00666         Mdouble xballs_scale; //< sets the xballs argument scale (see xballs.txt)
00667         string xballs_additional_arguments; //< string where additional xballs argument can be specified (see xballs.txt)
00668         int format; //< sets the data file argument format (i.e. how many columns the data file has)
00669         int restart_version; //<to read new and old restart data
00670         bool restarted; //<to read new and old restart data
00671         bool Hertzian; //<make force law Hertzian
00672         int data_FixedParticles; //<determines how many particles are fixed when reading in data files
00673 
00674         
00675 private:
00676 
00677         ParticleHandler particleHandler;
00678         
00680         void Remove_Duplicate_Periodic_Particles();
00682         virtual int Check_and_Duplicate_Periodic_Particle(Particle* i, int nWallPeriodic);
00684         int Check_and_Duplicate_Periodic_Particles();
00685 
00686 
00687         bool append;
00688         bool rotation;
00689         int PeriodicCreated;
00690         int save_restart_data_counter;
00691 
00692         
00693 
00694 
00695 };
00696 
00697 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines