IGLib  1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
IG.Num.DifferentialFirstOrderSolverBase Class Referenceabstract

Base class for definition of a system of first order ordinary differential equations (initial problem). More...

+ Inheritance diagram for IG.Num.DifferentialFirstOrderSolverBase:
+ Collaboration diagram for IG.Num.DifferentialFirstOrderSolverBase:

Public Member Functions

 DifferentialFirstOrderSolverBase (DifferentialFirstOrderSystemBase equations)
 Constructs a solver for the specified system of first order ordinary differential equations. More...
 
double[][] GetResultsArray ()
 Creates and returns an array containing all stored results. More...
 
void StoreSavedState ()
 Stores the saved solver-extended state of the problem (property SavedState) to the list of results (property Results). More...
 
void SaveState (double parameterValue, double[] functionValues, int stepNumber, double stepLength)
 Saves the current values of the problem parameter (independent variable) and function values to the auxiliary state array (property SavedState), together with the specified step number and step length. More...
 
void SaveState (double[] state, int stepNumber, int stepLength)
 Saves the current state of the problem (including the current parameter and function values, step number and step length) to the auxiliary state array (property SavedState). More...
 
double GetSavedParameter (double[] savedState)
 Retrieves the value of parameter (independent variable) from the saved state and returns it. More...
 
int GetSavedStepNumber (double[] savedState)
 Retrieves the step number from the saved state and returns it. More...
 
double GetSavedStepSize (double[] savedState)
 Retrieves the step size from the saved state and returns it. More...
 
void GetSavedFunctionValues (double[] savedState, double[] functionValues)
 Retrieves the calculated function values from the saved state and copies them to the provided array. More...
 
void GetSavedState (double[] savedState, double[] state)
 Retrieves the calculated function values from the saved state and copies them to the provided array. More...
 
void InitializeSolver ()
 Performs all the initializations that are necessary before solving the equations. This includes transcribing basic problem data from the problem object, transcribing initial state from equations object as well as allocating all auxiliary variables. More...
 
abstract void CalculateTrial (double stepLength)
 Calculates a trial solution after the specified increase in step size. More...
 
virtual void CalculateWithFixedStep (double finalTime)
 

Public Attributes

int _outputFrequency
 
bool _doOutput = (DefaultOutputLevel > 0 && DefaultOutputFrequency!=0)
 
int _storingFrequency = DefaultStoringFrequency
 
bool _doStoreResults = DefaultStoringFrequency != 0
 

Static Public Attributes

static int DefaultOutputLevel = 0
 Default output level for solvers of first order systems of differential equations. More...
 
static int DefaultOutputFrequency = 5
 Default output frequency, sefines how often output is made. More...
 
static int DefaultFileSaveFrequency = 5
 
static int DefaultStoringFrequency = 1
 

Protected Member Functions

virtual void InitializeProblemData ()
 Initializes basic problem data according to equations. More...
 
virtual void InitializeSolverInternals ()
 Initializes the solver state. More...
 

Protected Attributes

int _outputLevel = DefaultOutputLevel
 
int _fileSaveFrequency = DefaultFileSaveFrequency
 
bool _doFileSave
 
List< double[]> _results = new List<double[]>()
 
int _numEquations
 
int _numStateVariables
 
int _numSavedStateVariables = 0
 
bool _isHistoryDependent = false
 
DifferentialFirstOrderSystemBase _problem
 
double _initialParameter
 
double _finalParameter
 
double _numSteps
 
bool _isFixedStep = true
 
double _initialStepLength
 
double _stepLength
 
double _stepNumber = 0
 
double _parameter
 
double _nextParameter
 
double[] _functionValues
 
double[] _nextFunctionValues
 
double[] _state
 
double[] _nextState
 
double[] _savedState
 

Properties

int OutputLevel [get, set]
 Level of output to console produced during operation (0 means no output). More...
 
int OutputFrequency [get, set]
 
bool DoOutput [get, set]
 
int FileSaveFrequency [get, set]
 
bool DoFileSave [get, set]
 
TextWriter FileSaver [get, set]
 
int StoringFrequency [get, protected set]
 
bool DoStoreResults [get, protected set]
 
List< double[]> Results [get]
 Gets a reference to the list where results are stored. More...
 
virtual int NumEquations [get, protected set]
 Number of equations in the system of equations. More...
 
int NumStateVariables [get, set]
 Number of state variables, including independent variable and function values. More...
 
virtual int NumSavedStateVariables [get]
 Gets the required length of the saved state array. More...
 
bool IsHistoryDependent [get, set]
 Flag indicating whether the problem is history dependent (meaning that it has additional state variables that are not calculated by the solver). More...
 
DifferentialFirstOrderSystemBase Problem [get, protected set]
 Definition of a system of first order ordinary differential equations with initial condition. More...
 
double InitialParameter [get, protected set]
 Initial value of parameter (independent variable). More...
 
double FinalParameter [get, protected set]
 Final value of parameter (independent variable). More...
 
double NumSteps [get, protected set]
 Number of steps. More...
 
bool IsFixedStep [get, protected set]
 Flag indicating whether a fixed step is used (as contrary to adaptive step). More...
 
double InitialStepLength [get, set]
 Initial step length. More...
 
double StepLength [get, set]
 Step length. More...
 
double StepNumber [get, protected set]
 Current step number. More...
 
double Parameter [get, protected set]
 Current value of independent parameter. More...
 
double NextParameter [get, protected set]
 Value of independent parameter in the next step. More...
 
double[] FunctionValues [get, protected set]
 Array of current function values. More...
 
double[] NextFunctionValues [get, protected set]
 Array of function values in the next step. More...
 
double[] State [get, protected set]
 Current state of the problem. More...
 
double[] NextState [get, protected set]
 State of the problem for the next step. More...
 
double[] SavedState [get, protected set]
 Array of state and other variables to be saved or restored. More...
 

Private Member Functions

 DifferentialFirstOrderSolverBase ()
 

Private Attributes

TextWriter _fileSaver = null
 

Detailed Description

Base class for definition of a system of first order ordinary differential equations (initial problem).

Notes on storing the current state:

Solver is only aware of the parameter (independent variable) and function values. These are stored separately (function values are stored in an array) and define the current state of the problem for the solver (beside the step number and step length).

Problem definition may include additional state variables. Current state of the problem includes the current parameter (independent variable) and function values and eventually some additional state variables (such a history variables) but exclude step number and step length.

Problem definition object stores its state into (or restores from) a packed state array. In this array, the first element is always the vlue of independent variable (problem parameter), followed by values of searched functions (solutions of the problem), followed by eventual additional state variables.

When saving the state from the solver, the solver packs the state into an array that includes the complete problem state (as vould be stored by the problem definition object) plus the step number and step length. Sometimes this array does not include all the data, e.g. it may exclude additional values of state variables of the problem definition object (this is when the state that is saved was not created by the problem definition object but by solver, which is not aware of the additional state variables). However, the order of the saved parameters is always the same as that of the problem definition object, only some data may be unavailable. The solver gets the number of problem state parameters from the problem definition object when it is initialized.

In view of the above, the order of values in the saved state array is as follows

- value of independent variable (problem parameter, e.g. time).

- valus of functions that are searched for

- eventual additional state variables of the problem; these have unspecified values when the saved state is packed merely by the solver, without assistance of the problem definition object.

- step number; this has unspecified value when the saved state is packed by the problem definition object, since it is not aware of the solver.

- step size used to calculate the saved state; this has unspecified value when the saved state is packed by the problem definition object, since it is not aware of the solver.

$A Igor Mar2009;

Constructor & Destructor Documentation

IG.Num.DifferentialFirstOrderSolverBase.DifferentialFirstOrderSolverBase ( )
inlineprivate
IG.Num.DifferentialFirstOrderSolverBase.DifferentialFirstOrderSolverBase ( DifferentialFirstOrderSystemBase  equations)
inline

Constructs a solver for the specified system of first order ordinary differential equations.

Parameters
equations

Member Function Documentation

double [][] IG.Num.DifferentialFirstOrderSolverBase.GetResultsArray ( )
inline

Creates and returns an array containing all stored results.

The returned array does not change when new results are stored by the solver. To include new results, either call this method again or use the Results property, which gives a reference to teh actual result list that is updated.

Returns
void IG.Num.DifferentialFirstOrderSolverBase.StoreSavedState ( )
inline

Stores the saved solver-extended state of the problem (property SavedState) to the list of results (property Results).

void IG.Num.DifferentialFirstOrderSolverBase.SaveState ( double  parameterValue,
double[]  functionValues,
int  stepNumber,
double  stepLength 
)
inline

Saves the current values of the problem parameter (independent variable) and function values to the auxiliary state array (property SavedState), together with the specified step number and step length.

This does not necessarily include the complete state of the problem as defined by the Problem object (since the problem can include additional state variables that the solver is not aware of, such as history variables), but the order of elements will be the same (eventually missed parameters are just set to 0).

Parameters
stateState to be saved. Stat will normally be obtained from the Problem object.
stepNumberThe step number to be stored with the state (this is not part of the state as defined by the Problem object).
stepLengthThe step length to be stored with the state (this is not part of the state as defined by the Problem object).
void IG.Num.DifferentialFirstOrderSolverBase.SaveState ( double[]  state,
int  stepNumber,
int  stepLength 
)
inline

Saves the current state of the problem (including the current parameter and function values, step number and step length) to the auxiliary state array (property SavedState).

Parameters
stateState to be saved. Stat will normally be obtained from the Problem object.
stepNumberThe step number to be stored with the state (this is not part of the state as defined by the Problem object).
stepLengthThe step length to be stored with the state (this is not part of the state as defined by the Problem object).
double IG.Num.DifferentialFirstOrderSolverBase.GetSavedParameter ( double[]  savedState)
inline

Retrieves the value of parameter (independent variable) from the saved state and returns it.

Parameters
savedStateArray containing saved state.
Exceptions
ArgumentExceptionWhen the specified array containing the saved state is null or it has too few elements.
int IG.Num.DifferentialFirstOrderSolverBase.GetSavedStepNumber ( double[]  savedState)
inline

Retrieves the step number from the saved state and returns it.

Parameters
savedStateArray containing saved state.
Exceptions
ArgumentExceptionWhen the specified array containing the saved state is null or it has too few elements.
double IG.Num.DifferentialFirstOrderSolverBase.GetSavedStepSize ( double[]  savedState)
inline

Retrieves the step size from the saved state and returns it.

Parameters
savedStateArray containing saved state.
Exceptions
ArgumentExceptionWhen the specified array containing the saved state is null or it has too few elements.
void IG.Num.DifferentialFirstOrderSolverBase.GetSavedFunctionValues ( double[]  savedState,
double[]  functionValues 
)
inline

Retrieves the calculated function values from the saved state and copies them to the provided array.

Parameters
savedStateArray containing saved state.
functionValuesArray where state will be restored. It must be allocated with size greater or equal to the number of state parameters.
Exceptions
ArgumentExceptionWhen the specified array containing the saved state is null or it has too few elements, or when the provided array to store copied values is null or has too few elements.
void IG.Num.DifferentialFirstOrderSolverBase.GetSavedState ( double[]  savedState,
double[]  state 
)
inline

Retrieves the calculated function values from the saved state and copies them to the provided array.

Parameters
savedStateArray containing saved state.
stateArray where state will be stored. It must be allocated with size greater or equal to the number of elements of the state parameters (property NumStateVariables).
Exceptions
ArgumentExceptionWhen the specified array containing the state is null or its has too few elements, or when the provided array to store copied values is null or has too few elements.
virtual void IG.Num.DifferentialFirstOrderSolverBase.InitializeProblemData ( )
inlineprotectedvirtual

Initializes basic problem data according to equations.

Problem must be defined before running this.

Call base class method wen overriding!

virtual void IG.Num.DifferentialFirstOrderSolverBase.InitializeSolverInternals ( )
inlineprotectedvirtual

Initializes the solver state.

Allocates auxiliary variables and sets the initial conditions from the problem object.

Call base class method when overriding!

void IG.Num.DifferentialFirstOrderSolverBase.InitializeSolver ( )
inline

Performs all the initializations that are necessary before solving the equations. This includes transcribing basic problem data from the problem object, transcribing initial state from equations object as well as allocating all auxiliary variables.

abstract void IG.Num.DifferentialFirstOrderSolverBase.CalculateTrial ( double  stepLength)
pure virtual

Calculates a trial solution after the specified increase in step size.

Parameters
stepLengthLength by which parameter value is incremented.
virtual void IG.Num.DifferentialFirstOrderSolverBase.CalculateWithFixedStep ( double  finalTime)
inlinevirtual

Member Data Documentation

int IG.Num.DifferentialFirstOrderSolverBase.DefaultOutputLevel = 0
static

Default output level for solvers of first order systems of differential equations.

int IG.Num.DifferentialFirstOrderSolverBase._outputLevel = DefaultOutputLevel
protected
int IG.Num.DifferentialFirstOrderSolverBase.DefaultOutputFrequency = 5
static

Default output frequency, sefines how often output is made.

int IG.Num.DifferentialFirstOrderSolverBase._outputFrequency
bool IG.Num.DifferentialFirstOrderSolverBase._doOutput = (DefaultOutputLevel > 0 && DefaultOutputFrequency!=0)
int IG.Num.DifferentialFirstOrderSolverBase.DefaultFileSaveFrequency = 5
static
int IG.Num.DifferentialFirstOrderSolverBase._fileSaveFrequency = DefaultFileSaveFrequency
protected
bool IG.Num.DifferentialFirstOrderSolverBase._doFileSave
protected
TextWriter IG.Num.DifferentialFirstOrderSolverBase._fileSaver = null
private
int IG.Num.DifferentialFirstOrderSolverBase.DefaultStoringFrequency = 1
static
int IG.Num.DifferentialFirstOrderSolverBase._storingFrequency = DefaultStoringFrequency
bool IG.Num.DifferentialFirstOrderSolverBase._doStoreResults = DefaultStoringFrequency != 0
List<double[]> IG.Num.DifferentialFirstOrderSolverBase._results = new List<double[]>()
protected
int IG.Num.DifferentialFirstOrderSolverBase._numEquations
protected
int IG.Num.DifferentialFirstOrderSolverBase._numStateVariables
protected
int IG.Num.DifferentialFirstOrderSolverBase._numSavedStateVariables = 0
protected
bool IG.Num.DifferentialFirstOrderSolverBase._isHistoryDependent = false
protected
DifferentialFirstOrderSystemBase IG.Num.DifferentialFirstOrderSolverBase._problem
protected
double IG.Num.DifferentialFirstOrderSolverBase._initialParameter
protected
double IG.Num.DifferentialFirstOrderSolverBase._finalParameter
protected
double IG.Num.DifferentialFirstOrderSolverBase._numSteps
protected
bool IG.Num.DifferentialFirstOrderSolverBase._isFixedStep = true
protected
double IG.Num.DifferentialFirstOrderSolverBase._initialStepLength
protected
double IG.Num.DifferentialFirstOrderSolverBase._stepLength
protected
double IG.Num.DifferentialFirstOrderSolverBase._stepNumber = 0
protected
double IG.Num.DifferentialFirstOrderSolverBase._parameter
protected
double IG.Num.DifferentialFirstOrderSolverBase._nextParameter
protected
double [] IG.Num.DifferentialFirstOrderSolverBase._functionValues
protected
double [] IG.Num.DifferentialFirstOrderSolverBase._nextFunctionValues
protected
double [] IG.Num.DifferentialFirstOrderSolverBase._state
protected
double [] IG.Num.DifferentialFirstOrderSolverBase._nextState
protected
double [] IG.Num.DifferentialFirstOrderSolverBase._savedState
protected

Property Documentation

int IG.Num.DifferentialFirstOrderSolverBase.OutputLevel
getset

Level of output to console produced during operation (0 means no output).

int IG.Num.DifferentialFirstOrderSolverBase.OutputFrequency
getset
bool IG.Num.DifferentialFirstOrderSolverBase.DoOutput
getset
int IG.Num.DifferentialFirstOrderSolverBase.FileSaveFrequency
getset
bool IG.Num.DifferentialFirstOrderSolverBase.DoFileSave
getsetprivate
TextWriter IG.Num.DifferentialFirstOrderSolverBase.FileSaver
getset
int IG.Num.DifferentialFirstOrderSolverBase.StoringFrequency
getprotected set
bool IG.Num.DifferentialFirstOrderSolverBase.DoStoreResults
getprotected set
List<double[]> IG.Num.DifferentialFirstOrderSolverBase.Results
get

Gets a reference to the list where results are stored.

Results after each step are stored as plain double array where elements are ordered the same as when the solver state is stored. The array is usually copied from the array addressed by the SavedState property by using the StoreSavedState function.

virtual int IG.Num.DifferentialFirstOrderSolverBase.NumEquations
getprotected set

Number of equations in the system of equations.

int IG.Num.DifferentialFirstOrderSolverBase.NumStateVariables
getset

Number of state variables, including independent variable and function values.

virtual int IG.Num.DifferentialFirstOrderSolverBase.NumSavedStateVariables
get

Gets the required length of the saved state array.

bool IG.Num.DifferentialFirstOrderSolverBase.IsHistoryDependent
getset

Flag indicating whether the problem is history dependent (meaning that it has additional state variables that are not calculated by the solver).

DifferentialFirstOrderSystemBase IG.Num.DifferentialFirstOrderSolverBase.Problem
getprotected set

Definition of a system of first order ordinary differential equations with initial condition.

double IG.Num.DifferentialFirstOrderSolverBase.InitialParameter
getprotected set

Initial value of parameter (independent variable).

double IG.Num.DifferentialFirstOrderSolverBase.FinalParameter
getprotected set

Final value of parameter (independent variable).

double IG.Num.DifferentialFirstOrderSolverBase.NumSteps
getprotected set

Number of steps.

bool IG.Num.DifferentialFirstOrderSolverBase.IsFixedStep
getprotected set

Flag indicating whether a fixed step is used (as contrary to adaptive step).

double IG.Num.DifferentialFirstOrderSolverBase.InitialStepLength
getset

Initial step length.

double IG.Num.DifferentialFirstOrderSolverBase.StepLength
getset

Step length.

double IG.Num.DifferentialFirstOrderSolverBase.StepNumber
getprotected set

Current step number.

double IG.Num.DifferentialFirstOrderSolverBase.Parameter
getprotected set

Current value of independent parameter.

double IG.Num.DifferentialFirstOrderSolverBase.NextParameter
getprotected set

Value of independent parameter in the next step.

double [] IG.Num.DifferentialFirstOrderSolverBase.FunctionValues
getprotected set

Array of current function values.

double [] IG.Num.DifferentialFirstOrderSolverBase.NextFunctionValues
getprotected set

Array of function values in the next step.

double [] IG.Num.DifferentialFirstOrderSolverBase.State
getprotected set

Current state of the problem.

This array contains complete state of the problem, which makes possible to restore the state witout losing anything. State is generated by the problem object and has nothing to do with solver. It includes value of independent variable (function parameter), all function values and eventual additional (history) variables necessary to define the state.

double [] IG.Num.DifferentialFirstOrderSolverBase.NextState
getprotected set

State of the problem for the next step.

This array contains complete state of the problem, which makes possible to restore the state witout losing anything. State is generated by the problem object and has nothing to do with solver. It includes value of independent variable (function parameter), all function values and eventual additional (history) variables necessary to define the state.

double [] IG.Num.DifferentialFirstOrderSolverBase.SavedState
getprotected set

Array of state and other variables to be saved or restored.

Number of elements is two more than number of elements in state array, the one before the last element being the step number (cast to double), and the last being the step length used to produce the current results.

This array can be used to just save the normal state because the order of the first elements is the same.


The documentation for this class was generated from the following file: