//this program corresponds to Section C of the report. It is used to study the time evolution of area in phase-space. /* */ // Applet for plotting solutions to oscillator problem import javax.swing.*; import P251.*; import java.io.*; public class Blobplot extends P251Applet { //FileOutputStream fout; //fout = new FileOutputStream("area.text"); //FileOutputStream("area.txt"); DoubleWell dw1; // dynamics object VariableSet vars; // variables (time, x, momentum) double[] y,xplot, pplot, xplotgrid, pplotgrid, t; // arrays for plotting double[][][] x; int boxsize = 100; //this is size of the box double xstep = 0.1/ (double) boxsize; //this is the distance between points in box double time = 0.0; int N=10000; // number of time steps private inputPanel ip1, ip2; // declare input panel objects private graphPanel gpPS; // declare graph panel objects public void fillPanels() { ip1 = new inputPanel(); ip1.addField("dt",.01); ip1.addField("A",1.); ip1.addField("force",4.); ip1.addField("N",5); addPanel(ip1); // adds input panel 1 to applet ip2 = new inputPanel(); ip2.addField("omega",Math.PI); ip2.addField("mass",1.); ip2.addField("damping",1.); addPanel(ip2); // adds input panel 2 to applet gpPS = new graphPanel(900,600,false); //phase space plot gpPS.setXLabel("x"); gpPS.setYLabel("p"); gpPS.setTitle("phase space plot"); gpPS.setDotSize(2); addPanel(gpPS); // adds graph panel to applet } //end of fillPanels public void initValues() { dw1 = new DoubleWell(); // initialize object dw1.setdt(.01); // initialize DoubleWell parameters dw1.setA(1.); dw1.setforce(4.); dw1.setomega(Math.PI); dw1.setmass(1.); dw1.setdamping(1.); //initialize input field values to match the parameters above ip1.setValue(0, dw1.getdt()); //"dt" ip1.setValue(1, dw1.getA()); //"A" ip1.setValue(2, dw1.getforce()); //"force" ip1.setValue(3, N); ip2.setValue(0, dw1.getomega()); //"omega" ip2.setValue(1, dw1.getmass()); //"mass" ip2.setValue(2, dw1.getdamping()); //"damping" //N = 5; // Number of Time Steps so that tmax < 100 xplot = new double[N+1]; // array of positions pplot = new double[N+1]; // array of momenta t = new double[N+1]; // array of times xplotgrid = new double[boxsize+1]; pplotgrid = new double[boxsize+1]; t[0] = 0.0; // initial time xplot[0] = -1.2; // initial x pplot[0] = 0.0; // initial p x = new double[boxsize+1][boxsize+1][2]; // here we create the 2d arrays to contain (x,p) of each point in the square blob //set up intial values of points in blob for(int i=0;i<=boxsize;i++){ for(int j=0;j<=boxsize;j++){ x[i][j][0]=xplot[0]+i*xstep; x[i][j][1]=pplot[0]+j*xstep; xplotgrid[j]=x[i][j][0]; pplotgrid[j]=x[i][j][1]; } gpPS.addData(xplotgrid,pplotgrid,"name"); } System.out.println(" " + time + "," + Math.log(area())); y = new double[2]; y[0]=x[0][0][0]; y[1]=x[0][0][1]; vars = new VariableSet(0.0,y); // set initial variables dw1.setvars(vars); } //end of initValues public void compute () { int i; readValues(); //this is for time evolution for (i=1; i<=N; i++){ //this is for moving each point in new time for(int k=0; k<=boxsize;k++){ for(int j=0;j<=boxsize; j++){ y[0]=x[k][j][0]; y[1]=x[k][j][1]; vars.setvars(time,y); dw1.setvars(vars); vars = dw1.nextvars(); // advance in time 1 step dw1.setvars(vars); // bring old variables up to date y = vars.getx(); // extract x and p x[k][j][0] = y[0]; x[k][j][1] = y[1]; xplotgrid[j]=y[0]; pplotgrid[j]=y[1]; } //end of i loop: now trajectories have been calculated if(i%20==0){ //choose to plot every 20 time steps so that picture becomes clearer gpPS.addData(xplotgrid,pplotgrid,"name"); } //t[0] = t[N]; // setup t for next round //xplot[0] = xplot[N]; // setup x for next round //pplot[0] = pplot[N]; // setup p for next round } time = vars.gettime(); // extract and store t for plotting System.out.println(" " + time + "," + Math.log(area())); //this shows the log of area } } //this is function used to find the area. The idea is to find sum of area of parallelogram with vertices cosecutive (x,p)'s public double area(){ double A=0.0,Bx,By,Cx,Cy; for(int i=0; i