11 #include <dpsim/Solver.h>
13 #include <dpsim-models/Solver/ODEInterface.h>
15 #include <arkode/arkode.h>
16 #include <arkode/arkode_direct.h>
17 #include <nvector/nvector_serial.h>
18 #include <sunlinsol/sunlinsol_dense.h>
19 #include <sunmatrix/sunmatrix_dense.h>
45 SUNLinearSolver
LS{
nullptr};
67 CPS::ODEInterface::JacFn mJacFunction;
72 int StateSpace(realtype t, N_Vector y, N_Vector ydot);
74 static int JacobianWrapper(realtype t, N_Vector y, N_Vector fy, SUNMatrix J,
75 void *user_data, N_Vector tmp1, N_Vector tmp2,
77 int Jacobian(realtype t, N_Vector y, N_Vector fy, SUNMatrix J, N_Vector tmp1,
78 N_Vector tmp2, N_Vector tmp3);
80 int check_flag(
void *flagvalue,
const std::string &funcname,
int opt);
84 ODESolver(String name,
const CPS::ODEInterface::Ptr &comp,
85 bool implicit_integration, Real timestep);
92 : Task(solver.
mName +
".Solve"), mSolver(solver) {
93 mAttributeDependencies.push_back(solver.
mComponent->mOdePreState);
94 mModifiedAttributes.push_back(solver.
mComponent->mOdePostState);
97 void execute(Real time, Int timeStepCount);
104 return CPS::Task::List{std::make_shared<SolveTask>(*
this)};
110 Real
step(Real initial_time);
std::function< void(double, const double *, double *)> StSpFn
Use this to pass the individual components StateSpace implementation to the ODESolver class.
Tasks to be defined by every component.
Solver class for ODE (Ordinary Differential Equation) systems.
ODESolver(String name, const CPS::ODEInterface::Ptr &comp, bool implicit_integration, Real timestep)
Create solve object with corresponding component and information on the integration type.
virtual CPS::Task::List getTasks()
Get tasks for scheduler.
CPS::ODEInterface::Ptr mComponent
Component to simulate, possible specialized component needed.
Real step(Real initial_time)
Solve system for the current time.
void * mArkode_mem
Memory block allocated by ARKode.
int mFlag
Template Jacobian Matrix (implicit solver)
realtype abstol
Scalar absolute tolerance.
SUNLinearSolver LS
Empty linear solver object.
int check_flag(void *flagvalue, const std::string &funcname, int opt)
ARKode- standard error detection function; in DAE-solver not detection function is used -> for effici...
N_Vector mStates
State vector.
void initialize()
Initialize ARKode-solve_environment.
bool mImplicitIntegration
Indicates whether the ODE shall be solved using an implicit scheme.
~ODESolver()
Deallocate all memory.
Real mTimestep
Constant time step.
SUNMatrix A
Empty matrix for linear solve in each Newton step while solving the Jacobian Matrix.
Int mProbDim
Number of differential Variables (states)
realtype reltol
Relative tolerance.
static int StateSpaceWrapper(realtype t, N_Vector y, N_Vector ydot, void *user_data)
use wrappers similar to DAE_Solver
Base class for more specific solvers such as MNA, ODE or IDA.
String mName
Name for logging.