jabble
Class RungeKutta

java.lang.Object
  extended by jabble.Evolver
      extended by jabble.SingleLoopEvolver
          extended by jabble.RungeKutta

public abstract class RungeKutta
extends SingleLoopEvolver

Solves a 1D Ordinary Differential Equation using Runge-Kutta.

Runge-Kutta is a method of numerically integrate an ordinary differential equation by using a step at the midpoint of an interval to cancel out lower-order error terms. We use the fourth order formula, sometimes refered as RK4. Given an ODE dy/dx =  f(x, y), the algorithm is as follow:

k1 = h f(xn , yn)
k
2 = h f(xn + h/2, yn + k1/2)
k
3 = h f(xn + h/2, yn + k2/2)
k
4 = h f(xn + h, yn+ k3)
yn
+1 = yn + k1/6 + k2/3 + k3/3 + k4/6 + O(h5)

where:

In the Jabble framework, to use RungeKutta you must be working on a 1D grid. You need to create a class that extends RungeKutta, and declare the f() method, which corresponds to the f function. Instead of using the standard Field.at(Point) to calculate the value at a point, you should use the valueOf(Field): this way you can construct an f() method that calculates the function at the midpoint without doing so explicitely.

TODO: add example


Field Summary
 
Fields inherited from class jabble.Evolver
constantsMap, dDirs, fieldArrayMap, fieldMap, grid, stopTrigger
 
Constructor Summary
RungeKutta(java.lang.String fieldName)
          Creates a new instance of RungeKutta
 
Method Summary
protected  void calculateNewFields(Point point)
          Calculates the value of the fields at the given Point.
protected abstract  double f()
          Computes f(x, y), the function that defines the ODE to be solved.
protected  double f1()
          Computes k1.
protected  double f2()
          Computes k2.
protected  double f3()
          Computes k3.
protected  double f4()
          Computes k4.
 void solve(Field field)
          Solves the ODE over the given Field.
 void solveAtPoint(Field field, Point point)
          Solves the ODE over the given Field at the given Point.
protected  double valueOf(Field field)
          Returns the value of the Field at the current Point, or mid-Point.
 
Methods inherited from class jabble.SingleLoopEvolver
calculateNewFields
 
Methods inherited from class jabble.Evolver
evolve, evolve, evolve, getNPreviousSlicesNeeded, initializeFieldArray, initializeFieldArray, skipBoundaryPoint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RungeKutta

public RungeKutta(java.lang.String fieldName)
Creates a new instance of RungeKutta

Method Detail

valueOf

protected final double valueOf(Field field)
Returns the value of the Field at the current Point, or mid-Point. This method is intended to be used within f() instead of Field.at(Point): for example, instead of double phiValue = phi.at(point); one would use double phiValue = valueOf(phi);.

Parameters:
field - a Field used during the computation
Returns:
the value of the field at the current Point (or mid-Point)

f

protected abstract double f()
Computes f(x, y), the function that defines the ODE to be solved. The function is not passed parameters. To compute the value of the different fields use valueOf(Field).

Returns:
value of f(x, y)

f1

protected double f1()
Computes k1.

Returns:
value of k1.

f2

protected double f2()
Computes k2.

Returns:
value of k2.

f3

protected double f3()
Computes k3.

Returns:
value of k3.

f4

protected double f4()
Computes k4.

Returns:
value of k4.

calculateNewFields

protected void calculateNewFields(Point point)
Description copied from class: SingleLoopEvolver
Calculates the value of the fields at the given Point.

Specified by:
calculateNewFields in class SingleLoopEvolver
Parameters:
point - the point where to compute the new value of the fields

solveAtPoint

public void solveAtPoint(Field field,
                         Point point)
Solves the ODE over the given Field at the given Point. Used in those cases in which one needs to solve more than one ODE.

Parameters:
field - Field to store the solution of the equation
point - Point at which to calculate the value

solve

public void solve(Field field)
Solves the ODE over the given Field. Used in those cases in which one needs to solve more than one ODE.

Parameters:
field - Field to store the solution of the equation