//we use SI units #include #include #include #include #include double const kB=1.38064852e-23;//Boltzmann constant double const A=1e-10; //Angstrom void confiniziale(int N,double l, double m, double T,double** r,double** v); double maxwell_boltzmann(double m,double T,double v); void energia_temp(double eps,double sigma,double m,int n,double l,double** r0, double** v0, double& ene, double& t ); void forza(double eps,double sigma,double m,int n,double l,double** r0, double** f); double drand( void); int main(int argc, const char * argv[]) { double rho, l, eps, sigma;//densità, lato cella di simulazione, parametri LJ double const A=1e-10; //Angstrom double m=39.95*1.6747e-27;//mass atomo Argon int N;//numero di atomi long int Ntr;//numero time steps di rilassamento long int Nt;//numero time steps di simualazione double dt;//time step double *r0mat,*r1mat,*v0mat,*v1mat,*f0mat,*f1mat,*rDmat,*rD0mat; double **r0,**r1,**v0,**v1,**f0,**f1,**rD,**rD0;//array bidimensionali posizioni e velocità double T;//temperatura int Nstampa;//intervallo di passi per stampa e analisi double ene,temp; char cstampa; std::string namexyz; std::ofstream fxyz,flast,fstampa; eps=120*kB; sigma=3.4*A; std::cout << "Numero di atomi: \n"; std::cin >> N; std::cout << "Densità: (kg/m^3) \n"; std::cin >> rho; std::cout << "Tempertura (K): \n"; std::cin >> T; std::cout << "Time step (s): \n"; std::cin >> dt; std::cout << "Numero di passi rilassamento: \n"; std::cin >> Ntr; std::cout << "Numero di passi simulazione: \n"; std::cin >> Nt; std::cout << "Stampa ogni : \n"; std::cin >> Nstampa; std::cout << "Scrivi xyz file (t/f) : \n"; std::cin >> cstampa; if(cstampa=='t'){ std::cout << "Nome file xyz : \n"; std::cin >> namexyz; fxyz.open(namexyz,std::ios::out); } //trova lato scatola di simulazione l=pow(m*N/rho,1./3.); std::cout << "Lato cella Simulazione (m): " << l << '\n'; //alloca r0mat= new double[N*3]; r1mat= new double[N*3]; v0mat= new double[N*3]; v1mat= new double[N*3]; f0mat= new double[N*3]; f1mat= new double[N*3]; rDmat= new double[N*3]; rD0mat= new double[N*3]; r0= new double*[N]; r1= new double*[N]; v0= new double*[N]; v1= new double*[N]; f0= new double*[N]; f1= new double*[N]; rD= new double*[N]; rD0= new double*[N]; for (int i=0; il){ r1[i][k] -= l; }else if(r1[i][k] < 0.){ r1[i][k]+=l; } } } forza( eps, sigma, m, N, l, r1, f1); for(int i=0;if); //prima la direzione d=0.; for(int j=0;j<3;j++){ v0[i][j]=drand()-0.5; d+=pow(v0[i][j],2.); } d=sqrt(d); for(int j=0;j<3;j++) v0[i][j] *= v/d; i++; } } } } //metto a zero la velocità del centro di massa //tutte le masse sono uguali double vcm[3]= {0.,0.,0.}; for (int i=0; i