Skip to content

Commit

Permalink
Enable compilation in gcc 14 and clang 18 (code fixes) (#294)
Browse files Browse the repository at this point in the history
~~This integrates the changes in the #293 and #257 to have all in one
place.~~
Now #257 is rebased on the master (#293 merged).
  • Loading branch information
m-mirz committed May 30, 2024
2 parents f71d1a3 + f462ce3 commit 518be00
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ class SynchronGeneratorDQ : public MNASimPowerComp<Complex>,

// #### MNA Functions ####
/// Initializes variables of component
virtual void mnaCompInitialize(Real omega, Real timeStep,
Attribute<Matrix>::Ptr) override = 0;
virtual void
mnaCompInitialize(Real omega, Real timeStep,
Attribute<Matrix>::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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SynchronGeneratorDQODE : public SynchronGeneratorDQ,

// #### MNA Section ####
void mnaCompInitialize(Real omega, Real timeStep,
Attribute<Matrix>::Ptr leftVector);
Attribute<Matrix>::Ptr leftVector) override;

/// Add MNA pre step dependencies
void mnaCompPreStep(Real time, Int timeStepCount) override;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ class SynchronGeneratorDQ : public MNASimPowerComp<Real>,
void step(Matrix &voltage, Real time);

// #### MNA Functions ####
/// Initializes variables of component
virtual void mnaCompInitialize(Real omega, Real timeStep,
Attribute<Matrix>::Ptr) override = 0;

///
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SynchronGeneratorDQODE : public SynchronGeneratorDQ,

// #### MNA Section ####
void mnaCompInitialize(Real omega, Real timeStep,
Attribute<Matrix>::Ptr leftVector);
Attribute<Matrix>::Ptr leftVector) override;

void mnaCompPreStep(Real time, Int timeStepCount) override;
/// Add MNA pre step dependencies
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion dpsim/examples/cxx/cim_graphviz/cimviz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct GVC_s {
GVCOMMON_t common;

char *config_path;
boolean config_found;
bool config_found;

/* gvParseArgs */
char **input_filenames;
Expand Down
12 changes: 8 additions & 4 deletions dpsim/include/dpsim/DAESolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class DAESolver : public Solver {
/// Nodes of the Problem
CPS::SimNode<Complex>::List mNodes;

// Initial time t0
Real mT0;

// IDA simulation variables
/// Memory block allocated by IDA
void *mem = NULL;
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions dpsim/include/dpsim/DiakopticsSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
22 changes: 9 additions & 13 deletions dpsim/src/DAESolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 518be00

Please sign in to comment.