Class RungeKuttaZ
java.lang.Object
cnuphys.rk4.RungeKuttaZ
Static methods for Runge-Kutta 4 integration, including a constant stepsize
method and an adaptive stepsize method.
- Author:
- heddle
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintadaptiveStepToTf(double[] yo, double to, double tf, double h, IDerivative deriv, IStopper stopper, IRkListener listener, double[] relTolerance, double[] hdata) Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize This version uses an IRk4Listener to notify the listener that the next step has been advanced.intadaptiveStepToTf(double[] yo, double to, double tf, double h, List<Double> t, List<double[]> y, IDerivative deriv, IStopper stopper, double[] relTolerance, double[] hdata) Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize and a tolerance vector.doubleGet the maximum step sizedoubleGet the minimum step sizevoidsetMaxStepSize(double maxSS) Set the maximum step sizevoidsetMinStepSize(double minSS) Set the minimum step size
-
Field Details
-
DEFMINSTEPSIZE
public static double DEFMINSTEPSIZE -
DEFMAXSTEPSIZE
public static double DEFMAXSTEPSIZE
-
-
Constructor Details
-
RungeKuttaZ
public RungeKuttaZ()Create a RungeKutta object that can be used for integration
-
-
Method Details
-
adaptiveStepToTf
public int adaptiveStepToTf(double[] yo, double to, double tf, double h, List<Double> t, List<double[]> y, IDerivative deriv, IStopper stopper, double[] relTolerance, double[] hdata) throws RungeKuttaException Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize and a tolerance vector. This version uses an IRk4Listener to notify the listener that the next step has been advanced. A very typical case is a 2nd order ODE converted to a 1st order where the dependent variables are x, y, z, vx, vy, vz and the independent variable is time.- Parameters:
yo- initial values. Probably something like (xo, yo, zo, vxo, vyo, vzo).to- the initial value of the independent variable, e.g., time.tf- the maximum value of the independent variable.h- the starting steps sizet- a list of the values of t at each stepy- a list of the values of the state vector at each stepderiv- the derivative computer (interface). This is where the problem specificity resides.stopper- if notnullwill be used to exit the integration early because some condition has been reached.relTolerance- the error tolerance as fractional diffs. Note it is a vector, the same dimension of the problem, e.g., 6 for [x,y,z,vx,vy,vz].hdata- if not null, should be double[3]. Upon return, hdata[0] is the min stepsize used, hdata[1] is the average stepsize used, and hdata[2] is the max stepsize used- Returns:
- the number of steps used.
- Throws:
RungeKuttaException
-
adaptiveStepToTf
public int adaptiveStepToTf(double[] yo, double to, double tf, double h, IDerivative deriv, IStopper stopper, IRkListener listener, double[] relTolerance, double[] hdata) throws RungeKuttaException Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize This version uses an IRk4Listener to notify the listener that the next step has been advanced. A very typical case is a 2nd order ODE converted to a 1st order where the dependent variables are x, y, z, vx, vy, vz and the independent variable is time.- Parameters:
yo- initial values. Probably something like (xo, yo, zo, vxo, vyo, vzo).to- the initial value of the independent variable, e.g., time.tf- the maximum value of the independent variable.h- the starting steps sizederiv- the derivative computer (interface). This is where the problem specificity resides.stopper- if notnullwill be used to exit the integration early because some condition has been reached.listener- listens for each step * @param tableau the Butcher TableaurelTolerance- the error tolerance as fractional diffs. Note it is a vector, the samehdata- if not null, should be double[3]. Upon return, hdata[0] is the min stepsize used, hdata[1] is the average stepsize used, and hdata[2] is the max stepsize used- Returns:
- the number of steps used.
- Throws:
RungeKuttaException
-
setMaxStepSize
public void setMaxStepSize(double maxSS) Set the maximum step size- Parameters:
maxSS- the maximum stepsize is whatever units you are using
-
setMinStepSize
public void setMinStepSize(double minSS) Set the minimum step size- Parameters:
maxSS- the minimum stepsize is whatever units you are using
-
getMaxStepSize
public double getMaxStepSize()Get the maximum step size- Returns:
- the maximum stepsize is whatever units you are using
-
getMinStepSize
public double getMinStepSize()Get the minimum step size- Returns:
- the minimum stepsize is whatever units you are using
-