-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reuse code for MNA matrix stamp operations (#297)
### Summary This PR introduces the utility class `MNAStampUtils` for MNA matrix stamping operations. It standardizes and reuses the stamping logic for 1-phase and 3-phase EMT, DP and SP R, L, C components. The motivation is to make the codebase more maintainable and reduce redundancy. ### Additional Context - **Issue Reference**: These changes were discussed in issue [#288](#288) - Reuse conductance stamp code. - **Future Plans**: There are plans for future PRs to extend this approach to other components deriving from the `MNASimPowerComp` class. This might involve adding more variations of stamping functions to `MNAStampUtils` to accommodate different parameter lists or optimized logic for specific cases, such as components with a single terminal or symmetric phase impedances.
- Loading branch information
Showing
22 changed files
with
320 additions
and
1,261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#pragma once | ||
|
||
#include <dpsim-models/Logger.h> | ||
#include <dpsim-models/MathUtils.h> | ||
|
||
namespace CPS { | ||
class MNAStampUtils { | ||
public: | ||
static void stampConductance(Real conductance, SparseMatrixRow &mat, | ||
UInt node1Index, UInt node2Index, | ||
Bool isTerminal1NotGrounded, | ||
Bool isTerminal2NotGrounded, | ||
const Logger::Log &mSLog); | ||
|
||
static void stampAdmittance(Complex admittance, SparseMatrixRow &mat, | ||
UInt node1Index, UInt node2Index, | ||
Bool isTerminal1NotGrounded, | ||
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, | ||
const Logger::Log &mSLog); | ||
|
||
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 <typename T> | ||
static void stampValue(T value, SparseMatrixRow &mat, UInt node1Index, | ||
UInt node2Index, Bool isTerminal1NotGrounded, | ||
Bool isTerminal2NotGrounded, Int maxFreq, Int freqIdx, | ||
const Logger::Log &mSLog); | ||
|
||
template <typename T> | ||
static void stampMatrix(const MatrixVar<T> &matrix, SparseMatrixRow &mat, | ||
UInt node1Index, UInt node2Index, | ||
Bool isTerminal1NotGrounded, | ||
Bool isTerminal2NotGrounded, Int maxFreq, Int freqIdx, | ||
const Logger::Log &mSLog); | ||
|
||
template <typename T> | ||
static void stampValueNoConditions(T value, SparseMatrixRow &mat, | ||
UInt node1Index, UInt node2Index, | ||
Int maxFreq, Int freqIdx, | ||
const Logger::Log &mSLog); | ||
|
||
template <typename T> | ||
static void stampValueOnDiagonalNoConditions(T value, SparseMatrixRow &mat, | ||
UInt nodeIndex, Int maxFreq, | ||
Int freqIdx, | ||
const Logger::Log &mSLog); | ||
|
||
template <typename T> | ||
static void stampValueOffDiagonalNoConditions(T value, SparseMatrixRow &mat, | ||
UInt node1Index, | ||
UInt node2Index, Int maxFreq, | ||
Int freqIdx, | ||
const Logger::Log &mSLog); | ||
|
||
static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, | ||
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, | ||
const Logger::Log &mSLog); | ||
}; | ||
} // namespace CPS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.