예제 #1
0
TimeTest::TimeTest()
{

    double L0 = 3.405;
    double r_cut = 3*L0;
    int Nx = 8, Ny = 8, Nz = 8;
    int CellNx, CellNy, CellNz;
    double b = 5.26;
    double T = 100;
    CellNx = Nx*b/r_cut;
    //CellNx = 1;
    CellNy = CellNx;
    CellNz = CellNx;
    r_cut = Nx*b/(CellNx);
    string element = "Ar";

    vec time_steps_vec(3);
    time_steps_vec<<100<<500<<1000;
    vec N_vec(3);
    N_vec<<8<<12<<16;
    double numOfTimeSteps;
    bool writeVMD = false;
    bool writeMeasurements = false;
    //int N;
    double dt = 0.01;
    string filenamebase = "test";
    double mass =1;
    int max_time_step = numOfTimeSteps;
    for(int i=0;i<3;i++){
        Nx = N_vec(i);
        CellNx = Nx*b/r_cut;
        //CellNx = 1;
        CellNy = CellNx;
        CellNz = CellNx;
        r_cut = Nx*b/(CellNx);
        Ny= Nx;
        Nz = Nx;
        for(int j=0;j<3;j++){

            numOfTimeSteps = time_steps_vec(j);
            int max_time_step = numOfTimeSteps;
            CellSolver* mySolver = new CellSolver(CellNy, CellNx, CellNz, Nx,Ny, Nz,max_time_step, b, T, r_cut, element);
            cout<<"N: "<<Nx<<" numOfTimesteps: "<<numOfTimeSteps<<endl;
            mySolver->solve(0,numOfTimeSteps, dt,filenamebase, writeVMD, writeMeasurements);



            Lattice mol = Lattice(Nx,Nx,Nx, element,b, T, mass);
            Verlet_solver* vSolver = new Verlet_solver(mol);
            //vSolver->solve(0,1000,0.01,filenamebase);
            vSolver->solve(0,numOfTimeSteps,dt,filenamebase);
        }
    }
}
예제 #2
0
  void setupLattice(){

    if( OPT_DEBUG ) std::cout << "Setting up lattice for cell " << ident << std::endl;

    std::vector< std::pair<SurfaceCard*,bool> > surfaceCards;
    
    for( geom_list_t::iterator i = geom.begin(); i!=geom.end(); ++i){
      geom_list_entry_t entry = *i;
      if( entry.first == SURFNUM ){
        SurfaceCard* surf = parent_deck.lookup_surface_card( std::abs(entry.second) );
        assert(surf);
        surfaceCards.push_back( std::make_pair(surf, (entry.second>0) ) );
      }
    }

    int num_finite_dims = 0;
    Vector3d v1, v2, v3;

    std::vector< std::pair<Vector3d, double> > planes;

    if( surfaceCards.size() == 1 ){ 
      planes = surfaceCards.at(0).first->getMacrobodyPlaneParams();
      if( surfaceCards.at(0).second != false ){
        std::cerr << "Warning: macrobody lattice with positive sense, will proceed as if it was negative.";
      }
    }
    else{
      for( unsigned int i = 0; i < surfaceCards.size(); ++i){
        planes.push_back( surfaceCards.at(i).first->getPlaneParams() );
        if( surfaceCards.at(i).second == true ){ planes[i].first = -planes[i].first; }
      }
    }

    if( OPT_DEBUG ){
      for( unsigned int i = 0; i < planes.size(); ++i){
        std::cout << " plane " << i << " normal = " << planes[i].first << " d = " << planes[i].second  << std::endl;
      }
    }
    if( lat_type == HEXAHEDRAL ){
      assert( planes.size() == 2 || planes.size() == 4 || planes.size() == 6 );
      if( planes.size() == 2 ){

        num_finite_dims = 1;
        v1 = planes[0].first.normalize() * std::fabs( planes[0].second - planes[1].second ); 

      }
      else if( planes.size() == 4 ){
        num_finite_dims = 2;
        
        Vector3d v3 = planes[0].first.cross( planes[2].first ).normalize(); // infer a third (infinite) direction
        
        // vector from planes[1] to planes[0]
        Vector3d xv = planes[0].first.normalize() * std::fabs( planes[0].second - planes[1].second );

        // direction of l.v1: cross product of normals planes[2] and v3
        Vector3d xv2 = planes[2].first.normalize().cross( v3 ).normalize();
        v1 = latticeVectorHelper( xv, xv2 );

        Vector3d yv = planes[2].first.normalize() * std::fabs( planes[2].second - planes[3].second );
        Vector3d yv2 = planes[0].first.normalize().cross( v3 ).normalize();
        v2 = latticeVectorHelper( yv, yv2 );


      }
      else{ // planes.size() == 6 
        num_finite_dims = 3;

        // vector from planes[1] to planes[0]
        Vector3d xv = planes[0].first.normalize() * std::fabs( planes[0].second - planes[1].second );

        // direction of v1: cross product of normals planes[2] and planes[4]
        Vector3d xv2 = planes[2].first.normalize().cross( planes[4].first.normalize() ).normalize();
        v1 = latticeVectorHelper( xv, xv2 );

        Vector3d yv = planes[2].first.normalize() * std::fabs( planes[2].second - planes[3].second );
        Vector3d yv2 = planes[0].first.normalize().cross( planes[4].first.normalize() ).normalize();
        v2 = latticeVectorHelper( yv, yv2 );

        Vector3d zv = planes[4].first.normalize() * std::fabs( planes[4].second - planes[5].second );
        Vector3d zv2 = planes[0].first.normalize().cross( planes[2].first.normalize() ).normalize();
        v3 = latticeVectorHelper( zv, zv2 );
        
      }
      
    }
    else if( lat_type == HEXAGONAL ){
      assert( planes.size() == 6 || planes.size() == 8 );

      v3 = planes[0].first.cross( planes[2].first ).normalize(); // prism's primary axis

      // vector from planes[1] to planes[0]
      Vector3d xv = planes[0].first.normalize() * std::fabs( planes[0].second - planes[1].second );
      
      // direction of l.v1: cross product of normals average(planes[2]+planes[4]) and v3
      // TODO: this averaging trick only works with regular hexagons...
      Vector3d xv2 = (planes[2].first.normalize()+planes[4].first.normalize()).normalize().cross( v3 ).normalize();
      v1 = latticeVectorHelper( xv, xv2 );
      
      Vector3d yv = planes[2].first.normalize() * std::fabs( planes[2].second - planes[3].second );
      Vector3d yv2 = (planes[1].first.normalize()+planes[4].first.normalize()).normalize().cross( v3 ).normalize();
      v2 = latticeVectorHelper( yv, yv2 );
      

      if( planes.size() == 6 ){
        num_finite_dims = 2;
        
      }
      else{ // planes.size() == 8
        num_finite_dims = 3;

        Vector3d zv = planes[6].first.normalize() * std::fabs( planes[6].second - planes[7].second );
        Vector3d zv2 = v3;
        v3 = latticeVectorHelper( zv, zv2 );
      }
    }

    if( OPT_DEBUG )std::cout << " dims " << num_finite_dims << " vectors " << v1 << v2 << v3 << std::endl;
    
    Lattice l;
    if( fill->hasData() ){
      l = Lattice( num_finite_dims, v1, v2, v3, fill->getData() );
    }
    else{
      FillNode n( this->universe );
      l = Lattice( num_finite_dims, v1, v2, v3,  n );
    }

    lattice = new ImmediateRef<Lattice>( l );

    
  }
예제 #3
0
파일: readdat.c 프로젝트: lis55/project1
void ReadInputData(void)
{
  int Ibeg,i;
  double Boxf,Rhof,Rho;
  FILE *FilePtr;

  FilePtr=fopen("input","r");
  fscanf(FilePtr,"%*s %*s %*s %*s\n");
  fscanf(FilePtr,"%d %d %d %d",&Ibeg,&NumberOfEquilibrationCycles,&NumberOfProductionCycles,&SamplingFrequency);
  fscanf(FilePtr,"%*s\n");
  fscanf(FilePtr,"%lf\n",&MaximumDisplacement);
  fscanf(FilePtr,"%*s\n");
  fscanf(FilePtr,"%d\n",&NumberOfDisplacementsPerCycle);
  fscanf(FilePtr,"%*s %*s %*s\n");
  fscanf(FilePtr,"%d %lf %lf\n",&NumberOfParticles,&Temp,&Rho);
  fscanf(FilePtr,"%*s %*s %*s %*s\n");
  fscanf(FilePtr,"%lf %lf %lf %lf\n",&Epsilon,&Sigma,&Mass,&CutOff);
  fclose(FilePtr);

  // initialize the random number generator with the system time
  InitializeRandomNumberGenerator(time(0l));

  if(NumberOfParticles>Npmax)
  {
    printf("Error: number of particles too large\n");
    exit(1);
  }

  Box=pow(NumberOfParticles/Rho,1.0/3.0);

  // read/generate configuration
  if(Ibeg==0)
  {
    // generate configuration from lattice
    Lattice();
  }
  else
  {
    printf(" Read confs from disk\n");
    FilePtr=fopen("restart.dat","r");
    fscanf(FilePtr,"%lf\n",&Boxf);
    fscanf(FilePtr,"%d\n",&NumberOfParticles);
    fscanf(FilePtr,"%lf\n",&MaximumDisplacement);
    Rhof=NumberOfParticles/CUBE(Boxf);
    if(fabs(Boxf-Box)>1.0e-6)
      printf("%lf %lf\n",Rho,Rhof);
    for(i=0;i<NumberOfParticles;i++)
    {
      fscanf(FilePtr,"%lf %lf %lf\n",&Positions[i].x,&Positions[i].y,&Positions[i].z);
      Positions[i].x*=Box/Boxf;
      Positions[i].y*=Box/Boxf;
      Positions[i].z*=Box/Boxf;
    }
    fclose(FilePtr);
  }

  // write input data

  printf("  Number Of Equilibration Cycles             : %d\n",NumberOfEquilibrationCycles);
  printf("  Number Of Production Cycles                : %d\n",NumberOfProductionCycles);
  printf("  Sample Frequency                           : %d\n",SamplingFrequency);
  printf("  Number Of Att. To Displ. A Part. Per Cycle : %d\n",NumberOfDisplacementsPerCycle);
  printf("  Maximum Displacement                       : %lf\n",MaximumDisplacement);
  printf("  Number Of Particles                        : %d\n",NumberOfParticles);
  printf("  Temperature                                : %lf\n",Temp);
  printf("  Density                                    : %lf\n",Rho);
  printf("  Box Length                                 : %lf\n",Box);
  printf("  Model Parameters\n");
  printf("    Sigma                                    : %lf\n",Sigma);
  printf("    Epsilon                                  : %lf\n",Epsilon);
  printf("    Mass                                     : %lf\n",Mass);
  printf("    CutOff                                   : %lf\n",CutOff);

  // calculate parameters:
  Beta=1.0/Temp;
      
  // calculate Cut-off radius potential

  CutOff=MIN(CutOff,0.5*Box);
}