Skip to content

Solver Class

Jacob Fields edited this page Jun 11, 2020 · 2 revisions

Solver is an abstract class for a numerical integrator. While its design was intended for Runge-Kutta style integrators, it will likely work with many other kinds of solvers.

Protected Fields

Field Description
const unsigned int nStages The number of stages used by this solver.

Public Methods

Method Description
Solver(const unsigned int n) A basic constructor for a Solver object that sets the number of stages. This should be called in the initialization list for any derived Solver class.
virtual Result setStageTime(double srcTime, double &destTime, double dt, unsigned int stage) A method to set the time variable for a particular stage in the Solver. The srcTime argument is the current/original time, destTime is a reference to a double to store the calculated time in, dt is the time step, and stage is the current stage for the Solver. If stage is greater than nStages-1, it should return INVALID_STAGE. Otherwise, it always returns SUCCESS.
virtual Result calcStage(ODE *ode, std::shared_ptr<FieldMap>& fieldMap, double dt, unsigned int stage) Calculate the righthand-side for a particular stage of the solver and update the intermediate solution accordingly. This function is called by the evolveStep method in ODE. Consequently, ode is a pointer to the ODE object that called the Solver and provides the rhs function for the Solver. The fieldMap argument contains all the data inside the ODE, which is otherwise inaccessible (this is a holdover from OOPS, where the Solver is called inside a loop over all the Grid objects). The dt argument contains the time step, and stage indicates the stage to use in Solver. It should return INVALID_STAGE if the stage is too large. Otherwise, it returns SUCCESS.
virtual Result combineStages(std::shared_ptr<FieldMap>& fieldMap, double dt) This method performs the final step of the Solver procedure where all the different estimates of the right-hand side are combined together. The result should be stored in the intermediate solution, which evolveStep will then transfer into the final solution. The fieldMap argument contains all the data on the Grid, and dt indicates the time step.
int getNStages() const Get the number of stages used in this Solver.

Derived Classes

Class Description
RK4 An implementation of the classic 4th-order Runge-Kutta integrator.
RKCK An implementation of the Cash-Karp 4th/5th-order adaptive Runge-Kutta integrator. It has additional functions, double getRecommendedStepSize(), double getErrorTolerance(), and void setErrorTolerance(double) to facilitate adaptivity.

Implementation Details

All derivative classes must implement setStageTime, calcStage, and combineStages. For precise examples of how this works, look at the source code for the RK4 class (include/rk4.h and src/rk4.cpp).

Clone this wiki locally