9#include <dpsim-models/SimPowerComp.h>
10#include <dpsim/ODESolver.h>
15 bool implicit_integration, Real timestep)
16 : Solver(name, CPS::Logger::Level::info),
mComponent(comp),
33 mStSpFunction = [dummy](
double t,
const double y[],
double ydot[]) {
34 dummy->odeStateSpace(t, y, ydot);
36 mJacFunction = [dummy](
double t,
const double y[],
double fy[],
double J[],
37 double tmp1[],
double tmp2[],
double tmp3[]) {
38 dummy->odeJacobian(t, y, fy, J, tmp1, tmp2, tmp3);
45 return self->StateSpace(t, y, ydot);
48int ODESolver::StateSpace(realtype t, N_Vector y, N_Vector ydot) {
49 mStSpFunction(t, NV_DATA_S(y), NV_DATA_S(ydot));
53int ODESolver::JacobianWrapper(realtype t, N_Vector y, N_Vector fy, SUNMatrix J,
54 void *user_data, N_Vector tmp1, N_Vector tmp2,
57 return self->Jacobian(t, y, fy, J, tmp1, tmp2, tmp3);
60int ODESolver::Jacobian(realtype t, N_Vector y, N_Vector fy, SUNMatrix J,
61 N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) {
62 mJacFunction(t, NV_DATA_S(y), NV_DATA_S(fy), SM_DATA_D(J), NV_DATA_S(tmp1),
63 NV_DATA_S(tmp2), NV_DATA_S(tmp3));
69 realtype T0 = (realtype)initial_time;
70 realtype Tf = (realtype)initial_time +
mTimestep;
130 while (Tf - t > 1.0e-15) {
153void ODESolver::SolveTask::execute(Real time, Int timeStepCount) {
170 if (opt == 0 && flagvalue == NULL) {
171 std::cout <<
"\nSUNDIALS_ERROR: " << funcname
172 <<
" failed - returned NULL pointer\n\n";
178 errflag = (
int *)flagvalue;
180 std::cout <<
"\nSUNDIALS_ERROR: " << funcname
181 <<
" failed with flag = " << *errflag <<
"\n\n";
187 else if (opt == 2 && flagvalue == NULL) {
188 std::cout <<
"\nMEMORY_ERROR: " << funcname
189 <<
" failed - returned NULL pointer\n\n";
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.
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.