Skip to content

Commit

Permalink
Reuse conductance/admittance stamping logic for switches
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 12a4c6c commit 5fffc7f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 497 deletions.
71 changes: 6 additions & 65 deletions dpsim-models/src/DP/DP_Ph1_Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,78 +54,19 @@ void DP::Ph1::Switch::mnaCompApplySystemMatrixStamp(
Complex conductance = (**mIsClosed) ? Complex(1. / **mClosedResistance, 0)
: Complex(1. / **mOpenResistance, 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_TRACE(mSLog, "-- Stamp ---");
if (terminalNotGrounded(0))
SPDLOG_LOGGER_TRACE(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(conductance),
matrixNodeIndex(0), matrixNodeIndex(0));
if (terminalNotGrounded(1))
SPDLOG_LOGGER_TRACE(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(conductance),
matrixNodeIndex(1), matrixNodeIndex(1));
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
SPDLOG_LOGGER_TRACE(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(-conductance),
matrixNodeIndex(0), matrixNodeIndex(1));
SPDLOG_LOGGER_TRACE(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), mSLog);
}

void DP::Ph1::Switch::mnaCompApplySwitchSystemMatrixStamp(
Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
Complex conductance = (closed) ? Complex(1. / **mClosedResistance, 0)
: Complex(1. / **mOpenResistance, 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_TRACE(mSLog, "-- Stamp ---");
if (terminalNotGrounded(0))
SPDLOG_LOGGER_TRACE(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(conductance),
matrixNodeIndex(0), matrixNodeIndex(0));
if (terminalNotGrounded(1))
SPDLOG_LOGGER_TRACE(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(conductance),
matrixNodeIndex(1), matrixNodeIndex(1));
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
SPDLOG_LOGGER_TRACE(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(-conductance),
matrixNodeIndex(0), matrixNodeIndex(1));
SPDLOG_LOGGER_TRACE(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), mSLog);
}

void DP::Ph1::Switch::mnaCompApplyRightSideVectorStamp(Matrix &rightVector) {}
Expand Down
53 changes: 6 additions & 47 deletions dpsim-models/src/DP/DP_Ph1_varResSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,60 +47,19 @@ void DP::Ph1::varResSwitch::mnaCompApplySystemMatrixStamp(
Complex conductance = (**mIsClosed) ? Complex(1. / **mClosedResistance, 0)
: Complex(1. / **mOpenResistance, 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);
}
MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0),
matrixNodeIndex(1), terminalNotGrounded(0),
terminalNotGrounded(1), mSLog);
}

void DP::Ph1::varResSwitch::mnaCompApplySwitchSystemMatrixStamp(
Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
Complex conductance = (closed) ? Complex(1. / **mClosedResistance, 0)
: Complex(1. / **mOpenResistance, 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 ---");
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), mSLog);
}

void DP::Ph1::varResSwitch::mnaCompApplyRightSideVectorStamp(
Expand Down
60 changes: 6 additions & 54 deletions dpsim-models/src/DP/DP_Ph3_SeriesSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,67 +50,19 @@ void DP::Ph3::SeriesSwitch::mnaCompApplySystemMatrixStamp(
Complex conductance = (**mIsClosed) ? Complex(1. / **mClosedResistance, 0)
: Complex(1. / **mOpenResistance, 0);

// 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);
}

if (terminalNotGrounded(0))
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
matrixNodeIndices(0)[0], matrixNodeIndices(0)[0]);
if (terminalNotGrounded(1))
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
matrixNodeIndices(1)[0], matrixNodeIndices(1)[0]);
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
matrixNodeIndices(0)[0], matrixNodeIndices(1)[0]);
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
matrixNodeIndices(1)[0], matrixNodeIndices(0)[0]);
}
MNAStampUtils::stampAdmittanceAs3x3ScalarMatrix(
conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
}

void DP::Ph3::SeriesSwitch::mnaCompApplySwitchSystemMatrixStamp(
Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
Complex conductance = (closed) ? Complex(1. / **mClosedResistance, 0)
: Complex(1. / **mOpenResistance, 0);

// 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);
}

if (terminalNotGrounded(0))
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
matrixNodeIndices(0)[0], matrixNodeIndices(0)[0]);
if (terminalNotGrounded(1))
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
matrixNodeIndices(1)[0], matrixNodeIndices(1)[0]);
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
matrixNodeIndices(0)[0], matrixNodeIndices(1)[0]);
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
matrixNodeIndices(1)[0], matrixNodeIndices(0)[0]);
}
MNAStampUtils::stampAdmittanceAs3x3ScalarMatrix(
conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
}

void DP::Ph3::SeriesSwitch::mnaCompAddPostStepDependencies(
Expand Down
60 changes: 6 additions & 54 deletions dpsim-models/src/EMT/EMT_Ph3_SeriesSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,67 +65,19 @@ void EMT::Ph3::SeriesSwitch::mnaCompApplySystemMatrixStamp(
Real conductance =
(**mIsClosed) ? 1. / **mClosedResistance : 1. / **mOpenResistance;

// 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);
}

if (terminalNotGrounded(0))
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
matrixNodeIndices(0)[0], matrixNodeIndices(0)[0]);
if (terminalNotGrounded(1))
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
matrixNodeIndices(1)[0], matrixNodeIndices(1)[0]);
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
matrixNodeIndices(0)[0], matrixNodeIndices(1)[0]);
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
matrixNodeIndices(1)[0], matrixNodeIndices(0)[0]);
}
MNAStampUtils::stampConductanceAs3x3ScalarMatrix(
conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
}

void EMT::Ph3::SeriesSwitch::mnaCompApplySwitchSystemMatrixStamp(
Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
Real conductance =
(closed) ? 1. / **mClosedResistance : 1. / **mOpenResistance;

// 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);
}

if (terminalNotGrounded(0))
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
matrixNodeIndices(0)[0], matrixNodeIndices(0)[0]);
if (terminalNotGrounded(1))
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
matrixNodeIndices(1)[0], matrixNodeIndices(1)[0]);
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
matrixNodeIndices(0)[0], matrixNodeIndices(1)[0]);
SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
matrixNodeIndices(1)[0], matrixNodeIndices(0)[0]);
}
MNAStampUtils::stampConductanceAs3x3ScalarMatrix(
conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
}

void EMT::Ph3::SeriesSwitch::mnaCompAddPostStepDependencies(
Expand Down
Loading

0 comments on commit 5fffc7f

Please sign in to comment.