PV Diagram

Set V:   
Set T:   
Set N:   

Init

Another test of the hard-sphere model to see if it obeys the ideal gas law.  The pressure shown in the table is calculated using the change in momentum due to collisions. These readings are averaged over 100 time steps to reduce statistical fluctuations.  We are, however, cheating in order to remove fluctuations on the graph by using the ideal gas law, P=NT/V, to calculate an approximate pressure.  See the pressure script for a comparison of pressure calculation techniques.


Script Example

<script language="JavaScript">
conid=0;
gid=0;
minVol=50;

function setVol(v){
    newVol=eval(v);
    if(newVol<minVol){
        alert("Volume cannot be less than "+minVol+".");
        document.dataForm.volField.value=minVol;
        newVol=minVol;
    }
    document.Molecular.setVolumeIsothermal(newVol,10);
}

function setTemp(t){
    newTemp=eval(t);
    document.Molecular.setTemp(newTemp);
}

function setNum(n){
    newNum=eval(n);
    document.Molecular.setParticles(newNum);
}


function initPhyslet(){
     document.Molecular.setAutoRefresh(false);
     document.Molecular.setDefault();
     document.Molecular.setPiston("5", true);
     document.Molecular.setPeriodicH(false);
     document.Molecular.setDefaultSize(0.5);
     document.Molecular.createParticles(25);
     eid=document.Molecular.getEnsembleID();
     document.Molecular.setTemp(20);
     document.Molecular.setAutoRefresh(true);

     document.DataTable.setDefault();
     document.DataTable.setDataStride(1,2);
     document.DataTable.setDataStride(2,2);
     document.DataTable.setDataStride(3,2);
     document.DataTable.setSeriesLabel(1,"P");
     document.DataTable.setSeriesLabel(2,"V");  
     document.DataTable.setSeriesLabel(3,"T");
     document.DataTable.setSeriesLabel(4,"N");
     document.DataTable.sizeToFit(true);
     tid=document.DataTable.getTableID();

     document.DataGraph.setAutoscaleX(true);
     document.DataGraph.setAutoscaleY(true);
     document.DataGraph.setMinMaxX(0,10);
     document.DataGraph.setMinMaxY(0,10);
     document.DataGraph.clearSeries(1);
     document.DataGraph.setSeriesStyle(1,true,0);
     document.DataGraph.setSeriesRGB(1,255,0,0);

     document.DataGraph.setLabelY("Pressure"); 
     document.DataGraph.setLabelX("Volume"); 
     document.DataGraph.setTitle("PV Diagram"); 
     document.DataGraph.setLastPointMarker(1, true);
     gid=document.DataGraph.getGraphID();

     document.Molecular.deleteDataConnections(); 
     cid=document.Molecular.makeDataConnection(eid,tid,1,"(pt+pr+pb+pl)/4","0"); 
     document.Molecular.setConnectionSmoothing(cid,100);
     document.Molecular.makeDataConnection(eid,tid,2,"v","0");  
     document.Molecular.makeDataConnection(eid,tid,3,"t","0"); 
     document.Molecular.makeDataConnection(eid,tid,4,"n","0"); 

     cid=document.Molecular.makeDataConnection(eid,gid,1,"v","p"); 
  
     document.Molecular.forward();
}
</script>