jabble
Class IteratedCrankNicholson

java.lang.Object
  extended by jabble.Evolver
      extended by jabble.IteratedCrankNicholson

public abstract class IteratedCrankNicholson
extends Evolver

This class implements the Iterated Crank-Nicholson template algorithm. It provides the common iteration and averaging pattern for the algorithm, leaving out only the part relative to the specific equation.

Given a finite difference expression ut+dt = ut + dt f(ut), where ut is a field at the time t, ut+dt is the same field at the following time step, and f the stencil used to calculate du, the Iterated Crank-Nicholson is defined as:

ut+dt = ICN(ut, dt, f, k):

  1. n = 0; u = ut;
    set the current iteration to 0 and initialize average to ut.
  2. ut+dt = ut + dt f(u);
    calculate solution using the average to compute the differential.
  3. if (n == k) return ud+dt;
    return the solution if all iterations are done.
  4. u = (ut + ut+dt) / 2;
    calculate average between solutions at previous and following time steps.
  5. n = n + 1;
    increase the iteration counter.
  6. go to step 2.

where:

In the Jabble framework, this class will take care of performing the iteration and the averaging. One needs to specify:

Notice that more than one field can be calculated at the same time.

The following is a sample code for an IteratedCrankNicholson class that solves the Advection equation dphi / dt = dphi / dx :

public class AdvectionCartesian1DICN extends IteratedCrankNicholson {

     // Constant representing the X direction
     private static final int X = 0;

     // The fields on which to use the ICN method
     private Field previousPhi;
     private Field phi;
     private Field averagePhi;

     // The time differential
     private Field dt;

     // The finite difference expression
     //used during the iterations
     protected void calculateNewFields(Point point) {
         double dtValue = dt.at(point);
         double phiValue = previousPhi.at(point);
         phiValue += dtValue * centeredDifference(averagePhi, X);
         phi.setAt(point,phiValue);
     }
   
 }

Reference:


Field Summary
 
Fields inherited from class jabble.Evolver
constantsMap, dDirs, fieldArrayMap, fieldMap, grid, stopTrigger
 
Constructor Summary
protected IteratedCrankNicholson()
          Creates a new Iterated Crank-Nicholson evolver, with the default of 2 iterations.
protected IteratedCrankNicholson(int nIterations)
          Creates a new Iterated Crank-Nicholson evolver, specifying the number of iterations.
 
Method Summary
protected  void calculateNewFields()
          Implements the skeleton of the template algorythm.
protected abstract  void calculateNewFields(Point point)
          Calculate the new value of the fields at the given point.
 
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

IteratedCrankNicholson

protected IteratedCrankNicholson(int nIterations)
Creates a new Iterated Crank-Nicholson evolver, specifying the number of iterations.

Parameters:
nIterations - number of iterations for the Iterated Crank-Nicholson algorithm

IteratedCrankNicholson

protected IteratedCrankNicholson()
Creates a new Iterated Crank-Nicholson evolver, with the default of 2 iterations.

Method Detail

calculateNewFields

protected abstract void calculateNewFields(Point point)
Calculate the new value of the fields at the given point. One should calculate a field (phi) given the value at the previous time step (previousPhi) and the increment as a function of the ICN averaged field (averagePhi).

Parameters:
point - the point at which to calculate the value of the new fields.

calculateNewFields

protected final void calculateNewFields()
Implements the skeleton of the template algorythm. To specialize it for a particular set of equations, override calculateNewFields(Point)

Specified by:
calculateNewFields in class Evolver