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};
61 CPS::ODEInterface::JacFn mJacFunction;
66 int StateSpace(realtype t, N_Vector y, N_Vector ydot);
68 static int JacobianWrapper(realtype t, N_Vector y, N_Vector fy, SUNMatrix J,
69 void *user_data, N_Vector tmp1, N_Vector tmp2,
71 int Jacobian(realtype t, N_Vector y, N_Vector fy, SUNMatrix J, N_Vector tmp1,
72 N_Vector tmp2, N_Vector tmp3);
74 int check_flag(
void *flagvalue,
const std::string &funcname,
int opt);
78 ODESolver(String name,
const CPS::ODEInterface::Ptr &comp,
79 bool implicit_integration, Real timestep);
86 : Task(solver.
mName +
".Solve"), mSolver(solver) {
87 mAttributeDependencies.push_back(solver.
mComponent->mOdePreState);
88 mModifiedAttributes.push_back(solver.
mComponent->mOdePostState);
91 void execute(Real time, Int timeStepCount);
98 return CPS::Task::List{std::make_shared<SolveTask>(*
this)};
104 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.
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
Reusable error-checking flag.
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.
String mName
Name for logging.