package comp599.a1.numerical;

public class SymplecticEuler implements Integrator {




	/** 
     * @return the name of this numerical integration method
     */
	

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

	@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+4){
			yout[i+2]=(dydt[i]+h*dydt[i+2]);
			yout[i+3]=(dydt[i+1]+h*dydt[i+3]);
			yout[i]=y[i]+h*yout[i+2];
			yout[i+1]=y[i+1]+h*yout[i+3];
		}
		if(subSteps==true){
			derivs.derivs(t, yout, dydt);
			for(int i=0; i<y.length;i=i+4){
				yout[i+2]=(dydt[i]+h*dydt[i+2]);
				yout[i+3]=(dydt[i+1]+h*dydt[i+3]);
				yout[i]=yout[i]+h*yout[i+2];
				yout[i+1]=yout[i+1]+h*yout[i+3];
			}
			derivs.derivs(t, yout, dydt);
			for(int i=0; i<y.length;i=i+4){
				yout[i+2]=(dydt[i]+h*dydt[i+2]);
				yout[i+3]=(dydt[i+1]+h*dydt[i+3]);
				yout[i]=yout[i]+h*yout[i+2];
				yout[i+1]=yout[i+1]+h*yout[i+3];
			}
			derivs.derivs(t, yout, dydt);
			for(int i=0; i<y.length;i=i+4){
				yout[i+2]=(dydt[i]+h*dydt[i+2]);
				yout[i+3]=(dydt[i+1]+h*dydt[i+3]);
				yout[i]=yout[i]+h*yout[i+2];
				yout[i+1]=yout[i+1]+h*yout[i+3];
			}
		}
	}
}
