//this program corresponds to Section D of the report. It is used to study the time evolution of length in phase-space. /*
*/ // Applet for plotting solutions to oscillator problem import javax.swing.*; import P251.*; import java.io.*; public class Lineplot 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; // here x is no longer a matrix but series of points int boxsize = 10000; double xstep = 0.1/ (double) boxsize; double time = 0.0; int N=2000; // number of time steps private inputPanel ip1, ip2; // declare input panel objects //private graphPanel gpX, gpP, 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 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 //set up the template for plotting 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][2]; // pair x and p as a line for(int j=0;j<=boxsize;j++){ //initialize it to be point in circle. x[j][0] = -0.6 + 0.05* Math.cos(Math.PI*2*j/boxsize); x[j][1] = 0.8 + 0.05* Math.sin(Math.PI*2*j/boxsize); xplotgrid[j]=x[j][0]; pplotgrid[j]=x[j][1]; } gpPS.addData(xplotgrid,pplotgrid,"name"); System.out.println(" " + time + "," + Math.log(length())); //here we print out the log of length (circumference) y = new double[2]; y[0]=x[0][0]; y[1]=x[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 j=0;j<=boxsize; j++){ y[0]=x[j][0]; y[1]=x[j][1]; //xplotgrid[0]=y[0]; //pplotgrid[0]=y[1]; //xplotgrid[j] = y[0]; //pplotgrid[j] = y[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[j][0] = y[0]; x[j][1] = y[1]; xplotgrid[j]=y[0]; pplotgrid[j]=y[1]; } //end of i loop: now trajectories have been calculated /* I skip plotting in order to make program faster if(i%20==0){ // gpPS.setDotSize(1); 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(length())); } } //this is function used to find the length. The idea is to find the length of line segment connected consecutive (x,p)'s. public double length(){ double L=0.0,Bx,By; //for(int i=0; i<10; i++){ // for(int j=0; j<10; j++){ for(int i=0; i