NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Thermodynamics => Topic started by: Fu-Kwun Hwang on November 04, 2005, 09:10:02 am



Title: particle model for solid/liquid/gas states
Post by: Fu-Kwun Hwang on November 04, 2005, 09:10:02 am
Matter can be either in solid,liquid or gas state  due to the change in temperature.
This is an animation of particle model for such situation.  
Because we need to add enough particles and calculated all the interactions between any two particles. the animation is a slow motion to illustrate a real situation.


You can change the gravity and Temperature of the system. You can also drag any one of the green box to change the volume of the container.

A smaller attraction force between particle was assumed: F(r)=-k/r for 2D simulation (equilibrium to 1/r2 for 3D).

The initial state is g=10.0 and T=250K. Wait for a few minutes, you will find something similar to the following image, similar to a solid state.  Particles are located at nearly fixed locations.

If you increase the temperature , you might found the system change to liquid state. The particles try to fill the lower part of the container.  There are still attracted to each other and particle can moving around.

If you increase to even higher temperature, you will find the system change to gas state. Particles try to fill the whole volume of the container.


Title: Re: particle model for solid/liquid/gas states
Post by: lookang on February 20, 2009, 12:27:21 pm
Hi Prof,

what mathematical model equation is this using.

is there any wikipedia page on the mathematical equations used?
some how the equations used in EJS xml doesnt look like
http://en.wikipedia.org/wiki/Kinetic_theory

i am looking at


initialisation:
int n2=(int)Math.sqrt(n);
double dx=(xr-xl)/n2,dy=range/n2;
for(int i=0;i<n;i++){
 x=xl2+ (i%n2)*dx+size*1.5;
 y=ymin+dy*((i/n2))+size;
// x=(xr-xl-R)*(Math.random()-0.5);
// y=range*(Math.random()-0.5);
}
setV();
_view.getElement("Trace").reset();


evolution:
dvx/dt = (getF(i,x,y)-b*vx)/m
dvy/dt = (getF(i,y,x)-b*vy)/m-g


fixed:
double v,cta;
for(int i=0;i<n;i++){
if(x>xr){
  x=2*xr-x;
  vx=-rr*vx;
}else if(x  x=2*xl-x;
  vx=-rr*vx;
}
if(y>ymax){
  y=2*ymax-y;
  vy=-vy;
}else if(y  y=2*ymin+size-y;
  vy=-rr*vy;
}
 v=Math.sqrt(vx*vx+vy*vy);
 if(v<vmin){
   cta=Math.PI*2*Math.random();
   vx=vmin*2*Math.cos(cta);
   vy=vmin*2*Math.sin(cta);
 }
}
x0=x[n2];
y0=y[n2];
ymin2=ymin;

custom:
public void setVmin(){
 b=0.2*(1.-(T-T0)/(Tmax-T0));
 vmin=Math.sqrt((T-T0)/Tk);
 if(vmin>vmax/2)vmin=vmax/2.;
}

double r,dx,dy,f,f2;
public double getF (int id,double x[],double y[]) {
 f=0.;
  for(int i=0;i<n;i++){
   if(i!=id){
    dx=x[id]-x; dy=y-y[id];
    r=Math.sqrt(dx*dx+dy*dy);
//    if(r>R3)f2=0.;
//    else if(r>R) f2=F0*(1.5-0.5*r/R)/r;
    if(r>R)f2=F0*R/r;
    else f2=F0+(R-r)*(Fmax-F0)/R;
//     f2=F0*R/r;
//    if(r     f+=f2*dx/r;
   }
 }
  return f/n;
}


Title: Re: particle model for solid/liquid/gas states
Post by: Fu-Kwun Hwang on February 20, 2009, 01:04:15 pm
Code:
public double getF (int id,double x[],double y[]) {
 f=0.;
  for(int i=0;i<n;i++){
   if(i!=id){
    dx=x[id]-x[i]; dy=y[i]-y[id];
    r=Math.sqrt(dx*dx+dy*dy);
//    if(r>R3)f2=0.;
//    else if(r>R) f2=F0*(1.5-0.5*r/R)/r;
    if(r>R)f2=F0*R/r;
    else f2=F0+(R-r)*(Fmax-F0)/R;
//     f2=F0*R/r;
//    if(r     f+=f2*dx/r;
   }
 }
  return f/n;
}

I have tested the above code with different models. (some lines has been removed, some are just comment out!)
As far as I can remembered: I did tried with Lennard-Jones potential , but I did not get a good result. (did not find the good parameter space values for the simulation).
You can tried with different model by yourself. This is the beauty of using EJS to build and test you own model.

The above code assume F(r)=-Fo/r; in the vector r direction.
 Then, the x component is calculated as Fx(r)=F(r)*x/r=-Fo*x/r2; (similar for Fy(r)=F(r)*y/r;)
Actually, this is  Columb's Law in 2D.
For Columb's Law in 3D: The formula is the famous F(r)=-F0/r2;

You can understand the above relations with Gauss Law. The model assume space is uniform.
In 3D: The surface area at r is 4*π*r2 so  force is proportional to  r-2 (or 1/r2).
In 2D: The surface area at r is 2*π*r so  force is proportional to  r-1 (or 1/r).
 Just like the B field at distance r from a straight current line is proportional to 1/r;