Package cnuphys.rk4

Class RungeKuttaZ

java.lang.Object
cnuphys.rk4.RungeKuttaZ

public class RungeKuttaZ extends Object
Static methods for Runge-Kutta 4 integration, including a constant stepsize method and an adaptive stepsize method.
Author:
heddle
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static double
     
    static double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a RungeKutta object that can be used for integration
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    adaptiveStepToTf(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.
    int
    adaptiveStepToTf(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.
    double
    Get the maximum step size
    double
    Get the minimum step size
    void
    setMaxStepSize(double maxSS)
    Set the maximum step size
    void
    setMinStepSize(double minSS)
    Set the minimum step size

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 size
      t - a list of the values of t at each step
      y - a list of the values of the state vector at each step
      deriv - the derivative computer (interface). This is where the problem specificity resides.
      stopper - if not null will 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 size
      deriv - the derivative computer (interface). This is where the problem specificity resides.
      stopper - if not null will be used to exit the integration early because some condition has been reached.
      listener - listens for each step * @param tableau the Butcher Tableau
      relTolerance - the error tolerance as fractional diffs. Note it is a vector, the same
      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
    • 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