Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions dpsim-models/include/dpsim-models/MNAStampUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,52 @@ class MNAStampUtils {
UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded,
const Logger::Log &mSLog, Int maxFreq = 1, Int freqIdx = 0);

static void stampIdealTransformer(Real ratio, SparseMatrixRow &mat,

UInt primaryVirtualNode, UInt secondaryNode,
UInt branchEqNode,

Bool primaryNotGrounded,
Bool secondaryNotGrounded,

Int maxFreq, Int freqIdx,

const Logger::Log &mSLog);

// Complex wrapper
static void stampIdealTransformer(Complex ratio, SparseMatrixRow &mat,

UInt primaryVirtualNode, UInt secondaryNode,
UInt branchEqNode,

Bool primaryNotGrounded,
Bool secondaryNotGrounded,

const Logger::Log &mSLog, Int maxFreq,
Int freqIdx);

static void stampIdealTransformerAs3x3(Real ratio, SparseMatrixRow &mat,

UInt primaryBaseNode,
UInt secondaryBaseNode,
UInt branchEqNode,

Bool primaryNotGrounded,
Bool secondaryNotGrounded,

const Logger::Log &mSLog);

static void stampIdealTransformerAs3x3(Complex ratio, SparseMatrixRow &mat,

UInt primaryBaseNode,
UInt secondaryBaseNode,
UInt branchEqNode,

Bool primaryNotGrounded,
Bool secondaryNotGrounded,

const Logger::Log &mSLog);

private:
template <typename T>
static void stampValue(T value, SparseMatrixRow &mat, UInt node1Index,
Expand Down Expand Up @@ -100,5 +146,31 @@ class MNAStampUtils {
Matrix::Index column, Complex value,
Int maxFreq, Int freqIdx,
const Logger::Log &mSLog);
// Template implementation
template <typename T>
static void stampIdealTransformerTemplate(T ratio, SparseMatrixRow &mat,

UInt primaryVirtualNode,
UInt secondaryNode,
UInt branchEqNode,

Bool primaryNotGrounded,
Bool secondaryNotGrounded,

Int maxFreq, Int freqIdx,

const Logger::Log &mSLog);

template <typename T>
static void stampIdealTransformerAs3x3Template(T ratio, SparseMatrixRow &mat,

UInt primaryBaseNode,
UInt secondaryBaseNode,
UInt branchEqNode,

Bool primaryNotGrounded,
Bool secondaryNotGrounded,

const Logger::Log &mSLog);
};
} // namespace CPS
58 changes: 23 additions & 35 deletions dpsim-models/src/DP/DP_Ph1_Transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*********************************************************************************/

#include <dpsim-models/DP/DP_Ph1_Transformer.h>
#include <dpsim-models/MNAStampUtils.h>

using namespace CPS;

Expand Down Expand Up @@ -216,44 +217,31 @@ void DP::Ph1::Transformer::mnaParentInitialize(

void DP::Ph1::Transformer::mnaCompApplySystemMatrixStamp(
SparseMatrixRow &systemMatrix) {

// Ideal transformer equations
if (terminalNotGrounded(0)) {
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->matrixNodeIndex(),
mVirtualNodes[1]->matrixNodeIndex(),
Complex(-1.0, 0));
Math::setMatrixElement(systemMatrix, mVirtualNodes[1]->matrixNodeIndex(),
mVirtualNodes[0]->matrixNodeIndex(),
Complex(1.0, 0));
}
if (terminalNotGrounded(1)) {
Math::setMatrixElement(systemMatrix, matrixNodeIndex(1),
mVirtualNodes[1]->matrixNodeIndex(), **mRatio);
Math::setMatrixElement(systemMatrix, mVirtualNodes[1]->matrixNodeIndex(),
matrixNodeIndex(1), -**mRatio);
}
MNAStampUtils::stampIdealTransformer(**mRatio, systemMatrix,

// Add subcomps to system matrix
for (auto subcomp : mSubComponents)
if (auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
mnasubcomp->mnaApplySystemMatrixStamp(systemMatrix);
// Original:
// (v0,v1) += -1
mVirtualNodes[0]->matrixNodeIndex(),

if (terminalNotGrounded(0)) {
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(Complex(-1.0, 0)),
mVirtualNodes[0]->matrixNodeIndex(),
mVirtualNodes[1]->matrixNodeIndex());
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(Complex(1.0, 0)),
mVirtualNodes[1]->matrixNodeIndex(),
mVirtualNodes[0]->matrixNodeIndex());
}
if (terminalNotGrounded(1)) {
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(**mRatio), matrixNodeIndex(1),
mVirtualNodes[1]->matrixNodeIndex());
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(-**mRatio),
mVirtualNodes[1]->matrixNodeIndex(), matrixNodeIndex(1));
// Original:
// (n1,v1) += ratio
matrixNodeIndex(1),

// Branch equation node (v1)
mVirtualNodes[1]->matrixNodeIndex(),

terminalNotGrounded(0),
terminalNotGrounded(1),

mSLog, mFrequencies.size(), 0);

// Add subcomponents to system matrix
for (auto subcomp : mSubComponents) {
if (auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp)) {
mnasubcomp->mnaApplySystemMatrixStamp(systemMatrix);
}
}
}

Expand Down
115 changes: 16 additions & 99 deletions dpsim-models/src/EMT/EMT_Ph3_Transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*********************************************************************************/

#include <dpsim-models/EMT/EMT_Ph3_Transformer.h>
#include <dpsim-models/MNAStampUtils.h>

using namespace CPS;

Expand Down Expand Up @@ -232,110 +233,26 @@ void EMT::Ph3::Transformer::mnaParentInitialize(
mTerminals[0]->node()->name(), mTerminals[0]->node()->matrixNodeIndex(),
mTerminals[1]->node()->name(), mTerminals[1]->node()->matrixNodeIndex());
}

void EMT::Ph3::Transformer::mnaCompApplySystemMatrixStamp(
SparseMatrixRow &systemMatrix) {
// Ideal transformer equations
if (terminalNotGrounded(0)) {
Math::setMatrixElement(
systemMatrix, mVirtualNodes[0]->matrixNodeIndex(PhaseType::A),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::A), -1.);
Math::setMatrixElement(
systemMatrix, mVirtualNodes[0]->matrixNodeIndex(PhaseType::B),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::B), -1.);
Math::setMatrixElement(
systemMatrix, mVirtualNodes[0]->matrixNodeIndex(PhaseType::C),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::C), -1.);

Math::setMatrixElement(systemMatrix,
mVirtualNodes[1]->matrixNodeIndex(PhaseType::A),
mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), 1.);
Math::setMatrixElement(systemMatrix,
mVirtualNodes[1]->matrixNodeIndex(PhaseType::B),
mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), 1.);
Math::setMatrixElement(systemMatrix,
mVirtualNodes[1]->matrixNodeIndex(PhaseType::C),
mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), 1.);
}
if (terminalNotGrounded(1)) {
Math::setMatrixElement(systemMatrix, matrixNodeIndex(1, 0),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::A),
(**mRatio).real());
Math::setMatrixElement(systemMatrix, matrixNodeIndex(1, 1),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::B),
(**mRatio).real());
Math::setMatrixElement(systemMatrix, matrixNodeIndex(1, 2),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::C),
(**mRatio).real());
Math::setMatrixElement(systemMatrix,
mVirtualNodes[1]->matrixNodeIndex(PhaseType::A),
matrixNodeIndex(1, 0), -(**mRatio).real());
Math::setMatrixElement(systemMatrix,
mVirtualNodes[1]->matrixNodeIndex(PhaseType::B),
matrixNodeIndex(1, 1), -(**mRatio).real());
Math::setMatrixElement(systemMatrix,
mVirtualNodes[1]->matrixNodeIndex(PhaseType::C),
matrixNodeIndex(1, 2), -(**mRatio).real());
}

// Add subcomps to system matrix
for (auto subcomp : mSubComponents)
if (auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
mnasubcomp->mnaApplySystemMatrixStamp(systemMatrix);
MNAStampUtils::stampIdealTransformerAs3x3(
**mRatio, systemMatrix,

if (terminalNotGrounded(0)) {
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(Complex(-1.0, 0)),
mVirtualNodes[0]->matrixNodeIndex(PhaseType::A),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::A));
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(Complex(-1.0, 0)),
mVirtualNodes[0]->matrixNodeIndex(PhaseType::B),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::B));
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(Complex(-1.0, 0)),
mVirtualNodes[0]->matrixNodeIndex(PhaseType::C),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::C));

SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(Complex(1.0, 0)),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::A),
mVirtualNodes[0]->matrixNodeIndex(PhaseType::A));
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(Complex(1.0, 0)),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::B),
mVirtualNodes[0]->matrixNodeIndex(PhaseType::B));
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(Complex(1.0, 0)),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::C),
mVirtualNodes[0]->matrixNodeIndex(PhaseType::C));
}
if (terminalNotGrounded(1)) {
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(**mRatio), matrixNodeIndex(1, 0),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::A));
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(**mRatio), matrixNodeIndex(1, 1),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::B));
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(**mRatio), matrixNodeIndex(1, 2),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::C));

SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(-**mRatio),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::A),
matrixNodeIndex(1, 0));
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(-**mRatio),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::B),
matrixNodeIndex(1, 1));
SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
Logger::complexToString(-**mRatio),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::C),
matrixNodeIndex(1, 2));
}
}
// Primary base (A-phase start)
mVirtualNodes[0]->matrixNodeIndex(PhaseType::A),

// Secondary base (A-phase start)
mVirtualNodes[1]->matrixNodeIndex(PhaseType::A),

// Branch equation node (SINGLE node, not phased)
mVirtualNodes[1]->matrixNodeIndex(PhaseType::A),

// Grounding flags
terminalNotGrounded(0), terminalNotGrounded(1),

mSLog);
}
void EMT::Ph3::Transformer::mnaParentAddPreStepDependencies(
AttributeBase::List &prevStepDependencies,
AttributeBase::List &attributeDependencies,
Expand Down
Loading
Loading