Commit e89fec70 authored by Markus Mirz's avatar Markus Mirz
Browse files

rename simNodes

parent 454f17d9
......@@ -69,7 +69,7 @@ namespace CPS {
/// Initialize state matrices with size according to phase type and frequency number
void initialize(Matrix frequencies);
/// Returns matrix index for specified phase
UInt simNode(PhaseType phaseType = PhaseType::Single) {
UInt matrixNodeIndex(PhaseType phaseType = PhaseType::Single) {
if ((phaseType == PhaseType::A || phaseType == PhaseType::Single)
&& (mPhaseType == PhaseType::Single
|| mPhaseType == PhaseType::A
......@@ -87,7 +87,7 @@ namespace CPS {
return 0;
}
/// Returns all matrix indices
std::vector<UInt> simNodes() {
std::vector<UInt> matrixNodeIndices() {
if (mPhaseType == PhaseType::B)
return { mSimNode[1] };
else if (mPhaseType == PhaseType::C)
......
......@@ -106,14 +106,14 @@ namespace CPS {
}
return mTerminals[index]->node();
};
UInt simNode(UInt nodeIndex) {
UInt matrixNodeIndex(UInt nodeIndex) {
return mSimNodes[nodeIndex * 3];
}
UInt simNode(UInt nodeIndex, UInt phaseIndex) {
UInt matrixNodeIndex(UInt nodeIndex, UInt phaseIndex) {
return mSimNodes[nodeIndex * 3 + phaseIndex];
}
/// TODO replace with access to mSimNodes
std::vector<UInt> simNodes(UInt index) { return node(index)->simNodes(); }
std::vector<UInt> matrixNodeIndices(UInt index) { return node(index)->matrixNodeIndices(); }
/// Get nodes as base type TopologicalNode
TopologicalNode::List topologicalNodes();
......@@ -127,7 +127,7 @@ namespace CPS {
/// Get pointer to virtual node
typename Node<VarType>::Ptr virtualNode(UInt index);
/// Get vector of simulation node numbers from virtual Node
std::vector<UInt> virtualSimNodes(UInt index) { return virtualNode(index)->simNodes(); }
std::vector<UInt> virtualSimNodes(UInt index) { return virtualNode(index)->matrixNodeIndices(); }
/// Get simulation node number from virtual node
UInt virtualSimNode(UInt nodeIndex, UInt phaseIndex = 0) { return virtualSimNodes(nodeIndex)[phaseIndex]; }
......
......@@ -58,9 +58,9 @@ namespace CPS {
///
PhaseType phaseType() { return mPhaseType; }
///
virtual UInt simNode(PhaseType phaseType = PhaseType::Single) = 0;
virtual UInt matrixNodeIndex(PhaseType phaseType = PhaseType::Single) = 0;
///
virtual std::vector<UInt> simNodes() = 0;
virtual std::vector<UInt> matrixNodeIndices() = 0;
///
virtual void setSimNode(UInt phase, UInt simNode) = 0;
};
......
......@@ -64,8 +64,8 @@ namespace CPS {
///
MatrixComp initialVoltage();
///
UInt simNode() { return topologicalNodes()->simNode(mPhaseType); }
UInt matrixNodeIndex() { return topologicalNodes()->matrixNodeIndex(mPhaseType); }
///
std::vector<UInt> simNodes() { return topologicalNodes()->simNodes(); }
std::vector<UInt> matrixNodeIndices() { return topologicalNodes()->matrixNodeIndices(); }
};
}
......@@ -239,7 +239,7 @@ void Reader::processSvVoltage(SvVoltage* volt) {
mSLog->info("Node {} SimNode {}: {} V, {} deg",
mPowerflowNodes[node->mRID]->uid(),
mPowerflowNodes[node->mRID]->simNode(),
mPowerflowNodes[node->mRID]->matrixNodeIndex(),
std::abs(mPowerflowNodes[node->mRID]->initialSingleVoltage()),
std::arg(mPowerflowNodes[node->mRID]->initialSingleVoltage())*180/PI
);
......@@ -284,8 +284,8 @@ SystemTopology Reader::systemTopology() {
for (auto node : mPowerflowNodes) {
// The index of the node in the list should not matter anymore
//system.mNodes[node.second->simNode()] = node.second;
system.addNodeAt(node.second, node.second->simNode());
//system.mNodes[node.second->matrixNodeIndex()] = node.second;
system.addNodeAt(node.second, node.second->matrixNodeIndex());
}
return system;
......@@ -296,7 +296,7 @@ Matrix::Index Reader::mapTopologicalNode(String mrid) {
if (search == mPowerflowNodes.end()) {
return -1;
}
return search->second->simNode();
return search->second->matrixNodeIndex();
}
TopologicalComponent::Ptr Reader::mapEnergyConsumer(EnergyConsumer* consumer) {
......@@ -704,12 +704,12 @@ void Reader::processTopologicalNode(IEC61970::Base::Topology::TopologicalNode* t
mPowerflowNodes[topNode->mRID] = Node<VarType>::make(topNode->mRID, topNode->name, simNode, mPhase);
if (mPhase == PhaseType::ABC) {
mSLog->info("TopologicalNode {} phase A as simulation node {} ", topNode->mRID, mPowerflowNodes[topNode->mRID]->simNode(PhaseType::A));
mSLog->info("TopologicalNode {} phase B as simulation node {}", topNode->mRID, mPowerflowNodes[topNode->mRID]->simNode(PhaseType::B));
mSLog->info("TopologicalNode {} phase C as simulation node {}", topNode->mRID, mPowerflowNodes[topNode->mRID]->simNode(PhaseType::C));
mSLog->info("TopologicalNode {} phase A as simulation node {} ", topNode->mRID, mPowerflowNodes[topNode->mRID]->matrixNodeIndex(PhaseType::A));
mSLog->info("TopologicalNode {} phase B as simulation node {}", topNode->mRID, mPowerflowNodes[topNode->mRID]->matrixNodeIndex(PhaseType::B));
mSLog->info("TopologicalNode {} phase C as simulation node {}", topNode->mRID, mPowerflowNodes[topNode->mRID]->matrixNodeIndex(PhaseType::C));
}
else
mSLog->info("TopologicalNode {} as simulation node {}", topNode->mRID, mPowerflowNodes[topNode->mRID]->simNode());
mSLog->info("TopologicalNode {} as simulation node {}", topNode->mRID, mPowerflowNodes[topNode->mRID]->matrixNodeIndex());
for (auto term : topNode->Terminal) {
// Insert Terminal if it does not exist in the map and add reference to node.
......
......@@ -128,7 +128,7 @@ void DP::Ph1::AvVoltageSourceInverterDQ::updateMonitoredValues(const Matrix& lef
MatrixComp IgDP = MatrixComp::Zero(1, 1);
// minus sign before currents due to the connection
VcDP(0, 0) = Math::complexFromVectorElement(leftVector, mSubCapacitorF->simNode(0));
VcDP(0, 0) = Math::complexFromVectorElement(leftVector, mSubCapacitorF->matrixNodeIndex(0));
IfDP(0, 0) = -1. * mSubResistorF->attribute<MatrixComp>("i_intf")->get()(0, 0);
IgDP(0, 0) = -1. * mSubResistorC->attribute<MatrixComp>("i_intf")->get()(0, 0);
......@@ -384,7 +384,7 @@ void DP::Ph1::AvVoltageSourceInverterDQ::initializeFromPowerflow(Real frequency)
Logger::phasorToString(mIntfVoltage(0, 0)),
Logger::phasorToString(mIntfCurrent(0, 0)),
Logger::phasorToString(initialSingleVoltage(0)),
mTerminals[0]->node()->name(), mTerminals[0]->node()->simNode());
mTerminals[0]->node()->name(), mTerminals[0]->node()->matrixNodeIndex());
}
void DP::Ph1::AvVoltageSourceInverterDQ::mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
......
......@@ -126,52 +126,52 @@ void DP::Ph1::Capacitor::mnaInitializeHarm(Real omega, Real timeStep, std::vecto
void DP::Ph1::Capacitor::mnaApplySystemMatrixStamp(Matrix& systemMatrix) {
for (UInt freq = 0; freq < mNumFreqs; freq++) {
if (terminalNotGrounded(0))
Math::addToMatrixElement(systemMatrix, simNode(0), simNode(0), mEquivCond(freq,0), mNumFreqs, freq);
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), matrixNodeIndex(0), mEquivCond(freq,0), mNumFreqs, freq);
if (terminalNotGrounded(1))
Math::addToMatrixElement(systemMatrix, simNode(1), simNode(1), mEquivCond(freq,0), mNumFreqs, freq);
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), matrixNodeIndex(1), mEquivCond(freq,0), mNumFreqs, freq);
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
Math::addToMatrixElement(systemMatrix, simNode(0), simNode(1), -mEquivCond(freq,0), mNumFreqs, freq);
Math::addToMatrixElement(systemMatrix, simNode(1), simNode(0), -mEquivCond(freq,0), mNumFreqs, freq);
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), -mEquivCond(freq,0), mNumFreqs, freq);
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), matrixNodeIndex(0), -mEquivCond(freq,0), mNumFreqs, freq);
}
mSLog->info("-- Stamp frequency {:d} ---", freq);
if (terminalNotGrounded(0))
mSLog->info("Add {:e}+j{:e} to system at ({:d},{:d})",
mEquivCond(freq,0).real(), mEquivCond(freq,0).imag(), simNode(0), simNode(0));
mEquivCond(freq,0).real(), mEquivCond(freq,0).imag(), matrixNodeIndex(0), matrixNodeIndex(0));
if (terminalNotGrounded(1))
mSLog->info("Add {:e}+j{:e} to system at ({:d},{:d})",
mEquivCond(freq,0).real(), mEquivCond(freq,0).imag(), simNode(1), simNode(1));
mEquivCond(freq,0).real(), mEquivCond(freq,0).imag(), matrixNodeIndex(1), matrixNodeIndex(1));
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
mSLog->info("Add {:e}+j{:e} to system at ({:d},{:d})",
-mEquivCond(freq,0).real(), -mEquivCond(freq,0).imag(), simNode(0), simNode(1));
-mEquivCond(freq,0).real(), -mEquivCond(freq,0).imag(), matrixNodeIndex(0), matrixNodeIndex(1));
mSLog->info("Add {:e}+j{:e} to system at ({:d},{:d})",
-mEquivCond(freq,0).real(), -mEquivCond(freq,0).imag(), simNode(1), simNode(0));
-mEquivCond(freq,0).real(), -mEquivCond(freq,0).imag(), matrixNodeIndex(1), matrixNodeIndex(0));
}
}
}
void DP::Ph1::Capacitor::mnaApplySystemMatrixStampHarm(Matrix& systemMatrix, Int freqIdx) {
if (terminalNotGrounded(0))
Math::addToMatrixElement(systemMatrix, simNode(0), simNode(0), mEquivCond(freqIdx,0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), matrixNodeIndex(0), mEquivCond(freqIdx,0));
if (terminalNotGrounded(1))
Math::addToMatrixElement(systemMatrix, simNode(1), simNode(1), mEquivCond(freqIdx,0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), matrixNodeIndex(1), mEquivCond(freqIdx,0));
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
Math::addToMatrixElement(systemMatrix, simNode(0), simNode(1), -mEquivCond(freqIdx,0));
Math::addToMatrixElement(systemMatrix, simNode(1), simNode(0), -mEquivCond(freqIdx,0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), -mEquivCond(freqIdx,0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), matrixNodeIndex(0), -mEquivCond(freqIdx,0));
}
mSLog->info("-- Stamp frequency {:d} ---", freqIdx);
if (terminalNotGrounded(0))
mSLog->info("Add {:e}+j{:e} to system at ({:d},{:d})",
mEquivCond(freqIdx,0).real(), mEquivCond(freqIdx,0).imag(), simNode(0), simNode(0));
mEquivCond(freqIdx,0).real(), mEquivCond(freqIdx,0).imag(), matrixNodeIndex(0), matrixNodeIndex(0));
if (terminalNotGrounded(1))
mSLog->info("Add {:e}+j{:e} to system at ({:d},{:d})",
mEquivCond(freqIdx,0).real(), mEquivCond(freqIdx,0).imag(), simNode(1), simNode(1));
mEquivCond(freqIdx,0).real(), mEquivCond(freqIdx,0).imag(), matrixNodeIndex(1), matrixNodeIndex(1));
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
mSLog->info("Add {:e}+j{:e} to system at ({:d},{:d})",
-mEquivCond(freqIdx,0).real(), -mEquivCond(freqIdx,0).imag(), simNode(0), simNode(1));
-mEquivCond(freqIdx,0).real(), -mEquivCond(freqIdx,0).imag(), matrixNodeIndex(0), matrixNodeIndex(1));
mSLog->info("Add {:e}+j{:e} to system at ({:d},{:d})",
-mEquivCond(freqIdx,0).real(), -mEquivCond(freqIdx,0).imag(), simNode(1), simNode(0));
-mEquivCond(freqIdx,0).real(), -mEquivCond(freqIdx,0).imag(), matrixNodeIndex(1), matrixNodeIndex(0));
}
}
......@@ -183,18 +183,18 @@ void DP::Ph1::Capacitor::mnaApplyRightSideVectorStamp(Matrix& rightVector) {
+ -mPrevVoltCoeff(freq,0) * mIntfVoltage(0,freq);
if (terminalNotGrounded(0))
Math::setVectorElement(rightVector, simNode(0), mEquivCurrent(freq,0), mNumFreqs, freq);
Math::setVectorElement(rightVector, matrixNodeIndex(0), mEquivCurrent(freq,0), mNumFreqs, freq);
if (terminalNotGrounded(1))
Math::setVectorElement(rightVector, simNode(1), -mEquivCurrent(freq,0), mNumFreqs, freq);
Math::setVectorElement(rightVector, matrixNodeIndex(1), -mEquivCurrent(freq,0), mNumFreqs, freq);
SPDLOG_LOGGER_DEBUG(mSLog, "MNA EquivCurrent {:f}+j{:f}",
mEquivCurrent(freq,0).real(), mEquivCurrent(freq,0).imag());
if (terminalNotGrounded(0))
SPDLOG_LOGGER_DEBUG(mSLog, "Add {:f}+j{:f} to source vector at {:d}",
mEquivCurrent(freq,0).real(), mEquivCurrent(freq,0).imag(), simNode(0));
mEquivCurrent(freq,0).real(), mEquivCurrent(freq,0).imag(), matrixNodeIndex(0));
if (terminalNotGrounded(1))
SPDLOG_LOGGER_DEBUG(mSLog, "Add {:f}+j{:f} to source vector at {:d}",
-mEquivCurrent(freq,0).real(), -mEquivCurrent(freq,0).imag(), simNode(1));
-mEquivCurrent(freq,0).real(), -mEquivCurrent(freq,0).imag(), matrixNodeIndex(1));
}
}
......@@ -206,9 +206,9 @@ void DP::Ph1::Capacitor::mnaApplyRightSideVectorStampHarm(Matrix& rightVector) {
+ -mPrevVoltCoeff(freq,0) * mIntfVoltage(0,freq);
if (terminalNotGrounded(0))
Math::setVectorElement(rightVector, simNode(0), mEquivCurrent(freq,0), 1, 0, freq);
Math::setVectorElement(rightVector, matrixNodeIndex(0), mEquivCurrent(freq,0), 1, 0, freq);
if (terminalNotGrounded(1))
Math::setVectorElement(rightVector, simNode(1), -mEquivCurrent(freq,0), 1, 0, freq);
Math::setVectorElement(rightVector, matrixNodeIndex(1), -mEquivCurrent(freq,0), 1, 0, freq);
}
}
......@@ -219,9 +219,9 @@ void DP::Ph1::Capacitor::mnaApplyRightSideVectorStampHarm(Matrix& rightVector, I
+ -mPrevVoltCoeff(freq,0) * mIntfVoltage(0,freq);
if (terminalNotGrounded(0))
Math::setVectorElement(rightVector, simNode(0), mEquivCurrent(freq,0));
Math::setVectorElement(rightVector, matrixNodeIndex(0), mEquivCurrent(freq,0));
if (terminalNotGrounded(1))
Math::setVectorElement(rightVector, simNode(1), -mEquivCurrent(freq,0));
Math::setVectorElement(rightVector, matrixNodeIndex(1), -mEquivCurrent(freq,0));
}
void DP::Ph1::Capacitor::MnaPreStep::execute(Real time, Int timeStepCount) {
......@@ -248,9 +248,9 @@ void DP::Ph1::Capacitor::mnaUpdateVoltage(const Matrix& leftVector) {
for (UInt freq = 0; freq < mNumFreqs; freq++) {
mIntfVoltage(0,freq) = 0;
if (terminalNotGrounded(1))
mIntfVoltage(0,freq) = Math::complexFromVectorElement(leftVector, simNode(1), mNumFreqs, freq);
mIntfVoltage(0,freq) = Math::complexFromVectorElement(leftVector, matrixNodeIndex(1), mNumFreqs, freq);
if (terminalNotGrounded(0))
mIntfVoltage(0,freq) = mIntfVoltage(0,freq) - Math::complexFromVectorElement(leftVector, simNode(0), mNumFreqs, freq);
mIntfVoltage(0,freq) = mIntfVoltage(0,freq) - Math::complexFromVectorElement(leftVector, matrixNodeIndex(0), mNumFreqs, freq);
SPDLOG_LOGGER_DEBUG(mSLog, "Voltage {:e}<{:e}", std::abs(mIntfVoltage(0,freq)), std::arg(mIntfVoltage(0,freq)));
}
......@@ -260,9 +260,9 @@ void DP::Ph1::Capacitor::mnaUpdateVoltageHarm(const Matrix& leftVector, Int freq
// v1 - v0
mIntfVoltage(0,freqIdx) = 0;
if (terminalNotGrounded(1))
mIntfVoltage(0,freqIdx) = Math::complexFromVectorElement(leftVector, simNode(1));
mIntfVoltage(0,freqIdx) = Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
if (terminalNotGrounded(0))
mIntfVoltage(0,freqIdx) = mIntfVoltage(0,freqIdx) - Math::complexFromVectorElement(leftVector, simNode(0));
mIntfVoltage(0,freqIdx) = mIntfVoltage(0,freqIdx) - Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
SPDLOG_LOGGER_DEBUG(mSLog, "Voltage {:s}", Logger::phasorToString(mIntfVoltage(0,freqIdx)));
}
......
......@@ -65,30 +65,30 @@ void DP::Ph1::ControlledVoltageSource::mnaInitialize(Real omega, Real timeStep,
void DP::Ph1::ControlledVoltageSource::mnaApplySystemMatrixStamp(Matrix& systemMatrix) {
for (UInt freq = 0; freq < mNumFreqs; freq++) {
if (terminalNotGrounded(0)) {
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->simNode(), simNode(0), Complex(-1, 0), mNumFreqs, freq);
Math::setMatrixElement(systemMatrix, simNode(0), mVirtualNodes[0]->simNode(), Complex(-1, 0), mNumFreqs, freq);
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(0), Complex(-1, 0), mNumFreqs, freq);
Math::setMatrixElement(systemMatrix, matrixNodeIndex(0), mVirtualNodes[0]->matrixNodeIndex(), Complex(-1, 0), mNumFreqs, freq);
}
if (terminalNotGrounded(1)) {
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->simNode(), simNode(1), Complex(1, 0), mNumFreqs, freq);
Math::setMatrixElement(systemMatrix, simNode(1), mVirtualNodes[0]->simNode(), Complex(1, 0), mNumFreqs, freq);
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(1), Complex(1, 0), mNumFreqs, freq);
Math::setMatrixElement(systemMatrix, matrixNodeIndex(1), mVirtualNodes[0]->matrixNodeIndex(), Complex(1, 0), mNumFreqs, freq);
}
mSLog->info("-- Stamp frequency {:d} ---", freq);
if (terminalNotGrounded(0)) {
mSLog->info("Add {:f} to system at ({:d},{:d})", -1., simNode(0), mVirtualNodes[0]->simNode());
mSLog->info("Add {:f} to system at ({:d},{:d})", -1., mVirtualNodes[0]->simNode(), simNode(0));
mSLog->info("Add {:f} to system at ({:d},{:d})", -1., matrixNodeIndex(0), mVirtualNodes[0]->matrixNodeIndex());
mSLog->info("Add {:f} to system at ({:d},{:d})", -1., mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(0));
}
if (terminalNotGrounded(1)) {
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., mVirtualNodes[0]->simNode(), simNode(1));
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., simNode(1), mVirtualNodes[0]->simNode());
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(1));
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., matrixNodeIndex(1), mVirtualNodes[0]->matrixNodeIndex());
}
}
}
void DP::Ph1::ControlledVoltageSource::mnaApplyRightSideVectorStamp(Matrix& rightVector) {
Math::setVectorElement(rightVector, mVirtualNodes[0]->simNode(), mIntfVoltage(0, 0), mNumFreqs);
Math::setVectorElement(rightVector, mVirtualNodes[0]->matrixNodeIndex(), mIntfVoltage(0, 0), mNumFreqs);
SPDLOG_LOGGER_DEBUG(mSLog, "Add {:s} to source vector at {:d}",
Logger::complexToString(mIntfVoltage(0, 0)), mVirtualNodes[0]->simNode());
Logger::complexToString(mIntfVoltage(0, 0)), mVirtualNodes[0]->matrixNodeIndex());
}
void DP::Ph1::ControlledVoltageSource::MnaPreStep::execute(Real time, Int timeStepCount) {
......@@ -101,6 +101,6 @@ void DP::Ph1::ControlledVoltageSource::MnaPostStep::execute(Real time, Int timeS
void DP::Ph1::ControlledVoltageSource::mnaUpdateCurrent(const Matrix& leftVector) {
for (UInt freq = 0; freq < mNumFreqs; freq++) {
mIntfCurrent(0, freq) = Math::complexFromVectorElement(leftVector, mVirtualNodes[0]->simNode(), mNumFreqs, freq);
mIntfCurrent(0, freq) = Math::complexFromVectorElement(leftVector, mVirtualNodes[0]->matrixNodeIndex(), mNumFreqs, freq);
}
}
......@@ -87,9 +87,9 @@ void DP::Ph1::CurrentSource::mnaApplyRightSideVectorStamp(Matrix& rightVector) {
mIntfCurrent(0,0) = mCurrentRef->get();
if (terminalNotGrounded(0))
Math::setVectorElement(rightVector, simNode(0), -mIntfCurrent(0,0));
Math::setVectorElement(rightVector, matrixNodeIndex(0), -mIntfCurrent(0,0));
if (terminalNotGrounded(1))
Math::setVectorElement(rightVector, simNode(1), mIntfCurrent(0,0));
Math::setVectorElement(rightVector, matrixNodeIndex(1), mIntfCurrent(0,0));
}
void DP::Ph1::CurrentSource::MnaPostStep::execute(Real time, Int timeStepCount) {
......@@ -99,7 +99,7 @@ void DP::Ph1::CurrentSource::MnaPostStep::execute(Real time, Int timeStepCount)
void DP::Ph1::CurrentSource::mnaUpdateVoltage(const Matrix& leftVector) {
mIntfVoltage(0,0) = 0;
if (terminalNotGrounded(0))
mIntfVoltage(0,0) = Math::complexFromVectorElement(leftVector, simNode(0));
mIntfVoltage(0,0) = Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
if (terminalNotGrounded(1))
mIntfVoltage(0,0) = mIntfVoltage(0,0) - Math::complexFromVectorElement(leftVector, simNode(1));
mIntfVoltage(0,0) = mIntfVoltage(0,0) - Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
}
......@@ -122,52 +122,52 @@ void DP::Ph1::Inductor::mnaInitializeHarm(Real omega, Real timeStep, std::vector
void DP::Ph1::Inductor::mnaApplySystemMatrixStamp(Matrix& systemMatrix) {
for (UInt freq = 0; freq < mNumFreqs; freq++) {
if (terminalNotGrounded(0))
Math::addToMatrixElement(systemMatrix, simNode(0), simNode(0), mEquivCond(freq,0), mNumFreqs, freq);
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), matrixNodeIndex(0), mEquivCond(freq,0), mNumFreqs, freq);
if (terminalNotGrounded(1))
Math::addToMatrixElement(systemMatrix, simNode(1), simNode(1), mEquivCond(freq,0), mNumFreqs, freq);
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), matrixNodeIndex(1), mEquivCond(freq,0), mNumFreqs, freq);
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
Math::addToMatrixElement(systemMatrix, simNode(0), simNode(1), -mEquivCond(freq,0), mNumFreqs, freq);
Math::addToMatrixElement(systemMatrix, simNode(1), simNode(0), -mEquivCond(freq,0), mNumFreqs, freq);
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), -mEquivCond(freq,0), mNumFreqs, freq);
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), matrixNodeIndex(0), -mEquivCond(freq,0), mNumFreqs, freq);
}
mSLog->info("-- Stamp frequency {:d} ---", freq);
if (terminalNotGrounded(0))
mSLog->info("Add {:s} to system at ({:d},{:d})",
Logger::complexToString(mEquivCond(freq,0)), simNode(0), simNode(0));
Logger::complexToString(mEquivCond(freq,0)), matrixNodeIndex(0), matrixNodeIndex(0));
if (terminalNotGrounded(1))
mSLog->info("Add {:s} to system at ({:d},{:d})",
Logger::complexToString(mEquivCond(freq,0)), simNode(1), simNode(1));
Logger::complexToString(mEquivCond(freq,0)), matrixNodeIndex(1), matrixNodeIndex(1));
if ( terminalNotGrounded(0) && terminalNotGrounded(1) ) {
mSLog->info("Add {:s} to system at ({:d},{:d})",
Logger::complexToString(-mEquivCond(freq,0)), simNode(0), simNode(1));
Logger::complexToString(-mEquivCond(freq,0)), matrixNodeIndex(0), matrixNodeIndex(1));
mSLog->info("Add {:s} to system at ({:d},{:d})",
Logger::complexToString(-mEquivCond(freq,0)), simNode(1), simNode(0));
Logger::complexToString(-mEquivCond(freq,0)), matrixNodeIndex(1), matrixNodeIndex(0));
}
}
}
void DP::Ph1::Inductor::mnaApplySystemMatrixStampHarm(Matrix& systemMatrix, Int freqIdx) {
if (terminalNotGrounded(0))
Math::addToMatrixElement(systemMatrix, simNode(0), simNode(0), mEquivCond(freqIdx,0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), matrixNodeIndex(0), mEquivCond(freqIdx,0));
if (terminalNotGrounded(1))
Math::addToMatrixElement(systemMatrix, simNode(1), simNode(1), mEquivCond(freqIdx,0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), matrixNodeIndex(1), mEquivCond(freqIdx,0));
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
Math::addToMatrixElement(systemMatrix, simNode(0), simNode(1), -mEquivCond(freqIdx,0));
Math::addToMatrixElement(systemMatrix, simNode(1), simNode(0), -mEquivCond(freqIdx,0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), -mEquivCond(freqIdx,0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), matrixNodeIndex(0), -mEquivCond(freqIdx,0));
}
mSLog->info("-- Stamp frequency {:d} ---", freqIdx);
if (terminalNotGrounded(0))
mSLog->info("Add {:f}+j{:f} to system at ({:d},{:d})",
mEquivCond(freqIdx,0).real(), mEquivCond(freqIdx,0).imag(), simNode(0), simNode(0));
mEquivCond(freqIdx,0).real(), mEquivCond(freqIdx,0).imag(), matrixNodeIndex(0), matrixNodeIndex(0));
if (terminalNotGrounded(1))
mSLog->info("Add {:f}+j{:f} to system at ({:d},{:d})",
mEquivCond(freqIdx,0).real(), mEquivCond(freqIdx,0).imag(), simNode(1), simNode(1));
mEquivCond(freqIdx,0).real(), mEquivCond(freqIdx,0).imag(), matrixNodeIndex(1), matrixNodeIndex(1));
if ( terminalNotGrounded(0) && terminalNotGrounded(1) ) {
mSLog->info("Add {:f}+j{:f} to system at ({:d},{:d})",
-mEquivCond(freqIdx,0).real(), -mEquivCond(freqIdx,0).imag(), simNode(0), simNode(1));
-mEquivCond(freqIdx,0).real(), -mEquivCond(freqIdx,0).imag(), matrixNodeIndex(0), matrixNodeIndex(1));
mSLog->info("Add {:f}+j{:f} to system at ({:d},{:d})",
-mEquivCond(freqIdx,0).real(), -mEquivCond(freqIdx,0).imag(), simNode(1), simNode(0));
-mEquivCond(freqIdx,0).real(), -mEquivCond(freqIdx,0).imag(), matrixNodeIndex(1), matrixNodeIndex(0));
}
}
......@@ -179,17 +179,17 @@ void DP::Ph1::Inductor::mnaApplyRightSideVectorStamp(Matrix& rightVector) {
+ mPrevCurrFac(freq,0) * mIntfCurrent(0,freq);
if (terminalNotGrounded(0))
Math::setVectorElement(rightVector, simNode(0), mEquivCurrent(freq,0), mNumFreqs, freq);
Math::setVectorElement(rightVector, matrixNodeIndex(0), mEquivCurrent(freq,0), mNumFreqs, freq);
if (terminalNotGrounded(1))
Math::setVectorElement(rightVector, simNode(1), -mEquivCurrent(freq,0), mNumFreqs, freq);
Math::setVectorElement(rightVector, matrixNodeIndex(1), -mEquivCurrent(freq,0), mNumFreqs, freq);
SPDLOG_LOGGER_DEBUG(mSLog, "MNA EquivCurrent {:s}", Logger::complexToString(mEquivCurrent(freq,0)));
if (terminalNotGrounded(0))
SPDLOG_LOGGER_DEBUG(mSLog, "Add {:s} to source vector at {:d}",
Logger::complexToString(mEquivCurrent(freq,0)), simNode(0));
Logger::complexToString(mEquivCurrent(freq,0)), matrixNodeIndex(0));
if (terminalNotGrounded(1))
SPDLOG_LOGGER_DEBUG(mSLog, "Add {:s} to source vector at {:d}",
Logger::complexToString(-mEquivCurrent(freq,0)), simNode(1));
Logger::complexToString(-mEquivCurrent(freq,0)), matrixNodeIndex(1));
}
}
......@@ -201,9 +201,9 @@ void DP::Ph1::Inductor::mnaApplyRightSideVectorStampHarm(Matrix& rightVector) {
+ mPrevCurrFac(freq,0) * mIntfCurrent(0,freq);
if (terminalNotGrounded(0))
Math::setVectorElement(rightVector, simNode(0), mEquivCurrent(freq,0), 1, 0, freq);
Math::setVectorElement(rightVector, matrixNodeIndex(0), mEquivCurrent(freq,0), 1, 0, freq);
if (terminalNotGrounded(1))
Math::setVectorElement(rightVector, simNode(1), -mEquivCurrent(freq,0), 1, 0, freq);
Math::setVectorElement(rightVector, matrixNodeIndex(1), -mEquivCurrent(freq,0), 1, 0, freq);
}
}
......@@ -231,9 +231,9 @@ void DP::Ph1::Inductor::mnaUpdateVoltage(const Matrix& leftVector) {
for (UInt freq = 0; freq < mNumFreqs; freq++) {
mIntfVoltage(0,freq) = 0;
if (terminalNotGrounded(1))
mIntfVoltage(0,freq) = Math::complexFromVectorElement(leftVector, simNode(1), mNumFreqs, freq);
mIntfVoltage(0,freq) = Math::complexFromVectorElement(leftVector, matrixNodeIndex(1), mNumFreqs, freq);
if (terminalNotGrounded(0))
mIntfVoltage(0,freq) = mIntfVoltage(0,freq) - Math::complexFromVectorElement(leftVector, simNode(0), mNumFreqs, freq);
mIntfVoltage(0,freq) = mIntfVoltage(0,freq) - Math::complexFromVectorElement(leftVector, matrixNodeIndex(0), mNumFreqs, freq);
SPDLOG_LOGGER_DEBUG(mSLog, "Voltage {:s}", Logger::phasorToString(mIntfVoltage(0,freq)));
}
......@@ -243,9 +243,9 @@ void DP::Ph1::Inductor::mnaUpdateVoltageHarm(const Matrix& leftVector, Int freqI
// v1 - v0
mIntfVoltage(0,freqIdx) = 0;
if (terminalNotGrounded(1))
mIntfVoltage(0,freqIdx) = Math::complexFromVectorElement(leftVector, simNode(1));
mIntfVoltage(0,freqIdx) = Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
if (terminalNotGrounded(0))
mIntfVoltage(0,freqIdx) = mIntfVoltage(0,freqIdx) - Math::complexFromVectorElement(leftVector, simNode(0));
mIntfVoltage(0,freqIdx) = mIntfVoltage(0,freqIdx) - Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
SPDLOG_LOGGER_DEBUG(mSLog, "Voltage {:s}", Logger::phasorToString(mIntfVoltage(0,freqIdx)));
}
......
......@@ -151,13 +151,13 @@ void DP::Ph1::Inverter::mnaApplySystemMatrixStamp(Matrix& systemMatrix) {
for (UInt freq = 0; freq < mNumFreqs; freq++) {
mSLog->info("Stamp frequency {:d}", freq);
if (terminalNotGrounded(0)) {
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->simNode(), simNode(0), Complex(1, 0), mNumFreqs, freq);
Math::setMatrixElement(systemMatrix, simNode(0), mVirtualNodes[0]->simNode(), Complex(1, 0), mNumFreqs, freq);
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(0), Complex(1, 0), mNumFreqs, freq);
Math::setMatrixElement(systemMatrix, matrixNodeIndex(0), mVirtualNodes[0]->matrixNodeIndex(), Complex(1, 0), mNumFreqs, freq);
}
if (terminalNotGrounded(0)) {
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., mVirtualNodes[0]->simNode(), simNode(0));
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., simNode(0), mVirtualNodes[0]->simNode());
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(0));
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., matrixNodeIndex(0), mVirtualNodes[0]->matrixNodeIndex());
}
}
mSLog->info("--- Stamping into system matrix end ---");
......@@ -166,13 +166,13 @@ void DP::Ph1::Inverter::mnaApplySystemMatrixStamp(Matrix& systemMatrix) {
void DP::Ph1::Inverter::mnaApplySystemMatrixStampHarm(Matrix& systemMatrix, Int freqIdx) {
mSLog->info("Stamp frequency {:d}", freqIdx);
if (terminalNotGrounded(0)) {
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->simNode(), simNode(0), Complex(1, 0));
Math::setMatrixElement(systemMatrix, simNode(0), mVirtualNodes[0]->simNode(), Complex(1, 0));
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(0), Complex(1, 0));
Math::setMatrixElement(systemMatrix, matrixNodeIndex(0), mVirtualNodes[0]->matrixNodeIndex(), Complex(1, 0));
}
if (terminalNotGrounded(0)) {
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., mVirtualNodes[0]->simNode(), simNode(0));
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., simNode(0), mVirtualNodes[0]->simNode());
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(0));
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., matrixNodeIndex(0), mVirtualNodes[0]->matrixNodeIndex());
}
}
......@@ -180,10 +180,10 @@ void DP::Ph1::Inverter::mnaApplyRightSideVectorStamp(Matrix& rightVector) {
SPDLOG_LOGGER_DEBUG(mSLog, "Stamp harmonics into source vector");
for (UInt freq = 0; freq < mNumFreqs; freq++) {
if (terminalNotGrounded(0)) {
Math::setVectorElement(rightVector, mVirtualNodes[0]->simNode(), mIntfVoltage(0,freq), mNumFreqs, freq);
Math::setVectorElement(rightVector, mVirtualNodes[0]->matrixNodeIndex(), mIntfVoltage(0,freq), mNumFreqs, freq);
SPDLOG_LOGGER_DEBUG(mSLog, "Add {:s} to source vector at {:d}, harmonic {:d}",
Logger::complexToString(mIntfVoltage(0,freq)), mVirtualNodes[0]->simNode(), freq);
Logger::complexToString(mIntfVoltage(0,freq)), mVirtualNodes[0]->matrixNodeIndex(), freq);
}
}
}
......@@ -192,13 +192,13 @@ void DP::Ph1::Inverter::mnaApplyRightSideVectorStampHarm(Matrix& rightVector) {
SPDLOG_LOGGER_DEBUG(mSLog, "Stamp harmonics into source vector");
for (UInt freq = 0; freq < mNumFreqs; freq++) {
if (terminalNotGrounded(0)) {
Math::setVectorElement(rightVector, mVirtualNodes[0]->simNode(), mIntfVoltage(0,freq), 1, 0, freq);