jabble
Class ProblemSolver

java.lang.Object
  extended by jabble.ProblemSolver

public class ProblemSolver
extends java.lang.Object

The master class that brings all objects together to solve a given problem.


Constructor Summary
ProblemSolver(Problem problem)
          Creates a new ProblemSolver for the given Problem.
 
Method Summary
 ProblemSolver addIndicator(java.lang.String shorthand)
          Allows to create simple indicators for aggregate functions of a field.
 ProblemSolver addIndicator(java.lang.String name, Indicator indicator)
          Adds the given indicator so that it's value is computed and saved.
 ProblemSolver dontEvolveLastCoordinate()
          Tells the ProblemSolver not to evolve the last coordinate, which is typically the time coordinate and is evolved with t = previousT + dt.
 long getElapsedMillisec()
          Returns the time the computation took in milliseconds.
 java.util.Date getEndTime()
          Returns the time at which the actual computation ended.
 int getNPerformedIterations()
          Returns the number of iterations actually performed during the resolution.
 java.util.Date getStartTime()
          Returns the time at which the actual computation started.
 ProblemSolver recordError(java.lang.String filename)
          Changes the name of the file to which the error field output is saved.
 ProblemSolver recordEvolution(java.lang.String filename, int interval)
          Changes the filename for saving the output, and sets the number of iterations between two saves.
 ProblemSolver recordEvolutionInterval(int interval)
          Saves the output of the computation every interval number of iterations.
 ProblemSolver setConstraintEvolver(Evolver evolver, int maxIterations, java.lang.String fieldName, double truncationError)
          Changes the constraint evolver.
 void setDataStructuresFactory(java.lang.String dataStructuresFactory)
          Changes the implementation of the data structures.
 void setDebug(boolean debug)
          Turns debugging on and off.
 ProblemSolver setEvolver(Evolver evolver)
          Specifies which Evolver should be used for the evolution.
 ProblemSolver setFreeEvolution(boolean freeEvolution)
          Solves the problem using Free Evolution.
 ProblemSolver setNumberOfIterations(int nIterations)
          Specifies the number of iterations to be done to compute the solution.
 ProblemSolver setStopTrigger(Trigger stopTrigger)
          Sets a Trigger to stop the evolution if a condition is met (look at the stopOnXxx methods to stop on simple conditions).
 void solve()
          Starts the solution of the given problem with all the given options.
 ProblemSolver stopAfterTimePeriod(long millisec)
          Stops the evolution after a given period of time.
 ProblemSolver stopOnConvergence(java.lang.String fieldName, double truncationError)
          Stops the evolution when the change of value for the given field is less than the truncationError.
 ProblemSolver stopOnIndicatorOutsideRange(java.lang.String indicatorShorthand, double min, double max)
          Stops the evolution when the value of the indicator is outside the given range.
 ProblemSolver stopOnIndicatorOverThreshold(java.lang.String indicatorShorthand, double threshold)
          Stops the evolution when the value of the indicator is above the given threshold.
 ProblemSolver stopOnIndicatorUnderThreshold(java.lang.String indicatorShorthand, double threshold)
          Stops the evolution when the value of the indicator is below the given threshold.
 ProblemSolver stopOnNanOrInfinity()
          Stops the evolution if a NAN or Infinity value appears on any Field.
 ProblemSolver verifyResult(double tolerance)
          Compares the result of the evolution with the exact solution given in the problem.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProblemSolver

public ProblemSolver(Problem problem)
Creates a new ProblemSolver for the given Problem.

Parameters:
problem - a Jabble Problem
Method Detail

setDebug

public void setDebug(boolean debug)
Turns debugging on and off. Has to be changed before any calculation is done. Default is on.

Parameters:
debug - new debugging setting

setDataStructuresFactory

public void setDataStructuresFactory(java.lang.String dataStructuresFactory)
Changes the implementation of the data structures.

Parameters:
dataStructuresFactory - class name that implements the DataStructuresFactory

addIndicator

public ProblemSolver addIndicator(java.lang.String name,
                                  Indicator indicator)
Adds the given indicator so that it's value is computed and saved.

Parameters:
name - the name given to distinguish the indicator
indicator - an indicator object
Returns:
this ProblemSolver

addIndicator

public ProblemSolver addIndicator(java.lang.String shorthand)
Allows to create simple indicators for aggregate functions of a field.

For example, given the field 'phi' in the equation, we can have the following:

Parameters:
shorthand - the name of the indicator (such as totalEnergy or averageMomentum)
Returns:
this ProblemSolver

setEvolver

public ProblemSolver setEvolver(Evolver evolver)
Specifies which Evolver should be used for the evolution. If not specified, the default will be taken from the problem (see Problem.getDefaultEvolver).

Parameters:
evolver - the evolver to be used to compute the solution
Returns:
this ProblemSolver

setConstraintEvolver

public ProblemSolver setConstraintEvolver(Evolver evolver,
                                          int maxIterations,
                                          java.lang.String fieldName,
                                          double truncationError)
Changes the constraint evolver.

Parameters:
evolver - the Evolver to use to solve the constraints
maxIterations - number of iterations for the constraints evolver
fieldName - the name of the field to check for the truncation error
truncationError - acceptable truncation error
Returns:
this ProblemSolver

setFreeEvolution

public ProblemSolver setFreeEvolution(boolean freeEvolution)
Solves the problem using Free Evolution. In free evolution, the contraints are solved only on the initial conditions.

Parameters:
freeEvolution - true to set free evolution
Returns:
this ProblemSolver

setNumberOfIterations

public ProblemSolver setNumberOfIterations(int nIterations)
Specifies the number of iterations to be done to compute the solution. If a stop condition is specified, fewer number of iterations will be computed.

Parameters:
nIterations - a positive integer
Returns:
this ProblemSolver

setStopTrigger

public ProblemSolver setStopTrigger(Trigger stopTrigger)
Sets a Trigger to stop the evolution if a condition is met (look at the stopOnXxx methods to stop on simple conditions). By default, no stop condition is set.

Parameters:
stopTrigger - a Trigger object that will stop the evolution
Returns:
this ProblemSolver

dontEvolveLastCoordinate

public ProblemSolver dontEvolveLastCoordinate()
Tells the ProblemSolver not to evolve the last coordinate, which is typically the time coordinate and is evolved with t = previousT + dt.

Returns:
this ProblemSolver

stopOnConvergence

public ProblemSolver stopOnConvergence(java.lang.String fieldName,
                                       double truncationError)
Stops the evolution when the change of value for the given field is less than the truncationError.

Parameters:
fieldName - the name of a field
truncationError - the truncation allowed
Returns:
this ProblemSolver

stopOnIndicatorOutsideRange

public ProblemSolver stopOnIndicatorOutsideRange(java.lang.String indicatorShorthand,
                                                 double min,
                                                 double max)
Stops the evolution when the value of the indicator is outside the given range. Useful to monitor quantities that the solution must conserve (i.e. totalProbability, totalEnergy, ...), and to make the evolution stop as soon as that condition is violated.

Parameters:
indicatorShorthand - an indicator (i.e. totalProbability, averagePhi, ...)
min - the minimum value the indicator can have before stopping the evolution
max - the maximum value the indicator can have before stopping the evolution
Returns:
this ProblemSolver

stopOnIndicatorOverThreshold

public ProblemSolver stopOnIndicatorOverThreshold(java.lang.String indicatorShorthand,
                                                  double threshold)
Stops the evolution when the value of the indicator is above the given threshold. Useful to monitor quantities that must be under a certain value for the solution to be valid (i.e. maxPressure, averageMomentum, ...), and to make the evolution stop as soon as that condition is violated.

Parameters:
indicatorShorthand - the name of the indicator
threshold - the maximum value the indicator can have before stopping the evolution
Returns:
this ProblemSolver

stopOnIndicatorUnderThreshold

public ProblemSolver stopOnIndicatorUnderThreshold(java.lang.String indicatorShorthand,
                                                   double threshold)
Stops the evolution when the value of the indicator is below the given threshold. Useful to monitor quantities that must be over a certain value for the solution to be valid (i.e. minDensity, averageMass, ...), and to make the evolution stop as soon as that condition is violated.

Parameters:
indicatorShorthand - the name of the indicator
threshold - the minimum value the indicator can have before stopping the evolution
Returns:
this ProblemSolver

stopAfterTimePeriod

public ProblemSolver stopAfterTimePeriod(long millisec)
Stops the evolution after a given period of time.

Parameters:
millisec - the period of time expressed in milliseconds
Returns:
this ProblemSolver

stopOnNanOrInfinity

public ProblemSolver stopOnNanOrInfinity()
Stops the evolution if a NAN or Infinity value appears on any Field. In theory, this should help halting the calculation when an instability is found. Unfortunately, diverging to the point of reaching an infinity takes some time, so one is better off using a stopOnIndicatorOutsideRange to block the evolution beforehand.

Returns:
this ProblemSolver

verifyResult

public ProblemSolver verifyResult(double tolerance)
Compares the result of the evolution with the exact solution given in the problem.

Parameters:
tolerance - the maximum difference allowed between calculated solution and exact solution
Returns:
this ProblemSolver

recordEvolution

public ProblemSolver recordEvolution(java.lang.String filename,
                                     int interval)
Changes the filename for saving the output, and sets the number of iterations between two saves.

Parameters:
filename - the name of the output file
interval - number of iterations between saves
Returns:
this ProblemSolver

recordEvolutionInterval

public ProblemSolver recordEvolutionInterval(int interval)
Saves the output of the computation every interval number of iterations.

Parameters:
interval - number of iterations between saving to the output
Returns:
this ProblemSolver

recordError

public ProblemSolver recordError(java.lang.String filename)
Changes the name of the file to which the error field output is saved.

Parameters:
filename - the name of a file
Returns:
this ProblemSolver

solve

public void solve()
Starts the solution of the given problem with all the given options.


getStartTime

public java.util.Date getStartTime()
Returns the time at which the actual computation started.

Returns:
Date when the computation started

getEndTime

public java.util.Date getEndTime()
Returns the time at which the actual computation ended.

Returns:
Date when the computation ended

getElapsedMillisec

public long getElapsedMillisec()
Returns the time the computation took in milliseconds.

Returns:
time taken by the computation

getNPerformedIterations

public int getNPerformedIterations()
Returns the number of iterations actually performed during the resolution.

Returns:
the number of iterations