[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Fw: java no debian...



Still
> * Konnichiwa Francisco Welington de Sousa Lima-sama:
>> Obrigado pela sua atenção still,
>>    Mas no momento estou na universidade e o PC que tem o java tá em
>> minha
>> casa , mas se você me ajudar, posso instalar os java aqui neste PC do
>> trabalho ele é um PIV e tem o debian sarge 3.1, você tem tempo para
>> isso? porque hoje sou fazer as suas modificações a noite quando chegar
>> do trabalho.
>
> 	Veja esse documento sobre como instalar o Java da Sun no Debian:
>
> http://www.yak.net/fqa/412.html
>
> 	Após criar o .deb do Java da Sun, instale-o e veja os arquivos
> /usr/bin/java e javac conforme eu havia lhe passado no e-mail anterior.
> 	Depois "poste" os resultados na lista.
>
> []'s,
>
> Still
Ok, obrigado, vai ai os programas que tenho.
> --
> Nelson Luiz Campos                  .''`.     | I hear; I forget.
> Engenheiro Eletricista             : :'  :    | I see; I remember. Linux
> User #89621 UIN 11464303     `. `'`     | I do; I understand. gpgID:
> 55577339 Skype Still_by_Still `-       | Chinese Proverb


F. W. S. Lima
Departamento de Física
Centro de Ciência da Natureza
Campus Petrônio Portela
Universidade Federal do Piauí
Teresina-Piauí-Brasil
wel@ufpi.br,wel@fisica.ufc.br, wel@sobral.org

package org.opensourcephysics.stp.md;
import org.opensourcephysics.stp.applets.*;

public class LJFluidApplet extends STPApplet {
	public void init() {
		LJfluidApp app = new LJfluidApp();
        STPAnimationControl c = new STPAnimationControl(app);
        c.setEditable("Quench rate");
        c.addOutput("Density");
        c.addOutput("Number of time steps");
        c.addOutput("Time step dt");
        c.addOutput("Temperature");
        c.addOutput("Energy");
        c.addOutput("<T>");
        c.addOutput("Heat capacity");
        c.addOutput("<PA/NkT>");
        c.addOutput("Initial kinetic energy");
        c.addOutput("Initial total energy");        
		startAnimation(app, c);
	}

	public static void main(String[] args) {
		LJFluidApplet applet = new LJFluidApplet();
		AppletHelper.run(applet);
	}
}


package org.opensourcephysics.stp.md;
import org.opensourcephysics.display.*;
import org.opensourcephysics.numerics.*;
import java.awt.*;
/**
* Simulates Lennard Jones interactions .
* @author Jan Tobochnik
* @author Joshua Gould
* @author Peter Sibley
*
*/
public class LJfluid implements Drawable {
   public double x[],y[],vx[],vy[],ax[],ay[];
   public int N;                 // number of particles
   public double Lx,Ly;
   public double rho = N/(Lx*Ly);
   public double initialKineticEnergy;
   public int steps = 0;
   public double dt = 0.01;
   private double rCutoff2 = 3.0*3.0;
   public double t;
   public double totalKineticEnergy,totalPotentialEnergy;
   public double totalPotentialEnergyAccumulator;
   public double totalKineticEnergyAccumulator,totalKineticEnergySquaredAccumulator;
   public double virial,virialAccumulator;
   public String initialConfiguration;
   Histogram velocityHistogram = new Histogram();
   public double radius = 0.5;             // radius of particles on screen
   public LJfluid() {}

   public void setArrays() {
      x = new double[N];
      y = new double[N];
      vx = new double[N];
      vy = new double[N];
      ax = new double[N];
      ay = new double[N];
   }

   public void initialize() {
      reset();
      setArrays();
      if (initialConfiguration.equals("crystal")) {
         setCrystalPositions();
      }
      else {
         setRandomPositions();
      }
      setVelocities();
      accel();
   }

   public void setRandomPositions() {
      // particles placed at random, but not closer than rMinimumSquared
      double rMinimumSquared = Math.pow(2.0,1.0/3.0);
      boolean overlap;
      for (int i = 0; i < N; ++i) {
         do {
            overlap = false;
            x[i] = Lx*Math.random();
            y[i] = Ly*Math.random();
            int j = 0;
            while (j < i && !overlap) {
               double dx = x[i] - x[j];
               double dy = y[i] - y[j];
               if (dx*dx + dy*dy < rMinimumSquared) {
                  overlap = true;
               }
               j++;
            }
         }
         while (overlap);
      }
   }

   public void setCrystalPositions() {
      // place particles on triangular lattice
      double dnx = Math.sqrt(N);
      int ns = (int)dnx;
      if (dnx - ns > 0.001) {
         ns++;
      }
      double ax = Lx/ns;
      double ay = Ly/ns;
      int i = 0;
      int iy = 0;
      while (i < N) {
         for (int ix = 0; ix < ns; ++ix) {
            if (i < N) {
               y[i] = ay*(iy + 0.5);
               if (iy % 2 == 0)
                  x[i] = ax*(ix + 0.25);
               else
                  x[i] = ax*(ix + 0.75);
               i++;
            }
         }
         iy++;
      }
   }

   public void setVelocities() {
      double twoPi = 2.0*Math.PI;
      for (int i = 0; i < N; ++i) {
         double r = Math.random(); // use to generate exponential distribution
         double a = -Math.log(r);
         double theta = twoPi*Math.random();
         // assign velocities according to Maxwell-Boltzmann distribution using Box-Muller method
         vx[i] = Math.sqrt(2.0*a*initialKineticEnergy)*Math.cos(theta);
         vy[i] = Math.sqrt(2.0*a*initialKineticEnergy)*Math.sin(theta);
      }
      // zero center of mass momentum
      double vxSum = 0.0;
      double vySum = 0.0;
      for (int i = 0; i < N; ++i) {
         vxSum += vx[i];
         vySum += vy[i];
      }
      double vxcm = vxSum/N;   // center of mass momentum (velocity)
      double vycm = vySum/N;
      for (int i = 0; i < N; ++i) {
         vx[i] -= vxcm;
         vy[i] -= vycm;
         appendVelocityPoint(i);
      }
   }

   public void reset() {
      t = 0;
      Ly = Lx*Math.sqrt(0.75);
      rho = N/(Lx*Ly);
      resetAverages();
      velocityHistogram.setBinWidth(2*initialKineticEnergy/N); // assuming vmax=2*initalTemp and bin width = Vmax/N
      velocityHistogram.setBinOffset(initialKineticEnergy/N);
   }

   public void resetAverages() {
      steps = 0;
      virialAccumulator = 0;
      totalPotentialEnergyAccumulator = 0;
      totalKineticEnergyAccumulator = 0;
      totalKineticEnergySquaredAccumulator = 0;
      velocityHistogram.clear();
   }

   public double getMeanTemperature() {
      return totalKineticEnergyAccumulator/(N*steps);
   }

   public double getInstantaneousTemperature() {
      return totalKineticEnergy/N;
   }

   public double getInstantaneousTotalEnergy() {
      return totalKineticEnergy + totalPotentialEnergy;
   }

   public double getInstantanousKineticEnergy() {
      totalKineticEnergy = 0;
      for (int i = 0; i < N; i++) {
         totalKineticEnergy += (vx[i]*vx[i] + vy[i]*vy[i]);
      }
      totalKineticEnergy = 0.5*totalKineticEnergy;
      return totalKineticEnergy;
   }
 
   public double getMeanEnergy() {
      return totalKineticEnergyAccumulator/steps + totalPotentialEnergyAccumulator/steps;
   }
   
   public double getMeanPressure() {
      double meanVirial;
      meanVirial = virialAccumulator/steps;
      return 1.0 + 0.5*meanVirial/(N*getMeanTemperature());   // quantity PV/NkT
   }

   public double getInstantanousPressure() {
      return 1.0 + 0.5*virial/totalKineticEnergy;      // quantity PV/NkT
   }

   public double getHeatCapacity() {
      double meanTemperature = getMeanTemperature();
      double meanTemperatureSquared = totalKineticEnergySquaredAccumulator/steps;
      double sigma2 = meanTemperatureSquared - meanTemperature*meanTemperature;
      // heat capacity related to fluctuations of temperature
      double denom = sigma2/(N*meanTemperature*meanTemperature) - 1.0;
      return N/denom;
   }

   public void accel() {
      virial = 0;
      double dx,dy,fx,fy,r2,fOverR,oneOverR2,oneOverR6;
      totalPotentialEnergy = 0;
      for (int i = 0; i < N; i++) {
         ax[i] = 0;
         ay[i] = 0;
      }
      for (int i = 0; i < N-1; i++) {
         for (int j = i+1; j < N; j++) {
            dx = pbc(x[i] - x[j],Lx);
            dy = pbc(y[i] - y[j],Ly);
            r2 = dx*dx + dy*dy;
            if (r2 < rCutoff2) {
               oneOverR2 = 1.0/r2;
               oneOverR6 = oneOverR2*oneOverR2*oneOverR2;
               fOverR = 48.0*oneOverR6*(oneOverR6 - 0.5)*oneOverR2;
               fx = fOverR*dx;
               fy = fOverR*dy;
               ax[i] += fx;
               ay[i] += fy;
               ax[j] -= fx;
               ay[j] -= fy;
               totalPotentialEnergy += 4.0*(oneOverR6*oneOverR6 - oneOverR6);
               virial += dx*fx + dy*fy;
            }
         }
      }
   }

   private double pbc(double ds, double L) {
      if (ds > 0.5*L) {
         ds -= L;
      }
      else if (ds < -0.5*L) {
         ds += L;
      }
      return ds;
   }

   private double image(double s, double L) {
      if (s > L) {
         s -= L;
      }
      else if (s < 0) {
         s += L;
      }
      return s;
   }

   public void step() { // velocity Verlet algorithm
      double dt2half = 0.5*dt*dt;
      double oneHalfDt = 0.5*dt;
      totalKineticEnergy = 0;
      for (int i = 0; i < N; i++) {
         x[i] += vx[i]*dt + ax[i]*dt2half;
         y[i] += vy[i]*dt + ay[i]*dt2half;
         x[i] = image(x[i],Lx);
         y[i] = image(y[i],Ly);
         vx[i] += ax[i]*oneHalfDt;
         vy[i] += ay[i]*oneHalfDt;
      }
      accel();
      for (int i = 0; i < N; i++) {
         vx[i] += ax[i]*oneHalfDt;
         vy[i] += ay[i]*oneHalfDt;
         totalKineticEnergy += (vx[i]*vx[i] + vy[i]*vy[i]);
         appendVelocityPoint(i);
      }
      totalKineticEnergy = 0.5*totalKineticEnergy;
      steps++;
      totalPotentialEnergyAccumulator += totalPotentialEnergy;
      totalKineticEnergyAccumulator += totalKineticEnergy;
      totalKineticEnergySquaredAccumulator += totalKineticEnergy*totalKineticEnergy;
      virialAccumulator += virial;
      t += dt;
   }
   
   public void quench(double quenchRate) {
      for (int i = 0; i < N; i++) {
         vx[i] *= quenchRate;
         vy[i] *= quenchRate;
      }
   }
   
   public void appendVelocityPoint(int i){
      velocityHistogram.append(vx[i]);
      //	velocityHistogram.append(vy[i]);
   }

   public Histogram getVelocityHistogram(){
      return velocityHistogram;
   }
   public void draw (DrawingPanel myWorld, Graphics g) {
      if (x == null) {
         return;
      }
      int pxRadius = Math.abs(myWorld.xToPix(radius) - myWorld.xToPix(0));
      int pyRadius = Math.abs(myWorld.yToPix(radius) - myWorld.yToPix(0));
      g.setColor(Color.red);
      for (int i = 0; i < N; i++) {
         int xpix = myWorld.xToPix(x[i]) - pxRadius;
         int ypix = myWorld.yToPix(y[i]) - pyRadius;
         g.fillOval(xpix, ypix, 2*pxRadius, 2*pyRadius);
      }
      g.setColor(Color.black);
      int xpix = myWorld.xToPix(0);
      int ypix = myWorld.yToPix(0);
      int lx = myWorld.xToPix(Lx) - myWorld.xToPix(0);
      int ly = myWorld.yToPix(Ly) - myWorld.yToPix(0);
      g.drawRect(xpix,ypix,lx,ly);
   }
}
package org.opensourcephysics.stp.md;
import org.opensourcephysics.controls.*;
import org.opensourcephysics.display.*;
import javax.swing.*;
import java.awt.geom.*;
import java.awt.*;
import java.util.*;
import java.text.DecimalFormat;
/**
* Shows Lennard Jones interactions.
* @author Jan Tobochnik
* @author Joshua Gould
* @author Peter Sibley
*
*/
public class LJfluidApp extends AbstractAnimation {
   LJfluid lj;
   DrawingPanel drawingPanelLJ;
   DrawingFrame drawingFrameLJ;
   PlottingPanel plottingPanelTemperature;
   PlottingPanel plottingPanelPressure;
   PlottingPanel plottingPanelVelocityHistogram;
   DrawingFrame drawingFrameTemperature;
   DrawingFrame drawingFramePressure;
   DrawingFrame drawingFrameVelocityHistogram;
   Dataset temperature= new Dataset();
   Dataset pressure= new Dataset();
   Thread animationThread;
   DecimalFormat numberFormatTwoDigits = (DecimalFormat)DecimalFormat.getInstance();
   DecimalFormat numberFormatFourDigits = (DecimalFormat)DecimalFormat.getInstance();
   
   public LJfluidApp() {
      numberFormatTwoDigits.setMaximumFractionDigits(2);
      numberFormatTwoDigits.setMinimumFractionDigits(2);
      numberFormatTwoDigits.setGroupingSize(100);
      // never show commas so we set grouping size to a big number.
      numberFormatFourDigits.setMaximumFractionDigits(4);
      numberFormatFourDigits.setMinimumFractionDigits(4);
      numberFormatFourDigits.setGroupingSize(100);
      lj = new LJfluid();
      drawingPanelLJ = new DrawingPanel();
      drawingPanelLJ.addDrawable(lj);
      drawingPanelLJ.setPreferredMinMax(-0.1*lj.Lx, 1.1*lj.Lx,-0.1*lj.Lx, 1.1*lj.Lx);
      drawingFrameLJ = new DrawingFrame(drawingPanelLJ);
      drawingFrameLJ.setTitle("LJ Display");
      plottingPanelTemperature = new PlottingPanel("time", "T", "");
      plottingPanelTemperature.setPreferredMinMaxX(0,10);
      plottingPanelTemperature.setAutoscaleX(true);
      plottingPanelTemperature.setPreferredMinMaxY(0,2);
      plottingPanelTemperature.addDrawable(temperature);
      drawingFrameTemperature = new DrawingFrame(plottingPanelTemperature);
      drawingFrameTemperature.setLocation(20,300);
      drawingFrameTemperature.setTitle("T versus time");
      plottingPanelPressure = new PlottingPanel("time", "pressure", "");
      plottingPanelPressure.setPreferredMinMaxX(0,10);
      plottingPanelPressure.setAutoscaleX(true);
      plottingPanelPressure.setPreferredMinMaxY(0,2);
      plottingPanelPressure.addDrawable(pressure);
      drawingFramePressure = new DrawingFrame(plottingPanelPressure);
      drawingFramePressure.setLocation(20,300);
      drawingFramePressure.setTitle("Pressure versus time");
      plottingPanelVelocityHistogram = new PlottingPanel("v_x", "P(v_x)", "");
      plottingPanelVelocityHistogram.setAutoscaleX(true);
      plottingPanelVelocityHistogram.setAutoscaleY(true);
      plottingPanelVelocityHistogram.addDrawable(lj.getVelocityHistogram());
      drawingFrameVelocityHistogram = new DrawingFrame(plottingPanelVelocityHistogram);
      drawingFrameVelocityHistogram.setTitle("P(v_x) versus v_x");
   }

   public void initializeAnimation() {
      lj.N = control.getInt("N");
      lj.initialKineticEnergy = control.getDouble("initial kinetic energy per particle");
      lj.Lx = control.getDouble("Lx");
      lj.initialConfiguration = control.getString("initial configuration");
      lj.dt= control.getDouble("dt");
      double tmax = control.getDouble("Maximum for temperature axis");
      double pmax = control.getDouble("Maximum for pressure axis");
      plottingPanelTemperature.setPreferredMinMaxY(0,tmax);
      plottingPanelPressure.setPreferredMinMaxY(0,pmax);
      lj.initialize();
      control.println("Initial kinetic energy = " + numberFormatFourDigits.format(lj.getInstantanousKineticEnergy()));
      control.println("Initial total energy = " + numberFormatFourDigits.format(lj.getInstantaneousTotalEnergy()));
      pressure.clear();
      temperature.clear();
      renderPanels();
   }
   
   public void renderPanels() {
      double tmax = control.getDouble("Maximum for temperature axis");
      double pmax = control.getDouble("Maximum for pressure axis");
      plottingPanelTemperature.setPreferredMinMaxY(0,tmax);
      plottingPanelPressure.setPreferredMinMaxY(0,pmax);
      drawingPanelLJ.setPreferredMinMax(-0.1*lj.Lx, 1.1*lj.Lx,-0.1*lj.Lx, 1.1*lj.Lx);
      plottingPanelTemperature.render();
      plottingPanelPressure.render();
      plottingPanelVelocityHistogram.render();
      drawingPanelLJ.render();
  }

   public void doStep() {
      double quenchRate = control.getDouble("Quench rate");
      for (int i = 0; i < 20; i++) {
         lj.step();
         lj.quench(quenchRate);
      }
      if (lj.steps % 100 == 0) {// sample every 100 steps
         pressure.append(lj.t,lj.getInstantanousPressure());
         temperature.append(lj.t,lj.getInstantaneousTemperature());
         plottingPanelTemperature.render();
         plottingPanelPressure.render();
         plottingPanelVelocityHistogram.render();
      }
      renderPanels();
   }

   public void stopAnimation() {
      super.stopAnimation();
      control.println("Density = " + numberFormatFourDigits.format(lj.rho));
      control.println("Number of time steps = " + lj.steps);
      control.println("Time step dt = " + numberFormatFourDigits.format(lj.dt));
      control.println("Temperature = " + numberFormatFourDigits.format(lj.getInstantaneousTemperature()));
      control.println("Energy = " + numberFormatFourDigits.format(lj.getInstantaneousTotalEnergy()));
      control.println("<T> = " + numberFormatFourDigits.format(lj.getMeanTemperature()));
      control.println("Heat capacity = " + numberFormatFourDigits.format(lj.getHeatCapacity()));
      control.println("<PA/NkT> = " + numberFormatFourDigits.format(lj.getMeanPressure()));
   }

   public void resetAnimation() {
      control.setValue("N", 64);
      control.setValue("Lx", 18.0);
      control.setValue("initial kinetic energy per particle", 1.0);
      control.setValue("dt", 0.01);
      control.setValue("initial configuration", "crystal");
      control.setValue("Maximum for temperature axis", 2.0);
      control.setValue("Maximum for pressure axis", 2.0);
      control.setValue("Quench rate", 1.0);
      lj.initialConfiguration = "crystal";
      lj.initialize();
      pressure.clear();
      temperature.clear();
      control.clearMessages();
      renderPanels();
   }

   public static void main (String[] args) {
      LJfluidApp app = new LJfluidApp();
      AnimationControl control = new AnimationControl(app);
      // DISABLED - kip - control.setStepModeEditing(true);
      app.setControl(control);
   }
}

Title: History of Changes

Molecular Dynamics

July 31, Peter Sibley

Added author tags in source.

July 29, Harvey Gould

Added method getInstantanousKineticEnergy so that initial total energy is computed corectly. Made cosmetic changes in LJFluidApp.

July 12, Peter Sibley

Changed control.getDouble("Maximum for Temperature Scale") to "Maximum for Temperature axis".

July 11, Jan Tobochnik

I fixed the lennard-jones program. You forgot to add virial = 0; at the beginning of the accel method.

I'm not sure I like the long names for the variables, though it does give a better idea what they mean.

Also, on the plots the fluctuations in the data look so large. I'm not sure the y axes should be rescaled automatically. It might be more meaningful for the temperature at least to force the y axis to begin at 0.

July 10. Peter Sibley.

I think the pressure fuunction is screwed up have a look at getPressure in LJfluid.java.

  • set time plots to default to zero for their xmin.
  • altered display to show "Initial Total energy ..."
  • reset clears message box.
  • changed histogram to plot v_x.
  • changed defaults to L_x=18 , temp = 1
  • corrected the plotting window so temperature is really temperature (it was plotting pressure in that window before)
  • added output for instaneous energy in the message box.
  • added dt as a parameter.

Updated 29 July 2002.

Reply to: