DPsim
Loading...
Searching...
No Matches
EMT_Ph3_RxLine.cpp
Go to the documentation of this file.
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
11
12using namespace CPS;
13
14// !!! TODO: Adaptions to use in EMT_Ph3 models phase-to-ground peak variables
15// !!! with initialization from phase-to-phase RMS variables
16
19
21 Logger::Level logLevel)
23 CompositePowerComp<Real>(uid, name, true, true, logLevel) {
24 mUseSubcomponents = useSubcomponents;
25 mDirectState = mAttributes->create<Matrix>("direct_state");
26 **mDirectState = Matrix::Zero(6, 1);
30
31 SPDLOG_LOGGER_INFO(mSLog, "Create {} {}", this->type(), name);
32 **mIntfVoltage = Matrix::Zero(3, 1);
33 **mIntfCurrent = Matrix::Zero(3, 1);
34
35 mSLog->flush();
36}
37
41 copy->setParameters(**mSeriesRes, **mSeriesInd);
42 return copy;
43}
44
47 return;
48 mSubCompCreated = true;
49
51 return;
52
53 // Default model with virtual node in between
55 std::make_shared<EMT::Ph3::Resistor>(**mName + "_res", mLogLevel);
56 mSubResistor->setParameters(**mSeriesRes);
57 mSubResistor->connect({mTerminals[0]->node(), mVirtualNodes[0]});
60
62 std::make_shared<EMT::Ph3::Inductor>(**mName + "_ind", mLogLevel);
63 mSubInductor->setParameters(**mSeriesInd);
64 mSubInductor->connect({mVirtualNodes[0], mTerminals[1]->node()});
67
69 std::make_shared<EMT::Ph3::Resistor>(**mName + "_snubber_res", mLogLevel);
70 Matrix defaultSnubRes = Matrix::Zero(3, 3);
71 defaultSnubRes << 1e6, 0, 0, 0, 1e6, 0, 0, 0, 1e6;
72 mInitialResistor->setParameters(defaultSnubRes);
73 mInitialResistor->connect({SimNode::GND, mTerminals[1]->node()});
77}
78
80 // Match PiLine's RMS line-to-neutral power-flow phasors to the peak
81 // phase-to-ground values used by the EMT subcomponents. The virtual node is
82 // not initialized yet here, so deriving the branch voltage from it would
83 // start the inductor with an arbitrary (usually zero) voltage.
84 Real omega = 2. * PI * frequency;
85 MatrixComp impedance = MatrixComp::Zero(3, 3);
86 impedance << Complex((**mSeriesRes)(0, 0), omega * (**mSeriesInd)(0, 0)),
87 Complex((**mSeriesRes)(0, 1), omega * (**mSeriesInd)(0, 1)),
88 Complex((**mSeriesRes)(0, 2), omega * (**mSeriesInd)(0, 2)),
89 Complex((**mSeriesRes)(1, 0), omega * (**mSeriesInd)(1, 0)),
90 Complex((**mSeriesRes)(1, 1), omega * (**mSeriesInd)(1, 1)),
91 Complex((**mSeriesRes)(1, 2), omega * (**mSeriesInd)(1, 2)),
92 Complex((**mSeriesRes)(2, 0), omega * (**mSeriesInd)(2, 0)),
93 Complex((**mSeriesRes)(2, 1), omega * (**mSeriesInd)(2, 1)),
94 Complex((**mSeriesRes)(2, 2), omega * (**mSeriesInd)(2, 2));
95
96 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
97 vInitABC(0, 0) =
99 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
100 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
101
102 MatrixComp iInit = impedance.inverse() * vInitABC;
103 **mIntfCurrent = iInit.real();
104 **mIntfVoltage = vInitABC.real();
105 // Initialization of virtual node
106 // Initial voltage of phase B,C is set after A
107 MatrixComp vInitTerm0 = MatrixComp::Zero(3, 1);
108 vInitTerm0(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(0);
109 vInitTerm0(1, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_B;
110 vInitTerm0(2, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_C;
111
112 mVirtualNodes[0]->setInitialVoltage(PEAK1PH_TO_RMS3PH *
113 (vInitTerm0 + **mSeriesRes * iInit));
114 if (!mUseSubcomponents) {
115 (**mDirectState).setZero();
116 (**mDirectState).block<3, 1>(0, 0) = iInit.real();
117 (**mDirectState).block<3, 1>(3, 0) =
118 (vInitABC - (**mSeriesRes).cast<Complex>() * iInit).real();
119 }
120
121 SPDLOG_LOGGER_INFO(mSLog,
122 "\n--- Initialization from powerflow ---"
123 "\nVoltage across: {:s}"
124 "\nCurrent: {:s}"
125 "\nTerminal 0 voltage: {:s}"
126 "\nTerminal 1 voltage: {:s}"
127 "\n--- Initialization from powerflow finished ---",
132}
133
137 mDirectInductorAdmittance = (timeStep / 2.) * (**mSeriesInd).inverse();
138}
139
141 SparseMatrixRow &systemMatrix) {
143 return;
146 const Matrix snubberConductance = Matrix::Identity(3, 3) * 1e-6;
148 (**mSeriesRes).inverse(), systemMatrix, mDirectTerminalIndices[0][0],
154 snubberConductance, systemMatrix, mDirectTerminalIndices[1][0], 0,
156}
157
159 for (UInt terminal = 0; terminal < 2; ++terminal) {
161 for (UInt phase = 0; phase < 3; ++phase)
164 }
165 for (UInt phase = 0; phase < 3; ++phase)
167 mVirtualNodes[0]->matrixNodeIndex(static_cast<PhaseType>(phase));
168}
169
172 return;
173 for (UInt phase = 0; phase < 3; ++phase) {
175 mDirectHistory(phase));
177 Math::setVectorElement(rightVector, mDirectTerminalIndices[1][phase],
178 -mDirectHistory(phase));
179 }
180}
181
186
188 if (mUseSubcomponents) {
190 return;
191 }
192 for (UInt phase = 0; phase < 3; ++phase) {
194 rightVector, mDirectMidpointIndices[phase],
196 mDirectMidpointIndices[phase]));
198 const UInt index = mDirectTerminalIndices[1][phase];
200 rightVector, index,
202 }
203 }
204}
205
207 AttributeBase::List &prevStepDependencies,
208 AttributeBase::List &attributeDependencies,
209 AttributeBase::List &modifiedAttributes) {
211 prevStepDependencies.push_back(mDirectState);
212 modifiedAttributes.push_back(mRightVector);
213};
214
216 AttributeBase::List &prevStepDependencies,
217 AttributeBase::List &attributeDependencies,
218 AttributeBase::List &modifiedAttributes,
219 Attribute<Matrix>::Ptr &leftVector) {
220 attributeDependencies.push_back(leftVector);
221 modifiedAttributes.push_back(mIntfCurrent);
222 modifiedAttributes.push_back(mIntfVoltage);
224 modifiedAttributes.push_back(mDirectState);
225};
226
227void EMT::Ph3::RxLine::mnaParentPreStep(Real time, Int timeStepCount) {
228 if (!mUseSubcomponents) {
229 mDirectHistory.noalias() =
230 mDirectInductorAdmittance * (**mDirectState).block<3, 1>(3, 0);
231 mDirectHistory += (**mDirectState).block<3, 1>(0, 0);
232 }
234}
235
237 Attribute<Matrix>::Ptr &leftVector) {
238 if (!mUseSubcomponents) {
239 Eigen::Matrix<Real, 3, 1> v0 = Eigen::Matrix<Real, 3, 1>::Zero();
240 Eigen::Matrix<Real, 3, 1> v1 = Eigen::Matrix<Real, 3, 1>::Zero();
241 Eigen::Matrix<Real, 3, 1> vmid;
243 for (UInt phase = 0; phase < 3; ++phase)
244 v0(phase) = Math::realFromVectorElement(
245 **leftVector, mDirectTerminalIndices[0][phase]);
247 for (UInt phase = 0; phase < 3; ++phase)
248 v1(phase) = Math::realFromVectorElement(
249 **leftVector, mDirectTerminalIndices[1][phase]);
250 for (UInt phase = 0; phase < 3; ++phase)
251 vmid(phase) = Math::realFromVectorElement(**leftVector,
253 **mIntfVoltage = v1 - v0;
255 (**mDirectState).block<3, 1>(0, 0) = **mIntfCurrent;
256 (**mDirectState).block<3, 1>(3, 0) = v1 - vmid;
257 return;
258 }
259 mnaCompUpdateVoltage(**leftVector);
260 mnaCompUpdateCurrent(**leftVector);
261}
262
264 // v1 - v0
265 (**mIntfVoltage).setZero();
266 if (terminalNotGrounded(1)) {
267 (**mIntfVoltage)(0, 0) =
269 (**mIntfVoltage)(1, 0) =
271 (**mIntfVoltage)(2, 0) =
273 }
274 if (terminalNotGrounded(0)) {
275 (**mIntfVoltage)(0, 0) =
276 (**mIntfVoltage)(0, 0) -
278 (**mIntfVoltage)(1, 0) =
279 (**mIntfVoltage)(1, 0) -
281 (**mIntfVoltage)(2, 0) =
282 (**mIntfVoltage)(2, 0) -
284 }
285}
286
288 if (!mUseSubcomponents) {
289 Eigen::Matrix<Real, 3, 1> v1 = Eigen::Matrix<Real, 3, 1>::Zero();
290 Eigen::Matrix<Real, 3, 1> vmid;
292 for (UInt phase = 0; phase < 3; ++phase)
293 v1(phase) = Math::realFromVectorElement(
294 leftVector, mDirectTerminalIndices[1][phase]);
295 for (UInt phase = 0; phase < 3; ++phase)
296 vmid(phase) = Math::realFromVectorElement(leftVector,
299 return;
300 }
301 **mIntfCurrent = mSubInductor->intfCurrent();
302}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
const Attribute< Matrix >::Ptr mSeriesRes
Resistance along the line [ohms].
const Attribute< Matrix >::Ptr mSeriesInd
Inductance along the line [H].
PiLine(CPS::AttributeList::Ptr attributeList)
void addMNASubComponent(typename SimPowerComp< Real >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
Bool mnaHasCompactRightSideVectorStamp() const override
Composite stamps touch only their cached terminal and virtual-node rows.
void mnaAddCompactRightSideVectorStamp(Matrix &rightVector) override
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
std::array< Bool, 2 > mDirectTerminalConnected
Attribute< Matrix >::Ptr mDirectState
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
std::shared_ptr< Resistor > mSubResistor
Resistor submodel.
std::shared_ptr< Inductor > mSubInductor
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Bool mnaHasCompactRightSideVectorStamp() const override
Composite stamps touch only their cached terminal and virtual-node rows.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
std::array< UInt, 3 > mDirectMidpointIndices
void mnaCompUpdateCurrent(const Matrix &leftVector) override
RxLine(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, logging level.
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre and post step operations.
SimPowerComp< Real >::Ptr clone(String name) override
DEPRECATED: Delete method.
void createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
std::shared_ptr< Resistor > mInitialResistor
Inductor end to ground resistor to facilitate initialization.
void mnaAddCompactRightSideVectorStamp(Matrix &rightVector) override
void mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
void initializeParentFromNodesAndTerminals(Real frequency) override
Derives values from power flow data and pushes them to subcomponents.
std::array< std::array< UInt, 3 >, 2 > mDirectTerminalIndices
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
String type()
Get component type (cross-platform)
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixToString(const Matrix &mat)
Definition Logger.cpp:31
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
Attribute< Matrix >::Ptr mRightVector
static void stampConductanceMatrix(const Matrix &conductanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog)
static Real realFromVectorElement(const Matrix &mat, Matrix::Index row)
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
static void addToVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0)
static Ptr GND
Definition SimNode.h:37
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::List mTerminals
SimTerminal< Real >::Ptr terminal(UInt index)
void setVirtualNodeNumber(UInt num)
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
SimNode< Real >::List mVirtualNodes
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
void setTerminalNumber(UInt num)
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.
static std::shared_ptr< RxLine > make(Args &&...args)
Definition PtrFactory.h:19
#define PI
Definition Definitions.h:43
#define RMS3PH_TO_PEAK1PH
Definition Definitions.h:50
#define SHIFT_TO_PHASE_C
Definition Definitions.h:47
#define PEAK1PH_TO_RMS3PH
Definition Definitions.h:51
#define SHIFT_TO_PHASE_B
Definition Definitions.h:46
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:79
std::string String
Definition Definitions.h:63
double Real
Definition Definitions.h:60
int Int
Definition Definitions.h:59
std::complex< Real > Complex
Definition Definitions.h:61
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:82
bool Bool
Definition Definitions.h:62
unsigned int UInt
Definition Definitions.h:58
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72