00001
00002 #define HARDBALLS
00003
00007 //#define ADSORPTION
00008 enum AtomType {
00009 undefined=0,
00010 hydrogen=1,
00011 helium=2,
00012 carbon=12,
00013 oxygen=16,
00014 maxAtomTypes
00015 };
00016 union State {
00017
00018
00019
00020 unsigned int locked: 1;
00021 unsigned int done: 1;
00022 };
00023 class Molecule {
00024 int type;
00025 #ifdef OMP
00026 int id;
00027
00028
00029 State state;
00030 #endif
00031 #ifdef COLLISIONTIME
00032 REAL time,dt;
00033 Molecule *target;
00034 #endif
00035 #ifdef LOCAL
00036 int gridcell;
00037 Ptr<Molecule> *ptr;
00038 #endif
00039 REAL
00040 energy,
00041 #ifdef ADSORPTION
00042 residencetime,
00043 #endif
00044 x[DIM],
00045 v[DIM];
00046
00047 public:
00048 Molecule();
00049 inline void Type(int t) {type=t;}
00050 inline int Type() {return type;}
00051 #ifdef COLLISIONTIME
00052 inline REAL Time(){return time;}
00053 inline void Time(REAL t){time=t;}
00054 inline REAL TimeStep(){return dt;}
00055 inline void TimeStep(REAL step){dt=step;}
00056 inline void Target(Molecule *a){target=a;}
00057 inline Molecule *Target(){return target;}
00058 #endif
00059 #ifdef OMP
00060
00061 inline bool islocked() {return state.locked==1;}
00062
00063 inline void lock() {state.locked=1;}
00064
00065 inline void unlock() {state.locked=0;}
00066 inline bool isdone() {return state.done==1;}
00067 inline void done() {state.done==1;}
00068 inline void ready() {state.done=0;}
00069
00070
00071
00072 inline int index() {return id;}
00073
00074 inline void index(int i) {id=i;}
00075 #endif
00076 #ifdef LOCAL
00077
00078 inline int GridCell() { return gridcell; }
00079 inline void GridCell(int icell) { gridcell=icell; }
00080 inline Ptr<Molecule> *getPtr() { return ptr; }
00081 inline void putPtr(Ptr<Molecule> *p) { ptr=p; }
00082 #endif
00083
00084
00085 inline void InternalEnergy(REAL e) { energy=e; }
00086 inline REAL InternalEnergy() { return energy; }
00087 #ifdef ADSORPTION
00088
00092 inline REAL ReleaseTime() {return residencetime;}
00093 inline void ReleaseTime(REAL t) {residencetime=t;}
00094 #endif
00095 inline REAL Coordinate(int i) {
00096 if(i>=DIM) {
00097 cerr<<"SubAtom coordinate index "<<i
00098 <<" exceeds "<<DIM<<endl;cerr.flush();
00099 return 0.0;
00100 }
00101 return x[i];
00102 }
00103 inline void Coordinate(int i, REAL y) {
00104 if(i>=DIM) {
00105 cerr<<"SubAtom coordinate index "<<i
00106 <<" exceeds "<<DIM<<endl;cerr.flush();
00107 }
00108 x[i]=y;
00109 }
00110 inline REAL* Coordinates() { return x; }
00111 inline void Coordinates(REAL y[]) { for (int i=0;i<DIM;i++) y[i]=x[i]; }
00112 inline void setCoordinates(REAL y[]) { for (int i=0;i<DIM;i++) x[i]=y[i]; }
00113 inline REAL Velocity(int i) {
00114 if(i>=DIM) {
00115 cerr<<"SubAtom velocity index "<<i
00116 <<" exceeds "<<DIM<<endl;cerr.flush();
00117 return 0.0;
00118 }
00119 return v[i];
00120 }
00121 inline void Velocity(int i, REAL u) {
00122 if(i>=DIM) {
00123 cerr<<"Molecule velocity index "<<i
00124 <<" exceeds "<<DIM<<endl;cerr.flush();
00125 }
00126 v[i]=u;
00127 }
00128 inline REAL* Velocity() { return v; }
00129 inline void Velocity(REAL u[]) { for (int i=0;i<DIM;i++) u[i]=v[i]; }
00130 inline void setVelocity(REAL u[]) { for (int i=0;i<DIM;i++) v[i]=u[i]; }
00132 REAL KineticEnergy();
00134 void Temperature(REAL temperature);
00135 void Move();
00136 void copy(Molecule *molecule);
00137 };
00141 namespace Potential {
00142 const REAL small=1.0e-20, large=1.0e20;
00143 extern REAL cutoff;
00144 extern REAL sigma, eta;
00145 inline void strength(REAL strength) {
00146 eta=strength;
00147 }
00148 inline REAL strength() { return eta; }
00149 inline void lengthscale(REAL lengthscale) {
00150 sigma=lengthscale;
00151 }
00152 inline REAL lengthscale() { return sigma; }
00153 inline void Cutoff(REAL newcutoff) { cutoff=newcutoff; }
00154 inline REAL Cutoff() { return cutoff; }
00155 inline REAL value(REAL r) {
00156 if(r<small) r=small;
00157
00158 REAL x=sigma/r,
00159 val=r>cutoff?0.0:eta*(pow(x,12.0) - pow(x,6.0));
00160
00161 return val<large?val:large;
00162
00163
00164
00165 }
00166 inline REAL force(REAL r) {
00167 return eta/sigma*(-12.0*pow(sigma/r,13.0) + 6.0*pow(sigma/r,7));
00168 }
00169 REAL value(REAL r);
00170 REAL derivative(REAL r);
00171
00172 };
00176 namespace Geom {
00177 void distvec(REAL a[], REAL b[], REAL c[]);
00178 REAL distance(REAL a[], REAL b[]);
00179 REAL distance(int dim, REAL a[], REAL b[]);
00180 REAL sclp(REAL a[], REAL b[]);
00181 REAL length(REAL a[]);
00182 REAL area(REAL a[], REAL b[]);
00183 REAL normalize(REAL a[]);
00184 int hash(int i, int j, int n);
00185 }