From 0f2d996d2861c63c90a1c12ce4322f53f5cb9f5a Mon Sep 17 00:00:00 2001 From: Georgii Tishenin Date: Wed, 17 Jul 2024 13:05:48 +0200 Subject: [PATCH 1/3] MNAStampUtils: Fix stamping of full matrix Signed-off-by: Georgii Tishenin --- .../include/dpsim-models/MNAStampUtils.h | 20 +---- dpsim-models/src/MNAStampUtils.cpp | 73 +++++++------------ 2 files changed, 29 insertions(+), 64 deletions(-) diff --git a/dpsim-models/include/dpsim-models/MNAStampUtils.h b/dpsim-models/include/dpsim-models/MNAStampUtils.h index 1dca3b4130..1abaf77e0c 100644 --- a/dpsim-models/include/dpsim-models/MNAStampUtils.h +++ b/dpsim-models/include/dpsim-models/MNAStampUtils.h @@ -66,23 +66,9 @@ class MNAStampUtils { Int freqIdx, const Logger::Log &mSLog); template - static void stampValueNoConditions(T value, SparseMatrixRow &mat, - UInt node1Index, UInt node2Index, - Int maxFreq, Int freqIdx, - const Logger::Log &mSLog); - - template - static void stampValueOnDiagonalNoConditions(T value, SparseMatrixRow &mat, - UInt nodeIndex, Int maxFreq, - Int freqIdx, - const Logger::Log &mSLog); - - template - static void stampValueOffDiagonalNoConditions(T value, SparseMatrixRow &mat, - UInt node1Index, - UInt node2Index, Int maxFreq, - Int freqIdx, - const Logger::Log &mSLog); + static void stampToMatrix(T value, SparseMatrixRow &mat, UInt row1, + UInt column1, UInt row2, UInt column2, Int maxFreq, + Int freqIdx, const Logger::Log &mSLog); static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Real value, Int maxFreq, diff --git a/dpsim-models/src/MNAStampUtils.cpp b/dpsim-models/src/MNAStampUtils.cpp index de3159f9ad..ce17d72929 100644 --- a/dpsim-models/src/MNAStampUtils.cpp +++ b/dpsim-models/src/MNAStampUtils.cpp @@ -95,14 +95,14 @@ void MNAStampUtils::stampValue(T value, SparseMatrixRow &mat, UInt node1Index, Bool isTerminal2NotGrounded, Int maxFreq, Int freqIdx, const Logger::Log &mSLog) { if (isTerminal1NotGrounded && isTerminal2NotGrounded) { - stampValueNoConditions(value, mat, node1Index, node2Index, maxFreq, freqIdx, - mSLog); + stampToMatrix(value, mat, node1Index, node1Index, node2Index, node2Index, + maxFreq, freqIdx, mSLog); } else if (isTerminal1NotGrounded) { - stampValueOnDiagonalNoConditions(value, mat, node1Index, maxFreq, freqIdx, - mSLog); + addToMatrixElement(mat, node1Index, node1Index, value, maxFreq, freqIdx, + mSLog); } else if (isTerminal2NotGrounded) { - stampValueOnDiagonalNoConditions(value, mat, node2Index, maxFreq, freqIdx, - mSLog); + addToMatrixElement(mat, node2Index, node2Index, value, maxFreq, freqIdx, + mSLog); } } @@ -121,22 +121,22 @@ void MNAStampUtils::stampMatrix(const MatrixVar &matrix, 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, mSLog); + stampToMatrix(matrix(i, j), mat, node1Index + i, node1Index + j, + node2Index + i, 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, mSLog); + addToMatrixElement(mat, node1Index + i, node1Index + j, matrix(i, j), + 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, mSLog); + addToMatrixElement(mat, node2Index + i, node2Index + j, matrix(i, j), + maxFreq, freqIdx, mSLog); } } } @@ -149,52 +149,31 @@ void MNAStampUtils::stampValueAsScalarMatrix( Int maxFreq, Int freqIdx, const Logger::Log &mSLog) { if (isTerminal1NotGrounded && isTerminal2NotGrounded) { for (UInt i = 0; i < sizeOfScalarMatrix; i++) { - stampValueNoConditions(value, mat, node1Index + i, node2Index + i, - maxFreq, freqIdx, mSLog); + stampToMatrix(value, mat, node1Index + i, node1Index + i, node2Index + i, + node2Index + i, maxFreq, freqIdx, mSLog); } } else if (isTerminal1NotGrounded) { for (UInt i = 0; i < sizeOfScalarMatrix; i++) { - stampValueOnDiagonalNoConditions(value, mat, node1Index + i, maxFreq, - freqIdx, mSLog); + addToMatrixElement(mat, node1Index + i, node1Index + i, value, maxFreq, + freqIdx, mSLog); } } else if (isTerminal2NotGrounded) { for (UInt i = 0; i < sizeOfScalarMatrix; i++) { - stampValueOnDiagonalNoConditions(value, mat, node2Index + i, maxFreq, - freqIdx, mSLog); + addToMatrixElement(mat, node2Index + i, node2Index + i, value, maxFreq, + freqIdx, mSLog); } } } template -void MNAStampUtils::stampValueNoConditions(T value, SparseMatrixRow &mat, - UInt node1Index, UInt node2Index, - 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, mSLog); -} - -template -void MNAStampUtils::stampValueOnDiagonalNoConditions(T value, - SparseMatrixRow &mat, - UInt nodeIndex, - 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, const Logger::Log &mSLog) { - addToMatrixElement(mat, node1Index, node2Index, -value, maxFreq, freqIdx, - mSLog); - addToMatrixElement(mat, node2Index, node1Index, -value, maxFreq, freqIdx, - mSLog); +void MNAStampUtils::stampToMatrix(T value, SparseMatrixRow &mat, UInt row1, + UInt column1, UInt row2, UInt column2, + Int maxFreq, Int freqIdx, + const Logger::Log &mSLog) { + addToMatrixElement(mat, row1, column1, value, maxFreq, freqIdx, mSLog); + addToMatrixElement(mat, row1, column2, -value, maxFreq, freqIdx, mSLog); + addToMatrixElement(mat, row2, column1, -value, maxFreq, freqIdx, mSLog); + addToMatrixElement(mat, row2, column2, value, maxFreq, freqIdx, mSLog); } // These wrapper functions standardize the signatures of "Math::addToMatrixElement" for Real and Complex "value" parameters, From 15ed6ee676c02161405601eb0856125438077e66 Mon Sep 17 00:00:00 2001 From: Georgii Tishenin Date: Wed, 17 Jul 2024 17:21:26 +0200 Subject: [PATCH 2/3] MNAStampUtils: add matrix stamp functions with optimized logic Signed-off-by: Georgii Tishenin --- .../include/dpsim-models/MNAStampUtils.h | 22 ++++++ dpsim-models/src/MNAStampUtils.cpp | 72 ++++++++++++++----- 2 files changed, 77 insertions(+), 17 deletions(-) diff --git a/dpsim-models/include/dpsim-models/MNAStampUtils.h b/dpsim-models/include/dpsim-models/MNAStampUtils.h index 1abaf77e0c..d3372bf41b 100644 --- a/dpsim-models/include/dpsim-models/MNAStampUtils.h +++ b/dpsim-models/include/dpsim-models/MNAStampUtils.h @@ -26,6 +26,15 @@ class MNAStampUtils { Bool isTerminal2NotGrounded, const Logger::Log &mSLog); + static void stamp3x3ConductanceMatrixBetween2Nodes( + const Matrix &conductanceMat, SparseMatrixRow &mat, UInt node1Index, + UInt node2Index, const Logger::Log &mSLog); + + static void stamp3x3ConductanceMatrixNodeToGround(const Matrix &conductanceMat, + SparseMatrixRow &mat, + UInt nodeIndex, + const Logger::Log &mSLog); + static void stampAdmittanceMatrix( const MatrixComp &admittanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, @@ -57,6 +66,19 @@ class MNAStampUtils { Bool isTerminal2NotGrounded, Int maxFreq, Int freqIdx, const Logger::Log &mSLog); + template + static void stampMatrixBetween2Nodes(const MatrixVar &matrix, + UInt sizeOfMatrix, SparseMatrixRow &mat, + UInt node1Index, UInt node2Index, + Int maxFreq, Int freqIdx, + const Logger::Log &mSLog); + + template + static void stampMatrixNodeToGround(const MatrixVar &matrix, + UInt sizeOfMatrix, SparseMatrixRow &mat, + UInt nodeIndex, Int maxFreq, Int freqIdx, + const Logger::Log &mSLog); + template static void stampValueAsScalarMatrix(T value, UInt sizeOfScalarMatrix, SparseMatrixRow &mat, UInt node1Index, diff --git a/dpsim-models/src/MNAStampUtils.cpp b/dpsim-models/src/MNAStampUtils.cpp index ce17d72929..6362607eca 100644 --- a/dpsim-models/src/MNAStampUtils.cpp +++ b/dpsim-models/src/MNAStampUtils.cpp @@ -44,6 +44,29 @@ void MNAStampUtils::stampConductanceMatrix(const Matrix &conductanceMat, SPDLOG_LOGGER_DEBUG(mSLog, "Stamping completed."); } +void MNAStampUtils::stamp3x3ConductanceMatrixBetween2Nodes( + const Matrix &conductanceMat, SparseMatrixRow &mat, UInt node1Index, + UInt node2Index, const Logger::Log &mSLog) { + SPDLOG_LOGGER_DEBUG( + mSLog, "Start stamping 3x3 conductance matrix between two nodes..."); + + stampMatrixBetween2Nodes(conductanceMat, 3, mat, node1Index, node2Index, 1, 0, + mSLog); + + SPDLOG_LOGGER_DEBUG(mSLog, "Stamping completed."); +} + +void MNAStampUtils::stamp3x3ConductanceMatrixNodeToGround( + const Matrix &conductanceMat, SparseMatrixRow &mat, UInt nodeIndex, + const Logger::Log &mSLog) { + SPDLOG_LOGGER_DEBUG( + mSLog, "Start stamping 3x3 conductance matrix from node to ground..."); + + stampMatrixNodeToGround(conductanceMat, 3, mat, nodeIndex, 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, @@ -119,25 +142,40 @@ void MNAStampUtils::stampMatrix(const MatrixVar &matrix, } if (isTerminal1NotGrounded && isTerminal2NotGrounded) { - for (UInt i = 0; i < numRows; i++) { - for (UInt j = 0; j < numCols; j++) { - stampToMatrix(matrix(i, j), mat, node1Index + i, node1Index + j, - node2Index + i, node2Index + j, maxFreq, freqIdx, mSLog); - } - } + stampMatrixBetween2Nodes(matrix, numRows, mat, node1Index, node2Index, + maxFreq, freqIdx, mSLog); } else if (isTerminal1NotGrounded) { - for (UInt i = 0; i < numRows; i++) { - for (UInt j = 0; j < numCols; j++) { - addToMatrixElement(mat, node1Index + i, node1Index + j, matrix(i, j), - maxFreq, freqIdx, mSLog); - } - } + stampMatrixNodeToGround(matrix, numRows, mat, node1Index, maxFreq, freqIdx, + mSLog); } else if (isTerminal2NotGrounded) { - for (UInt i = 0; i < numRows; i++) { - for (UInt j = 0; j < numCols; j++) { - addToMatrixElement(mat, node2Index + i, node2Index + j, matrix(i, j), - maxFreq, freqIdx, mSLog); - } + stampMatrixNodeToGround(matrix, numRows, mat, node2Index, maxFreq, freqIdx, + mSLog); + } +} + +template +void MNAStampUtils::stampMatrixBetween2Nodes(const MatrixVar &matrix, + UInt sizeOfMatrix, + SparseMatrixRow &mat, + UInt node1Index, UInt node2Index, + Int maxFreq, Int freqIdx, + const Logger::Log &mSLog) { + for (UInt i = 0; i < sizeOfMatrix; i++) { + for (UInt j = 0; j < sizeOfMatrix; j++) { + stampToMatrix(matrix(i, j), mat, node1Index + i, node1Index + j, + node2Index + i, node2Index + j, maxFreq, freqIdx, mSLog); + } + } +} + +template +void MNAStampUtils::stampMatrixNodeToGround( + const MatrixVar &matrix, UInt sizeOfMatrix, SparseMatrixRow &mat, + UInt nodeIndex, Int maxFreq, Int freqIdx, const Logger::Log &mSLog) { + for (UInt i = 0; i < sizeOfMatrix; i++) { + for (UInt j = 0; j < sizeOfMatrix; j++) { + addToMatrixElement(mat, nodeIndex + i, nodeIndex + j, matrix(i, j), + maxFreq, freqIdx, mSLog); } } } From c06b0e9000db0ca0622b554113422dcd7c301520 Mon Sep 17 00:00:00 2001 From: Georgii Tishenin Date: Wed, 17 Jul 2024 17:45:10 +0200 Subject: [PATCH 3/3] Reuse conductance stamping logic for EMT synchron generators Signed-off-by: Georgii Tishenin --- ...T_Ph3_ReducedOrderSynchronGeneratorVBR.cpp | 140 +----------------- .../src/EMT/EMT_Ph3_SynchronGeneratorVBR.cpp | 23 +-- 2 files changed, 8 insertions(+), 155 deletions(-) diff --git a/dpsim-models/src/EMT/EMT_Ph3_ReducedOrderSynchronGeneratorVBR.cpp b/dpsim-models/src/EMT/EMT_Ph3_ReducedOrderSynchronGeneratorVBR.cpp index 2147953464..be6e7cf5a0 100644 --- a/dpsim-models/src/EMT/EMT_Ph3_ReducedOrderSynchronGeneratorVBR.cpp +++ b/dpsim-models/src/EMT/EMT_Ph3_ReducedOrderSynchronGeneratorVBR.cpp @@ -184,25 +184,8 @@ void EMT::Ph3::ReducedOrderSynchronGeneratorVBR::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { if (mModelAsNortonSource) { - // Stamp conductance matrix - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 0), mConductanceMatrix(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 1), mConductanceMatrix(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 2), mConductanceMatrix(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 0), mConductanceMatrix(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 1), mConductanceMatrix(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 2), mConductanceMatrix(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 0), mConductanceMatrix(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 1), mConductanceMatrix(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 2), mConductanceMatrix(2, 2)); + MNAStampUtils::stamp3x3ConductanceMatrixNodeToGround( + mConductanceMatrix, systemMatrix, matrixNodeIndex(0), mSLog); } else { // Stamp voltage source Math::addToMatrixElement( @@ -225,121 +208,10 @@ void EMT::Ph3::ReducedOrderSynchronGeneratorVBR::mnaCompApplySystemMatrixStamp( mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), 1); // Stamp conductance matrix - - // set upper left block, 3x3 entries - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), - mConductanceMatrix(0, 0)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), - mConductanceMatrix(0, 1)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), - mConductanceMatrix(0, 2)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), - mConductanceMatrix(1, 0)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), - mConductanceMatrix(1, 1)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), - mConductanceMatrix(1, 2)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), - mConductanceMatrix(2, 0)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), - mConductanceMatrix(2, 1)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), - mConductanceMatrix(2, 2)); - - // set buttom right block, 3x3 entries - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 0), mConductanceMatrix(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 1), mConductanceMatrix(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 2), mConductanceMatrix(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 0), mConductanceMatrix(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 1), mConductanceMatrix(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 2), mConductanceMatrix(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 0), mConductanceMatrix(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 1), mConductanceMatrix(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 2), mConductanceMatrix(2, 2)); - - // Set off diagonal blocks - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), - matrixNodeIndex(0, 0), -mConductanceMatrix(0, 0)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), - matrixNodeIndex(0, 1), -mConductanceMatrix(0, 1)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), - matrixNodeIndex(0, 2), -mConductanceMatrix(0, 2)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), - matrixNodeIndex(0, 0), -mConductanceMatrix(1, 0)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), - matrixNodeIndex(0, 1), -mConductanceMatrix(1, 1)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), - matrixNodeIndex(0, 2), -mConductanceMatrix(1, 2)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), - matrixNodeIndex(0, 0), -mConductanceMatrix(2, 0)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), - matrixNodeIndex(0, 1), -mConductanceMatrix(2, 1)); - Math::addToMatrixElement(systemMatrix, - mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), - matrixNodeIndex(0, 2), -mConductanceMatrix(2, 2)); - - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), - -mConductanceMatrix(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), - -mConductanceMatrix(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), - -mConductanceMatrix(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), - -mConductanceMatrix(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), - -mConductanceMatrix(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), - -mConductanceMatrix(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), - -mConductanceMatrix(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), - -mConductanceMatrix(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), - -mConductanceMatrix(2, 2)); + MNAStampUtils::stamp3x3ConductanceMatrixBetween2Nodes( + mConductanceMatrix, systemMatrix, + mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), matrixNodeIndex(0), + mSLog); } } diff --git a/dpsim-models/src/EMT/EMT_Ph3_SynchronGeneratorVBR.cpp b/dpsim-models/src/EMT/EMT_Ph3_SynchronGeneratorVBR.cpp index a74c47ff63..86b38cb519 100644 --- a/dpsim-models/src/EMT/EMT_Ph3_SynchronGeneratorVBR.cpp +++ b/dpsim-models/src/EMT/EMT_Ph3_SynchronGeneratorVBR.cpp @@ -258,27 +258,8 @@ void EMT::Ph3::SynchronGeneratorVBR::mnaCompPreStep(Real time, void EMT::Ph3::SynchronGeneratorVBR::mnaCompApplySystemMatrixStamp( SparseMatrixRow &systemMatrix) { if (terminalNotGrounded(0)) { - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 0), mConductanceMat(0, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 1), mConductanceMat(0, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), - matrixNodeIndex(0, 2), mConductanceMat(0, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 0), mConductanceMat(1, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 1), mConductanceMat(1, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), - matrixNodeIndex(0, 2), mConductanceMat(1, 2)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 0), mConductanceMat(2, 0)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 1), mConductanceMat(2, 1)); - Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), - matrixNodeIndex(0, 2), mConductanceMat(2, 2)); - // SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance, matrixNodeIndex(0,0), matrixNodeIndex(0,0)); - // SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance, matrixNodeIndex(0,1), matrixNodeIndex(0,1)); - // SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance, matrixNodeIndex(0,2), matrixNodeIndex(0,2)); + MNAStampUtils::stamp3x3ConductanceMatrixNodeToGround( + mConductanceMat, systemMatrix, matrixNodeIndex(0), mSLog); } }