Skip to content

Commit

Permalink
Replace enum for enabling eigenvalue extraction by bool
Browse files Browse the repository at this point in the history
Signed-off-by: Georgii Tishenin <[email protected]>
  • Loading branch information
georgii-tishenin committed Feb 5, 2024
1 parent 2af9d8c commit 177e9f3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
1 change: 0 additions & 1 deletion dpsim-models/include/dpsim-models/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ namespace CPS {
enum class PowerflowBusType { PV, PQ, VD, None };
enum class GeneratorType {PVNode, IdealVoltageSource, IdealCurrentSource, TransientStability, FullOrder, FullOrderVBR, SG6aOrderVBR, SG6bOrderVBR, SG5OrderVBR, SG4OrderVBR, SG3OrderVBR, SG4OrderPCM, SG4OrderTPM, SG6OrderPCM, None};
enum class SGOrder {SG3Order, SG4Order, SG5Order, SG6aOrder, SG6bOrder};
enum class EigenvalueExtractionMode { Disabled, AtStart, AtEveryStep };

// ### Exceptions ###
class Exception : public std::exception { };
Expand Down
4 changes: 2 additions & 2 deletions dpsim/examples/cxx/Circuits/EMT_DP_SinglePhaseRLC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void runEMT(Real resistance)
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.setDomain(Domain::EMT);
sim.setEigenvalueExtractionMode(EigenvalueExtractionMode::AtStart);
sim.doEigenvalueExtraction(true);
sim.addLogger(logger);

sim.run();
Expand Down Expand Up @@ -115,7 +115,7 @@ void runDP()
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.setDomain(Domain::DP);
sim.setEigenvalueExtractionMode(EigenvalueExtractionMode::AtEveryStep);
sim.doEigenvalueExtraction(true);
sim.addLogger(logger);

sim.run();
Expand Down
4 changes: 2 additions & 2 deletions dpsim/include/dpsim/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ namespace DPsim {
///
void setSolverType(Solver::Type solverType = Solver::Type::MNA) { mSolverType = solverType; }
///
void setEigenvalueExtractionMode(CPS::EigenvalueExtractionMode eigenvalueExtractionMode) { mEigenvalueExtractionMode = eigenvalueExtractionMode; }
void doEigenvalueExtraction(Bool isEigenvalueExtractionEnabled = true) { mIsEigenvalueExtractionEnabled = isEigenvalueExtractionEnabled; }
/// set solver and component to initialization or simulation behaviour
void setSolverAndComponentBehaviour(Solver::Behaviour behaviour) { mSolverBehaviour = behaviour; }
///
Expand Down Expand Up @@ -274,6 +274,6 @@ namespace DPsim {
void logAttribute(String name, CPS::AttributeBase::Ptr attr);

private:
CPS::EigenvalueExtractionMode mEigenvalueExtractionMode = CPS::EigenvalueExtractionMode::Disabled;
Bool mIsEigenvalueExtractionEnabled = false;
};
}
6 changes: 3 additions & 3 deletions dpsim/include/dpsim/Solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ namespace DPsim {
/// Solver behaviour initialization or simulation
Behaviour mBehaviour = Solver::Behaviour::Simulation;

/// Eigenvalue extraction type
CPS::EigenvalueExtractionMode mEigenvalueExtractionMode = CPS::EigenvalueExtractionMode::Disabled;
/// Enables extraction of eigenvalues
Bool mIsEigenvalueExtractionEnabled = false;

public:
Solver(String name, CPS::Logger::Level logLevel) :
Expand Down Expand Up @@ -128,7 +128,7 @@ namespace DPsim {
void setMaxNumberOfIterations(int maxIterations) {mMaxIterations = maxIterations;}

/// ### Eigenvalue Extraction ###
void setEigenvalueExtractionMode(CPS::EigenvalueExtractionMode eigenvalueExtractionMode) { mEigenvalueExtractionMode = eigenvalueExtractionMode; }
void doEigenvalueExtraction(Bool isEigenvalueExtractionEnabled) { mIsEigenvalueExtractionEnabled = isEigenvalueExtractionEnabled; }
///
virtual void extractEigenvalues(Real time, Int timeStepCount){
// no default implementation for all types of solvers
Expand Down
4 changes: 2 additions & 2 deletions dpsim/src/MNASolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void MnaSolver<VarType>::initialize() {
SPDLOG_LOGGER_INFO(mSLog, "--- Initial system matrices and vectors ---");
logSystemMatrices();

if (Solver::mEigenvalueExtractionMode != CPS::EigenvalueExtractionMode::Disabled)
if (Solver::mIsEigenvalueExtractionEnabled)
{
SPDLOG_LOGGER_INFO(mSLog, "--- Initialize eigenvalue extractor ---");
mMNAEigenvalueExtractor.initialize(mSystem, mNumMatrixNodeIndices, Solver::mTimeStep);
Expand Down Expand Up @@ -587,7 +587,7 @@ Task::List MnaSolver<VarType>::getTasks() {
l.push_back(createSolveTaskRecomp());
} else {
l.push_back(createSolveTask());
if (mEigenvalueExtractionMode == CPS::EigenvalueExtractionMode::AtEveryStep)
if (mIsEigenvalueExtractionEnabled)
{
l.push_back(createExtractEigenvaluesTask());
}
Expand Down
12 changes: 2 additions & 10 deletions dpsim/src/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void Simulation::createMNASolver() {
solver->doInitFromNodesAndTerminals(mInitFromNodesAndTerminals);
solver->doSystemMatrixRecomputation(mSystemMatrixRecomputation);
solver->setDirectLinearSolverConfiguration(mDirectLinearSolverConfiguration);
solver->setEigenvalueExtractionMode(mEigenvalueExtractionMode);
solver->doEigenvalueExtraction(mIsEigenvalueExtractionEnabled);
solver->initialize();
solver->setMaxNumberOfIterations(mMaxIterations);
}
Expand Down Expand Up @@ -357,15 +357,7 @@ void Simulation::start() {
// In dynamic simulations increase simulation time to calculate first results at t=timestep
mTime += **mTimeStep;
}

if (mEigenvalueExtractionMode == CPS::EigenvalueExtractionMode::AtStart)
{
if (mSolvers.size() == 1)
{
mSolvers[0]->extractEigenvalues(0.0, 1.0);
}
}


mSimulationStartTimePoint = std::chrono::steady_clock::now();
}

Expand Down

0 comments on commit 177e9f3

Please sign in to comment.