Skip to content

Commit

Permalink
make mConductance a local variable
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Schroeder <jonas.schroeder1@rwth-aachen.de>
  • Loading branch information
JTS22 committed Oct 28, 2022
1 parent a4c9b5c commit 512537a
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 96 deletions.
4 changes: 0 additions & 4 deletions dpsim-models/include/dpsim-models/Base/Base_Ph1_Resistor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ namespace CPS {
namespace Base {
namespace Ph1 {
class Resistor {
protected:
///Conductance [S]
///CHECK: Does this have to be its own member variable?
Real mConductance;
public:
///Resistance [ohm]
CPS::Attribute<Real>::Ptr mResistance;
Expand Down
4 changes: 0 additions & 4 deletions dpsim-models/include/dpsim-models/Base/Base_Ph3_Resistor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ namespace CPS {
namespace Base {
namespace Ph3 {
class Resistor {
protected:
///Conductance [S]
///CHECK: Does this have to be its own member variable?
Matrix mConductance;
public:
///Resistance [ohm]
CPS::Attribute<Matrix>::Ptr mResistance;
Expand Down
83 changes: 42 additions & 41 deletions dpsim-models/src/DP/DP_Ph3_Resistor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ void DP::Ph3::Resistor::initializeFromNodesAndTerminals(Real frequency) {
(**mIntfVoltage)(2, 0) = Complex(
voltMag * cos(voltPhase + 2. / 3. * M_PI),
voltMag * sin(voltPhase + 2. / 3. * M_PI));
mConductance = (**mResistance).inverse();
**mIntfCurrent = mConductance * **mIntfVoltage;
**mIntfCurrent = (**mResistance).inverse() * **mIntfVoltage;

mSLog->info("\n--- Initialization from powerflow ---"
"\nVoltage across amplitude and phase: \n{:s}"
Expand All @@ -62,6 +61,8 @@ void DP::Ph3::Resistor::mnaInitialize(Real omega, Real timeStep, Attribute<Matri

void DP::Ph3::Resistor::mnaApplySystemMatrixStamp(Matrix& systemMatrix) {

Matrix conductance = (**mResistance).inverse();

//// Set diagonal entries
//if (terminalNotGrounded(0))
// Math::addToMatrixElement(systemMatrix, matrixNodeIndices(0), matrixNodeIndices(0), conductance);
Expand All @@ -75,50 +76,50 @@ void DP::Ph3::Resistor::mnaApplySystemMatrixStamp(Matrix& systemMatrix) {
// Set diagonal entries
if (terminalNotGrounded(0)) {
// set upper left block, 3x3 entries
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), matrixNodeIndex(0, 0), Complex(mConductance(0, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), matrixNodeIndex(0, 1), Complex(mConductance(0, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), matrixNodeIndex(0, 2), Complex(mConductance(0, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), matrixNodeIndex(0, 0), Complex(mConductance(1, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), matrixNodeIndex(0, 1), Complex(mConductance(1, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), matrixNodeIndex(0, 2), Complex(mConductance(1, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), matrixNodeIndex(0, 0), Complex(mConductance(2, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), matrixNodeIndex(0, 1), Complex(mConductance(2, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), matrixNodeIndex(0, 2), Complex(mConductance(2, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), matrixNodeIndex(0, 0), Complex(conductance(0, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), matrixNodeIndex(0, 1), Complex(conductance(0, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), matrixNodeIndex(0, 2), Complex(conductance(0, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), matrixNodeIndex(0, 0), Complex(conductance(1, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), matrixNodeIndex(0, 1), Complex(conductance(1, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), matrixNodeIndex(0, 2), Complex(conductance(1, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), matrixNodeIndex(0, 0), Complex(conductance(2, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), matrixNodeIndex(0, 1), Complex(conductance(2, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), matrixNodeIndex(0, 2), Complex(conductance(2, 2), 0));
}
if (terminalNotGrounded(1)) {
// set buttom right block, 3x3 entries
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), matrixNodeIndex(1, 0), Complex(mConductance(0, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), matrixNodeIndex(1, 1), Complex(mConductance(0, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), matrixNodeIndex(1, 2), Complex(mConductance(0, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), matrixNodeIndex(1, 0), Complex(mConductance(1, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), matrixNodeIndex(1, 1), Complex(mConductance(1, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), matrixNodeIndex(1, 2), Complex(mConductance(1, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), matrixNodeIndex(1, 0), Complex(mConductance(2, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), matrixNodeIndex(1, 1), Complex(mConductance(2, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), matrixNodeIndex(1, 2), Complex(mConductance(2, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), matrixNodeIndex(1, 0), Complex(conductance(0, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), matrixNodeIndex(1, 1), Complex(conductance(0, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), matrixNodeIndex(1, 2), Complex(conductance(0, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), matrixNodeIndex(1, 0), Complex(conductance(1, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), matrixNodeIndex(1, 1), Complex(conductance(1, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), matrixNodeIndex(1, 2), Complex(conductance(1, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), matrixNodeIndex(1, 0), Complex(conductance(2, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), matrixNodeIndex(1, 1), Complex(conductance(2, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), matrixNodeIndex(1, 2), Complex(conductance(2, 2), 0));
}
// Set off diagonal blocks, 2x3x3 entries
if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), matrixNodeIndex(1, 0), -Complex(mConductance(0, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), matrixNodeIndex(1, 1), -Complex(mConductance(0, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), matrixNodeIndex(1, 2), -Complex(mConductance(0, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), matrixNodeIndex(1, 0), -Complex(mConductance(1, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), matrixNodeIndex(1, 1), -Complex(mConductance(1, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), matrixNodeIndex(1, 2), -Complex(mConductance(1, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), matrixNodeIndex(1, 0), -Complex(mConductance(2, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), matrixNodeIndex(1, 1), -Complex(mConductance(2, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), matrixNodeIndex(1, 2), -Complex(mConductance(2, 2), 0));


Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), matrixNodeIndex(0, 0), -Complex(mConductance(0, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), matrixNodeIndex(0, 1), -Complex(mConductance(0, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), matrixNodeIndex(0, 2), -Complex(mConductance(0, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), matrixNodeIndex(0, 0), -Complex(mConductance(1, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), matrixNodeIndex(0, 1), -Complex(mConductance(1, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), matrixNodeIndex(0, 2), -Complex(mConductance(1, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), matrixNodeIndex(0, 0), -Complex(mConductance(2, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), matrixNodeIndex(0, 1), -Complex(mConductance(2, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), matrixNodeIndex(0, 2), -Complex(mConductance(2, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), matrixNodeIndex(1, 0), -Complex(conductance(0, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), matrixNodeIndex(1, 1), -Complex(conductance(0, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 0), matrixNodeIndex(1, 2), -Complex(conductance(0, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), matrixNodeIndex(1, 0), -Complex(conductance(1, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), matrixNodeIndex(1, 1), -Complex(conductance(1, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 1), matrixNodeIndex(1, 2), -Complex(conductance(1, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), matrixNodeIndex(1, 0), -Complex(conductance(2, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), matrixNodeIndex(1, 1), -Complex(conductance(2, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, 2), matrixNodeIndex(1, 2), -Complex(conductance(2, 2), 0));


Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), matrixNodeIndex(0, 0), -Complex(conductance(0, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), matrixNodeIndex(0, 1), -Complex(conductance(0, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 0), matrixNodeIndex(0, 2), -Complex(conductance(0, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), matrixNodeIndex(0, 0), -Complex(conductance(1, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), matrixNodeIndex(0, 1), -Complex(conductance(1, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 1), matrixNodeIndex(0, 2), -Complex(conductance(1, 2), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), matrixNodeIndex(0, 0), -Complex(conductance(2, 0), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), matrixNodeIndex(0, 1), -Complex(conductance(2, 1), 0));
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1, 2), matrixNodeIndex(0, 2), -Complex(conductance(2, 2), 0));
}

//if (terminalNotGrounded(0))
Expand Down Expand Up @@ -154,7 +155,7 @@ void DP::Ph3::Resistor::mnaUpdateVoltage(const Matrix& leftVector) {
}

void DP::Ph3::Resistor::mnaUpdateCurrent(const Matrix& leftVector) {
**mIntfCurrent = mConductance * **mIntfVoltage;
**mIntfCurrent = (**mResistance).inverse() * **mIntfVoltage;

SPDLOG_LOGGER_DEBUG(mSLog, "Current A: {} < {}", std::abs((**mIntfCurrent)(0,0)), std::arg((**mIntfCurrent)(0,0)));
}
Loading

0 comments on commit 512537a

Please sign in to comment.