From a8f07478a7194516c4233def1364fe313cc0eaa5 Mon Sep 17 00:00:00 2001 From: Georgii Tishenin Date: Sat, 18 May 2024 13:49:18 +0200 Subject: [PATCH 1/7] Add utility class for MNA matrix stamping operations Signed-off-by: Georgii Tishenin --- .../include/dpsim-models/MNAStampUtils.h | 68 +++++++++ dpsim-models/src/CMakeLists.txt | 1 + dpsim-models/src/MNAStampUtils.cpp | 130 ++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 dpsim-models/include/dpsim-models/MNAStampUtils.h create mode 100644 dpsim-models/src/MNAStampUtils.cpp diff --git a/dpsim-models/include/dpsim-models/MNAStampUtils.h b/dpsim-models/include/dpsim-models/MNAStampUtils.h new file mode 100644 index 0000000000..c2df127ef5 --- /dev/null +++ b/dpsim-models/include/dpsim-models/MNAStampUtils.h @@ -0,0 +1,68 @@ +#pragma once + +#include + +namespace CPS { +class MNAStampUtils { +public: + static void stampConductance(Real conductance, SparseMatrixRow &mat, + UInt node1Index, UInt node2Index, + Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded); + + static void stampAdmittance(Complex admittance, SparseMatrixRow &mat, + UInt node1Index, UInt node2Index, + Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded, Int maxFreq = 1, + Int freqIdx = 0); + + static void stampConductanceMatrix(const Matrix &conductanceMat, + SparseMatrixRow &mat, UInt node1Index, + UInt node2Index, + Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded); + + static void stampAdmittanceMatrix(const MatrixComp &admittanceMat, + SparseMatrixRow &mat, UInt node1Index, + UInt node2Index, + Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded, + Int maxFreq = 1, Int freqIdx = 0); + +private: + template + static void stampValue(T value, SparseMatrixRow &mat, UInt node1Index, + UInt node2Index, Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded, Int maxFreq, Int freqIdx); + + template + static void + stampMatrix(const MatrixVar &matrix, SparseMatrixRow &mat, UInt node1Index, + UInt node2Index, Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded, Int maxFreq, Int freqIdx); + + template + static void stampValueNoConditions(T value, SparseMatrixRow &mat, + UInt node1Index, UInt node2Index, + Int maxFreq, Int freqIdx); + + template + static void stampValueOnDiagonalNoConditions(T value, SparseMatrixRow &mat, + UInt nodeIndex, Int maxFreq, + Int freqIdx); + + template + static void stampValueOffDiagonalNoConditions(T value, SparseMatrixRow &mat, + UInt node1Index, + UInt node2Index, Int maxFreq, + Int freqIdx); + + static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, + Matrix::Index column, Real value, Int maxFreq, + Int freqIdx); + + static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, + Matrix::Index column, Complex value, Int maxFreq, + Int freqIdx); +}; +} // namespace CPS \ No newline at end of file diff --git a/dpsim-models/src/CMakeLists.txt b/dpsim-models/src/CMakeLists.txt index 230c6cccc3..50cafa8a3d 100644 --- a/dpsim-models/src/CMakeLists.txt +++ b/dpsim-models/src/CMakeLists.txt @@ -1,6 +1,7 @@ add_library(dpsim-models STATIC Logger.cpp MathUtils.cpp + MNAStampUtils.cpp Attribute.cpp TopologicalNode.cpp TopologicalTerminal.cpp diff --git a/dpsim-models/src/MNAStampUtils.cpp b/dpsim-models/src/MNAStampUtils.cpp new file mode 100644 index 0000000000..2b27a41e3e --- /dev/null +++ b/dpsim-models/src/MNAStampUtils.cpp @@ -0,0 +1,130 @@ +#include + +using namespace CPS; + +void MNAStampUtils::stampConductance(Real conductance, SparseMatrixRow &mat, + UInt node1Index, UInt node2Index, + Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded) { + stampValue(conductance, mat, node1Index, node2Index, isTerminal1NotGrounded, + isTerminal2NotGrounded, 1, 0); +} + +void MNAStampUtils::stampAdmittance(Complex admittance, SparseMatrixRow &mat, + UInt node1Index, UInt node2Index, + Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded, Int maxFreq, + Int freqIdx) { + stampValue(admittance, mat, node1Index, node2Index, isTerminal1NotGrounded, + isTerminal2NotGrounded, maxFreq, freqIdx); +} + +void MNAStampUtils::stampConductanceMatrix(const Matrix &conductanceMat, + SparseMatrixRow &mat, + UInt node1Index, UInt node2Index, + Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded) { + stampMatrix(conductanceMat, mat, node1Index, node2Index, + isTerminal1NotGrounded, isTerminal2NotGrounded, 1, 0); +} + +void MNAStampUtils::stampAdmittanceMatrix(const MatrixComp &admittanceMat, + SparseMatrixRow &mat, UInt node1Index, + UInt node2Index, + Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded, + Int maxFreq, Int freqIdx) { + stampMatrix(admittanceMat, mat, node1Index, node2Index, + isTerminal1NotGrounded, isTerminal2NotGrounded, maxFreq, freqIdx); +} + +template +void MNAStampUtils::stampValue(T value, SparseMatrixRow &mat, UInt node1Index, + UInt node2Index, Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded, Int maxFreq, + Int freqIdx) { + if (isTerminal1NotGrounded && isTerminal2NotGrounded) { + stampValueNoConditions(value, mat, node1Index, node2Index, maxFreq, + freqIdx); + } else if (isTerminal1NotGrounded) { + stampValueOnDiagonalNoConditions(value, mat, node1Index, maxFreq, freqIdx); + } else if (isTerminal2NotGrounded) { + stampValueOnDiagonalNoConditions(value, mat, node2Index, maxFreq, freqIdx); + } +} + +template +void MNAStampUtils::stampMatrix(const MatrixVar &matrix, + SparseMatrixRow &mat, UInt node1Index, + UInt node2Index, Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded, Int maxFreq, + Int freqIdx) { + Int numRows = matrix.rows(); + Int numCols = matrix.cols(); + if (numRows != numCols) { + throw InvalidArgumentException(); + } + + if (isTerminal1NotGrounded && isTerminal2NotGrounded) { + for (UInt i = 0; i < numRows; i++) { + for (UInt j = 0; j < numCols; j++) { + stampValueNoConditions(matrix(i, j), mat, node1Index + i, + node2Index + j, maxFreq, freqIdx); + } + } + } else if (isTerminal1NotGrounded) { + for (UInt i = 0; i < numRows; i++) { + for (UInt j = 0; j < numCols; j++) { + stampValueOnDiagonalNoConditions(matrix(i, j), mat, node1Index + i, + maxFreq, freqIdx); + } + } + } else if (isTerminal2NotGrounded) { + for (UInt i = 0; i < numRows; i++) { + for (UInt j = 0; j < numCols; j++) { + stampValueOnDiagonalNoConditions(matrix(i, j), mat, node2Index + j, + maxFreq, freqIdx); + } + } + } +} + +template +void MNAStampUtils::stampValueNoConditions(T value, SparseMatrixRow &mat, + UInt node1Index, UInt node2Index, + Int maxFreq, Int freqIdx) { + stampValueOnDiagonalNoConditions(value, mat, node1Index, maxFreq, freqIdx); + stampValueOnDiagonalNoConditions(value, mat, node2Index, maxFreq, freqIdx); + stampValueOffDiagonalNoConditions(value, mat, node1Index, node2Index, maxFreq, + freqIdx); +} + +template +void MNAStampUtils::stampValueOnDiagonalNoConditions(T value, + SparseMatrixRow &mat, + UInt nodeIndex, + Int maxFreq, Int freqIdx) { + addToMatrixElement(mat, nodeIndex, nodeIndex, value, maxFreq, freqIdx); +} + +template +void MNAStampUtils::stampValueOffDiagonalNoConditions( + T value, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, + Int maxFreq, Int freqIdx) { + addToMatrixElement(mat, node1Index, node2Index, -value, maxFreq, freqIdx); + addToMatrixElement(mat, node2Index, node1Index, -value, maxFreq, freqIdx); +} + +// These wrapper functions standardize the signatures of "Math::addToMatrixElement" for Real and Complex "value" parameters, +// facilitating the use of templates in the stamping logic. +void MNAStampUtils::addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, + Matrix::Index column, Real value, + Int maxFreq, Int freqIdx) { + Math::addToMatrixElement(mat, row, column, value); +} + +void MNAStampUtils::addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, + Matrix::Index column, Complex value, + Int maxFreq, Int freqIdx) { + Math::addToMatrixElement(mat, row, column, value, maxFreq, freqIdx); +} From c31ee09e4c5f54acba049e07ec5068154d0cea95 Mon Sep 17 00:00:00 2001 From: Georgii Tishenin Date: Sat, 18 May 2024 13:51:18 +0200 Subject: [PATCH 2/7] Reuse admittance stamping logic for DP R,L,C components Signed-off-by: Georgii Tishenin --- .../include/dpsim-models/MNASimPowerComp.h | 1 + dpsim-models/src/DP/DP_Ph1_Capacitor.cpp | 77 +--------- dpsim-models/src/DP/DP_Ph1_Inductor.cpp | 75 +-------- dpsim-models/src/DP/DP_Ph1_Resistor.cpp | 74 +-------- dpsim-models/src/DP/DP_Ph3_Capacitor.cpp | 102 +----------- dpsim-models/src/DP/DP_Ph3_Inductor.cpp | 91 +---------- dpsim-models/src/DP/DP_Ph3_Resistor.cpp | 145 +----------------- 7 files changed, 32 insertions(+), 533 deletions(-) diff --git a/dpsim-models/include/dpsim-models/MNASimPowerComp.h b/dpsim-models/include/dpsim-models/MNASimPowerComp.h index 31d254b6d8..ba9511c5d5 100644 --- a/dpsim-models/include/dpsim-models/MNASimPowerComp.h +++ b/dpsim-models/include/dpsim-models/MNASimPowerComp.h @@ -4,6 +4,7 @@ #include #include +#include namespace CPS { diff --git a/dpsim-models/src/DP/DP_Ph1_Capacitor.cpp b/dpsim-models/src/DP/DP_Ph1_Capacitor.cpp index c42e50457f..2edc3fba3c 100644 --- a/dpsim-models/src/DP/DP_Ph1_Capacitor.cpp +++ b/dpsim-models/src/DP/DP_Ph1_Capacitor.cpp @@ -123,81 +123,18 @@ void DP::Ph1::Capacitor::mnaCompInitializeHarm( void DP::Ph1::Capacitor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { for (UInt freq = 0; freq < mNumFreqs; freq++) { - if (terminalNotGrounded(0)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(0), mEquivCond(freq, 0), - mNumFreqs, freq); - if (terminalNotGrounded(1)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(1), mEquivCond(freq, 0), - mNumFreqs, freq); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), -mEquivCond(freq, 0), - mNumFreqs, freq); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(0), -mEquivCond(freq, 0), - mNumFreqs, freq); - } - - SPDLOG_LOGGER_INFO(mSLog, "-- Stamp frequency {:d} ---", freq); - if (terminalNotGrounded(0)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - mEquivCond(freq, 0).real(), mEquivCond(freq, 0).imag(), - matrixNodeIndex(0), matrixNodeIndex(0)); - if (terminalNotGrounded(1)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - mEquivCond(freq, 0).real(), mEquivCond(freq, 0).imag(), - matrixNodeIndex(1), matrixNodeIndex(1)); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - -mEquivCond(freq, 0).real(), - -mEquivCond(freq, 0).imag(), matrixNodeIndex(0), - matrixNodeIndex(1)); - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - -mEquivCond(freq, 0).real(), - -mEquivCond(freq, 0).imag(), matrixNodeIndex(1), - matrixNodeIndex(0)); - } + MNAStampUtils::stampAdmittance(mEquivCond(freq, 0), systemMatrix, + matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), + terminalNotGrounded(1), mNumFreqs, freq); } } void DP::Ph1::Capacitor::mnaCompApplySystemMatrixStampHarm( SparseMatrixRow &systemMatrix, Int freqIdx) { - if (terminalNotGrounded(0)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(0), mEquivCond(freqIdx, 0)); - if (terminalNotGrounded(1)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(1), mEquivCond(freqIdx, 0)); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), -mEquivCond(freqIdx, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(0), -mEquivCond(freqIdx, 0)); - } - - SPDLOG_LOGGER_INFO(mSLog, "-- Stamp frequency {:d} ---", freqIdx); - if (terminalNotGrounded(0)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - mEquivCond(freqIdx, 0).real(), - mEquivCond(freqIdx, 0).imag(), matrixNodeIndex(0), - matrixNodeIndex(0)); - if (terminalNotGrounded(1)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - mEquivCond(freqIdx, 0).real(), - mEquivCond(freqIdx, 0).imag(), matrixNodeIndex(1), - matrixNodeIndex(1)); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - -mEquivCond(freqIdx, 0).real(), - -mEquivCond(freqIdx, 0).imag(), matrixNodeIndex(0), - matrixNodeIndex(1)); - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - -mEquivCond(freqIdx, 0).real(), - -mEquivCond(freqIdx, 0).imag(), matrixNodeIndex(1), - matrixNodeIndex(0)); - } + MNAStampUtils::stampAdmittance( + mEquivCond(freqIdx, 0), systemMatrix, matrixNodeIndex(0), + matrixNodeIndex(1), terminalNotGrounded(0), terminalNotGrounded(1)); } void DP::Ph1::Capacitor::mnaCompApplyRightSideVectorStamp(Matrix &rightVector) { diff --git a/dpsim-models/src/DP/DP_Ph1_Inductor.cpp b/dpsim-models/src/DP/DP_Ph1_Inductor.cpp index aa53c01147..9fa4eb7770 100644 --- a/dpsim-models/src/DP/DP_Ph1_Inductor.cpp +++ b/dpsim-models/src/DP/DP_Ph1_Inductor.cpp @@ -112,79 +112,18 @@ void DP::Ph1::Inductor::mnaCompInitializeHarm( void DP::Ph1::Inductor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { for (UInt freq = 0; freq < mNumFreqs; freq++) { - if (terminalNotGrounded(0)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(0), mEquivCond(freq, 0), - mNumFreqs, freq); - if (terminalNotGrounded(1)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(1), mEquivCond(freq, 0), - mNumFreqs, freq); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), -mEquivCond(freq, 0), - mNumFreqs, freq); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(0), -mEquivCond(freq, 0), - mNumFreqs, freq); - } - - SPDLOG_LOGGER_INFO(mSLog, "-- Stamp frequency {:d} ---", freq); - if (terminalNotGrounded(0)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(mEquivCond(freq, 0)), - matrixNodeIndex(0), matrixNodeIndex(0)); - if (terminalNotGrounded(1)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(mEquivCond(freq, 0)), - matrixNodeIndex(1), matrixNodeIndex(1)); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(-mEquivCond(freq, 0)), - matrixNodeIndex(0), matrixNodeIndex(1)); - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(-mEquivCond(freq, 0)), - matrixNodeIndex(1), matrixNodeIndex(0)); - } + MNAStampUtils::stampAdmittance(mEquivCond(freq, 0), systemMatrix, + matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), + terminalNotGrounded(1), mNumFreqs, freq); } } void DP::Ph1::Inductor::mnaCompApplySystemMatrixStampHarm( SparseMatrixRow &systemMatrix, Int freqIdx) { - if (terminalNotGrounded(0)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(0), mEquivCond(freqIdx, 0)); - if (terminalNotGrounded(1)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(1), mEquivCond(freqIdx, 0)); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), -mEquivCond(freqIdx, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(0), -mEquivCond(freqIdx, 0)); - } - - SPDLOG_LOGGER_INFO(mSLog, "-- Stamp frequency {:d} ---", freqIdx); - if (terminalNotGrounded(0)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:f}+j{:f} to system at ({:d},{:d})", - mEquivCond(freqIdx, 0).real(), - mEquivCond(freqIdx, 0).imag(), matrixNodeIndex(0), - matrixNodeIndex(0)); - if (terminalNotGrounded(1)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:f}+j{:f} to system at ({:d},{:d})", - mEquivCond(freqIdx, 0).real(), - mEquivCond(freqIdx, 0).imag(), matrixNodeIndex(1), - matrixNodeIndex(1)); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - SPDLOG_LOGGER_INFO(mSLog, "Add {:f}+j{:f} to system at ({:d},{:d})", - -mEquivCond(freqIdx, 0).real(), - -mEquivCond(freqIdx, 0).imag(), matrixNodeIndex(0), - matrixNodeIndex(1)); - SPDLOG_LOGGER_INFO(mSLog, "Add {:f}+j{:f} to system at ({:d},{:d})", - -mEquivCond(freqIdx, 0).real(), - -mEquivCond(freqIdx, 0).imag(), matrixNodeIndex(1), - matrixNodeIndex(0)); - } + MNAStampUtils::stampAdmittance( + mEquivCond(freqIdx, 0), systemMatrix, matrixNodeIndex(0), + matrixNodeIndex(1), terminalNotGrounded(0), terminalNotGrounded(1)); } void DP::Ph1::Inductor::mnaCompApplyRightSideVectorStamp(Matrix &rightVector) { diff --git a/dpsim-models/src/DP/DP_Ph1_Resistor.cpp b/dpsim-models/src/DP/DP_Ph1_Resistor.cpp index 6c20c74c08..2ad676c548 100644 --- a/dpsim-models/src/DP/DP_Ph1_Resistor.cpp +++ b/dpsim-models/src/DP/DP_Ph1_Resistor.cpp @@ -77,81 +77,19 @@ void DP::Ph1::Resistor::mnaCompApplySystemMatrixStamp( Complex conductance = Complex(1. / **mResistance, 0); for (UInt freq = 0; freq < mNumFreqs; freq++) { - // Set diagonal entries - if (terminalNotGrounded(0)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(0), conductance, mNumFreqs, - freq); - if (terminalNotGrounded(1)) - // Set off diagonal entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(1), conductance, mNumFreqs, - freq); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), -conductance, mNumFreqs, - freq); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(0), -conductance, mNumFreqs, - freq); - } - - SPDLOG_LOGGER_INFO(mSLog, "-- Stamp frequency {:d} ---", freq); - if (terminalNotGrounded(0)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(conductance), - matrixNodeIndex(0), matrixNodeIndex(0)); - if (terminalNotGrounded(1)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(conductance), - matrixNodeIndex(1), matrixNodeIndex(1)); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(-conductance), - matrixNodeIndex(0), matrixNodeIndex(1)); - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(-conductance), - matrixNodeIndex(1), matrixNodeIndex(0)); - } + MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0), + matrixNodeIndex(1), terminalNotGrounded(0), + terminalNotGrounded(1), mNumFreqs, freq); } } void DP::Ph1::Resistor::mnaCompApplySystemMatrixStampHarm( SparseMatrixRow &systemMatrix, Int freqIdx) { Complex conductance = Complex(1. / **mResistance, 0); - // Set diagonal entries - if (terminalNotGrounded(0)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(0), conductance); - if (terminalNotGrounded(1)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(1), conductance); - // Set off diagonal entries - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), -conductance); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(0), -conductance); - } - SPDLOG_LOGGER_INFO(mSLog, "-- Stamp for frequency {:f} ---", - mFrequencies(freqIdx, 0)); - if (terminalNotGrounded(0)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(conductance), matrixNodeIndex(0), - matrixNodeIndex(0)); - if (terminalNotGrounded(1)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(conductance), matrixNodeIndex(1), - matrixNodeIndex(1)); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(-conductance), - matrixNodeIndex(0), matrixNodeIndex(1)); - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(-conductance), - matrixNodeIndex(1), matrixNodeIndex(0)); - } + MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0), + matrixNodeIndex(1), terminalNotGrounded(0), + terminalNotGrounded(1)); } void DP::Ph1::Resistor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/DP/DP_Ph3_Capacitor.cpp b/dpsim-models/src/DP/DP_Ph3_Capacitor.cpp index 53ad089247..cb7009e280 100644 --- a/dpsim-models/src/DP/DP_Ph3_Capacitor.cpp +++ b/dpsim-models/src/DP/DP_Ph3_Capacitor.cpp @@ -138,105 +138,9 @@ void DP::Ph3::Capacitor::mnaCompInitialize(Real omega, Real timeStep, void DP::Ph3::Capacitor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - - if (terminalNotGrounded(0)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 0), mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 1), mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 2), mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 0), mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 1), mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 2), mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 0), mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 1), mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 2), mEquivCond(2, 2)); - } - if (terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 0), mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 1), mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 2), mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 0), mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 1), mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 2), mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 0), mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 1), mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 2), mEquivCond(2, 2)); - } - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 0), -mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 1), -mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 2), -mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 0), -mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 1), -mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 2), -mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 0), -mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 1), -mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 2), -mEquivCond(2, 2)); - - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 0), -mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 1), -mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 2), -mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 0), -mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 1), -mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 2), -mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 0), -mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 1), -mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 2), -mEquivCond(2, 2)); - } /* - mLog.debug() << "\n--- Apply system matrix stamp ---" << std::endl; - if (terminalNotGrounded(0)) { - mLog.debug() << "Add " << mEquivCond(0, 0) << " to " << matrixNodeIndex(0, 0) << "," << matrixNodeIndex(0, 0) << std::endl; - mLog.debug() << "Add " << mEquivCond(1, 0) << " to " << matrixNodeIndex(0, 1) << "," << matrixNodeIndex(0, 1) << std::endl; - mLog.debug() << "Add " << mEquivCond(2, 0) << " to " << matrixNodeIndex(0, 2) << "," << matrixNodeIndex(0, 2) << std::endl; - } - if (terminalNotGrounded(1)) { - mLog.debug() << "Add " << mEquivCond(0, 0) << " to " << matrixNodeIndex(1, 0) << "," << matrixNodeIndex(1, 0) << std::endl; - mLog.debug() << "Add " << mEquivCond(0, 1) << " to " << matrixNodeIndex(1, 1) << "," << matrixNodeIndex(1, 1) << std::endl; - mLog.debug() << "Add " << mEquivCond(0, 2) << " to " << matrixNodeIndex(1, 2) << "," << matrixNodeIndex(1, 2) << std::endl; - } - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - mLog.debug() << "Add " << -mEquivCond(0, 0) << " to " << matrixNodeIndex(0, 0) << "," << matrixNodeIndex(1, 0) << std::endl - << "Add " << -mEquivCond(0, 0) << " to " << matrixNodeIndex(1, 0) << "," << matrixNodeIndex(0, 0) << std::endl; - mLog.debug() << "Add " << -mEquivCond(1, 0) << " to " << matrixNodeIndex(0, 1) << "," << matrixNodeIndex(1, 1) << std::endl - << "Add " << -mEquivCond(1, 0) << " to " << matrixNodeIndex(1, 1) << "," << matrixNodeIndex(0, 1) << std::endl; - mLog.debug() << "Add " << -mEquivCond(2, 0) << " to " << matrixNodeIndex(0, 2) << "," << matrixNodeIndex(1, 2) << std::endl - << "Add " << -mEquivCond(2, 0) << " to " << matrixNodeIndex(1, 2) << "," << matrixNodeIndex(0, 2) << std::endl; - }*/ + MNAStampUtils::stampAdmittanceMatrix( + mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), terminalNotGrounded(1)); } void DP::Ph3::Capacitor::mnaCompApplyRightSideVectorStamp(Matrix &rightVector) { diff --git a/dpsim-models/src/DP/DP_Ph3_Inductor.cpp b/dpsim-models/src/DP/DP_Ph3_Inductor.cpp index 099093a476..c7a3153826 100644 --- a/dpsim-models/src/DP/DP_Ph3_Inductor.cpp +++ b/dpsim-models/src/DP/DP_Ph3_Inductor.cpp @@ -107,94 +107,9 @@ void DP::Ph3::Inductor::mnaCompInitialize(Real omega, Real timeStep, void DP::Ph3::Inductor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - - if (terminalNotGrounded(0)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 0), mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 1), mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 2), mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 0), mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 1), mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 2), mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 0), mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 1), mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 2), mEquivCond(2, 2)); - } - if (terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 0), mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 1), mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 2), mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 0), mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 1), mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 2), mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 0), mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 1), mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 2), mEquivCond(2, 2)); - } - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 0), -mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 1), -mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 2), -mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 0), -mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 1), -mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 2), -mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 0), -mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 1), -mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 2), -mEquivCond(2, 2)); - - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 0), -mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 1), -mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 2), -mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 0), -mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 1), -mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 2), -mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 0), -mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 1), -mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 2), -mEquivCond(2, 2)); - } - - // if (terminalNotGrounded(0)) - // mLog.debug() << "Add " << mEquivCond << " to system at " << matrixNodeIndex(0) << "," << matrixNodeIndex(0) << std::endl; - // if (terminalNotGrounded(1)) - // mLog.debug() << "Add " << mEquivCond << " to system at " << matrixNodeIndex(1) << "," << matrixNodeIndex(1) << std::endl; - // if (terminalNotGrounded(0) && terminalNotGrounded(1)) - // mLog.debug() << "Add " << -mEquivCond << " to system at " << matrixNodeIndex(0) << "," << matrixNodeIndex(1) << std::endl - // << "Add " << -mEquivCond << " to system at " << matrixNodeIndex(1) << "," << matrixNodeIndex(0) << std::endl; + MNAStampUtils::stampAdmittanceMatrix( + mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), terminalNotGrounded(1)); } void DP::Ph3::Inductor::mnaCompApplyRightSideVectorStamp(Matrix &rightVector) { diff --git a/dpsim-models/src/DP/DP_Ph3_Resistor.cpp b/dpsim-models/src/DP/DP_Ph3_Resistor.cpp index 90691b4610..9459b8126d 100644 --- a/dpsim-models/src/DP/DP_Ph3_Resistor.cpp +++ b/dpsim-models/src/DP/DP_Ph3_Resistor.cpp @@ -56,147 +56,12 @@ void DP::Ph3::Resistor::mnaCompInitialize(Real omega, Real timeStep, void DP::Ph3::Resistor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { + MatrixComp conductance = Matrix::Zero(3, 3); + conductance.real() = (**mResistance).inverse(); - MatrixFixedSize<3, 3> conductance = (**mResistance).inverse(); - - //// Set diagonal entries - //if (terminalNotGrounded(0)) - // Math::addToMatrixElement(systemMatrix, matrixNodeIndices(0), matrixNodeIndices(0), conductance); - //if (terminalNotGrounded(1)) - // Math::addToMatrixElement(systemMatrix, matrixNodeIndices(1), matrixNodeIndices(1), conductance); - //// Set off diagonal entries - //if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - // Math::addToMatrixElement(systemMatrix, matrixNodeIndices(0), matrixNodeIndices(1), -conductance); - // Math::addToMatrixElement(systemMatrix, matrixNodeIndices(1), matrixNodeIndices(0), -conductance); - //} - // Set diagonal entries - if (terminalNotGrounded(0)) { - // set upper left block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 0), - Complex(conductance(0, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 1), - Complex(conductance(0, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 2), - Complex(conductance(0, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 0), - Complex(conductance(1, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 1), - Complex(conductance(1, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 2), - Complex(conductance(1, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 0), - Complex(conductance(2, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 1), - Complex(conductance(2, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 2), - Complex(conductance(2, 2), 0)); - } - if (terminalNotGrounded(1)) { - // set buttom right block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 0), - Complex(conductance(0, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 1), - Complex(conductance(0, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 2), - Complex(conductance(0, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 0), - Complex(conductance(1, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 1), - Complex(conductance(1, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 2), - Complex(conductance(1, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 0), - Complex(conductance(2, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 1), - Complex(conductance(2, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 2), - Complex(conductance(2, 2), 0)); - } - // Set off diagonal blocks, 2x3x3 entries - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 0), - -Complex(conductance(0, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 1), - -Complex(conductance(0, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 2), - -Complex(conductance(0, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 0), - -Complex(conductance(1, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 1), - -Complex(conductance(1, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 2), - -Complex(conductance(1, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 0), - -Complex(conductance(2, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 1), - -Complex(conductance(2, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 2), - -Complex(conductance(2, 2), 0)); - - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 0), - -Complex(conductance(0, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 1), - -Complex(conductance(0, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 2), - -Complex(conductance(0, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 0), - -Complex(conductance(1, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 1), - -Complex(conductance(1, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 2), - -Complex(conductance(1, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 0), - -Complex(conductance(2, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 1), - -Complex(conductance(2, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 2), - -Complex(conductance(2, 2), 0)); - } - - //if (terminalNotGrounded(0)) - // SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance, matrixNodeIndex(0,0), matrixNodeIndex(0,0)); - //if (terminalNotGrounded(1)) - // SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance, matrixNodeIndex(1,0), matrixNodeIndex(1,0)); - //if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - // SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance, matrixNodeIndex(0,0), matrixNodeIndex(1,0)); - // SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance, matrixNodeIndex(1,0), matrixNodeIndex(0,0)); - //} + MNAStampUtils::stampAdmittanceMatrix( + conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), terminalNotGrounded(1)); } void DP::Ph3::Resistor::mnaCompAddPostStepDependencies( From a9c2b0537c87ba118e43799a9f1da1d730f94817 Mon Sep 17 00:00:00 2001 From: Georgii Tishenin Date: Sat, 18 May 2024 13:52:06 +0200 Subject: [PATCH 3/7] Reuse conductance stamping logic for EMT R,L,C components Signed-off-by: Georgii Tishenin --- dpsim-models/src/EMT/EMT_Ph1_Capacitor.cpp | 15 +--- dpsim-models/src/EMT/EMT_Ph1_Inductor.cpp | 15 +--- dpsim-models/src/EMT/EMT_Ph1_Resistor.cpp | 31 +------- dpsim-models/src/EMT/EMT_Ph3_Capacitor.cpp | 85 +-------------------- dpsim-models/src/EMT/EMT_Ph3_Inductor.cpp | 85 +-------------------- dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp | 87 +--------------------- 6 files changed, 18 insertions(+), 300 deletions(-) diff --git a/dpsim-models/src/EMT/EMT_Ph1_Capacitor.cpp b/dpsim-models/src/EMT/EMT_Ph1_Capacitor.cpp index d85454f067..9a61d7db08 100644 --- a/dpsim-models/src/EMT/EMT_Ph1_Capacitor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph1_Capacitor.cpp @@ -59,18 +59,9 @@ void EMT::Ph1::Capacitor::mnaCompInitialize(Real omega, Real timeStep, void EMT::Ph1::Capacitor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - if (terminalNotGrounded(0)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(0), mEquivCond); - if (terminalNotGrounded(1)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(1), mEquivCond); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), -mEquivCond); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(0), -mEquivCond); - } + MNAStampUtils::stampConductance(mEquivCond, systemMatrix, matrixNodeIndex(0), + matrixNodeIndex(1), terminalNotGrounded(0), + terminalNotGrounded(1)); } void EMT::Ph1::Capacitor::mnaCompApplyRightSideVectorStamp( diff --git a/dpsim-models/src/EMT/EMT_Ph1_Inductor.cpp b/dpsim-models/src/EMT/EMT_Ph1_Inductor.cpp index 97ab706d04..919d9d730e 100644 --- a/dpsim-models/src/EMT/EMT_Ph1_Inductor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph1_Inductor.cpp @@ -57,18 +57,9 @@ void EMT::Ph1::Inductor::mnaCompInitialize(Real omega, Real timeStep, void EMT::Ph1::Inductor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - if (terminalNotGrounded(0)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(0), mEquivCond); - if (terminalNotGrounded(1)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(1), mEquivCond); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), -mEquivCond); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(0), -mEquivCond); - } + MNAStampUtils::stampConductance(mEquivCond, systemMatrix, matrixNodeIndex(0), + matrixNodeIndex(1), terminalNotGrounded(0), + terminalNotGrounded(1)); } void EMT::Ph1::Inductor::mnaCompApplyRightSideVectorStamp(Matrix &rightVector) { diff --git a/dpsim-models/src/EMT/EMT_Ph1_Resistor.cpp b/dpsim-models/src/EMT/EMT_Ph1_Resistor.cpp index 6ec21320ee..1e0d0c4e7c 100644 --- a/dpsim-models/src/EMT/EMT_Ph1_Resistor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph1_Resistor.cpp @@ -52,34 +52,9 @@ void EMT::Ph1::Resistor::mnaCompInitialize(Real omega, Real timeStep, void EMT::Ph1::Resistor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { Real conductance = 1. / **mResistance; - // Set diagonal entries - if (terminalNotGrounded(0)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(0), conductance); - if (terminalNotGrounded(1)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(1), conductance); - // Set off diagonal entries - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), -conductance); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(0), -conductance); - } - - if (terminalNotGrounded(0)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:f} to system at ({:d},{:d})", conductance, - matrixNodeIndex(0), matrixNodeIndex(0)); - if (terminalNotGrounded(1)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:f} to system at ({:d},{:d})", conductance, - matrixNodeIndex(1), matrixNodeIndex(1)); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - SPDLOG_LOGGER_INFO(mSLog, "Add {:f} to system at ({:d},{:d})", -conductance, - matrixNodeIndex(0), matrixNodeIndex(1)); - SPDLOG_LOGGER_INFO(mSLog, "Add {:f} to system at ({:d},{:d})", -conductance, - matrixNodeIndex(1), matrixNodeIndex(0)); - } - mSLog->flush(); + MNAStampUtils::stampConductance(conductance, systemMatrix, matrixNodeIndex(0), + matrixNodeIndex(1), terminalNotGrounded(0), + terminalNotGrounded(1)); } void EMT::Ph1::Resistor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/EMT/EMT_Ph3_Capacitor.cpp b/dpsim-models/src/EMT/EMT_Ph3_Capacitor.cpp index 355fa26521..ce1699860a 100644 --- a/dpsim-models/src/EMT/EMT_Ph3_Capacitor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph3_Capacitor.cpp @@ -76,88 +76,9 @@ void EMT::Ph3::Capacitor::mnaCompInitialize(Real omega, Real timeStep, void EMT::Ph3::Capacitor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - if (terminalNotGrounded(0)) { - // set upper left block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 0), mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 1), mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 2), mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 0), mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 1), mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 2), mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 0), mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 1), mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 2), mEquivCond(2, 2)); - } - if (terminalNotGrounded(1)) { - // set buttom right block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 0), mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 1), mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 2), mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 0), mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 1), mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 2), mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 0), mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 1), mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 2), mEquivCond(2, 2)); - } - // Set off diagonal blocks, 2x3x3 entries - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 0), -mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 1), -mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 2), -mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 0), -mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 1), -mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 2), -mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 0), -mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 1), -mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 2), -mEquivCond(2, 2)); - - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 0), -mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 1), -mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 2), -mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 0), -mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 1), -mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 2), -mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 0), -mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 1), -mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 2), -mEquivCond(2, 2)); - } + MNAStampUtils::stampConductanceMatrix( + mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), terminalNotGrounded(1)); SPDLOG_LOGGER_INFO(mSLog, "\nEquivalent Conductance: {:s}", Logger::matrixToString(mEquivCond)); diff --git a/dpsim-models/src/EMT/EMT_Ph3_Inductor.cpp b/dpsim-models/src/EMT/EMT_Ph3_Inductor.cpp index d329a4de23..9d5e416987 100644 --- a/dpsim-models/src/EMT/EMT_Ph3_Inductor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph3_Inductor.cpp @@ -90,88 +90,9 @@ void EMT::Ph3::Inductor::mnaCompInitialize(Real omega, Real timeStep, void EMT::Ph3::Inductor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - if (terminalNotGrounded(0)) { - // set upper left block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 0), mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 1), mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 2), mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 0), mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 1), mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 2), mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 0), mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 1), mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 2), mEquivCond(2, 2)); - } - if (terminalNotGrounded(1)) { - // set buttom right block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 0), mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 1), mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 2), mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 0), mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 1), mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 2), mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 0), mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 1), mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 2), mEquivCond(2, 2)); - } - // Set off diagonal blocks, 2x3x3 entries - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 0), -mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 1), -mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 2), -mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 0), -mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 1), -mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 2), -mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 0), -mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 1), -mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 2), -mEquivCond(2, 2)); - - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 0), -mEquivCond(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 1), -mEquivCond(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 2), -mEquivCond(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 0), -mEquivCond(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 1), -mEquivCond(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 2), -mEquivCond(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 0), -mEquivCond(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 1), -mEquivCond(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 2), -mEquivCond(2, 2)); - } + MNAStampUtils::stampConductanceMatrix( + mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), terminalNotGrounded(1)); SPDLOG_LOGGER_INFO(mSLog, "\nEquivalent Conductance: {:s}", Logger::matrixToString(mEquivCond)); diff --git a/dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp b/dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp index c4dcff8d8e..c13bbf5031 100644 --- a/dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp @@ -69,93 +69,12 @@ void EMT::Ph3::Resistor::mnaCompInitialize(Real omega, Real timeStep, void EMT::Ph3::Resistor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - Matrix conductance = Matrix::Zero(3, 3); Math::invertMatrix(**mResistance, conductance); - // Set diagonal entries - if (terminalNotGrounded(0)) { - // set upper left block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 0), conductance(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 1), conductance(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 2), conductance(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 0), conductance(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 1), conductance(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 2), conductance(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 0), conductance(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 1), conductance(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 2), conductance(2, 2)); - } - if (terminalNotGrounded(1)) { - // set buttom right block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 0), conductance(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 1), conductance(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 2), conductance(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 0), conductance(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 1), conductance(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 2), conductance(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 0), conductance(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 1), conductance(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 2), conductance(2, 2)); - } - // Set off diagonal blocks, 2x3x3 entries - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 0), -conductance(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 1), -conductance(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 2), -conductance(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 0), -conductance(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 1), -conductance(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 2), -conductance(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 0), -conductance(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 1), -conductance(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 2), -conductance(2, 2)); - - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 0), -conductance(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 1), -conductance(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 2), -conductance(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 0), -conductance(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 1), -conductance(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 2), -conductance(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 0), -conductance(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 1), -conductance(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 2), -conductance(2, 2)); - } + MNAStampUtils::stampConductanceMatrix( + conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), terminalNotGrounded(1)); SPDLOG_LOGGER_INFO(mSLog, "\nConductance matrix: {:s}", Logger::matrixToString(conductance)); From cb37c9432cbb15122c624488fc257d9378003bc6 Mon Sep 17 00:00:00 2001 From: Georgii Tishenin Date: Sat, 18 May 2024 13:53:28 +0200 Subject: [PATCH 4/7] Reuse admittance stamping logic for SP R,L,C components Signed-off-by: Georgii Tishenin --- dpsim-models/src/SP/SP_Ph1_Capacitor.cpp | 36 +----- dpsim-models/src/SP/SP_Ph1_Inductor.cpp | 35 +----- dpsim-models/src/SP/SP_Ph1_Resistor.cpp | 41 +------ dpsim-models/src/SP/SP_Ph3_Capacitor.cpp | 105 +----------------- dpsim-models/src/SP/SP_Ph3_Inductor.cpp | 94 +--------------- dpsim-models/src/SP/SP_Ph3_Resistor.cpp | 134 +---------------------- 6 files changed, 20 insertions(+), 425 deletions(-) diff --git a/dpsim-models/src/SP/SP_Ph1_Capacitor.cpp b/dpsim-models/src/SP/SP_Ph1_Capacitor.cpp index f6739394bd..eec0190797 100644 --- a/dpsim-models/src/SP/SP_Ph1_Capacitor.cpp +++ b/dpsim-models/src/SP/SP_Ph1_Capacitor.cpp @@ -69,39 +69,9 @@ void SP::Ph1::Capacitor::mnaCompInitialize(Real omega, Real timeStep, void SP::Ph1::Capacitor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - - if (terminalNotGrounded(0)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(0), mSusceptance); - } - if (terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(1), mSusceptance); - } - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), -mSusceptance); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(0), -mSusceptance); - } - - SPDLOG_LOGGER_INFO(mSLog, "-- Matrix Stamp ---"); - if (terminalNotGrounded(0)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - mSusceptance.real(), mSusceptance.imag(), - matrixNodeIndex(0), matrixNodeIndex(0)); - if (terminalNotGrounded(1)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - mSusceptance.real(), mSusceptance.imag(), - matrixNodeIndex(1), matrixNodeIndex(1)); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - -mSusceptance.real(), -mSusceptance.imag(), - matrixNodeIndex(0), matrixNodeIndex(1)); - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - -mSusceptance.real(), -mSusceptance.imag(), - matrixNodeIndex(1), matrixNodeIndex(0)); - } + MNAStampUtils::stampAdmittance(mSusceptance, systemMatrix, matrixNodeIndex(0), + matrixNodeIndex(1), terminalNotGrounded(0), + terminalNotGrounded(1)); } void SP::Ph1::Capacitor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/SP/SP_Ph1_Inductor.cpp b/dpsim-models/src/SP/SP_Ph1_Inductor.cpp index 60d997f360..a1412d1b59 100644 --- a/dpsim-models/src/SP/SP_Ph1_Inductor.cpp +++ b/dpsim-models/src/SP/SP_Ph1_Inductor.cpp @@ -66,38 +66,9 @@ void SP::Ph1::Inductor::mnaCompInitialize(Real omega, Real timeStep, void SP::Ph1::Inductor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - if (terminalNotGrounded(0)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(0), mSusceptance); - } - if (terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(1), mSusceptance); - } - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), -mSusceptance); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(0), -mSusceptance); - } - - SPDLOG_LOGGER_INFO(mSLog, "-- Matrix Stamp ---"); - if (terminalNotGrounded(0)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - mSusceptance.real(), mSusceptance.imag(), - matrixNodeIndex(0), matrixNodeIndex(0)); - if (terminalNotGrounded(1)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - mSusceptance.real(), mSusceptance.imag(), - matrixNodeIndex(1), matrixNodeIndex(1)); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - -mSusceptance.real(), -mSusceptance.imag(), - matrixNodeIndex(0), matrixNodeIndex(1)); - SPDLOG_LOGGER_INFO(mSLog, "Add {:e}+j{:e} to system at ({:d},{:d})", - -mSusceptance.real(), -mSusceptance.imag(), - matrixNodeIndex(1), matrixNodeIndex(0)); - } + MNAStampUtils::stampAdmittance(mSusceptance, systemMatrix, matrixNodeIndex(0), + matrixNodeIndex(1), terminalNotGrounded(0), + terminalNotGrounded(1)); } void SP::Ph1::Inductor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/SP/SP_Ph1_Resistor.cpp b/dpsim-models/src/SP/SP_Ph1_Resistor.cpp index 14fe9ac4d0..a95fc00bac 100644 --- a/dpsim-models/src/SP/SP_Ph1_Resistor.cpp +++ b/dpsim-models/src/SP/SP_Ph1_Resistor.cpp @@ -107,44 +107,9 @@ void SP::Ph1::Resistor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { Complex conductance = Complex(1. / **mResistance, 0); - for (UInt freq = 0; freq < mNumFreqs; freq++) { - // Set diagonal entries - if (terminalNotGrounded(0)) - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(0), conductance, mNumFreqs, - freq); - if (terminalNotGrounded(1)) - // Set off diagonal entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(1), conductance, mNumFreqs, - freq); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), -conductance, mNumFreqs, - freq); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), - matrixNodeIndex(0), -conductance, mNumFreqs, - freq); - } - - SPDLOG_LOGGER_INFO(mSLog, "-- Stamp frequency {:d} ---", freq); - if (terminalNotGrounded(0)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(conductance), - matrixNodeIndex(0), matrixNodeIndex(0)); - if (terminalNotGrounded(1)) - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(conductance), - matrixNodeIndex(1), matrixNodeIndex(1)); - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(-conductance), - matrixNodeIndex(0), matrixNodeIndex(1)); - SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})", - Logger::complexToString(-conductance), - matrixNodeIndex(1), matrixNodeIndex(0)); - } - } + MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0), + matrixNodeIndex(1), terminalNotGrounded(0), + terminalNotGrounded(1)); } void SP::Ph1::Resistor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/SP/SP_Ph3_Capacitor.cpp b/dpsim-models/src/SP/SP_Ph3_Capacitor.cpp index 6b64b84666..c3aa2b2fd8 100644 --- a/dpsim-models/src/SP/SP_Ph3_Capacitor.cpp +++ b/dpsim-models/src/SP/SP_Ph3_Capacitor.cpp @@ -76,108 +76,9 @@ void SP::Ph3::Capacitor::mnaCompInitialize(Real omega, Real timeStep, void SP::Ph3::Capacitor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - if (terminalNotGrounded(0)) { - // set upper left block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 0), mSusceptance(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 1), mSusceptance(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 2), mSusceptance(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 0), mSusceptance(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 1), mSusceptance(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 2), mSusceptance(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 0), mSusceptance(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 1), mSusceptance(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 2), mSusceptance(2, 2)); - } - if (terminalNotGrounded(1)) { - // set buttom right block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 0), mSusceptance(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 1), mSusceptance(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 2), mSusceptance(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 0), mSusceptance(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 1), mSusceptance(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 2), mSusceptance(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 0), mSusceptance(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 1), mSusceptance(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 2), mSusceptance(2, 2)); - } - // Set off diagonal blocks, 2x3x3 entries - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 0), -mSusceptance(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 1), -mSusceptance(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 2), -mSusceptance(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 0), -mSusceptance(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 1), -mSusceptance(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 2), -mSusceptance(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 0), -mSusceptance(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 1), -mSusceptance(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 2), -mSusceptance(2, 2)); - - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 0), -mSusceptance(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 1), -mSusceptance(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 2), -mSusceptance(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 0), -mSusceptance(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 1), -mSusceptance(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 2), -mSusceptance(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 0), -mSusceptance(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 1), -mSusceptance(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 2), -mSusceptance(2, 2)); - } - //TODO : ADD UPDATED LOGGER - /*mLog.debug() << "\n--- Apply system matrix stamp ---" << std::endl; - if (terminalNotGrounded(0)) { - mLog.debug() << "Add " << mEquivCond(0, 0) << " to " << matrixNodeIndex(0, 0) << "," << matrixNodeIndex(0, 0) << std::endl; - mLog.debug() << "Add " << mEquivCond(1, 0) << " to " << matrixNodeIndex(0, 1) << "," << matrixNodeIndex(0, 1) << std::endl; - mLog.debug() << "Add " << mEquivCond(2, 0) << " to " << matrixNodeIndex(0, 2) << "," << matrixNodeIndex(0, 2) << std::endl; - } - if (terminalNotGrounded(1)) { - mLog.debug() << "Add " << mEquivCond(0, 0) << " to " << matrixNodeIndex(1, 0) << "," << matrixNodeIndex(1, 0) << std::endl; - mLog.debug() << "Add " << mEquivCond(0, 1) << " to " << matrixNodeIndex(1, 1) << "," << matrixNodeIndex(1, 1) << std::endl; - mLog.debug() << "Add " << mEquivCond(0, 2) << " to " << matrixNodeIndex(1, 2) << "," << matrixNodeIndex(1, 2) << std::endl; - } - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - mLog.debug() << "Add " << -mEquivCond(0, 0) << " to " << matrixNodeIndex(0, 0) << "," << matrixNodeIndex(1, 0) << std::endl - << "Add " << -mEquivCond(0, 0) << " to " << matrixNodeIndex(1, 0) << "," << matrixNodeIndex(0, 0) << std::endl; - mLog.debug() << "Add " << -mEquivCond(1, 0) << " to " << matrixNodeIndex(0, 1) << "," << matrixNodeIndex(1, 1) << std::endl - << "Add " << -mEquivCond(1, 0) << " to " << matrixNodeIndex(1, 1) << "," << matrixNodeIndex(0, 1) << std::endl; - mLog.debug() << "Add " << -mEquivCond(2, 0) << " to " << matrixNodeIndex(0, 2) << "," << matrixNodeIndex(1, 2) << std::endl - << "Add " << -mEquivCond(2, 0) << " to " << matrixNodeIndex(1, 2) << "," << matrixNodeIndex(0, 2) << std::endl; - }*/ + MNAStampUtils::stampAdmittanceMatrix( + mSusceptance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), terminalNotGrounded(1)); } void SP::Ph3::Capacitor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/SP/SP_Ph3_Inductor.cpp b/dpsim-models/src/SP/SP_Ph3_Inductor.cpp index e76e51aa81..ae827f16ef 100644 --- a/dpsim-models/src/SP/SP_Ph3_Inductor.cpp +++ b/dpsim-models/src/SP/SP_Ph3_Inductor.cpp @@ -78,97 +78,9 @@ void SP::Ph3::Inductor::mnaCompInitialize(Real omega, Real timeStep, void SP::Ph3::Inductor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - if (terminalNotGrounded(0)) { - // set upper left block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 0), mSusceptance(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 1), mSusceptance(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 2), mSusceptance(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 0), mSusceptance(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 1), mSusceptance(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 2), mSusceptance(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 0), mSusceptance(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 1), mSusceptance(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 2), mSusceptance(2, 2)); - } - if (terminalNotGrounded(1)) { - // set buttom right block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 0), mSusceptance(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 1), mSusceptance(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 2), mSusceptance(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 0), mSusceptance(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 1), mSusceptance(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 2), mSusceptance(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 0), mSusceptance(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 1), mSusceptance(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 2), mSusceptance(2, 2)); - } - // Set off diagonal blocks, 2x3x3 entries - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 0), -mSusceptance(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 1), -mSusceptance(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 2), -mSusceptance(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 0), -mSusceptance(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 1), -mSusceptance(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 2), -mSusceptance(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 0), -mSusceptance(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 1), -mSusceptance(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 2), -mSusceptance(2, 2)); - - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 0), -mSusceptance(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 1), -mSusceptance(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 2), -mSusceptance(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 0), -mSusceptance(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 1), -mSusceptance(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 2), -mSusceptance(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 0), -mSusceptance(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 1), -mSusceptance(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 2), -mSusceptance(2, 2)); - } - - /* - if (terminalNotGrounded(0)) - mLog.debug() << "Add " << mEquivCond << " to system at " << matrixNodeIndex(0) << "," << matrixNodeIndex(0) << std::endl; - if (terminalNotGrounded(1)) - mLog.debug() << "Add " << mEquivCond << " to system at " << matrixNodeIndex(1) << "," << matrixNodeIndex(1) << std::endl; - if (terminalNotGrounded(0) && terminalNotGrounded(1)) - mLog.debug() << "Add " << -mEquivCond << " to system at " << matrixNodeIndex(0) << "," << matrixNodeIndex(1) << std::endl - << "Add " << -mEquivCond << " to system at " << matrixNodeIndex(1) << "," << matrixNodeIndex(0) << std::endl;*/ + MNAStampUtils::stampAdmittanceMatrix( + mSusceptance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), terminalNotGrounded(1)); } void SP::Ph3::Inductor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/SP/SP_Ph3_Resistor.cpp b/dpsim-models/src/SP/SP_Ph3_Resistor.cpp index 3a33b2c647..009c17680f 100644 --- a/dpsim-models/src/SP/SP_Ph3_Resistor.cpp +++ b/dpsim-models/src/SP/SP_Ph3_Resistor.cpp @@ -53,137 +53,13 @@ void SP::Ph3::Resistor::mnaCompInitialize(Real omega, Real timeStep, void SP::Ph3::Resistor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { + MatrixComp conductance = Matrix::Zero(3, 3); + conductance.real() = (**mResistance).inverse(); - Matrix conductance = (**mResistance).inverse(); + MNAStampUtils::stampAdmittanceMatrix( + conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), terminalNotGrounded(1)); - if (terminalNotGrounded(0)) { - // set upper left block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 0), - Complex(conductance(0, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 1), - Complex(conductance(0, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 2), - Complex(conductance(0, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 0), - Complex(conductance(1, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 1), - Complex(conductance(1, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 2), - Complex(conductance(1, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 0), - Complex(conductance(2, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 1), - Complex(conductance(2, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 2), - Complex(conductance(2, 2), 0)); - } - if (terminalNotGrounded(1)) { - // set buttom right block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 0), - Complex(conductance(0, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 1), - Complex(conductance(0, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(1, 2), - Complex(conductance(0, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 0), - Complex(conductance(1, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 1), - Complex(conductance(1, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(1, 2), - Complex(conductance(1, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 0), - Complex(conductance(2, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 1), - Complex(conductance(2, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(1, 2), - Complex(conductance(2, 2), 0)); - } - // Set off diagonal blocks, 2x3x3 entries - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 0), - -Complex(conductance(0, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 1), - -Complex(conductance(0, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(1, 2), - -Complex(conductance(0, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 0), - -Complex(conductance(1, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 1), - -Complex(conductance(1, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(1, 2), - -Complex(conductance(1, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 0), - -Complex(conductance(2, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 1), - -Complex(conductance(2, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(1, 2), - -Complex(conductance(2, 2), 0)); - - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 0), - -Complex(conductance(0, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 1), - -Complex(conductance(0, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), - matrixNodeIndex(0, 2), - -Complex(conductance(0, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 0), - -Complex(conductance(1, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 1), - -Complex(conductance(1, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), - matrixNodeIndex(0, 2), - -Complex(conductance(1, 2), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 0), - -Complex(conductance(2, 0), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 1), - -Complex(conductance(2, 1), 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), - matrixNodeIndex(0, 2), - -Complex(conductance(2, 2), 0)); - } - - // TODO: add Log - /*if (terminalNotGrounded(0)) - mLog.debug() << "Add " << conductance << " to " << matrixNodeIndex(0, 0) << "," << matrixNodeIndex(0, 0) << std::endl; - if (terminalNotGrounded(1)) - mLog.debug() << "Add " << conductance << " to " << matrixNodeIndex(1, 0) << "," << matrixNodeIndex(1, 0) << std::endl; - if (terminalNotGrounded(0) && terminalNotGrounded(1)) { - mLog.debug() << "Add " << -conductance << " to " << matrixNodeIndex(0, 0) << "," << matrixNodeIndex(1, 0) << std::endl; - mLog.debug() << "Add " << -conductance << " to " << matrixNodeIndex(1, 0) << "," << matrixNodeIndex(0, 0) << std::endl; - }*/ } void SP::Ph3::Resistor::mnaCompAddPostStepDependencies( From d5604adbffe23738bb8c4c89542795621ebb1d9b Mon Sep 17 00:00:00 2001 From: Georgii Tishenin Date: Thu, 30 May 2024 22:15:49 +0200 Subject: [PATCH 5/7] Format MNASimPowerComp.h Signed-off-by: Georgii Tishenin --- dpsim-models/include/dpsim-models/MNASimPowerComp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpsim-models/include/dpsim-models/MNASimPowerComp.h b/dpsim-models/include/dpsim-models/MNASimPowerComp.h index ba9511c5d5..8190627e5a 100644 --- a/dpsim-models/include/dpsim-models/MNASimPowerComp.h +++ b/dpsim-models/include/dpsim-models/MNASimPowerComp.h @@ -2,9 +2,9 @@ #pragma once +#include #include #include -#include namespace CPS { From 6560485faccda26d5eb40e40923a906551478a13 Mon Sep 17 00:00:00 2001 From: Georgii Tishenin Date: Thu, 30 May 2024 22:21:10 +0200 Subject: [PATCH 6/7] Log stamping in MNAStampUtils Signed-off-by: Georgii Tishenin --- .../include/dpsim-models/MNAStampUtils.h | 50 +++++---- dpsim-models/src/DP/DP_Ph1_Capacitor.cpp | 15 +-- dpsim-models/src/DP/DP_Ph1_Inductor.cpp | 15 +-- dpsim-models/src/DP/DP_Ph1_Resistor.cpp | 10 +- dpsim-models/src/DP/DP_Ph3_Capacitor.cpp | 2 +- dpsim-models/src/DP/DP_Ph3_Inductor.cpp | 2 +- dpsim-models/src/DP/DP_Ph3_Resistor.cpp | 2 +- dpsim-models/src/EMT/EMT_Ph1_Capacitor.cpp | 2 +- dpsim-models/src/EMT/EMT_Ph1_Inductor.cpp | 2 +- dpsim-models/src/EMT/EMT_Ph1_Resistor.cpp | 2 +- dpsim-models/src/EMT/EMT_Ph3_Capacitor.cpp | 2 +- dpsim-models/src/EMT/EMT_Ph3_Inductor.cpp | 2 +- dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp | 2 +- dpsim-models/src/MNAStampUtils.cpp | 105 ++++++++++++------ dpsim-models/src/SP/SP_Ph1_Capacitor.cpp | 2 +- dpsim-models/src/SP/SP_Ph1_Inductor.cpp | 2 +- dpsim-models/src/SP/SP_Ph1_Resistor.cpp | 2 +- dpsim-models/src/SP/SP_Ph3_Capacitor.cpp | 2 +- dpsim-models/src/SP/SP_Ph3_Inductor.cpp | 2 +- dpsim-models/src/SP/SP_Ph3_Resistor.cpp | 3 +- 20 files changed, 137 insertions(+), 89 deletions(-) diff --git a/dpsim-models/include/dpsim-models/MNAStampUtils.h b/dpsim-models/include/dpsim-models/MNAStampUtils.h index c2df127ef5..fea77ed126 100644 --- a/dpsim-models/include/dpsim-models/MNAStampUtils.h +++ b/dpsim-models/include/dpsim-models/MNAStampUtils.h @@ -1,5 +1,6 @@ #pragma once +#include #include namespace CPS { @@ -8,61 +9,68 @@ class MNAStampUtils { static void stampConductance(Real conductance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, - Bool isTerminal2NotGrounded); + Bool isTerminal2NotGrounded, + const Logger::Log &mSLog); static void stampAdmittance(Complex admittance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, - Bool isTerminal2NotGrounded, Int maxFreq = 1, + Bool isTerminal2NotGrounded, + const Logger::Log &mSLog, Int maxFreq = 1, Int freqIdx = 0); static void stampConductanceMatrix(const Matrix &conductanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, - Bool isTerminal2NotGrounded); + Bool isTerminal2NotGrounded, + const Logger::Log &mSLog); - static void stampAdmittanceMatrix(const MatrixComp &admittanceMat, - SparseMatrixRow &mat, UInt node1Index, - UInt node2Index, - Bool isTerminal1NotGrounded, - Bool isTerminal2NotGrounded, - Int maxFreq = 1, Int freqIdx = 0); + static void stampAdmittanceMatrix( + const MatrixComp &admittanceMat, SparseMatrixRow &mat, UInt node1Index, + UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, + const Logger::Log &mSLog, Int maxFreq = 1, Int freqIdx = 0); private: template static void stampValue(T value, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, - Bool isTerminal2NotGrounded, Int maxFreq, Int freqIdx); + Bool isTerminal2NotGrounded, Int maxFreq, Int freqIdx, + const Logger::Log &mSLog); template - static void - stampMatrix(const MatrixVar &matrix, SparseMatrixRow &mat, UInt node1Index, - UInt node2Index, Bool isTerminal1NotGrounded, - Bool isTerminal2NotGrounded, Int maxFreq, Int freqIdx); + static void stampMatrix(const MatrixVar &matrix, SparseMatrixRow &mat, + UInt node1Index, UInt node2Index, + Bool isTerminal1NotGrounded, + Bool isTerminal2NotGrounded, Int maxFreq, Int freqIdx, + const Logger::Log &mSLog); template static void stampValueNoConditions(T value, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, - Int maxFreq, Int freqIdx); + Int maxFreq, Int freqIdx, + const Logger::Log &mSLog); template static void stampValueOnDiagonalNoConditions(T value, SparseMatrixRow &mat, UInt nodeIndex, Int maxFreq, - Int freqIdx); + Int freqIdx, + const Logger::Log &mSLog); template static void stampValueOffDiagonalNoConditions(T value, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Int maxFreq, - Int freqIdx); + Int freqIdx, + const Logger::Log &mSLog); static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, - Matrix::Index column, Real value, Int maxFreq, - Int freqIdx); + Matrix::Index column, Real value, Int maxFreq, + Int freqIdx, const Logger::Log &mSLog); static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, - Matrix::Index column, Complex value, Int maxFreq, - Int freqIdx); + Matrix::Index column, Complex value, + Int maxFreq, Int freqIdx, + const Logger::Log &mSLog); }; } // namespace CPS \ No newline at end of file diff --git a/dpsim-models/src/DP/DP_Ph1_Capacitor.cpp b/dpsim-models/src/DP/DP_Ph1_Capacitor.cpp index 2edc3fba3c..08f0195da4 100644 --- a/dpsim-models/src/DP/DP_Ph1_Capacitor.cpp +++ b/dpsim-models/src/DP/DP_Ph1_Capacitor.cpp @@ -123,18 +123,19 @@ void DP::Ph1::Capacitor::mnaCompInitializeHarm( void DP::Ph1::Capacitor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { for (UInt freq = 0; freq < mNumFreqs; freq++) { - MNAStampUtils::stampAdmittance(mEquivCond(freq, 0), systemMatrix, - matrixNodeIndex(0), matrixNodeIndex(1), - terminalNotGrounded(0), - terminalNotGrounded(1), mNumFreqs, freq); + MNAStampUtils::stampAdmittance( + mEquivCond(freq, 0), systemMatrix, matrixNodeIndex(0), + matrixNodeIndex(1), terminalNotGrounded(0), terminalNotGrounded(1), + mSLog, mNumFreqs, freq); } } void DP::Ph1::Capacitor::mnaCompApplySystemMatrixStampHarm( SparseMatrixRow &systemMatrix, Int freqIdx) { - MNAStampUtils::stampAdmittance( - mEquivCond(freqIdx, 0), systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), terminalNotGrounded(0), terminalNotGrounded(1)); + MNAStampUtils::stampAdmittance(mEquivCond(freqIdx, 0), systemMatrix, + matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), terminalNotGrounded(1), + mSLog); } void DP::Ph1::Capacitor::mnaCompApplyRightSideVectorStamp(Matrix &rightVector) { diff --git a/dpsim-models/src/DP/DP_Ph1_Inductor.cpp b/dpsim-models/src/DP/DP_Ph1_Inductor.cpp index 9fa4eb7770..48fa904970 100644 --- a/dpsim-models/src/DP/DP_Ph1_Inductor.cpp +++ b/dpsim-models/src/DP/DP_Ph1_Inductor.cpp @@ -112,18 +112,19 @@ void DP::Ph1::Inductor::mnaCompInitializeHarm( void DP::Ph1::Inductor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { for (UInt freq = 0; freq < mNumFreqs; freq++) { - MNAStampUtils::stampAdmittance(mEquivCond(freq, 0), systemMatrix, - matrixNodeIndex(0), matrixNodeIndex(1), - terminalNotGrounded(0), - terminalNotGrounded(1), mNumFreqs, freq); + MNAStampUtils::stampAdmittance( + mEquivCond(freq, 0), systemMatrix, matrixNodeIndex(0), + matrixNodeIndex(1), terminalNotGrounded(0), terminalNotGrounded(1), + mSLog, mNumFreqs, freq); } } void DP::Ph1::Inductor::mnaCompApplySystemMatrixStampHarm( SparseMatrixRow &systemMatrix, Int freqIdx) { - MNAStampUtils::stampAdmittance( - mEquivCond(freqIdx, 0), systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), terminalNotGrounded(0), terminalNotGrounded(1)); + MNAStampUtils::stampAdmittance(mEquivCond(freqIdx, 0), systemMatrix, + matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), terminalNotGrounded(1), + mSLog); } void DP::Ph1::Inductor::mnaCompApplyRightSideVectorStamp(Matrix &rightVector) { diff --git a/dpsim-models/src/DP/DP_Ph1_Resistor.cpp b/dpsim-models/src/DP/DP_Ph1_Resistor.cpp index 2ad676c548..3ef1f4fb28 100644 --- a/dpsim-models/src/DP/DP_Ph1_Resistor.cpp +++ b/dpsim-models/src/DP/DP_Ph1_Resistor.cpp @@ -77,9 +77,9 @@ void DP::Ph1::Resistor::mnaCompApplySystemMatrixStamp( Complex conductance = Complex(1. / **mResistance, 0); for (UInt freq = 0; freq < mNumFreqs; freq++) { - MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), terminalNotGrounded(0), - terminalNotGrounded(1), mNumFreqs, freq); + MNAStampUtils::stampAdmittance( + conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), + terminalNotGrounded(0), terminalNotGrounded(1), mSLog, mNumFreqs, freq); } } @@ -88,8 +88,8 @@ void DP::Ph1::Resistor::mnaCompApplySystemMatrixStampHarm( Complex conductance = Complex(1. / **mResistance, 0); MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0), - matrixNodeIndex(1), terminalNotGrounded(0), - terminalNotGrounded(1)); + matrixNodeIndex(1), terminalNotGrounded(0), + terminalNotGrounded(1), mSLog); } void DP::Ph1::Resistor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/DP/DP_Ph3_Capacitor.cpp b/dpsim-models/src/DP/DP_Ph3_Capacitor.cpp index cb7009e280..5233267620 100644 --- a/dpsim-models/src/DP/DP_Ph3_Capacitor.cpp +++ b/dpsim-models/src/DP/DP_Ph3_Capacitor.cpp @@ -140,7 +140,7 @@ void DP::Ph3::Capacitor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { MNAStampUtils::stampAdmittanceMatrix( mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), - terminalNotGrounded(0), terminalNotGrounded(1)); + terminalNotGrounded(0), terminalNotGrounded(1), mSLog); } void DP::Ph3::Capacitor::mnaCompApplyRightSideVectorStamp(Matrix &rightVector) { diff --git a/dpsim-models/src/DP/DP_Ph3_Inductor.cpp b/dpsim-models/src/DP/DP_Ph3_Inductor.cpp index c7a3153826..be0ff3e8dc 100644 --- a/dpsim-models/src/DP/DP_Ph3_Inductor.cpp +++ b/dpsim-models/src/DP/DP_Ph3_Inductor.cpp @@ -109,7 +109,7 @@ void DP::Ph3::Inductor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { MNAStampUtils::stampAdmittanceMatrix( mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), - terminalNotGrounded(0), terminalNotGrounded(1)); + terminalNotGrounded(0), terminalNotGrounded(1), mSLog); } void DP::Ph3::Inductor::mnaCompApplyRightSideVectorStamp(Matrix &rightVector) { diff --git a/dpsim-models/src/DP/DP_Ph3_Resistor.cpp b/dpsim-models/src/DP/DP_Ph3_Resistor.cpp index 9459b8126d..2a93eb5306 100644 --- a/dpsim-models/src/DP/DP_Ph3_Resistor.cpp +++ b/dpsim-models/src/DP/DP_Ph3_Resistor.cpp @@ -61,7 +61,7 @@ void DP::Ph3::Resistor::mnaCompApplySystemMatrixStamp( MNAStampUtils::stampAdmittanceMatrix( conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), - terminalNotGrounded(0), terminalNotGrounded(1)); + terminalNotGrounded(0), terminalNotGrounded(1), mSLog); } void DP::Ph3::Resistor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/EMT/EMT_Ph1_Capacitor.cpp b/dpsim-models/src/EMT/EMT_Ph1_Capacitor.cpp index 9a61d7db08..5fcbba1961 100644 --- a/dpsim-models/src/EMT/EMT_Ph1_Capacitor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph1_Capacitor.cpp @@ -61,7 +61,7 @@ void EMT::Ph1::Capacitor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { MNAStampUtils::stampConductance(mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), terminalNotGrounded(0), - terminalNotGrounded(1)); + terminalNotGrounded(1), mSLog); } void EMT::Ph1::Capacitor::mnaCompApplyRightSideVectorStamp( diff --git a/dpsim-models/src/EMT/EMT_Ph1_Inductor.cpp b/dpsim-models/src/EMT/EMT_Ph1_Inductor.cpp index 919d9d730e..63e8a275da 100644 --- a/dpsim-models/src/EMT/EMT_Ph1_Inductor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph1_Inductor.cpp @@ -59,7 +59,7 @@ void EMT::Ph1::Inductor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { MNAStampUtils::stampConductance(mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), terminalNotGrounded(0), - terminalNotGrounded(1)); + terminalNotGrounded(1), mSLog); } void EMT::Ph1::Inductor::mnaCompApplyRightSideVectorStamp(Matrix &rightVector) { diff --git a/dpsim-models/src/EMT/EMT_Ph1_Resistor.cpp b/dpsim-models/src/EMT/EMT_Ph1_Resistor.cpp index 1e0d0c4e7c..a96950151c 100644 --- a/dpsim-models/src/EMT/EMT_Ph1_Resistor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph1_Resistor.cpp @@ -54,7 +54,7 @@ void EMT::Ph1::Resistor::mnaCompApplySystemMatrixStamp( Real conductance = 1. / **mResistance; MNAStampUtils::stampConductance(conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), terminalNotGrounded(0), - terminalNotGrounded(1)); + terminalNotGrounded(1), mSLog); } void EMT::Ph1::Resistor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/EMT/EMT_Ph3_Capacitor.cpp b/dpsim-models/src/EMT/EMT_Ph3_Capacitor.cpp index ce1699860a..a1a9350193 100644 --- a/dpsim-models/src/EMT/EMT_Ph3_Capacitor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph3_Capacitor.cpp @@ -78,7 +78,7 @@ void EMT::Ph3::Capacitor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { MNAStampUtils::stampConductanceMatrix( mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), - terminalNotGrounded(0), terminalNotGrounded(1)); + terminalNotGrounded(0), terminalNotGrounded(1), mSLog); SPDLOG_LOGGER_INFO(mSLog, "\nEquivalent Conductance: {:s}", Logger::matrixToString(mEquivCond)); diff --git a/dpsim-models/src/EMT/EMT_Ph3_Inductor.cpp b/dpsim-models/src/EMT/EMT_Ph3_Inductor.cpp index 9d5e416987..be7b68b3ec 100644 --- a/dpsim-models/src/EMT/EMT_Ph3_Inductor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph3_Inductor.cpp @@ -92,7 +92,7 @@ void EMT::Ph3::Inductor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { MNAStampUtils::stampConductanceMatrix( mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), - terminalNotGrounded(0), terminalNotGrounded(1)); + terminalNotGrounded(0), terminalNotGrounded(1), mSLog); SPDLOG_LOGGER_INFO(mSLog, "\nEquivalent Conductance: {:s}", Logger::matrixToString(mEquivCond)); diff --git a/dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp b/dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp index c13bbf5031..d90bd772dd 100644 --- a/dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp @@ -74,7 +74,7 @@ void EMT::Ph3::Resistor::mnaCompApplySystemMatrixStamp( MNAStampUtils::stampConductanceMatrix( conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), - terminalNotGrounded(0), terminalNotGrounded(1)); + terminalNotGrounded(0), terminalNotGrounded(1), mSLog); SPDLOG_LOGGER_INFO(mSLog, "\nConductance matrix: {:s}", Logger::matrixToString(conductance)); diff --git a/dpsim-models/src/MNAStampUtils.cpp b/dpsim-models/src/MNAStampUtils.cpp index 2b27a41e3e..4bb7b6bb0f 100644 --- a/dpsim-models/src/MNAStampUtils.cpp +++ b/dpsim-models/src/MNAStampUtils.cpp @@ -5,51 +5,76 @@ using namespace CPS; void MNAStampUtils::stampConductance(Real conductance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, - Bool isTerminal2NotGrounded) { + Bool isTerminal2NotGrounded, + const Logger::Log &mSLog) { + SPDLOG_LOGGER_DEBUG(mSLog, "Start stamping conductance..."); + stampValue(conductance, mat, node1Index, node2Index, isTerminal1NotGrounded, - isTerminal2NotGrounded, 1, 0); + isTerminal2NotGrounded, 1, 0, mSLog); + + SPDLOG_LOGGER_DEBUG(mSLog, "Stamping completed."); } void MNAStampUtils::stampAdmittance(Complex admittance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, - Bool isTerminal2NotGrounded, Int maxFreq, + Bool isTerminal2NotGrounded, + const Logger::Log &mSLog, Int maxFreq, Int freqIdx) { + SPDLOG_LOGGER_DEBUG( + mSLog, "Start stamping admittance for frequency index {:d}...", + freqIdx); + stampValue(admittance, mat, node1Index, node2Index, isTerminal1NotGrounded, - isTerminal2NotGrounded, maxFreq, freqIdx); + isTerminal2NotGrounded, maxFreq, freqIdx, mSLog); + + SPDLOG_LOGGER_DEBUG(mSLog, "Stamping completed."); } void MNAStampUtils::stampConductanceMatrix(const Matrix &conductanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, - Bool isTerminal2NotGrounded) { + Bool isTerminal2NotGrounded, + const Logger::Log &mSLog) { + SPDLOG_LOGGER_DEBUG(mSLog, "Start stamping conductance matrix..."); + stampMatrix(conductanceMat, mat, node1Index, node2Index, - isTerminal1NotGrounded, isTerminal2NotGrounded, 1, 0); + isTerminal1NotGrounded, isTerminal2NotGrounded, 1, 0, mSLog); + + SPDLOG_LOGGER_DEBUG(mSLog, "Stamping completed."); } -void MNAStampUtils::stampAdmittanceMatrix(const MatrixComp &admittanceMat, - SparseMatrixRow &mat, UInt node1Index, - UInt node2Index, - Bool isTerminal1NotGrounded, - Bool isTerminal2NotGrounded, - Int maxFreq, Int freqIdx) { +void MNAStampUtils::stampAdmittanceMatrix( + const MatrixComp &admittanceMat, SparseMatrixRow &mat, UInt node1Index, + UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, + const Logger::Log &mSLog, Int maxFreq, Int freqIdx) { + SPDLOG_LOGGER_DEBUG( + mSLog, + "Start stamping admittance matrix for frequency index {:d}...", + freqIdx); + stampMatrix(admittanceMat, mat, node1Index, node2Index, - isTerminal1NotGrounded, isTerminal2NotGrounded, maxFreq, freqIdx); + isTerminal1NotGrounded, isTerminal2NotGrounded, maxFreq, freqIdx, + mSLog); + + SPDLOG_LOGGER_DEBUG(mSLog, "Stamping completed."); } template void MNAStampUtils::stampValue(T value, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, Int maxFreq, - Int freqIdx) { + Int freqIdx, const Logger::Log &mSLog) { if (isTerminal1NotGrounded && isTerminal2NotGrounded) { - stampValueNoConditions(value, mat, node1Index, node2Index, maxFreq, - freqIdx); + stampValueNoConditions(value, mat, node1Index, node2Index, maxFreq, freqIdx, + mSLog); } else if (isTerminal1NotGrounded) { - stampValueOnDiagonalNoConditions(value, mat, node1Index, maxFreq, freqIdx); + stampValueOnDiagonalNoConditions(value, mat, node1Index, maxFreq, freqIdx, + mSLog); } else if (isTerminal2NotGrounded) { - stampValueOnDiagonalNoConditions(value, mat, node2Index, maxFreq, freqIdx); + stampValueOnDiagonalNoConditions(value, mat, node2Index, maxFreq, freqIdx, + mSLog); } } @@ -58,7 +83,7 @@ void MNAStampUtils::stampMatrix(const MatrixVar &matrix, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, Int maxFreq, - Int freqIdx) { + Int freqIdx, const Logger::Log &mSLog) { Int numRows = matrix.rows(); Int numCols = matrix.cols(); if (numRows != numCols) { @@ -69,21 +94,21 @@ void MNAStampUtils::stampMatrix(const MatrixVar &matrix, for (UInt i = 0; i < numRows; i++) { for (UInt j = 0; j < numCols; j++) { stampValueNoConditions(matrix(i, j), mat, node1Index + i, - node2Index + j, maxFreq, freqIdx); + node2Index + j, maxFreq, freqIdx, mSLog); } } } else if (isTerminal1NotGrounded) { for (UInt i = 0; i < numRows; i++) { for (UInt j = 0; j < numCols; j++) { stampValueOnDiagonalNoConditions(matrix(i, j), mat, node1Index + i, - maxFreq, freqIdx); + maxFreq, freqIdx, mSLog); } } } else if (isTerminal2NotGrounded) { for (UInt i = 0; i < numRows; i++) { for (UInt j = 0; j < numCols; j++) { stampValueOnDiagonalNoConditions(matrix(i, j), mat, node2Index + j, - maxFreq, freqIdx); + maxFreq, freqIdx, mSLog); } } } @@ -92,39 +117,53 @@ void MNAStampUtils::stampMatrix(const MatrixVar &matrix, template void MNAStampUtils::stampValueNoConditions(T value, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, - Int maxFreq, Int freqIdx) { - stampValueOnDiagonalNoConditions(value, mat, node1Index, maxFreq, freqIdx); - stampValueOnDiagonalNoConditions(value, mat, node2Index, maxFreq, freqIdx); + Int maxFreq, Int freqIdx, + const Logger::Log &mSLog) { + stampValueOnDiagonalNoConditions(value, mat, node1Index, maxFreq, freqIdx, + mSLog); + stampValueOnDiagonalNoConditions(value, mat, node2Index, maxFreq, freqIdx, + mSLog); stampValueOffDiagonalNoConditions(value, mat, node1Index, node2Index, maxFreq, - freqIdx); + freqIdx, mSLog); } template void MNAStampUtils::stampValueOnDiagonalNoConditions(T value, SparseMatrixRow &mat, UInt nodeIndex, - Int maxFreq, Int freqIdx) { - addToMatrixElement(mat, nodeIndex, nodeIndex, value, maxFreq, freqIdx); + Int maxFreq, Int freqIdx, + const Logger::Log &mSLog) { + addToMatrixElement(mat, nodeIndex, nodeIndex, value, maxFreq, freqIdx, mSLog); } template void MNAStampUtils::stampValueOffDiagonalNoConditions( T value, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, - Int maxFreq, Int freqIdx) { - addToMatrixElement(mat, node1Index, node2Index, -value, maxFreq, freqIdx); - addToMatrixElement(mat, node2Index, node1Index, -value, maxFreq, freqIdx); + Int maxFreq, Int freqIdx, const Logger::Log &mSLog) { + addToMatrixElement(mat, node1Index, node2Index, -value, maxFreq, freqIdx, + mSLog); + addToMatrixElement(mat, node2Index, node1Index, -value, maxFreq, freqIdx, + mSLog); } // These wrapper functions standardize the signatures of "Math::addToMatrixElement" for Real and Complex "value" parameters, // facilitating the use of templates in the stamping logic. void MNAStampUtils::addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Real value, - Int maxFreq, Int freqIdx) { + Int maxFreq, Int freqIdx, + const Logger::Log &mSLog) { + SPDLOG_LOGGER_DEBUG(mSLog, "- Adding {:s} to system matrix element ({:d},{:d})", + Logger::realToString(value), row, column); + Math::addToMatrixElement(mat, row, column, value); } void MNAStampUtils::addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, - Int maxFreq, Int freqIdx) { + Int maxFreq, Int freqIdx, + const Logger::Log &mSLog) { + SPDLOG_LOGGER_DEBUG(mSLog, "- Adding {:s} to system matrix element ({:d},{:d})", + Logger::complexToString(value), row, column); + Math::addToMatrixElement(mat, row, column, value, maxFreq, freqIdx); } diff --git a/dpsim-models/src/SP/SP_Ph1_Capacitor.cpp b/dpsim-models/src/SP/SP_Ph1_Capacitor.cpp index eec0190797..3a07366a83 100644 --- a/dpsim-models/src/SP/SP_Ph1_Capacitor.cpp +++ b/dpsim-models/src/SP/SP_Ph1_Capacitor.cpp @@ -71,7 +71,7 @@ void SP::Ph1::Capacitor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { MNAStampUtils::stampAdmittance(mSusceptance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), terminalNotGrounded(0), - terminalNotGrounded(1)); + terminalNotGrounded(1), mSLog); } void SP::Ph1::Capacitor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/SP/SP_Ph1_Inductor.cpp b/dpsim-models/src/SP/SP_Ph1_Inductor.cpp index a1412d1b59..c7167e01ad 100644 --- a/dpsim-models/src/SP/SP_Ph1_Inductor.cpp +++ b/dpsim-models/src/SP/SP_Ph1_Inductor.cpp @@ -68,7 +68,7 @@ void SP::Ph1::Inductor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { MNAStampUtils::stampAdmittance(mSusceptance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), terminalNotGrounded(0), - terminalNotGrounded(1)); + terminalNotGrounded(1), mSLog); } void SP::Ph1::Inductor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/SP/SP_Ph1_Resistor.cpp b/dpsim-models/src/SP/SP_Ph1_Resistor.cpp index a95fc00bac..62880d0474 100644 --- a/dpsim-models/src/SP/SP_Ph1_Resistor.cpp +++ b/dpsim-models/src/SP/SP_Ph1_Resistor.cpp @@ -109,7 +109,7 @@ void SP::Ph1::Resistor::mnaCompApplySystemMatrixStamp( MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), terminalNotGrounded(0), - terminalNotGrounded(1)); + terminalNotGrounded(1), mSLog); } void SP::Ph1::Resistor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/SP/SP_Ph3_Capacitor.cpp b/dpsim-models/src/SP/SP_Ph3_Capacitor.cpp index c3aa2b2fd8..ac38f68188 100644 --- a/dpsim-models/src/SP/SP_Ph3_Capacitor.cpp +++ b/dpsim-models/src/SP/SP_Ph3_Capacitor.cpp @@ -78,7 +78,7 @@ void SP::Ph3::Capacitor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { MNAStampUtils::stampAdmittanceMatrix( mSusceptance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), - terminalNotGrounded(0), terminalNotGrounded(1)); + terminalNotGrounded(0), terminalNotGrounded(1), mSLog); } void SP::Ph3::Capacitor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/SP/SP_Ph3_Inductor.cpp b/dpsim-models/src/SP/SP_Ph3_Inductor.cpp index ae827f16ef..e40f7007f3 100644 --- a/dpsim-models/src/SP/SP_Ph3_Inductor.cpp +++ b/dpsim-models/src/SP/SP_Ph3_Inductor.cpp @@ -80,7 +80,7 @@ void SP::Ph3::Inductor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { MNAStampUtils::stampAdmittanceMatrix( mSusceptance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), - terminalNotGrounded(0), terminalNotGrounded(1)); + terminalNotGrounded(0), terminalNotGrounded(1), mSLog); } void SP::Ph3::Inductor::mnaCompAddPostStepDependencies( diff --git a/dpsim-models/src/SP/SP_Ph3_Resistor.cpp b/dpsim-models/src/SP/SP_Ph3_Resistor.cpp index 009c17680f..0b1117240e 100644 --- a/dpsim-models/src/SP/SP_Ph3_Resistor.cpp +++ b/dpsim-models/src/SP/SP_Ph3_Resistor.cpp @@ -58,8 +58,7 @@ void SP::Ph3::Resistor::mnaCompApplySystemMatrixStamp( MNAStampUtils::stampAdmittanceMatrix( conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), - terminalNotGrounded(0), terminalNotGrounded(1)); - + terminalNotGrounded(0), terminalNotGrounded(1), mSLog); } void SP::Ph3::Resistor::mnaCompAddPostStepDependencies( From 6d2b3c62a6229d4c36ca727d17c2a2588f4af3a1 Mon Sep 17 00:00:00 2001 From: Georgii Tishenin Date: Thu, 30 May 2024 22:54:19 +0200 Subject: [PATCH 7/7] Use fixed-size matrix types for conductance matrix of Ph_3_Resistor Signed-off-by: Georgii Tishenin --- dpsim-models/src/DP/DP_Ph3_Resistor.cpp | 2 +- dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp | 4 ++-- dpsim-models/src/SP/SP_Ph3_Resistor.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dpsim-models/src/DP/DP_Ph3_Resistor.cpp b/dpsim-models/src/DP/DP_Ph3_Resistor.cpp index 2a93eb5306..7ca6a3a828 100644 --- a/dpsim-models/src/DP/DP_Ph3_Resistor.cpp +++ b/dpsim-models/src/DP/DP_Ph3_Resistor.cpp @@ -56,7 +56,7 @@ void DP::Ph3::Resistor::mnaCompInitialize(Real omega, Real timeStep, void DP::Ph3::Resistor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - MatrixComp conductance = Matrix::Zero(3, 3); + MatrixFixedSizeComp<3, 3> conductance = Matrix::Zero(3, 3); conductance.real() = (**mResistance).inverse(); MNAStampUtils::stampAdmittanceMatrix( diff --git a/dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp b/dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp index d90bd772dd..88ce5229de 100644 --- a/dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp +++ b/dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp @@ -69,8 +69,8 @@ void EMT::Ph3::Resistor::mnaCompInitialize(Real omega, Real timeStep, void EMT::Ph3::Resistor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - Matrix conductance = Matrix::Zero(3, 3); - Math::invertMatrix(**mResistance, conductance); + MatrixFixedSize<3, 3> conductance = Matrix::Zero(3, 3); + conductance = (**mResistance).inverse(); MNAStampUtils::stampConductanceMatrix( conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), diff --git a/dpsim-models/src/SP/SP_Ph3_Resistor.cpp b/dpsim-models/src/SP/SP_Ph3_Resistor.cpp index 0b1117240e..8c6cebfc59 100644 --- a/dpsim-models/src/SP/SP_Ph3_Resistor.cpp +++ b/dpsim-models/src/SP/SP_Ph3_Resistor.cpp @@ -53,7 +53,7 @@ void SP::Ph3::Resistor::mnaCompInitialize(Real omega, Real timeStep, void SP::Ph3::Resistor::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { - MatrixComp conductance = Matrix::Zero(3, 3); + MatrixFixedSizeComp<3, 3> conductance = Matrix::Zero(3, 3); conductance.real() = (**mResistance).inverse(); MNAStampUtils::stampAdmittanceMatrix(