-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Martin Moraga <[email protected]>
- Loading branch information
1 parent
5c1ac32
commit f5d5ca0
Showing
13 changed files
with
458 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
dpsim-models/include/dpsim-models/SP/SP_Ph1_ResIndSeries.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* Copyright 2017-2021 Institute for Automation of Complex Power Systems, | ||
* EONERC, RWTH Aachen University | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*********************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <dpsim-models/MNASimPowerComp.h> | ||
#include <dpsim-models/Definitions.h> | ||
|
||
namespace CPS { | ||
namespace SP { | ||
namespace Ph1 { | ||
/// Static phasor ResIndSeries model (only implemented for dynamic simulations!) | ||
class ResIndSeries : | ||
public MNASimPowerComp<Complex>, | ||
public SharedFactory<ResIndSeries> { | ||
private: | ||
/// Impedance | ||
Complex mImpedance; | ||
public: | ||
/// Inductance [H] | ||
const Attribute<Real>::Ptr mInductance; | ||
///Resistance [ohm] | ||
const Attribute<Real>::Ptr mResistance; | ||
/// Defines UID, name and logging level | ||
ResIndSeries(String uid, String name, Logger::Level logLevel = Logger::Level::off); | ||
/// Defines name and logging level | ||
ResIndSeries(String name, Logger::Level logLevel = Logger::Level::off) | ||
: ResIndSeries(name, name, logLevel) { } | ||
|
||
SimPowerComp<Complex>::Ptr clone(String name); | ||
|
||
// #### General #### | ||
/// Sets model specific parameters | ||
void setParameters(Real resistance, Real inductance); | ||
/// Initializes component from power flow data | ||
void initializeFromNodesAndTerminals(Real frequency) override; | ||
|
||
|
||
// #### MNA section #### | ||
/// Initializes MNA specific variables | ||
void mnaCompInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) override; | ||
/// Stamps system matrix | ||
void mnaCompApplySystemMatrixStamp(Matrix& systemMatrix) override; | ||
/// Update interface voltage from MNA system result | ||
void mnaCompUpdateVoltage(const Matrix& leftVector) override; | ||
/// Update interface current from MNA system result | ||
void mnaCompUpdateCurrent(const Matrix& leftVector) override; | ||
/// MNA pre and post step operations | ||
void mnaCompPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) override; | ||
/// add MNA pre and post step dependencies | ||
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) override; | ||
|
||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* Copyright 2017-2021 Institute for Automation of Complex Power Systems, | ||
* EONERC, RWTH Aachen University | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*********************************************************************************/ | ||
|
||
#include <dpsim-models/SP/SP_Ph1_ResIndSeries.h> | ||
|
||
using namespace CPS; | ||
|
||
|
||
SP::Ph1::ResIndSeries::ResIndSeries(String uid, String name, Logger::Level logLevel) | ||
: MNASimPowerComp<Complex>(uid, name, false, true, logLevel), | ||
mInductance(mAttributes->create<Real>("L")), | ||
mResistance(mAttributes->create<Real>("R")) { | ||
setTerminalNumber(2); | ||
**mIntfVoltage = MatrixComp::Zero(1, 1); | ||
**mIntfCurrent = MatrixComp::Zero(1, 1); | ||
} | ||
|
||
SimPowerComp<Complex>::Ptr SP::Ph1::ResIndSeries::clone(String name) { | ||
auto copy = ResIndSeries::make(name, mLogLevel); | ||
copy->setParameters(**mResistance, **mInductance); | ||
return copy; | ||
} | ||
|
||
void SP::Ph1::ResIndSeries::setParameters(Real resistance, Real inductance) { | ||
**mResistance = resistance; | ||
**mInductance = inductance; | ||
} | ||
|
||
void SP::Ph1::ResIndSeries::initializeFromNodesAndTerminals(Real frequency) { | ||
|
||
Real omega = 2. * PI * frequency; | ||
mImpedance = { **mResistance, omega * **mInductance }; | ||
(**mIntfVoltage)(0,0) = initialSingleVoltage(1) - initialSingleVoltage(0); | ||
(**mIntfCurrent)(0,0) = (**mIntfVoltage)(0,0) / mImpedance; | ||
|
||
mSLog->info( | ||
"\n--- Initialization from powerflow ---" | ||
"\nVoltage across: {:s}" | ||
"\nCurrent: {:s}" | ||
"\nTerminal 0 voltage: {:s}" | ||
"\nTerminal 1 voltage: {:s}" | ||
"\n--- Initialization from powerflow finished ---", | ||
Logger::phasorToString((**mIntfVoltage)(0,0)), | ||
Logger::phasorToString((**mIntfCurrent)(0,0)), | ||
Logger::phasorToString(initialSingleVoltage(0)), | ||
Logger::phasorToString(initialSingleVoltage(1))); | ||
mSLog->flush(); | ||
} | ||
|
||
// #### MNA section #### | ||
|
||
void SP::Ph1::ResIndSeries::mnaCompInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) { | ||
updateMatrixNodeIndices(); | ||
**mRightVector = Matrix::Zero(0, 0); | ||
|
||
mSLog->info( | ||
"\n--- MNA initialization ---" | ||
"\nInitial voltage {:s}" | ||
"\nInitial current {:s}" | ||
"\n--- MNA initialization finished ---", | ||
Logger::phasorToString((**mIntfVoltage)(0, 0)), | ||
Logger::phasorToString((**mIntfCurrent)(0, 0))); | ||
} | ||
|
||
void SP::Ph1::ResIndSeries::mnaCompApplySystemMatrixStamp(Matrix& systemMatrix) { | ||
Complex conductance = 1. / mImpedance; | ||
|
||
for (UInt freq = 0; freq < mNumFreqs; freq++) { | ||
// Set diagonal entries | ||
if (terminalNotGrounded(0)) | ||
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), matrixNodeIndex(0), conductance, mNumFreqs, freq); | ||
if (terminalNotGrounded(1)) | ||
// Set off diagonal entries | ||
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), matrixNodeIndex(1), conductance, mNumFreqs, freq); | ||
if (terminalNotGrounded(0) && terminalNotGrounded(1)) { | ||
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1), -conductance, mNumFreqs, freq); | ||
Math::addToMatrixElement(systemMatrix, matrixNodeIndex(1), matrixNodeIndex(0), -conductance, mNumFreqs, freq); | ||
} | ||
|
||
mSLog->info("-- Stamp frequency {:d} ---", freq); | ||
if (terminalNotGrounded(0)) | ||
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(conductance), matrixNodeIndex(0), matrixNodeIndex(0)); | ||
if (terminalNotGrounded(1)) | ||
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(conductance), matrixNodeIndex(1), matrixNodeIndex(1)); | ||
if (terminalNotGrounded(0) && terminalNotGrounded(1)) { | ||
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(-conductance), matrixNodeIndex(0), matrixNodeIndex(1)); | ||
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(-conductance), matrixNodeIndex(1), matrixNodeIndex(0)); | ||
} | ||
} | ||
} | ||
|
||
void SP::Ph1::ResIndSeries::mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) { | ||
attributeDependencies.push_back(leftVector); | ||
modifiedAttributes.push_back(mIntfVoltage); | ||
modifiedAttributes.push_back(mIntfCurrent); | ||
} | ||
|
||
void SP::Ph1::ResIndSeries::mnaCompPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) { | ||
this->mnaUpdateVoltage(**leftVector); | ||
this->mnaUpdateCurrent(**leftVector); | ||
} | ||
|
||
void SP::Ph1::ResIndSeries::mnaCompUpdateVoltage(const Matrix& leftVector) { | ||
// v1 - v0 | ||
for (UInt freq = 0; freq < mNumFreqs; freq++) { | ||
(**mIntfVoltage)(0,freq) = 0; | ||
if (terminalNotGrounded(1)) | ||
(**mIntfVoltage)(0,freq) = Math::complexFromVectorElement(leftVector, matrixNodeIndex(1), mNumFreqs, freq); | ||
if (terminalNotGrounded(0)) | ||
(**mIntfVoltage)(0,freq) = (**mIntfVoltage)(0,freq) - Math::complexFromVectorElement(leftVector, matrixNodeIndex(0), mNumFreqs, freq); | ||
|
||
SPDLOG_LOGGER_DEBUG(mSLog, "Voltage {:s}", Logger::phasorToString((**mIntfVoltage)(0,freq))); | ||
} | ||
} | ||
|
||
void SP::Ph1::ResIndSeries::mnaCompUpdateCurrent(const Matrix& leftVector) { | ||
for (UInt freq = 0; freq < mNumFreqs; freq++) { | ||
(**mIntfCurrent)(0,freq) = (**mIntfVoltage)(0,freq) / mImpedance; | ||
SPDLOG_LOGGER_DEBUG(mSLog, "Current {:s}", Logger::phasorToString((**mIntfCurrent)(0,freq))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.