CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
RK4 Class Reference

#include <ConstantStepOdeSolver.h>

Inheritance diagram for RK4:
ConstantStepOdeSolver

Public Member Functions

const char * methodName () const override
 
 RK4 ()
 
 RK4 (const AbsODERHS &rhs)
 
- Public Member Functions inherited from ConstantStepOdeSolver
 ConstantStepOdeSolver ()
 
 ConstantStepOdeSolver (const AbsODERHS &rhs)
 
 ConstantStepOdeSolver (const ConstantStepOdeSolver &r)
 
double getCoordinate (const unsigned which, const unsigned idx) const
 
double getIntegrated (unsigned which, unsigned idx) const
 
double getPeakTime (unsigned which) const
 
const AbsODERHSgetRHS () const
 
AbsODERHSgetRHS ()
 
double getTime (const unsigned idx) const
 
double interpolateCoordinate (unsigned which, double t, bool cubic=false) const
 
double interpolateIntegrated (unsigned which, double t, bool cubic=false) const
 
double lastDeltaT () const
 
unsigned lastDim () const
 
double lastMaxT () const
 
unsigned lastRunLength () const
 
ConstantStepOdeSolveroperator= (const ConstantStepOdeSolver &r)
 
void run (const double *initialConditions, unsigned lenConditions, double dt, unsigned nSteps)
 
void setHistory (double dt, const double *data, unsigned dim, unsigned runLen)
 
void setRHS (const AbsODERHS &rhs)
 
void truncateCoordinate (unsigned which, double minValue, double maxValue)
 
void writeHistory (std::ostream &os, double dt, bool cubic=false) const
 
void writeIntegrated (std::ostream &os, unsigned which, double dt, bool cubic=false) const
 
virtual ~ConstantStepOdeSolver ()
 

Private Member Functions

void step (double t, double dt, const double *x, unsigned lenX, double *coordIncrement) const override
 

Private Attributes

std::vector< double > buf_
 

Additional Inherited Members

- Protected Attributes inherited from ConstantStepOdeSolver
AbsODERHSrhs_
 

Detailed Description

Definition at line 141 of file ConstantStepOdeSolver.h.

Constructor & Destructor Documentation

◆ RK4() [1/2]

RK4::RK4 ( )
inline

Definition at line 143 of file ConstantStepOdeSolver.h.

◆ RK4() [2/2]

RK4::RK4 ( const AbsODERHS rhs)
inlineexplicit

Definition at line 145 of file ConstantStepOdeSolver.h.

Member Function Documentation

◆ methodName()

const char* RK4::methodName ( ) const
inlineoverridevirtual

Implements ConstantStepOdeSolver.

Definition at line 147 of file ConstantStepOdeSolver.h.

147 { return "4th order Runge-Kutta"; }

◆ step()

void RK4::step ( double  t,
double  dt,
const double *  x,
unsigned  lenX,
double *  coordIncrement 
) const
overrideprivatevirtual

Implements ConstantStepOdeSolver.

Definition at line 314 of file ConstantStepOdeSolver.cc.

References buf_, AbsODERHS::calc(), dt, mps_fire::i, ConstantStepOdeSolver::rhs_, submitPVValidationJobs::t, and x.

314  {
315  const double halfstep = dt / 2.0;
316  if (buf_.size() < 4 * lenX)
317  buf_.resize(4 * lenX);
318  double* k1x = &buf_[0];
319  double* k2x = k1x + lenX;
320  double* k3x = k2x + lenX;
321  double* k4x = k3x + lenX;
322  rhs_->calc(t, x, lenX, k1x);
323  for (unsigned i = 0; i < lenX; ++i)
324  coordIncrement[i] = x[i] + halfstep * k1x[i];
325  rhs_->calc(t + halfstep, coordIncrement, lenX, k2x);
326  for (unsigned i = 0; i < lenX; ++i)
327  coordIncrement[i] = x[i] + halfstep * k2x[i];
328  rhs_->calc(t + halfstep, coordIncrement, lenX, k3x);
329  for (unsigned i = 0; i < lenX; ++i)
330  coordIncrement[i] = x[i] + dt * k3x[i];
331  rhs_->calc(t + dt, coordIncrement, lenX, k4x);
332  for (unsigned i = 0; i < lenX; ++i)
333  coordIncrement[i] = dt / 6.0 * (k1x[i] + 2.0 * (k2x[i] + k3x[i]) + k4x[i]);
334 }
float dt
Definition: AMPTWrapper.h:136
std::vector< double > buf_
virtual void calc(double t, const double *x, unsigned lenX, double *derivative)=0

Member Data Documentation

◆ buf_

std::vector<double> RK4::buf_
mutableprivate

Definition at line 152 of file ConstantStepOdeSolver.h.

Referenced by step().