示例#1
0
void DeleteAtoms::delete_porosity(int narg, char **arg)
{
  if (narg < 4) error->all(FLERR,"Illegal delete_atoms command");

  int iregion = domain->find_region(arg[1]);
  if (iregion == -1) error->all(FLERR,"Could not find delete_atoms region ID");

  double porosity_fraction = force->numeric(FLERR,arg[2]);
  int seed = force->inumeric(FLERR,arg[3]);
  options(narg-4,&arg[4]);

  RanMars *random = new RanMars(lmp,seed + comm->me);

  // allocate and initialize deletion list

  int nlocal = atom->nlocal;
  memory->create(dlist,nlocal,"delete_atoms:dlist");
  for (int i = 0; i < nlocal; i++) dlist[i] = 0;

  double **x = atom->x;

  for (int i = 0; i < nlocal; i++)
    if (domain->regions[iregion]->match(x[i][0],x[i][1],x[i][2]))
      if (random->uniform() <= porosity_fraction) dlist[i] = 1;
}
示例#2
0
int main() {
    clock_t t1,t2;
    t1=clock();
    //code goes here
    
    RanMars *random;
    double seed = time(0)%1000;
    cout << seed << endl;
    random = new RanMars(seed);
    
    cout << "----------------------" << endl;
    cout << "T* \t rho* \t kinetic \t virial \t total pressure" << endl;
    
    double low_temp = 1;
    int boxes = 10;
    
    Replica *r = new Replica[boxes];
    for (int i=0; i<boxes; i++) {
        r[i].set_temp(low_temp*pow(1.3,i));
    }
    
    int total_cycles=25000; //cycles - doesn't count the 500 initialization cycles
    int swap_freq = 2; //how many cycles to wait between trying swaps
    //this means on average a box gets swapped 2*3*10=60 steps
    
    double current_temp = low_temp;
    double *config = new double[total_cycles/swap_freq];
    config[0]=current_temp;
    
    double accept_count=0, total_count=0;
    
    //loop through many moves
    for (int ncycle=1; ncycle<=total_cycles; ncycle++) {
        if (ncycle%500==0) {
            t2=clock();
            float diff ((float)t2-(float)t1);
            float mins = diff / CLOCKS_PER_SEC /60;
            cout<< ncycle << " cycles in: " << mins << " minutes" << endl;
        }
        
        for (int i=0; i<boxes; i++) {
            r[i].cycle(ncycle, total_cycles);
        }
        
        if (ncycle<total_cycles) {
            //idk how often to try these swap moves? I know we need to let the boxes equlibrate a little bit...
            if (ncycle % swap_freq == 0) {
                //choose box1
                double rand = random->uniform();
                int n = floor(rand*boxes);
                
                //choose box2
                rand = random->uniform();
                int m = n-1;
                if (rand>.5) {
                    m = n+1;
                }
                
                //check end points
                //if temp m is out of bounds, wrap around
                if (m==-1) {
                    m=boxes-1;
                }
                if (m==boxes) {
                    m=0;
                }
                
//                cout << "(" << r[n].temp << "," << r[m].temp << ")" << endl;
                
                //swap box 1 and 2
                bool accept = swap(r[n],r[m], random);
                
                total_count++;
                if (accept) {
                    accept_count++;
                    
                    if (r[n].temp==current_temp)
                        current_temp = r[m].temp;
                    else if (r[m].temp==current_temp)
                        current_temp = r[n].temp;
                }
                config[ncycle/swap_freq]=current_temp;
            
                //display current acceptance rate - should converge to around 20%
                cout << accept_count/total_count << endl;
                
                //print temps visited by config #1
                ofstream temp_vists("files/tempsVisited.csv",ios::out);
                for (int i=0; i<total_cycles/swap_freq; i++) {
                    temp_vists << i << "," << config[i] << endl;
                }
            }
        }
    }
    
    return 0;
}