Skip to content

Commit

Permalink
Close eigenvalue logger on simulation stop
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 49601db commit 2af9d8c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 6 deletions.
3 changes: 2 additions & 1 deletion dpsim/include/dpsim/MNAEigenvalueExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace DPsim
MNAEigenvalueExtractor();

void initialize(const CPS::SystemTopology &topology, UInt numMatrixNodeIndices, Real timeStep);
void extractEigenvalues(const Matrix &powerSystemMatrix, Real time, Int timeStepCount);
void extractEigenvalues(const Matrix &powerSystemMatrix, Real time, Int timeStepCount);
void closeLogger();

private:
CPS::EigenvalueCompInterface::List mEigenvalueComponents;
Expand Down
2 changes: 1 addition & 1 deletion dpsim/include/dpsim/MNAEigenvalueLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace DPsim
MNAEigenvalueLogger();

void setLogAttributes(CPS::AttributeStatic<MatrixComp>::Ptr eigenvalues, CPS::AttributeStatic<MatrixComp>::Ptr discreteEigenvalues);

template <typename VarType>
void logInitialization(const MatrixVar<VarType> &signMatrix, const MatrixVar<VarType> &discretizationMatrix, const Matrix &branchNodeIncidenceMatrix, const Matrix &nodeBranchIncidenceMatrix);
template <typename VarType>
void logExtraction(Real time, Int timeStepCount, const MatrixVar<VarType> &stateMatrix);
void close();

private:
CPS::Logger::Log mSLog;
Expand Down
2 changes: 2 additions & 0 deletions dpsim/include/dpsim/MNASolverDirect.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ namespace DPsim {
// ### Eigenvalue extraction ###
/// Extract eigenvalues from power system conductance matrix
void extractEigenvalues(Real time, Int timeStepCount) override;
///
void closeEigenvalueLogger() override;

/// Sets the linear solver to "implementation" and creates an object
void setDirectLinearSolverImplementation(DirectLinearSolverImpl implementation);
Expand Down
10 changes: 8 additions & 2 deletions dpsim/include/dpsim/Solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ namespace DPsim {

/// ### Eigenvalue Extraction ###
void setEigenvalueExtractionMode(CPS::EigenvalueExtractionMode eigenvalueExtractionMode) { mEigenvalueExtractionMode = eigenvalueExtractionMode; }
///
virtual void extractEigenvalues(Real time, Int timeStepCount){};
///
virtual void extractEigenvalues(Real time, Int timeStepCount){
// no default implementation for all types of solvers
};
///
virtual void closeEigenvalueLogger(){
// no default implementation for all types of solvers
};
};
}
6 changes: 6 additions & 0 deletions dpsim/src/MNAEigenvalueExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ namespace DPsim
**mEigenvalues = 2.0 / mTimeStep * ((**mDiscreteEigenvalues).array() - 1.0) / ((**mDiscreteEigenvalues).array() + 1.0) + Complex(0.0, 1.0) * mSystemOmega;
}

template <typename VarType>
void MNAEigenvalueExtractor<VarType>::closeLogger()
{
mLogger.close();
}

template class MNAEigenvalueExtractor<Real>;
template class MNAEigenvalueExtractor<Complex>;
}
9 changes: 7 additions & 2 deletions dpsim/src/MNAEigenvalueLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace DPsim
SPDLOG_LOGGER_INFO(mSLog, "discretization matrix: {}", CPS::Logger::matrixVarToString(discretizationMatrix));
SPDLOG_LOGGER_INFO(mSLog, "branch <-> node incidence matrix: {}", CPS::Logger::matrixToString(branchNodeIncidenceMatrix));
SPDLOG_LOGGER_INFO(mSLog, "node <-> branch incidence matrix: {}", CPS::Logger::matrixToString(nodeBranchIncidenceMatrix));
mSLog->flush();
}
template void MNAEigenvalueLogger::logInitialization<Real>(const MatrixVar<Real> &signMatrix, const MatrixVar<Real> &discretizationMatrix, const Matrix &branchNodeIncidenceMatrix, const Matrix &nodeBranchIncidenceMatrix);
template void MNAEigenvalueLogger::logInitialization<Complex>(const MatrixVar<Complex> &signMatrix, const MatrixVar<Complex> &discretizationMatrix, const Matrix &branchNodeIncidenceMatrix, const Matrix &nodeBranchIncidenceMatrix);
Expand All @@ -32,11 +31,17 @@ namespace DPsim
SPDLOG_LOGGER_INFO(mSLog, "---- Extract eigenvalues ----");
SPDLOG_LOGGER_INFO(mSLog, "time: {}", CPS::Logger::realToString(time));
SPDLOG_LOGGER_INFO(mSLog, "discretized state matrix: {}", CPS::Logger::matrixVarToString(stateMatrix));
mSLog->flush();

mEigenvaluesLogger.log(time, timeStepCount);
mDiscreteEigenvaluesLogger.log(time, timeStepCount);
}
template void MNAEigenvalueLogger::logExtraction<Real>(Real time, Int timeStepCount, const MatrixVar<Real> &stateMatrix);
template void MNAEigenvalueLogger::logExtraction<Complex>(Real time, Int timeStepCount, const MatrixVar<Complex> &stateMatrix);

void MNAEigenvalueLogger::close()
{
mEigenvaluesLogger.close();
mDiscreteEigenvaluesLogger.close();
mSLog->flush();
}
}
6 changes: 6 additions & 0 deletions dpsim/src/MNASolverDirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ void MnaSolverDirect<VarType>::extractEigenvalues(Real time, Int timeStepCount)
MnaSolver<VarType>::mMNAEigenvalueExtractor.extractEigenvalues(((Matrix)mSwitchedMatrices[mCurrentSwitchStatus][0]), time, timeStepCount);
}

template <typename VarType>
void MnaSolverDirect<VarType>::closeEigenvalueLogger()
{
MnaSolver<VarType>::mMNAEigenvalueExtractor.closeLogger();
}

template <typename VarType>
void MnaSolverDirect<VarType>::logSystemMatrices() {
if (mFrequencyParallel) {
Expand Down
3 changes: 3 additions & 0 deletions dpsim/src/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ void Simulation::stop() {
for (auto lg : mLoggers)
lg->close();

for (auto solver : mSolvers)
solver->closeEigenvalueLogger();

SPDLOG_LOGGER_INFO(mLog, "Simulation finished.");
mLog->flush();
}
Expand Down

0 comments on commit 2af9d8c

Please sign in to comment.