00001 #include <math.h>
00002 #include <iostream>
00003 #include <cstdlib>
00004 using namespace std;
00005 #include "def.h"
00006 #include "run.h"
00007 #include "list.h"
00008 #include "collection.h"
00009 #include "model.h"
00010 #include "species.h"
00011 using namespace Species;
00012 #include "domain.h"
00013
00014
00015
00016
00017
00018
00019
00020 Molecule::Molecule() {
00021 type=-1;
00022 #ifdef OMP
00023 id=0;
00024 state.done=0;
00025 state.locked=0;
00026 #endif
00027 #ifdef LOCAL
00028 gridcell=-1;
00029 ptr=NULL;
00030 #endif
00031 time=Run::time.current;
00032 dt=Run::time.step;
00033 target=NULL;
00034 energy=0.0;
00035 }
00036 void Molecule::copy(Molecule *molecule) {
00037 type=molecule->Type();
00038 #ifdef LOCAL
00039 int gridcell=molecule->GridCell();
00040 #endif
00041 for(int i=0;i<DIM;i++) {
00042 x[i]=molecule->Coordinate(i);
00043 v[i]=molecule->Velocity(i);
00044 }
00045 }
00046 REAL Molecule::KineticEnergy() {
00047 REAL
00048 mass=species[type].Mass(),
00049 v2=0.0;
00050 for(int i=0;i<DIM;i++) {
00051 REAL vel=v[i];
00052 v2+=vel*vel;
00053 }
00054 return 0.5*mass*v2;
00055 }
00057 void Molecule::Temperature(REAL temperature
00058 ) {
00059 int ispecie=Type();
00060 REAL
00061 energy=temperature*BoltzmannConstant/AtomicMassUnit,
00062 cp=species[ispecie].Cp(),
00063 dof=DOF(cp),
00064 dofi=DOFI(dof);
00065 InternalEnergy(0.5*energy*dofi);
00066 }
00068 void Molecule::Move() {
00069 REAL
00070 mass=species[type].Mass();
00071 if (mass<SMALL) {
00072 cerr<<"MOLECULAR MASS "<<mass<<" FOR MOLECULE TYPE "<<type<<" OUT OF "<<Species::nspecies<<" IS TOO SMALL\n";return;
00073 }
00074 for (int i=0; i<DIM; i++) {
00075
00076
00077
00078
00079
00080 x[i]+=v[i]*dt;
00081 }
00082 time+=dt;
00083 }
00084 namespace Potential {
00085 REAL sigma=1.0, eta=1.0, cutoff=2.0;
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 REAL invdist(REAL x) {
00103 if(x<0.5) return log(2.0*x);
00104 else return -log(1.0-2.0*(x-0.5));
00105
00106 }
00107 }
00108 REAL Geom::normalize(REAL a[]) {
00109 REAL d=length(a);
00110 for(int i=0;i<DIM;i++)a[i]/=d;
00111 return d;
00112 }
00113 void Geom::distvec(REAL a[], REAL b[], REAL c[]) {
00114 for (int i=0;i<DIM;i++) c[i]=b[i]-a[i];
00115 }
00116 REAL Geom::distance(REAL a[], REAL b[]) {
00117 REAL d=0.0;
00118 for (int i=0;i<DIM;i++) {
00119 REAL r=b[i]-a[i];
00120 d+=r*r;
00121 }
00122 return sqrt(d);
00123 }
00124 REAL Geom::distance(int dim, REAL a[], REAL b[]) {
00125 REAL d=0.0;
00126 for (int i=0;i<dim;i++) {
00127 REAL r=b[i]-a[i];
00128 d+=r*r;
00129 }
00130 return sqrt(d);
00131 }
00132 REAL Geom::sclp(REAL a[], REAL b[]) {
00133 REAL c=0.0;
00134 for (int i=0;i<DIM;i++) c+=a[i]*b[i];
00135 return c;
00136 }
00137 int Geom::hash(int i, int j, int n) {
00138 return i>j?i*n+j:j*n+i;
00139 }
00140 REAL Geom::length(REAL a[]) {
00141 REAL d=0.0;
00142 for(int i=0;i<DIM;i++) {
00143 REAL r=a[i];
00144 d+=r*r;
00145 }
00146 return sqrt(d);
00147 }
00148 REAL Geom::area(REAL a[], REAL b[]) {
00149 REAL c[DIM];
00150 VECP(c,a,b);
00151 return LENGTH(c);
00152 }