DPsim
Loading...
Searching...
No Matches
EMT_Ph3_PiLine.cpp
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
9#include <dpsim-models/EMT/EMT_Ph3_PiLine.h>
10
11using namespace CPS;
12
13EMT::Ph3::PiLine::PiLine(String uid, String name, Logger::Level logLevel)
14 : Base::Ph3::PiLine(mAttributes),
15 CompositePowerComp<Real>(uid, name, true, true, logLevel) {
16 mPhaseType = PhaseType::ABC;
17 setVirtualNodeNumber(1);
18 setTerminalNumber(2);
19
20 SPDLOG_LOGGER_INFO(mSLog, "Create {} {}", this->type(), name);
21 **mIntfVoltage = Matrix::Zero(3, 1);
22 **mIntfCurrent = Matrix::Zero(3, 1);
23
24 mSLog->flush();
25}
26
28SimPowerComp<Real>::Ptr EMT::Ph3::PiLine::clone(String name) {
29 auto copy = PiLine::make(name, mLogLevel);
30 copy->setParameters(**mSeriesRes, **mSeriesInd, **mParallelCap,
32 return copy;
33}
34
37 return;
38 mSubCompCreated = true;
39
40 // By default there is always a small conductance to ground to
41 // avoid problems with floating nodes.
42 Matrix defaultParallelCond = Matrix::Zero(3, 3);
43 defaultParallelCond << 1e-6, 0, 0, 0, 1e-6, 0, 0, 0, 1e-6;
45 ((**mParallelCond)(0, 0) > 0) ? **mParallelCond : defaultParallelCond;
46
47 // Create series sub components
49 std::make_shared<EMT::Ph3::Resistor>(**mName + "_res", mLogLevel);
50 mSubSeriesResistor->setParameters(**mSeriesRes);
51 mSubSeriesResistor->connect({mTerminals[0]->node(), mVirtualNodes[0]});
54 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
55 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
56
58 std::make_shared<EMT::Ph3::Inductor>(**mName + "_ind", mLogLevel);
59 mSubSeriesInductor->setParameters(**mSeriesInd);
60 mSubSeriesInductor->connect({mVirtualNodes[0], mTerminals[1]->node()});
63 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
64 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
65
66 // Create parallel sub components
68 std::make_shared<EMT::Ph3::Resistor>(**mName + "_con0", mLogLevel);
69 mSubParallelResistor0->setParameters(2. * (**mParallelCond).inverse());
70 mSubParallelResistor0->connect(
71 SimNode::List{SimNode::GND, mTerminals[0]->node()});
74 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
75 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
76
78 std::make_shared<EMT::Ph3::Resistor>(**mName + "_con1", mLogLevel);
79 mSubParallelResistor1->setParameters(2. * (**mParallelCond).inverse());
80 mSubParallelResistor1->connect(
81 SimNode::List{SimNode::GND, mTerminals[1]->node()});
84 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
85 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
86
87 if ((**mParallelCap)(0, 0) > 0) {
88 mSubParallelCapacitor0 =
89 std::make_shared<EMT::Ph3::Capacitor>(**mName + "_cap0", mLogLevel);
90 mSubParallelCapacitor0->setParameters(**mParallelCap / 2.);
91 mSubParallelCapacitor0->connect(
92 SimNode::List{SimNode::GND, mTerminals[0]->node()});
93 mSubParallelCapacitor0->initialize(mFrequencies);
94 addMNASubComponent(mSubParallelCapacitor0,
95 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
96 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
97
98 mSubParallelCapacitor1 =
99 std::make_shared<EMT::Ph3::Capacitor>(**mName + "_cap1", mLogLevel);
100 mSubParallelCapacitor1->setParameters(**mParallelCap / 2.);
101 mSubParallelCapacitor1->connect(
102 SimNode::List{SimNode::GND, mTerminals[1]->node()});
103 mSubParallelCapacitor1->initialize(mFrequencies);
104 addMNASubComponent(mSubParallelCapacitor1,
105 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
106 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
107 }
108}
109
111 // Static calculation
112 Real omega = 2. * PI * frequency;
113 MatrixComp impedance = MatrixComp::Zero(3, 3);
114 impedance << Complex((**mSeriesRes)(0, 0), omega * (**mSeriesInd)(0, 0)),
115 Complex((**mSeriesRes)(0, 1), omega * (**mSeriesInd)(0, 1)),
116 Complex((**mSeriesRes)(0, 2), omega * (**mSeriesInd)(0, 2)),
117 Complex((**mSeriesRes)(1, 0), omega * (**mSeriesInd)(1, 0)),
118 Complex((**mSeriesRes)(1, 1), omega * (**mSeriesInd)(1, 1)),
119 Complex((**mSeriesRes)(1, 2), omega * (**mSeriesInd)(1, 2)),
120 Complex((**mSeriesRes)(2, 0), omega * (**mSeriesInd)(2, 0)),
121 Complex((**mSeriesRes)(2, 1), omega * (**mSeriesInd)(2, 1)),
122 Complex((**mSeriesRes)(2, 2), omega * (**mSeriesInd)(2, 2));
123
124 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
125 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(1) -
126 RMS3PH_TO_PEAK1PH * initialSingleVoltage(0);
127 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
128 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
129 MatrixComp iInit = impedance.inverse() * vInitABC;
130 **mIntfCurrent = iInit.real();
131 **mIntfVoltage = vInitABC.real();
132
133 // Initialization of virtual node
134 // Initial voltage of phase B,C is set after A
135 MatrixComp vInitTerm0 = MatrixComp::Zero(3, 1);
136 vInitTerm0(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(0);
137 vInitTerm0(1, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_B;
138 vInitTerm0(2, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_C;
139
140 mVirtualNodes[0]->setInitialVoltage(PEAK1PH_TO_RMS3PH *
141 (vInitTerm0 + **mSeriesRes * iInit));
142
143 SPDLOG_LOGGER_DEBUG(mSLog,
144 "\n--debug--"
145 "\n seriesRes: {:s}"
146 "\n seriesInd: {:s}"
147 "\n Impedance: {:s}"
148 "\n vInit: {:s}"
149 "\n iInit: {:s}",
150 Logger::matrixToString(**mSeriesRes),
151 Logger::matrixToString(**mSeriesInd),
152 Logger::matrixCompToString(impedance),
153 Logger::matrixCompToString(vInitABC),
154 Logger::matrixCompToString(iInit));
155
156 SPDLOG_LOGGER_INFO(
157 mSLog,
158 "\n--- Initialization from powerflow ---"
159 "\nVoltage across: {:s}"
160 "\nCurrent: {:s}"
161 "\nTerminal 0 voltage: {:s}"
162 "\nTerminal 1 voltage: {:s}"
163 "\nVirtual Node 1 voltage: {:s}"
164 "\n--- Initialization from powerflow finished ---",
165 Logger::matrixToString(**mIntfVoltage),
166 Logger::matrixToString(**mIntfCurrent),
167 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(0)),
168 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(1)),
169 Logger::phasorToString(mVirtualNodes[0]->initialSingleVoltage()));
170 mSLog->flush();
171}
172
174 AttributeBase::List &prevStepDependencies,
175 AttributeBase::List &attributeDependencies,
176 AttributeBase::List &modifiedAttributes) {
177 prevStepDependencies.push_back(mIntfCurrent);
178 prevStepDependencies.push_back(mIntfVoltage);
179 modifiedAttributes.push_back(mRightVector);
180}
181
185
187 AttributeBase::List &prevStepDependencies,
188 AttributeBase::List &attributeDependencies,
189 AttributeBase::List &modifiedAttributes,
190 Attribute<Matrix>::Ptr &leftVector) {
191 attributeDependencies.push_back(leftVector);
192 modifiedAttributes.push_back(mIntfVoltage);
193 modifiedAttributes.push_back(mIntfCurrent);
194}
195
196void EMT::Ph3::PiLine::mnaParentPostStep(Real time, Int timeStepCount,
197 Attribute<Matrix>::Ptr &leftVector) {
198 mnaCompUpdateVoltage(**leftVector);
199 mnaCompUpdateCurrent(**leftVector);
200}
201
202void EMT::Ph3::PiLine::mnaCompUpdateVoltage(const Matrix &leftVector) {
203 // v1 - v0
204 **mIntfVoltage = Matrix::Zero(3, 1);
205 if (terminalNotGrounded(1)) {
206 (**mIntfVoltage)(0, 0) =
207 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 0));
208 (**mIntfVoltage)(1, 0) =
209 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 1));
210 (**mIntfVoltage)(2, 0) =
211 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 2));
212 }
213 if (terminalNotGrounded(0)) {
214 (**mIntfVoltage)(0, 0) =
215 (**mIntfVoltage)(0, 0) -
216 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
217 (**mIntfVoltage)(1, 0) =
218 (**mIntfVoltage)(1, 0) -
219 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
220 (**mIntfVoltage)(2, 0) =
221 (**mIntfVoltage)(2, 0) -
222 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
223 }
224}
225
226void EMT::Ph3::PiLine::mnaCompUpdateCurrent(const Matrix &leftVector) {
227 **mIntfCurrent = mSubSeriesInductor->intfCurrent();
228}
229
230// #### Tear Methods ####
231MNAInterface::List EMT::Ph3::PiLine::mnaTearGroundComponents() {
232 MNAInterface::List gndComponents;
233
234 gndComponents.push_back(mSubParallelResistor0);
235 gndComponents.push_back(mSubParallelResistor1);
236
237 if ((**mParallelCap)(0, 0) > 0) {
238 gndComponents.push_back(mSubParallelCapacitor0);
239 gndComponents.push_back(mSubParallelCapacitor1);
240 }
241
242 return gndComponents;
243}
244
245void EMT::Ph3::PiLine::mnaTearInitialize(Real omega, Real timeStep) {
246 mSubSeriesResistor->mnaTearSetIdx(mTearIdx);
247 mSubSeriesResistor->mnaTearInitialize(omega, timeStep);
248 mSubSeriesInductor->mnaTearSetIdx(mTearIdx);
249 mSubSeriesInductor->mnaTearInitialize(omega, timeStep);
250}
251
252void EMT::Ph3::PiLine::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
253 mSubSeriesResistor->mnaTearApplyMatrixStamp(tearMatrix);
254 mSubSeriesInductor->mnaTearApplyMatrixStamp(tearMatrix);
255}
256
257void EMT::Ph3::PiLine::mnaTearApplyVoltageStamp(Matrix &voltageVector) {
258 mSubSeriesInductor->mnaTearApplyVoltageStamp(voltageVector);
259}
260
261void EMT::Ph3::PiLine::mnaTearPostStep(MatrixComp voltage, MatrixComp current) {
262 mSubSeriesInductor->mnaTearPostStep(voltage - (**mSeriesRes * current),
263 current);
264 (**mIntfCurrent) = mSubSeriesInductor->intfCurrent();
265}
const Attribute< Matrix >::Ptr mParallelCond
Conductance in parallel to the line [S].
const Attribute< Matrix >::Ptr mSeriesRes
Resistance along the line [ohms].
const Attribute< Matrix >::Ptr mSeriesInd
Inductance along the line [H].
const Attribute< Matrix >::Ptr mParallelCap
Capacitance in parallel to the line [F].
void addMNASubComponent(typename SimPowerComp< Real >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
PiLine(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
SimPowerComp< Real >::Ptr clone(String copySuffix) override
DEPRECATED: Delete method.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates internal voltage variable of the component.
std::shared_ptr< Resistor > mSubParallelResistor0
Parallel Resistor submodel at Terminal 0.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void initializeParentFromNodesAndTerminals(Real frequency) override
Derives values from power flow data and pushes them to subcomponents.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Updates internal current variable of the component.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
std::shared_ptr< Inductor > mSubSeriesInductor
std::shared_ptr< Resistor > mSubSeriesResistor
Series Resistor submodel.
void createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
std::shared_ptr< Resistor > mSubParallelResistor1
Parallel resistor submodel at Terminal 1.
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.
Attribute< Matrix >::Ptr mRightVector
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::List mTerminals
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
SimNode< Real >::List mVirtualNodes
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.