package comp599.a1.numerical;

public class SymplecticEuler3D implements Integrator {

/**
 * This method has to be completely updated.  How much more of my integrator is working on 2D is unclear at this
 * point.  I don't know how much more work I will have to do to get this running 3d.
 * @param subs
 */


	//the constructor method
	public SymplecticEuler3D(boolean subs){
		subSteps=subs;
	}
	
	private boolean subSteps=false;
	@Override
    public String getName(){
    	return "Symplectic3D";
    }
    

	@Override
    public void step(double[] y, int n, double t, double h, double[] yout, Function derivs){
		double[] dydt=new double[y.length];
		derivs.derivs(t, y, dydt);
		for(int i=0; i<y.length;i=i+6){
			yout[i+3]=(dydt[i]+h*dydt[i+3]);  //vnew = vold+ t*a
			yout[i+4]=(dydt[i+1]+h*dydt[i+4]);
			yout[i+5]=(dydt[i+2]+h*dydt[i+5]);
			yout[i]=y[i]+h*yout[i+3];  //xnew = xold+t*v
			yout[i+1]=y[i+1]+h*yout[i+4];
			yout[i+2]=y[i+2]+h*yout[i+5];
		}
		if(subSteps==true){
			derivs.derivs(t, yout, dydt);
			for(int i=0; i<y.length;i=i+6){
				yout[i+3]=(dydt[i]+h*dydt[i+3]);  //vnew = vold+ t*a
				yout[i+4]=(dydt[i+1]+h*dydt[i+4]);
				yout[i+5]=(dydt[i+2]+h*dydt[i+5]);
				yout[i]=y[i]+h*yout[i+3];  //xnew = xold+t*v
				yout[i+1]=y[i+1]+h*yout[i+4];
				yout[i+2]=y[i+2]+h*yout[i+5];
			}
			derivs.derivs(t, yout, dydt);
			for(int i=0; i<y.length;i=i+6){
				yout[i+3]=(dydt[i]+h*dydt[i+3]);  //vnew = vold+ t*a
				yout[i+4]=(dydt[i+1]+h*dydt[i+4]);
				yout[i+5]=(dydt[i+2]+h*dydt[i+5]);
				yout[i]=y[i]+h*yout[i+3];  //xnew = xold+t*v
				yout[i+1]=y[i+1]+h*yout[i+4];
				yout[i+2]=y[i+2]+h*yout[i+5];
			}
			derivs.derivs(t, yout, dydt);
			for(int i=0; i<y.length;i=i+6){
				yout[i+3]=(dydt[i]+h*dydt[i+3]);  //vnew = vold+ t*a
				yout[i+4]=(dydt[i+1]+h*dydt[i+4]);
				yout[i+5]=(dydt[i+2]+h*dydt[i+5]);
				yout[i]=y[i]+h*yout[i+3];  //xnew = xold+t*v
				yout[i+1]=y[i+1]+h*yout[i+4];
				yout[i+2]=y[i+2]+h*yout[i+5];
			}
		}
	}
}

