Gibbs Ensemble MCExamination of Java Code. Volume Exchange
private void trialVolume() {
double v1Old = firstPhase.volume();
double v2Old = secondPhase.volume();
double hOld = firstPhase.potentialEnergy.currentValue() + secondPhase.potentialEnergy.currentValue();
double vStep = (2.*rand.nextDouble()-1.)*maxVStep; //uniform step in volume
double v1New = v1Old + vStep;
double v2New = v2Old - vStep;
double v1Scale = v1New/v1Old;
double v2Scale = v2New/v2Old;
double r1Scale = Math.pow(v1Scale,1.0/(double)Simulation.D);
double r2Scale = Math.pow(v2Scale,1.0/(double)Simulation.D);
firstPhase.inflate(r1Scale); //perturb volumes
secondPhase.inflate(r2Scale);
double hNew = firstPhase.potentialEnergy.currentValue() //acceptance probability + secondPhase.potentialEnergy.currentValue();
if(hNew >= Double.MAX_VALUE ||
Math.exp(-(hNew-hOld)/temperature
+ firstPhase.moleculeCount*Math.log(v1Scale)
+ secondPhase.moleculeCount*Math.log(v2Scale))
{ //reject; restore volumes
firstPhase.inflate(1.0/r1Scale);
secondPhase.inflate(1.0/r2Scale);
//accept; nothing more to do
public class IntegratorGEMC extends Integrator