9 #include <dpsim-models/SimPowerComp.h>
10 #include <dpsim/ODESolver.h>
12 using namespace DPsim;
15 bool implicit_integration, Real timestep)
16 :
Solver(name, CPS::
Logger::Level::info), mComponent(comp),
17 mImplicitIntegration(implicit_integration), mTimestep(timestep) {
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);
93 return self->StateSpace(t, y, ydot);
96 int ODESolver::StateSpace(realtype t, N_Vector y, N_Vector ydot) {
97 mStSpFunction(t, NV_DATA_S(y), NV_DATA_S(ydot));
101 int ODESolver::JacobianWrapper(realtype t, N_Vector y, N_Vector fy, SUNMatrix J,
102 void *user_data, N_Vector tmp1, N_Vector tmp2,
105 return self->Jacobian(t, y, fy, J, tmp1, tmp2, tmp3);
108 int ODESolver::Jacobian(realtype t, N_Vector y, N_Vector fy, SUNMatrix J,
109 N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) {
110 mJacFunction(t, NV_DATA_S(y), NV_DATA_S(fy), SM_DATA_D(J), NV_DATA_S(tmp1),
111 NV_DATA_S(tmp2), NV_DATA_S(tmp3));
117 realtype T0 = (realtype)initial_time;
118 realtype Tf = (realtype)initial_time +
mTimestep;
177 while (Tf - t > 1.0e-15) {
200 void ODESolver::SolveTask::execute(Real time, Int timeStepCount) {
217 if (opt == 0 && flagvalue == NULL) {
218 std::cout <<
"\nSUNDIALS_ERROR: " << funcname
219 <<
" failed - returned NULL pointer\n\n";
225 errflag = (
int *)flagvalue;
227 std::cout <<
"\nSUNDIALS_ERROR: " << funcname
228 <<
" failed with flag = " << *errflag <<
"\n\n";
234 else if (opt == 2 && flagvalue == NULL) {
235 std::cout <<
"\nMEMORY_ERROR: " << funcname
236 <<
" 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
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.