Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. int change_volume_and_shape() {
  2.     // Calculate current volume
  3.     double volume = box[0] * box[1] * box[2];
  4.     double scale_factor = 1.;
  5.  
  6.     //Select a random axis
  7.     int random_axis = rnd.RandomIntAB(0, NDIM - 1);
  8.     double old_axis_length = box[random_axis];
  9.     box[random_axis] += 3 * rnd.RandomMinusOneOne();
  10.     double new_volume = box[0] * box[1] * box[2];
  11.  
  12.     //Acceptance criterion for volume change move
  13.     double prob = exp(-beta * pressure * (new_volume - volume) + (n_particles + 1.) * log(new_volume / volume));
  14.     if (rnd.RandomZeroOne() > prob) {
  15.         box[random_axis] = old_axis_length;
  16.         return 0;
  17.     }
  18.  
  19.     //Scale the particle coordinates and the box
  20.     scale_factor = box[random_axis] / old_axis_length;
  21.     for (int n = 0; n < n_particles; ++n) {
  22.         r[n][random_axis] *= scale_factor;
  23.     }
  24.     if (isThereAnyOverlap()) {
  25.         //Reject move and reset to original packing fraction and return
  26.         //Maybe copy old values instead? The multiplied values differ ~10^-14...
  27.         scale_factor = old_axis_length / box[random_axis];
  28.         for (int n = 0; n < n_particles; ++n) {
  29.             r[n][random_axis] *= scale_factor;
  30.         }
  31.         box[random_axis] = old_axis_length;
  32.  
  33.         return 0;
  34.     }
  35.     return 1;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement