
Science SPORE Prize
November 2011

The Open Source Physics Project is supported by NSF DUE-0442581.
|
Errata in An Introduction to Computer Simulation Methods
post and replies
Return to the Errata in An Introduction to Computer Simulation Methods thread
Login to post to this thread
|
Error in IdealDemon
- Feb 21, 2009 at 2:26PM
|
Larry Engelhardt
14 Posts
|
This is not actually an "error", as I initially thought that it was. Currently the variables systemEnergyAccumulator and demonEnergyAccumulator are being updated every time that a change is proposed, rather than being updated once per MCS. Unless the number of MCS is large, these two methods of averaging will yield different results. The code below shows the changes that will result in data only being accumulated once per MCS.
Alternate method for IdealDemon.java:
public void doOneMCStep() { for(int j = 0;j LESSTHAN N;++j) { int particleIndex = (int) (Math.random()*N); // choose particle at random double dv = (2.0*Math.random()-1.0)*delta; // random change in velocity double trialVelocity = v[particleIndex]+dv; double dE = 0.5*(trialVelocity*trialVelocity-v[particleIndex]*v[particleIndex]); if(dE LESSTHANOREQUALTO demonEnergy) { v[particleIndex] = trialVelocity; acceptedMoves++; systemEnergy += dE; demonEnergy -= dE; } } systemEnergyAccumulator += systemEnergy; demonEnergyAccumulator += demonEnergy; mcs++; }
Alternate code for IdealDemonApp.java:
control.println("Mean Ed = "+idealGas.demonEnergyAccumulator/idealGas.mcs); control.println("Mean E = "+idealGas.systemEnergyAccumulator/idealGas.mcs);
Post edited February 21, 2009 at 2:53 PM EST.
|
|
Re: Error in IdealDemon - Feb 23 2009 10:18AM
|
Jan Tobochnik
1 Posts
|
Dear Larry,
Usually, there is no harm and usually somewhat better statistics to update as often as possible as long as you are not slowing the simulation down significantly.
Yours,
Jan
|
|