COPASI API  4.40.278
CRungeKutta Class Reference

#include <CRungeKutta.h>

Public Types

enum  RKMethodStatus {
  INITIALIZE , RESTART , CONTINUE , ROOTFOUND ,
  END , ERROR
}
 

Public Member Functions

 CRungeKutta ()
 
std::string getErrorMesssage () const
 
RKMethodStatus operator() (const size_t *pDim, C_FLOAT64 *pY, C_FLOAT64 *pTime, C_FLOAT64 *pEndTime, const size_t rootCount, C_INT *pRoots, const RKMethodStatus &status, const bool &oneStep, C_FLOAT64 *rtol, C_FLOAT64 *atol, unsigned C_INT32 *pMaxSteps, EvalDeriv pEvalDerivatives, EvalRoot pEvalRoots)
 
 ~CRungeKutta ()
 

Private Member Functions

void advanceStep ()
 
void allocateSpace ()
 
bool checkODEState (const RKMethodStatus &status)
 
bool checkParameter (const size_t *pDim, C_FLOAT64 *pY, C_FLOAT64 *pTime, C_FLOAT64 *pEndTime, const size_t rootCount, C_INT *pRoots, const RKMethodStatus &status, C_FLOAT64 *rtol, C_FLOAT64 *atol, unsigned C_INT32 *pMaxSteps, EvalDeriv pEvalDerivatives, EvalRoot pEvalRoots)
 
void checkRoots ()
 
C_FLOAT64 deps (const C_FLOAT64 &)
 
void doOneStep ()
 
C_FLOAT64 estimateError ()
 
C_FLOAT64 infNorm (const size_t &, const C_FLOAT64 *)
 
void initialize (const size_t *pDim, C_FLOAT64 *pY, C_FLOAT64 *pTime, C_FLOAT64 *pEndTime, const size_t rootCount, C_INT *pRoots, const RKMethodStatus &status, C_FLOAT64 *rtol, C_FLOAT64 *atol, unsigned C_INT32 *pMaxSteps, EvalDeriv pEvalDerivatives, EvalRoot pEvalRoots)
 
void interpolation (const C_FLOAT64, C_FLOAT64 *)
 
C_FLOAT64 rootValue (const C_FLOAT64 &time)
 
void setCoeff ()
 
void setInitialStepSize ()
 
void setStatRecord ()
 

Private Attributes

C_FLOAT64 mA [8][8]
 
C_FLOAT64 mAbsTol
 
size_t mAcceptNum
 
C_FLOAT64 mB [8]
 
C_FLOAT64 mC [8]
 
bool mContinueFromInterpolation
 
C_FLOAT64 mE [8]
 
std::stringstream mErrorMessage
 
C_FLOAT64 mFac
 
C_FLOAT64 mFacMax
 
C_FLOAT64 mFacMaxRej
 
C_FLOAT64 mFacMin
 
size_t mfEvalNum
 
C_FLOAT64 mh
 
C_FLOAT64 mhMax
 
C_FLOAT64 mhMin
 
bool mhNoFailed
 
C_FLOAT64 mI [8][8]
 
C_FLOAT64 ** mK
 
unsigned C_INT32 mMaxSteps
 
RKMethodStatus mMethodStatus
 
size_t mOrderY
 
size_t mOrderYp
 
size_t mP
 
EvalDeriv mpDerivFunc
 
const size_t * mpDim
 
EvalRoot mpEventFunc
 
CBrent::EvalmpRootValueCalculator
 
C_FLOAT64mpY
 
size_t mRejectNum
 
C_FLOAT64 mRelTol
 
size_t mrEvalNum
 
CVectorCore< C_INTmRootFound
 
size_t mRootNum
 
C_FLOAT64mRootValueRight
 
C_FLOAT64mRootValuesLeft
 
C_FLOAT64mRootValueTmp
 
size_t mStage
 
size_t mStepNum
 
C_FLOAT64 mTEnd
 
C_FLOAT64 mTLeft
 
C_FLOAT64 mTRight
 
C_FLOAT64mYLeft
 
C_FLOAT64mYRight
 
C_FLOAT64mZ1
 
C_FLOAT64mZ2
 
C_FLOAT64mZ3
 

Member Enumeration Documentation

◆ RKMethodStatus

Enumerator
INITIALIZE 
RESTART 
CONTINUE 
ROOTFOUND 
END 
ERROR 

Constructor & Destructor Documentation

◆ CRungeKutta()

◆ ~CRungeKutta()

CRungeKutta::~CRungeKutta ( )

Member Function Documentation

◆ advanceStep()

void CRungeKutta::advanceStep ( )
private

Update time, results and other necessary stuff

References C_FLOAT64, mContinueFromInterpolation, mK, mpDim, mStage, mTLeft, mTRight, mYLeft, and mYRight.

Referenced by operator()().

◆ allocateSpace()

void CRungeKutta::allocateSpace ( )
private

Allocate space for arrays used

Update time, results and other necessary stuff

References C_FLOAT64, MAX_STAGE, mK, mpDim, mRootNum, mRootValueRight, mRootValuesLeft, mRootValueTmp, mStage, mYLeft, mYRight, mZ1, mZ2, mZ3, and pdelete.

Referenced by initialize().

◆ checkODEState()

bool CRungeKutta::checkODEState ( const RKMethodStatus status)
private

Check status of this ODE solver

Check the state attribute mODEState. If mODEState=0, first call of this method, initialization are required If mODEState=1, restart this method, method key parameters should be checked If mODEState=2, continue from last step which has an event (mODEState=3). First check if events left. If not, continue, else return with next event Else, method has error.

References CONTINUE, ERROR, INITIALIZE, mErrorMessage, mMethodStatus, and RESTART.

Referenced by operator()().

◆ checkParameter()

bool CRungeKutta::checkParameter ( const size_t *  pDim,
C_FLOAT64 pY,
C_FLOAT64 pTime,
C_FLOAT64 pEndTime,
const size_t  rootCount,
C_INT pRoots,
const RKMethodStatus status,
C_FLOAT64 rtol,
C_FLOAT64 atol,
unsigned C_INT32 pMaxSteps,
EvalDeriv  pEvalDerivatives,
EvalRoot  pEvalRoots 
)
private

Check parameters used in the integration

Check whether a slow function fired in this step Check parameters used in the integration

References mErrorMessage.

Referenced by initialize().

◆ checkRoots()

◆ deps()

C_FLOAT64 CRungeKutta::deps ( const C_FLOAT64 x)
inlineprivate

Calculate eps of a given value

References EPS0, and EPS1.

Referenced by operator()(), and setInitialStepSize().

◆ doOneStep()

void CRungeKutta::doOneStep ( )
private

Integral one step along time

References C_FLOAT64, mA, mB, mC, mh, mK, mpDerivFunc, mpDim, mStage, mTLeft, mTRight, mYLeft, mYRight, and mZ1.

Referenced by operator()().

◆ estimateError()

C_FLOAT64 CRungeKutta::estimateError ( )
private

Estimate error after executing one step If error is less than given tolerance, result is accept. Else, re-integral this step

References C_FLOAT64, mAbsTol, max, mE, mh, mK, mpDim, mRelTol, mStage, mYLeft, mYRight, mZ2, and mZ3.

Referenced by operator()().

◆ getErrorMesssage()

std::string CRungeKutta::getErrorMesssage ( ) const

◆ infNorm()

C_FLOAT64 CRungeKutta::infNorm ( const size_t &  len,
const C_FLOAT64 y 
)
private

Calculate infinity norm value

References C_FLOAT64.

Referenced by setInitialStepSize().

◆ initialize()

void CRungeKutta::initialize ( const size_t *  pDim,
C_FLOAT64 pY,
C_FLOAT64 pTime,
C_FLOAT64 pEndTime,
const size_t  rootCount,
C_INT pRoots,
const RKMethodStatus status,
C_FLOAT64 rtol,
C_FLOAT64 atol,
unsigned C_INT32 pMaxSteps,
EvalDeriv  pEvalDerivatives,
EvalRoot  pEvalRoots 
)
private

◆ interpolation()

void CRungeKutta::interpolation ( const C_FLOAT64  tInterp,
C_FLOAT64 yInterp 
)
private

Do interpolation at given time

Set initial step size of integrator

References C_FLOAT64, MAX_STAGE, mI, mK, mOrderY, mpDim, mStage, mTLeft, mTRight, and mYLeft.

Referenced by checkRoots(), and rootValue().

◆ operator()()

CRungeKutta::RKMethodStatus CRungeKutta::operator() ( const size_t *  pDim,
C_FLOAT64 pY,
C_FLOAT64 pTime,
C_FLOAT64 pEndTime,
const size_t  rootCount,
C_INT pRoots,
const RKMethodStatus status,
const bool &  oneStep,
C_FLOAT64 rtol,
C_FLOAT64 atol,
unsigned C_INT32 pMaxSteps,
EvalDeriv  pEvalDerivatives,
EvalRoot  pEvalRoots 
)

Do an integration step from the current state (pY, pTime) to the end time pEndTime

Parameters
constsize_t * pDim,
C_FLOAT64* pY,
C_FLOAT64* pTime,
C_FLOAT64* pEndTime,
constsize_t rootCount,
C_INT* pRoots,
constRKMethodStatus & status,
C_FLOAT64* rtol,
C_FLOAT64* atol,
EvalDerivpEvalDerivatives,
EvalRootpEvalRoots
Returns
RKMethodStatus status

Main function processing integration along time

References advanceStep(), C_FLOAT64, C_INT32, checkODEState(), checkRoots(), CONTINUE, deps(), doOneStep(), END, ERROR, estimateError(), INITIALIZE, initialize(), mAcceptNum, max, mContinueFromInterpolation, mErrorMessage, mFac, mFacMax, mFacMaxRej, mFacMin, mfEvalNum, mh, mhMin, mhNoFailed, min, mK, mMaxSteps, mMethodStatus, mP, mpDerivFunc, mpDim, mpY, mRejectNum, mRootNum, mRootValuesLeft, mStage, mStepNum, mTEnd, mTLeft, mTRight, mYLeft, mYRight, RESTART, ROOTFOUND, and setInitialStepSize().

◆ rootValue()

C_FLOAT64 CRungeKutta::rootValue ( const C_FLOAT64 time)
private

Calculate the maximum root value for the given time for all roots changing sign between mRootValueLeft and mRootValueRight. rootValue is a continuous function which is positive at the right and negative at the left.

Parameters
constC_FLOAT64 & time
Returns
const C_FLOAT64 rootValue

References C_FLOAT64, interpolation(), mpDim, mrEvalNum, mRootNum, mRootValueRight, mRootValuesLeft, mRootValueTmp, and mZ1.

Referenced by CRungeKutta().

◆ setCoeff()

void CRungeKutta::setCoeff ( )
private

Set coefficients for ODE45

References C_FLOAT64, mA, mB, mC, mE, mI, mOrderY, mOrderYp, mP, and mStage.

Referenced by initialize().

◆ setInitialStepSize()

void CRungeKutta::setInitialStepSize ( )
private

Set initial step size of integrator

References C_FLOAT64, deps(), infNorm(), max, mFac, mFacMax, mFacMaxRej, mFacMin, mh, mhMax, mhMin, min, mP, mpDerivFunc, mpDim, mTEnd, mTLeft, mYLeft, mZ1, mZ2, and mZ3.

Referenced by operator()().

◆ setStatRecord()

void CRungeKutta::setStatRecord ( )
private

Set statistic parameters

References mAcceptNum, mfEvalNum, mRejectNum, mrEvalNum, and mStepNum.

Referenced by initialize().

Member Data Documentation

◆ mA

C_FLOAT64 CRungeKutta::mA[8][8]
private

mA, a C_FLOAT64 two dimension array, recording coefficients a_ij

Referenced by doOneStep(), and setCoeff().

◆ mAbsTol

C_FLOAT64 CRungeKutta::mAbsTol
private

mAbsTol, absolute error tolerance mRelTol. relative error tolerance

Referenced by CRungeKutta(), estimateError(), and initialize().

◆ mAcceptNum

size_t CRungeKutta::mAcceptNum
private

mAcceptNum, a size_t variable, recording how many successful steps

Referenced by CRungeKutta(), operator()(), and setStatRecord().

◆ mB

C_FLOAT64 CRungeKutta::mB[8]
private

mB, a C_FLOAT64 array, recording coefficients b_i

Referenced by doOneStep(), and setCoeff().

◆ mC

C_FLOAT64 CRungeKutta::mC[8]
private

mC, a C_FLOAT64 array, recording coefficients c_i

Referenced by doOneStep(), and setCoeff().

◆ mContinueFromInterpolation

bool CRungeKutta::mContinueFromInterpolation
private

◆ mE

C_FLOAT64 CRungeKutta::mE[8]
private

mE, a C_FLOAT64 array, recording coefficients e_i for absolute error calculation

Referenced by estimateError(), and setCoeff().

◆ mErrorMessage

std::stringstream CRungeKutta::mErrorMessage
private

◆ mFac

C_FLOAT64 CRungeKutta::mFac
private

mFac, a number as a factor for step size control

Referenced by CRungeKutta(), operator()(), and setInitialStepSize().

◆ mFacMax

C_FLOAT64 CRungeKutta::mFacMax
private

mFacMax, maximum factor value

Referenced by CRungeKutta(), operator()(), and setInitialStepSize().

◆ mFacMaxRej

C_FLOAT64 CRungeKutta::mFacMaxRej
private

mFacMaxRej, maximum factor value after a rejected step

Referenced by CRungeKutta(), operator()(), and setInitialStepSize().

◆ mFacMin

C_FLOAT64 CRungeKutta::mFacMin
private

mFacMin, minimum factor value

Referenced by CRungeKutta(), operator()(), and setInitialStepSize().

◆ mfEvalNum

size_t CRungeKutta::mfEvalNum
private

mfEvalNum, a size_t variable, recording how many times mDerivFunc are called

Referenced by CRungeKutta(), operator()(), and setStatRecord().

◆ mh

C_FLOAT64 CRungeKutta::mh
private

◆ mhMax

C_FLOAT64 CRungeKutta::mhMax
private

mhMax, maximum step size

Referenced by CRungeKutta(), and setInitialStepSize().

◆ mhMin

C_FLOAT64 CRungeKutta::mhMin
private

mhMin, minimum step size

Referenced by CRungeKutta(), operator()(), and setInitialStepSize().

◆ mhNoFailed

bool CRungeKutta::mhNoFailed
private

mhNoFailed, a boolean variable mhNoFailed == true, success after a reject step mhNoFailed == false, previous step is accepted

Referenced by CRungeKutta(), and operator()().

◆ mI

C_FLOAT64 CRungeKutta::mI[8][8]
private

mI, a two dimension C_FLOAT64 array, for interpolation

Referenced by interpolation(), and setCoeff().

◆ mK

C_FLOAT64** CRungeKutta::mK
private

mK, a C_FLOAT64 pointer of a two dimension array, recording approximated derivatives (mStage*mDim)

Referenced by advanceStep(), allocateSpace(), CRungeKutta(), doOneStep(), estimateError(), interpolation(), operator()(), and ~CRungeKutta().

◆ mMaxSteps

unsigned C_INT32 CRungeKutta::mMaxSteps
private

Referenced by CRungeKutta(), initialize(), and operator()().

◆ mMethodStatus

RKMethodStatus CRungeKutta::mMethodStatus
private

mODEState, an int variable, recording the state of the solver Input: mODEState == 0, ODE solver is called firstly, need to be initialized mODEState == 1, ODE solver starts a new integration, without initialization mODEState == 2, ODE solver continues integration, coming back from event has been found

Output: mODEState == -2, some errors happened mODEState == 3, ODE solver stops at time t < tEnd, indicating having events mODEState == 4, ODE solver finishes integration at t == tEnd;

Referenced by checkODEState(), checkRoots(), CRungeKutta(), initialize(), and operator()().

◆ mOrderY

size_t CRungeKutta::mOrderY
private

mOrderY, the order of Y interpolation can achieve

Referenced by CRungeKutta(), interpolation(), and setCoeff().

◆ mOrderYp

size_t CRungeKutta::mOrderYp
private

mOrderYp, the order of Y prime interpolation can achieve

Referenced by CRungeKutta(), and setCoeff().

◆ mP

size_t CRungeKutta::mP
private

mP, the order this solver provides

Referenced by CRungeKutta(), operator()(), setCoeff(), and setInitialStepSize().

◆ mpDerivFunc

EvalDeriv CRungeKutta::mpDerivFunc
private

mpDerivFunc, function pointer of function calculating derivatives

Referenced by CRungeKutta(), doOneStep(), initialize(), operator()(), setInitialStepSize(), and ~CRungeKutta().

◆ mpDim

const size_t* CRungeKutta::mpDim
private

◆ mpEventFunc

EvalRoot CRungeKutta::mpEventFunc
private

mpEventFunc, function pointer of function calculating event values

Referenced by CRungeKutta(), initialize(), and ~CRungeKutta().

◆ mpRootValueCalculator

CBrent::Eval* CRungeKutta::mpRootValueCalculator
private

Pointer to method used for function evaluations for the Brent root finding method.

Referenced by checkRoots(), and CRungeKutta().

◆ mpY

C_FLOAT64* CRungeKutta::mpY
private

mY, a C_FLOAT64 pointer pointing to an array recording system values at previous step

Referenced by checkRoots(), CRungeKutta(), initialize(), and operator()().

◆ mRejectNum

size_t CRungeKutta::mRejectNum
private

mRejectNum, a size_t variable, recording how many rejected steps

Referenced by CRungeKutta(), operator()(), and setStatRecord().

◆ mRelTol

C_FLOAT64 CRungeKutta::mRelTol
private

◆ mrEvalNum

size_t CRungeKutta::mrEvalNum
private

mrEvalNum, a size_t variable, recording how many times mEventFunc are called

Referenced by checkRoots(), CRungeKutta(), rootValue(), and setStatRecord().

◆ mRootFound

CVectorCore< C_INT > CRungeKutta::mRootFound
private

Referenced by checkRoots(), and initialize().

◆ mRootNum

size_t CRungeKutta::mRootNum
private

mRootNum, a size_t variable, number of roots

Referenced by allocateSpace(), checkRoots(), CRungeKutta(), initialize(), operator()(), and rootValue().

◆ mRootValueRight

C_FLOAT64* CRungeKutta::mRootValueRight
private

mRootValueRight, a C_FLOAT64 array pointer, recording root value at current time mT

Referenced by allocateSpace(), checkRoots(), CRungeKutta(), rootValue(), and ~CRungeKutta().

◆ mRootValuesLeft

C_FLOAT64* CRungeKutta::mRootValuesLeft
private

mRootValueLeft, a C_FLOAT64 array pointer, recording root values at previous step

Referenced by allocateSpace(), checkRoots(), CRungeKutta(), operator()(), rootValue(), and ~CRungeKutta().

◆ mRootValueTmp

C_FLOAT64* CRungeKutta::mRootValueTmp
private

mRootValueRight, a C_FLOAT64 array pointer, recording root value at current time mT

Referenced by allocateSpace(), checkRoots(), CRungeKutta(), rootValue(), and ~CRungeKutta().

◆ mStage

size_t CRungeKutta::mStage
private

◆ mStepNum

size_t CRungeKutta::mStepNum
private

mStepNum, a size_t variable, recording how many steps are executed

Referenced by CRungeKutta(), operator()(), and setStatRecord().

◆ mTEnd

C_FLOAT64 CRungeKutta::mTEnd
private

mTEnd, terminal time this solver will reach

Referenced by CRungeKutta(), initialize(), operator()(), and setInitialStepSize().

◆ mTLeft

◆ mTRight

C_FLOAT64 CRungeKutta::mTRight
private

mTNew, new time in the next step

Referenced by advanceStep(), checkRoots(), CRungeKutta(), doOneStep(), interpolation(), and operator()().

◆ mYLeft

C_FLOAT64* CRungeKutta::mYLeft
private

mYOld, a C_FLOAT64 pointer pointing to an array recording mY

Referenced by advanceStep(), allocateSpace(), checkRoots(), CRungeKutta(), doOneStep(), estimateError(), interpolation(), operator()(), setInitialStepSize(), and ~CRungeKutta().

◆ mYRight

C_FLOAT64* CRungeKutta::mYRight
private

mYNew, a C_FLOAT64 pointer pointing to an array recording system values at new step

Referenced by advanceStep(), allocateSpace(), checkRoots(), CRungeKutta(), doOneStep(), estimateError(), operator()(), and ~CRungeKutta().

◆ mZ1

◆ mZ2

◆ mZ3


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