Skip to content

Commit

Permalink
MNAStampUtils: add matrix stamp functions with optimized logic
Browse files Browse the repository at this point in the history
Signed-off-by: Georgii Tishenin <georgii.tishenin@eonerc.rwth-aachen.de>
  • Loading branch information
georgii-tishenin committed Jul 17, 2024
1 parent 0f2d996 commit 15ed6ee
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 17 deletions.
22 changes: 22 additions & 0 deletions dpsim-models/include/dpsim-models/MNAStampUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -57,6 +66,19 @@ class MNAStampUtils {
Bool isTerminal2NotGrounded, Int maxFreq, Int freqIdx,
const Logger::Log &mSLog);

template <typename T>
static void stampMatrixBetween2Nodes(const MatrixVar<T> &matrix,
UInt sizeOfMatrix, SparseMatrixRow &mat,
UInt node1Index, UInt node2Index,
Int maxFreq, Int freqIdx,
const Logger::Log &mSLog);

template <typename T>
static void stampMatrixNodeToGround(const MatrixVar<T> &matrix,
UInt sizeOfMatrix, SparseMatrixRow &mat,
UInt nodeIndex, Int maxFreq, Int freqIdx,
const Logger::Log &mSLog);

template <typename T>
static void stampValueAsScalarMatrix(T value, UInt sizeOfScalarMatrix,
SparseMatrixRow &mat, UInt node1Index,
Expand Down
72 changes: 55 additions & 17 deletions dpsim-models/src/MNAStampUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -119,25 +142,40 @@ void MNAStampUtils::stampMatrix(const MatrixVar<T> &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 <typename T>
void MNAStampUtils::stampMatrixBetween2Nodes(const MatrixVar<T> &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 <typename T>
void MNAStampUtils::stampMatrixNodeToGround(
const MatrixVar<T> &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);
}
}
}
Expand Down

0 comments on commit 15ed6ee

Please sign in to comment.