Page MenuHomec4science

AbstractSolver.h
No OneTemporary

File Metadata

Created
Sat, May 25, 12:18

AbstractSolver.h

//
// Created by lionel on 25.11.19.
//
#ifndef ODELIBRARY_ABSTRACTSOLVER_H
#define ODELIBRARY_ABSTRACTSOLVER_H
#include <vector>
#include <Eigen/Dense>
/** This is an abstract class for the solver of differential equations.
* It provides a lot of method for setting up a solver.
* The only pure virtual method that needs to be overriden by the daughter classes is the step method.
*/
class AbstractSolver {
protected:
// variables for the setting
double stepSize;
double initialTime;
double finalTime;
// dimension of the differential system (size of y)
int dimension;
int nSteps;
Eigen::VectorXd initialValue; // y_0
/// function that throws exceptions if the dim is not the one of the solver
void checkSpaceDimension(int dim);
/// Checks that the time values are different and t0 < tf
void checkTimes();
/// Checks that the value of the step size is allowed for our algorithm
void checkStepSize(double h);
// variables for the rhs of the equation
Eigen::MatrixXd A; // Linear coefficients of the differential system
// (*g)(double t); // function g depending on time
std::function<Eigen::VectorXd(double)> g;
/**
* Step function will perform a step at a given time with a given value associated to that time.
* It must update the y value in place.
* It is purely virtual because it is specific to every algorithm.
* @param y : Eigen vector, the current value of the equation
* @param t : double, the current time where the step must be performed
*/
virtual void step(Eigen::VectorXd &y, double t) = 0;
public:
/// Default constructor, sets everything to 0
AbstractSolver();
AbstractSolver(double t0,double tf,int n,Eigen::VectorXd& y0);
virtual ~AbstractSolver();
/// sets the initial value of the time axis
void setInitialTime(double t0);
/// sets the final value of the time
void setFinalTime(double tf);
/**
* Sets the starting value at t0.
* @param y0
*/
void setInitialValue(Eigen::VectorXd & y0);
/**
* Sets the step size, returns an exception if the step size is not strictly positive.
* If the step size was already assigned it will print a warning in the error channel.
* @param h : step size
*/
void setStepSize(double h);
/**
* Sets the number of steps that are used for the algorithm
* @param n : number of step, an integer greater than one
*/
void setNumberOfSteps(int n);
/**
* Sets the right hand size of the equation. The equation is of type y' = A * y + g(t).
* It will also perform checks that the dimensions correspond with the other values of the problem and check that
* the function can be evaluated properly.
* @param rhsMatrix : a Eigen Matrix containing the linear part of the equation
* @param g_ : the time dependent function, returning an Eigen vector object given the time
*/
virtual void setRightHandSide(Eigen::MatrixXd & rhsMatrix, Eigen::VectorXd (*g_)(double t));
/// Sets the right hand size with a function specified as a std::function, general version
virtual void setRightHandSide(Eigen::MatrixXd & rhsMatrix, std::function<Eigen::VectorXd(double)> g_);
/// Getter for the initial time value
double getInitialTime() const;
/// Getter for the final time value
double getFinalTime() const;
/// Getter for the step size value
double getStepSize() const;
/// Getter for the dimension value
int getSpaceDimension() const;
/**
* The solve method will iterate on the time domain of the function, if it has been specified before.
* Outputs at every line space separated :
* 1. the time
* 2. all elements of the vector y for the given time
* The output of the solver will be written on the ostream object that is specified in the arguments, default will
* print to the terminal (std::cout).
* @param ostream: std::ostream type object on which the output will be printed, default : std::cout
*/
virtual void solve(std::ostream &stream = std::cout);
};
#endif //ODELIBRARY_ABSTRACTSOLVER_H

Event Timeline