From f462ce32afcaf822376ad04712b9d27eb9d99329 Mon Sep 17 00:00:00 2001 From: Leonardo Carreras Date: Tue, 21 May 2024 14:15:46 +0200 Subject: [PATCH] Fix compilation issues - In functions that implement interfaces, the overrides were not done explicitly. - The DAESolver was changed and a new attribute was created to preserve the override and handle the attribute internally. - A type error in cimviz was changed. - Applied clang-format. Signed-off-by: Leonardo Carreras --- .../DP/DP_Ph3_SynchronGeneratorDQ.h | 5 +++-- .../DP/DP_Ph3_SynchronGeneratorDQODE.h | 6 ++--- .../EMT/EMT_Ph3_SynchronGeneratorDQ.h | 4 +--- .../EMT/EMT_Ph3_SynchronGeneratorDQODE.h | 6 ++--- dpsim/examples/cxx/cim_graphviz/cimviz.cpp | 2 +- dpsim/include/dpsim/DAESolver.h | 12 ++++++---- dpsim/include/dpsim/DiakopticsSolver.h | 4 ++-- dpsim/src/DAESolver.cpp | 22 ++++++++----------- 8 files changed, 30 insertions(+), 31 deletions(-) diff --git a/dpsim-models/include/dpsim-models/DP/DP_Ph3_SynchronGeneratorDQ.h b/dpsim-models/include/dpsim-models/DP/DP_Ph3_SynchronGeneratorDQ.h index 5c58b087fd..6c450962b5 100644 --- a/dpsim-models/include/dpsim-models/DP/DP_Ph3_SynchronGeneratorDQ.h +++ b/dpsim-models/include/dpsim-models/DP/DP_Ph3_SynchronGeneratorDQ.h @@ -73,8 +73,9 @@ class SynchronGeneratorDQ : public MNASimPowerComp, // #### MNA Functions #### /// Initializes variables of component - virtual void mnaCompInitialize(Real omega, Real timeStep, - Attribute::Ptr) override = 0; + virtual void + mnaCompInitialize(Real omega, Real timeStep, + Attribute::Ptr leftVector) override = 0; /// Performs with the model of a synchronous generator /// to calculate the flux and current from the voltage vector. void mnaStep(Matrix &systemMatrix, Matrix &rightVector, Matrix &leftVector, diff --git a/dpsim-models/include/dpsim-models/DP/DP_Ph3_SynchronGeneratorDQODE.h b/dpsim-models/include/dpsim-models/DP/DP_Ph3_SynchronGeneratorDQODE.h index 17912d6330..f17a055c18 100644 --- a/dpsim-models/include/dpsim-models/DP/DP_Ph3_SynchronGeneratorDQODE.h +++ b/dpsim-models/include/dpsim-models/DP/DP_Ph3_SynchronGeneratorDQODE.h @@ -45,7 +45,7 @@ class SynchronGeneratorDQODE : public SynchronGeneratorDQ, // #### MNA Section #### void mnaCompInitialize(Real omega, Real timeStep, - Attribute::Ptr leftVector); + Attribute::Ptr leftVector) override; /// Add MNA pre step dependencies void mnaCompPreStep(Real time, Int timeStepCount) override; @@ -73,11 +73,11 @@ class SynchronGeneratorDQODE : public SynchronGeneratorDQ, /// Defines the ODE-System which shall be solved void odeStateSpace(double t, const double y[], - double ydot[]); // ODE-Class approach + double ydot[]) override; // ODE-Class approach /// Jacobian corresponding to the StateSpace system, needed for implicit solve void odeJacobian(double t, const double y[], double fy[], double J[], - double tmp1[], double tmp2[], double tmp3[]); + double tmp1[], double tmp2[], double tmp3[]) override; void odePreStep(); void odePostStep(); diff --git a/dpsim-models/include/dpsim-models/EMT/EMT_Ph3_SynchronGeneratorDQ.h b/dpsim-models/include/dpsim-models/EMT/EMT_Ph3_SynchronGeneratorDQ.h index 3b58467e84..033948f863 100644 --- a/dpsim-models/include/dpsim-models/EMT/EMT_Ph3_SynchronGeneratorDQ.h +++ b/dpsim-models/include/dpsim-models/EMT/EMT_Ph3_SynchronGeneratorDQ.h @@ -91,9 +91,7 @@ class SynchronGeneratorDQ : public MNASimPowerComp, void step(Matrix &voltage, Real time); // #### MNA Functions #### - /// Initializes variables of component - virtual void mnaCompInitialize(Real omega, Real timeStep, - Attribute::Ptr) override = 0; + /// void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override; /// diff --git a/dpsim-models/include/dpsim-models/EMT/EMT_Ph3_SynchronGeneratorDQODE.h b/dpsim-models/include/dpsim-models/EMT/EMT_Ph3_SynchronGeneratorDQODE.h index 856d189e6a..a2a29adffd 100644 --- a/dpsim-models/include/dpsim-models/EMT/EMT_Ph3_SynchronGeneratorDQODE.h +++ b/dpsim-models/include/dpsim-models/EMT/EMT_Ph3_SynchronGeneratorDQODE.h @@ -45,7 +45,7 @@ class SynchronGeneratorDQODE : public SynchronGeneratorDQ, // #### MNA Section #### void mnaCompInitialize(Real omega, Real timeStep, - Attribute::Ptr leftVector); + Attribute::Ptr leftVector) override; void mnaCompPreStep(Real time, Int timeStepCount) override; /// Add MNA pre step dependencies @@ -73,11 +73,11 @@ class SynchronGeneratorDQODE : public SynchronGeneratorDQ, /// Defines the ODE-System which shall be solved void odeStateSpace(double t, const double y[], - double ydot[]); // ODE-Class approach + double ydot[]) override; // ODE-Class approach /// Jacobian corresponding to the StateSpace system, needed for implicit solve void odeJacobian(double t, const double y[], double fy[], double J[], - double tmp1[], double tmp2[], double tmp3[]); + double tmp1[], double tmp2[], double tmp3[]) override; void odePreStep(); void odePostStep(); diff --git a/dpsim/examples/cxx/cim_graphviz/cimviz.cpp b/dpsim/examples/cxx/cim_graphviz/cimviz.cpp index 32599dd806..e1b1487d94 100644 --- a/dpsim/examples/cxx/cim_graphviz/cimviz.cpp +++ b/dpsim/examples/cxx/cim_graphviz/cimviz.cpp @@ -35,7 +35,7 @@ struct GVC_s { GVCOMMON_t common; char *config_path; - boolean config_found; + bool config_found; /* gvParseArgs */ char **input_filenames; diff --git a/dpsim/include/dpsim/DAESolver.h b/dpsim/include/dpsim/DAESolver.h index 355f73309b..25d9557b60 100644 --- a/dpsim/include/dpsim/DAESolver.h +++ b/dpsim/include/dpsim/DAESolver.h @@ -42,6 +42,9 @@ class DAESolver : public Solver { /// Nodes of the Problem CPS::SimNode::List mNodes; + // Initial time t0 + Real mT0; + // IDA simulation variables /// Memory block allocated by IDA void *mem = NULL; @@ -72,14 +75,15 @@ class DAESolver : public Solver { public: /// Create solve object with given parameters - DAESolver(String name, const CPS::SystemTopology &system, Real dt, Real t0); + DAESolver(String name, const CPS::SystemTopology &system, Real dt, Real mT0); /// Deallocate all memory ~DAESolver(); - /// Initialize Components & Nodes with inital values - void initialize(Real t0); + /// Initialize Components & Nodes with initial values + void initialize() final; + /// Solve system for the current time Real step(Real time); - CPS::Task::List getTasks(); + CPS::Task::List getTasks() override; }; } // namespace DPsim diff --git a/dpsim/include/dpsim/DiakopticsSolver.h b/dpsim/include/dpsim/DiakopticsSolver.h index 97292b4c2a..5bb020e1b8 100644 --- a/dpsim/include/dpsim/DiakopticsSolver.h +++ b/dpsim/include/dpsim/DiakopticsSolver.h @@ -94,7 +94,7 @@ class DiakopticsSolver : public Solver, public CPS::AttributeList { void initMatrices(); void applyTearComponentStamp(UInt compIdx); - void log(Real time, Int timeStepCount); + void log(Real time, Int timeStepCount) override; public: /// Currents through the removed network (as "seen" from the other subnets) @@ -107,7 +107,7 @@ class DiakopticsSolver : public Solver, public CPS::AttributeList { CPS::IdentifiedObject::List tearComponents, Real timeStep, CPS::Logger::Level logLevel); - CPS::Task::List getTasks(); + CPS::Task::List getTasks() override; class SubnetSolveTask : public CPS::Task { public: diff --git a/dpsim/src/DAESolver.cpp b/dpsim/src/DAESolver.cpp index a3da65e059..84adcddff3 100644 --- a/dpsim/src/DAESolver.cpp +++ b/dpsim/src/DAESolver.cpp @@ -66,10 +66,11 @@ DAESolver::DAESolver(String name, const CPS::SystemTopology &system, Real dt, } std::cout << "Nodes Setup Done" << std::endl; - initialize(t0); + mT0 = t0; + initialize(); } -void DAESolver::initialize(Real t0) { +void DAESolver::initialize() { int ret; int counter = 0; realtype *sval = NULL, *s_dtval = NULL; @@ -148,27 +149,22 @@ void DAESolver::initialize(Real t0) { std::cout << "Define Userdata" << std::endl; // This passes the solver instance as the user_data argument to the residual functions ret = IDASetUserData(mem, this); - // if (check_flag(&ret, "IDASetUserData", 1)) { - // throw CPS::Exception(); - // } + std::cout << "Call IDAInit" << std::endl; - ret = IDAInit(mem, &DAESolver::residualFunctionWrapper, t0, state, dstate_dt); - // if (check_flag(&ret, "IDAInit", 1)) { - // throw CPS::Exception(); - // } + ret = + IDAInit(mem, &DAESolver::residualFunctionWrapper, mT0, state, dstate_dt); + std::cout << "Call IDATolerances" << std::endl; ret = IDASStolerances(mem, rtol, abstol); - // if (check_flag(&ret, "IDASStolerances", 1)) { - // throw CPS::Exception(); - // } + std::cout << "Call IDA Solver Stuff" << std::endl; // Allocate and connect Matrix A and solver LS to IDA A = SUNDenseMatrix(mNEQ, mNEQ); LS = SUNDenseLinearSolver(state, A); ret = IDADlsSetLinearSolver(mem, LS, A); - //Optional IDA input functions + //TODO: Optional IDA input functions //ret = IDASetMaxNumSteps(mem, -1); //Max. number of timesteps until tout (-1 = unlimited) //ret = IDASetMaxConvFails(mem, 100); //Max. number of convergence failures at one step (void)ret;