SpherePackingScenarioGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Simulation.h
Go to the documentation of this file.
00001 /* 
00002    Packing of hard spheres via molecular dynamics
00003    Developed by Monica Skoge, 2006, Princeton University
00004    Contact: Aleksandar Donev (adonev@math.princeton.edu) with questions
00005    This code may be used, modified and distributed freely.
00006    Please cite:
00007 
00008    "Packing Hyperspheres in High-Dimensional Euclidean Spaces"
00009         M. Skoge, A. Donev, F. H. Stillinger and S. Torquato, 2006
00010 
00011    if you use these codes.      
00012  */
00013 
00014 
00015 
00016 #ifndef  _Simulation_H_
00017 #define  _Simulation_H_
00018 
00019 #include <math.h>
00020 #include <vector>
00021 #include <algorithm>
00022 #include <functional>
00023 #include <fstream>
00024 #include <iostream>
00025 #include "tarch/la/Vector.h"
00026 #include "GlobalValue.h"
00027 #include "Cells.h"
00028 #include "Event.h"
00029 #include "Sphere.h"
00030 #include "Heap.h"
00031 #include "Collisions.h"
00032 #include "algorithms/geometries/SphereGeometry.h"
00033 
00034 namespace algorithms{
00035 namespace ls2{
00036 class Simulation;
00037 //#define PI     3.141592653589793238462643
00038 #define VOLUMESPHERE_ls2 pow(tarch::la::PI,((double)(DIM))/2.)/exp(lgamma(1+((double)(DIM))/2.)) // volume prefactor for sphere
00039 #define DBL_EPSILON_ls2  2.2204460492503131e-016 // smallest # such that 1.0+DBL_EPSILON!=1.0
00040 #define Mass_ls2 1.0
00041 
00042 
00043 
00048 class Simulation {
00049 
00050 public:
00054         void growSphere();
00055         void findAllNeighbour(int i);
00056         void findNearestNeighbor(int i,double *criteria);
00057         double oneDimensionDistance(double r1,double r2);
00061         void getSpheres(std::vector<algorithms::geometries::SphereGeometry>& spheres) const;
00065 Simulation(
00066     double Size_i,
00067     int N_i,
00068     double r_i,
00069     double growthrate_i,
00070     double maxpf_i,
00071     double various_i,
00072     std::vector<double>& array
00073 );
00074 
00078         ~Simulation();
00079 
00080 
00081         //initial process
00085         int Optimalngrids();
00091         int Optimalngrids2(double maxr);
00095         void CreateSpheres(double temp);
00099         void CreateSphere(int Ncurrent);
00103         double Velocity(double temp);
00107         void VelocityGiver(double temp);
00111         void SetInitialEvents();
00115         void RecreateSpheres(const char* filename, double temp);
00119         void ReadPositions(const char* filename);
00123         void AssignCells();
00124 
00125         // Predicting next Event
00129         Event FindNextEvent(int i);
00133         void CollisionChecker(Event c);
00137         Event FindNextTransfer(int i);
00141         Event FindNextCollision(int i);
00145         void ForAllNeighbors(int, tarch::la::Vector<DIM, int>, tarch::la::Vector<DIM,int>, Collisions&);
00149         void PredictCollision(int i, int j, tarch::la::Vector<DIM, int> pboffset,
00150                         double& ctime, int& cpartner, 
00151                         tarch::la::Vector<DIM, int>& cpartnerpboffset);
00155         double CalculateCollision(int i, int j, tarch::la::Vector<DIM,double>  pboffset);
00159         double QuadraticFormula(double a, double b, double c);
00160 
00161         // Processing an Event
00165         void Process(int n);
00169         void ProcessEvent();
00173         void Collision(Event e);
00177         void Transfer(Event e);
00181         void UpdateCell(int i, tarch::la::Vector<DIM,int>& celli);
00185         void Synchronize(bool rescale);
00189         void ChangeNgrids(int newngrids);
00190 
00191         // Debugging
00195         void TrackPositions();
00199         void OutputEvents();
00203         void OutputCells();
00207         void GetInfo();
00211         int CheckSphereDiameters();
00212 
00213         // Statistics
00217         double Energy();
00221         double PackingFraction();
00225         void PrintStatistics();
00229         void RunTime();
00233         void WriteConfiguration(const char* wconfigfile);
00234 
00235         double getRadius() const;
00236         int getNumberGrids() const;
00237         double getPressure() const;
00238         double getFraction() const;
00239         double getEnergyChance() const;
00240         double getTotalEvents() const;
00241         double getCollisionrate() const;
00242 
00243 
00244 private:
00245 
00246         double _SIZE;
00250         double r;
00254         const int N;
00258         double growthrate;
00262         int ngrids;
00266         double gtime;
00270         double rtime;
00274         double collisionrate;
00275 
00276         // statistics
00280         double pressure;
00284         double xmomentum;
00288         double pf;
00292         double energy;
00296         double energychange;
00300         int ncollisions;
00304         int ntransfers;
00308         int nchecks;
00312         int nEventstot;
00316         int ncycles;
00320         time_t start, error, end;
00321 
00322         // arrays
00326         Sphere *s;
00330         Cells<DIM, int> cells;
00334         int *binlist;
00338         Heap h;
00342         tarch::la::Vector<DIM,double> *x;
00343         double maxpf;
00344         double various_radius;
00345         std::vector<Sphere> neighbor;
00346         std::vector<double>& _array;
00347 };
00348 }/* close namespace ls2 */
00349 }/* close namespace algorithms */
00350 #endif 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines