|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math.ode.sampling.AbstractStepInterpolator
public abstract class AbstractStepInterpolator
This abstract class represents an interpolator over the last step during an ODE integration.
The various ODE integrators provide objects extending this class to the step handlers. The handlers can use these objects to retrieve the state vector at intermediate times between the previous and the current grid points (dense output).
FirstOrderIntegrator
,
SecondOrderIntegrator
,
StepHandler
,
Serialized FormField Summary | |
---|---|
protected double[] |
currentState
current state |
protected double |
currentTime
current time |
protected double |
h
current time step |
protected double[] |
interpolatedDerivatives
interpolated derivatives |
protected double[] |
interpolatedState
interpolated state |
protected double |
interpolatedTime
interpolated time |
protected double |
previousTime
previous time |
Constructor Summary | |
---|---|
protected |
AbstractStepInterpolator()
Simple constructor. |
protected |
AbstractStepInterpolator(AbstractStepInterpolator interpolator)
Copy constructor. |
protected |
AbstractStepInterpolator(double[] y,
boolean forward)
Simple constructor. |
Method Summary | |
---|---|
protected abstract void |
computeInterpolatedStateAndDerivatives(double theta,
double oneMinusThetaH)
Compute the state and derivatives at the interpolated time. |
StepInterpolator |
copy()
Copy the instance. |
protected abstract StepInterpolator |
doCopy()
Really copy the finalized instance. |
protected void |
doFinalize()
Really finalize the step. |
void |
finalizeStep()
Finalize the step. |
double |
getCurrentTime()
Get the current grid point time. |
double[] |
getInterpolatedDerivatives()
Get the derivatives of the state vector of the interpolated point. |
double[] |
getInterpolatedState()
Get the state vector of the interpolated point. |
double |
getInterpolatedTime()
Get the time of the interpolated point. |
double |
getPreviousTime()
Get the previous grid point time. |
boolean |
isForward()
Check if the natural integration direction is forward. |
protected double |
readBaseExternal(ObjectInput in)
Read the base state of the instance. |
abstract void |
readExternal(ObjectInput in)
|
protected void |
reinitialize(double[] y,
boolean isForward)
Reinitialize the instance |
void |
setInterpolatedTime(double time)
Set the time of the interpolated point. |
void |
shift()
Shift one step forward. |
void |
storeTime(double t)
Store the current step time. |
protected void |
writeBaseExternal(ObjectOutput out)
Save the base state of the instance. |
abstract void |
writeExternal(ObjectOutput out)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected double previousTime
protected double currentTime
protected double h
protected double[] currentState
protected double interpolatedTime
protected double[] interpolatedState
protected double[] interpolatedDerivatives
Constructor Detail |
---|
protected AbstractStepInterpolator()
reinitialize(double[], boolean)
method should be called before using the
instance in order to initialize the internal arrays. This
constructor is used only in order to delay the initialization in
some cases. As an example, the EmbeddedRungeKuttaIntegrator
class uses the prototyping design pattern to create the step
interpolators by cloning an uninitialized model and latter
initializing the copy.
protected AbstractStepInterpolator(double[] y, boolean forward)
y
- reference to the integrator array holding the state at
the end of the stepforward
- integration direction indicatorprotected AbstractStepInterpolator(AbstractStepInterpolator interpolator)
The copied interpolator should have been finalized before the
copy, otherwise the copy will not be able to perform correctly
any derivative computation and will throw a NullPointerException
later. Since we don't want this constructor
to throw the exceptions finalization may involve and since we
don't want this method to modify the state of the copied
interpolator, finalization is not done
automatically, it remains under user control.
The copy is a deep copy: its arrays are separated from the original arrays of the instance.
interpolator
- interpolator to copy from.Method Detail |
---|
protected void reinitialize(double[] y, boolean isForward)
y
- reference to the integrator array holding the state at
the end of the stepisForward
- integration direction indicatorpublic StepInterpolator copy() throws DerivativeException
The copied instance is guaranteed to be independent from the original one. Both can be used with different settings for interpolated time without any side effect.
copy
in interface StepInterpolator
DerivativeException
- if this call induces an automatic
step finalization that throws oneStepInterpolator.setInterpolatedTime(double)
protected abstract StepInterpolator doCopy()
This method is called by copy()
after the
step has been finalized. It must perform a deep copy
to have an new instance completely independent for the
original instance.
public void shift()
storeTime
public void storeTime(double t)
t
- current timepublic double getPreviousTime()
getPreviousTime
in interface StepInterpolator
public double getCurrentTime()
getCurrentTime
in interface StepInterpolator
public double getInterpolatedTime()
StepInterpolator.setInterpolatedTime(double)
has not been called, it returns
the current grid point time.
getInterpolatedTime
in interface StepInterpolator
public void setInterpolatedTime(double time)
Setting the time outside of the current step is now allowed, but should be used with care since the accuracy of the interpolator will probably be very poor far from this step. This allowance has been added to simplify implementation of search algorithms near the step endpoints.
Setting the time changes the instance internal state. If a
specific state must be preserved, a copy of the instance must be
created using StepInterpolator.copy()
.
setInterpolatedTime
in interface StepInterpolator
time
- time of the interpolated pointpublic boolean isForward()
This method provides the integration direction as specified by the integrator itself, it avoid some nasty problems in degenerated cases like null steps due to cancellation at step initialization, step control or discrete events triggering.
isForward
in interface StepInterpolator
protected abstract void computeInterpolatedStateAndDerivatives(double theta, double oneMinusThetaH) throws DerivativeException
theta
- normalized interpolation abscissa within the step
(theta is zero at the previous time step and one at the current time step)oneMinusThetaH
- time gap between the interpolated time and
the current time
DerivativeException
- this exception is propagated to the caller if the
underlying user function triggers onepublic double[] getInterpolatedState() throws DerivativeException
The returned vector is a reference to a reused array, so it should not be modified and it should be copied if it needs to be preserved across several calls.
getInterpolatedState
in interface StepInterpolator
StepInterpolator.getInterpolatedTime()
DerivativeException
- if this call induces an automatic
step finalization that throws oneStepInterpolator.getInterpolatedDerivatives()
public double[] getInterpolatedDerivatives() throws DerivativeException
The returned vector is a reference to a reused array, so it should not be modified and it should be copied if it needs to be preserved across several calls.
getInterpolatedDerivatives
in interface StepInterpolator
StepInterpolator.getInterpolatedTime()
DerivativeException
- if this call induces an automatic
step finalization that throws oneStepInterpolator.getInterpolatedState()
public final void finalizeStep() throws DerivativeException
Some embedded Runge-Kutta integrators need fewer functions
evaluations than their counterpart step interpolators. These
interpolators should perform the last evaluations they need by
themselves only if they need them. This method triggers these
extra evaluations. It can be called directly by the user step
handler and it is called automatically if setInterpolatedTime(double)
is called.
Once this method has been called, no other evaluation will be performed on this step. If there is a need to have some side effects between the step handler and the differential equations (for example update some data in the equations once the step has been done), it is advised to call this method explicitly from the step handler before these side effects are set up. If the step handler induces no side effect, then this method can safely be ignored, it will be called transparently as needed.
Warning: since the step interpolator provided
to the step handler as a parameter of the handleStep
is valid only for the duration
of the handleStep
call, one cannot
simply store a reference and reuse it later. One should first
finalize the instance, then copy this finalized instance into a
new object that can be kept.
This method calls the protected doFinalize
method
if it has never been called during this step and set a flag
indicating that it has been called once. It is the
doFinalize
method which should perform the evaluations.
This wrapping prevents from calling doFinalize
several
times and hence evaluating the differential equations too often.
Therefore, subclasses are not allowed not reimplement it, they
should rather reimplement doFinalize
.
DerivativeException
- this exception is propagated to the
caller if the underlying user function triggers oneprotected void doFinalize() throws DerivativeException
DerivativeException
- this exception is propagated to the
caller if the underlying user function triggers onepublic abstract void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public abstract void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
protected void writeBaseExternal(ObjectOutput out) throws IOException
out
- stream where to save the state
IOException
- in case of write errorprotected double readBaseExternal(ObjectInput in) throws IOException
setInterpolatedTime(double)
method later,
once all rest of the object state has been set up properly.
in
- stream where to read the state from
IOException
- in case of read error
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |