jabble
Class Problem

java.lang.Object
  extended by jabble.Problem

public abstract class Problem
extends java.lang.Object

Defines an EquationSet with a set of initial conditions.

The equation set is defined by the prepareEquationSet() method, that one would need to implement to provide the set of equations. The initial conditions are set by implemention initialXxx methods. For example, a declared function initialPhi(double x, double y, double t) would be used to initialize the phi field for a 2D problem. If we need to initialize the field for phi at t - 1, we can declare initialPreviousPhi(Point point).

In general, three signatures are valid for initialization:

The number of "double" arguments has to match the number of coordinates.


Constructor Summary
Problem()
           
 
Method Summary
protected  double calculateDifferential(Grid grid, int xIndex)
          Calculates the space differential for the given coordinate.
protected abstract  double calculateTimeDifferential(Grid grid)
          Calculates the time differential.
 double getCoordinateCenter(int xIndex)
          The value at the center of the coordinate range.
 double getCoordinateRange(int xIndex)
          The range of the given coordinate.
 double getCourantFactor()
          Returns the Courant factor, which should be used in the expression to calculate the time differential.
protected  Evolver getDefaultEvolver()
          Returns the default Evolver to be used to solve the problem.
 int getGridSize(int xIndex)
          Returns the size for the given direction.
abstract  EquationSet prepareEquationSet()
          Creates the equation set that needs to be solved.
 void setCoordinateCenter(int xIndex, double center)
          Changes the center for the given coordinate.
 void setCoordinateRange(int xIndex, double range)
          Changes the range for the coordinate.
 void setCourantFactor(double courantFactor)
          Changes the Courant factor.
 void setGridSize(int... sizes)
          Changes the size of the grid for this problem.
 void setInitialCondition(java.util.List<Slice> slices)
          Initializes the set of slices according to the initial conditions.
 boolean verifyResult(java.util.List<Slice> slices, double tolerance)
          Compares the field value in the slices with the expected solution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Problem

public Problem()
Method Detail

prepareEquationSet

public abstract EquationSet prepareEquationSet()
Creates the equation set that needs to be solved. Typically one would use the EquationSetBuilder to simplify the task.

Returns:
an EquationSet object

setInitialCondition

public void setInitialCondition(java.util.List<Slice> slices)
Initializes the set of slices according to the initial conditions. This method will find all the initialXxx method and use them to initialize the appropriate fields.

Parameters:
slices - a list of slices to initialize

getCoordinateRange

public double getCoordinateRange(int xIndex)
The range of the given coordinate. The default value is 2.0. Override this to change the range of the coordinates.

Parameters:
xIndex - the index of the coordinate
Returns:
the range of the coordinate

setCoordinateRange

public void setCoordinateRange(int xIndex,
                               double range)
Changes the range for the coordinate.

Parameters:
xIndex - the coordinate index
range - the range to assign to the coordinate

getCoordinateCenter

public double getCoordinateCenter(int xIndex)
The value at the center of the coordinate range. For example, if a coordinate spans from -1.0 to 1.0 the center is at 0.0. The default value is 2.0. Override this method to change the value.

Parameters:
xIndex - the index of the coordinate
Returns:
the value of the coordinate at the center of its range

setCoordinateCenter

public void setCoordinateCenter(int xIndex,
                                double center)
Changes the center for the given coordinate.

Parameters:
xIndex - the coordinate index
center - the center value of the coordinate

getCourantFactor

public double getCourantFactor()
Returns the Courant factor, which should be used in the expression to calculate the time differential. Default is 0.24.

Returns:
The Courant factor.

setCourantFactor

public void setCourantFactor(double courantFactor)
Changes the Courant factor.

Parameters:
courantFactor - the Courant factor

calculateDifferential

protected double calculateDifferential(Grid grid,
                                       int xIndex)
Calculates the space differential for the given coordinate. The default way to calculate it is to take the coordinate range and divide it by (size - 1) along the corresponding grid direction.

Parameters:
grid - the Grid on which the computation will be performed
xIndex - a coordinate index
Returns:
the space differential

calculateTimeDifferential

protected abstract double calculateTimeDifferential(Grid grid)
Calculates the time differential. A problem need to implement this method to calculate the time differential appropriately for the given equation. One should use the Courant factor.

For example, let's say our expression is given by dt = C * dx2, we'll have:


    protected double calculateTimeDifferential(Grid grid) {
        double value = getCourantFactor();
        value *= calculateDifferential(grid, 0);
        value *= calculateDifferential(grid, 0);
        return value;
    }
 
In case normalization constants are used, the differentials in the expression should be normalized. For example:

    protected double calculateTimeDifferential(Grid grid) {
        double value = getCourantFactor();
        value *= calculateDifferential(grid, 0) / normalizationDx;
        return value;
    }
 

Parameters:
grid - the Grid for which the time differential will be used
Returns:
the time differential

verifyResult

public boolean verifyResult(java.util.List<Slice> slices,
                            double tolerance)
Compares the field value in the slices with the expected solution. This method will look for all the methods exactXxx and use them to compute the expected values for the solution.

Parameters:
slices - a list of slices with the solution to compare
tolerance - the difference allowed between the given solution and the exact solution
Returns:
true if the difference between the given solution and the exact solution is below the tolerance

getDefaultEvolver

protected Evolver getDefaultEvolver()
Returns the default Evolver to be used to solve the problem. Default null. Override this method to change the value.

Returns:
the default evolver to be used for this problem.

getGridSize

public int getGridSize(int xIndex)
Returns the size for the given direction.

Parameters:
xIndex - a direction index
Returns:
the size of the direction

setGridSize

public void setGridSize(int... sizes)
Changes the size of the grid for this problem. Using only one argument will set the same size on all directions.

Parameters:
sizes - the sizes for the directions on the Grid