Skip to content

Commit

Permalink
MNAStampUtils: Add functions for stamping value as a scalar matrix
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 authored and m-mirz committed Jun 20, 2024
1 parent ffc5080 commit 12a4c6c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 6 deletions.
20 changes: 20 additions & 0 deletions dpsim-models/include/dpsim-models/MNAStampUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ class MNAStampUtils {
UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded,
const Logger::Log &mSLog, Int maxFreq = 1, Int freqIdx = 0);

/// Stamps conductance as a 3x3 scalar matrix (a diagonal matrix, where all diagonal elements are equal to conductance).
static void stampConductanceAs3x3ScalarMatrix(
Real conductance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index,
Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded,
const Logger::Log &mSLog);

/// Stamps admittance as a 3x3 scalar matrix (a diagonal matrix, where all diagonal elements are equal to admittance).
static void stampAdmittanceAs3x3ScalarMatrix(
Complex admittance, 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,
Expand All @@ -45,6 +57,14 @@ class MNAStampUtils {
Bool isTerminal2NotGrounded, Int maxFreq, Int freqIdx,
const Logger::Log &mSLog);

template <typename T>
static void stampValueAsScalarMatrix(T value, UInt sizeOfScalarMatrix,
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,
Expand Down
65 changes: 59 additions & 6 deletions dpsim-models/src/MNAStampUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ void MNAStampUtils::stampAdmittance(Complex admittance, SparseMatrixRow &mat,
const Logger::Log &mSLog, Int maxFreq,
Int freqIdx) {
SPDLOG_LOGGER_DEBUG(
mSLog, "Start stamping admittance for frequency index {:d}...",
freqIdx);
mSLog, "Start stamping admittance for frequency index {:d}...", freqIdx);

stampValue(admittance, mat, node1Index, node2Index, isTerminal1NotGrounded,
isTerminal2NotGrounded, maxFreq, freqIdx, mSLog);
Expand All @@ -50,8 +49,7 @@ void MNAStampUtils::stampAdmittanceMatrix(
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}...",
mSLog, "Start stamping admittance matrix for frequency index {:d}...",
freqIdx);

stampMatrix(admittanceMat, mat, node1Index, node2Index,
Expand All @@ -61,6 +59,36 @@ void MNAStampUtils::stampAdmittanceMatrix(
SPDLOG_LOGGER_DEBUG(mSLog, "Stamping completed.");
}

void MNAStampUtils::stampConductanceAs3x3ScalarMatrix(
Real conductance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index,
Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded,
const Logger::Log &mSLog) {
SPDLOG_LOGGER_DEBUG(mSLog,
"Start stamping conductance as 3x3 scalar matrix...");

stampValueAsScalarMatrix(conductance, 3, mat, node1Index, node2Index,
isTerminal1NotGrounded, isTerminal2NotGrounded, 1, 0,
mSLog);

SPDLOG_LOGGER_DEBUG(mSLog, "Stamping completed.");
}

void MNAStampUtils::stampAdmittanceAs3x3ScalarMatrix(
Complex admittance, 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 as 3x3 scalar matrix for "
"frequency index {:d}...",
freqIdx);

stampValueAsScalarMatrix(admittance, 3, mat, node1Index, node2Index,
isTerminal1NotGrounded, isTerminal2NotGrounded,
maxFreq, freqIdx, mSLog);

SPDLOG_LOGGER_DEBUG(mSLog, "Stamping completed.");
}

template <typename T>
void MNAStampUtils::stampValue(T value, SparseMatrixRow &mat, UInt node1Index,
UInt node2Index, Bool isTerminal1NotGrounded,
Expand Down Expand Up @@ -114,6 +142,29 @@ void MNAStampUtils::stampMatrix(const MatrixVar<T> &matrix,
}
}

template <typename T>
void MNAStampUtils::stampValueAsScalarMatrix(
T value, UInt sizeOfScalarMatrix, SparseMatrixRow &mat, UInt node1Index,
UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded,
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);
}
} else if (isTerminal1NotGrounded) {
for (UInt i = 0; i < sizeOfScalarMatrix; i++) {
stampValueOnDiagonalNoConditions(value, mat, node1Index + i, maxFreq,
freqIdx, mSLog);
}
} else if (isTerminal2NotGrounded) {
for (UInt i = 0; i < sizeOfScalarMatrix; i++) {
stampValueOnDiagonalNoConditions(value, mat, node2Index + i, maxFreq,
freqIdx, mSLog);
}
}
}

template <typename T>
void MNAStampUtils::stampValueNoConditions(T value, SparseMatrixRow &mat,
UInt node1Index, UInt node2Index,
Expand Down Expand Up @@ -152,7 +203,8 @@ void MNAStampUtils::addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row,
Matrix::Index column, Real value,
Int maxFreq, Int freqIdx,
const Logger::Log &mSLog) {
SPDLOG_LOGGER_DEBUG(mSLog, "- Adding {:s} to system matrix element ({:d},{:d})",
SPDLOG_LOGGER_DEBUG(mSLog,
"- Adding {:s} to system matrix element ({:d},{:d})",
Logger::realToString(value), row, column);

Math::addToMatrixElement(mat, row, column, value);
Expand All @@ -162,7 +214,8 @@ void MNAStampUtils::addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row,
Matrix::Index column, Complex value,
Int maxFreq, Int freqIdx,
const Logger::Log &mSLog) {
SPDLOG_LOGGER_DEBUG(mSLog, "- Adding {:s} to system matrix element ({:d},{:d})",
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);
Expand Down

0 comments on commit 12a4c6c

Please sign in to comment.