DPsim
EMT_Ph3_RxLine.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_RxLine.h>
10 
11 using namespace CPS;
12 
13 // !!! TODO: Adaptions to use in EMT_Ph3 models phase-to-ground peak variables
14 // !!! with initialization from phase-to-phase RMS variables
15 
16 EMT::Ph3::RxLine::RxLine(String uid, String name, Logger::Level logLevel)
17  : Base::Ph3::PiLine(mAttributes),
18  CompositePowerComp<Real>(uid, name, true, true, logLevel) {
19  mPhaseType = PhaseType::ABC;
20  setVirtualNodeNumber(1);
21  setTerminalNumber(2);
22 
23  SPDLOG_LOGGER_INFO(mSLog, "Create {} {}", this->type(), name);
24  **mIntfVoltage = Matrix::Zero(3, 1);
25  **mIntfCurrent = Matrix::Zero(3, 1);
26 
27  mSLog->flush();
28 }
29 
32  auto copy = RxLine::make(name, mLogLevel);
33  copy->setParameters(**mSeriesRes, **mSeriesInd);
34  return copy;
35 }
36 
38 
39  // Static calculation
40  Real omega = 2. * PI * frequency;
41  MatrixComp impedance = MatrixComp::Zero(3, 3);
42  impedance << Complex((**mSeriesRes)(0, 0), omega * (**mSeriesInd)(0, 0)),
43  Complex((**mSeriesRes)(0, 1), omega * (**mSeriesInd)(0, 1)),
44  Complex((**mSeriesRes)(0, 2), omega * (**mSeriesInd)(0, 2)),
45  Complex((**mSeriesRes)(1, 0), omega * (**mSeriesInd)(1, 0)),
46  Complex((**mSeriesRes)(1, 1), omega * (**mSeriesInd)(1, 1)),
47  Complex((**mSeriesRes)(1, 2), omega * (**mSeriesInd)(1, 2)),
48  Complex((**mSeriesRes)(2, 0), omega * (**mSeriesInd)(2, 0)),
49  Complex((**mSeriesRes)(2, 1), omega * (**mSeriesInd)(2, 1)),
50  Complex((**mSeriesRes)(2, 2), omega * (**mSeriesInd)(2, 2));
51 
52  MatrixComp vInitABC = MatrixComp::Zero(3, 1);
53  vInitABC(0, 0) =
54  mVirtualNodes[0]->initialSingleVoltage() - initialSingleVoltage(0);
55  vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
56  vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
57 
58  **mIntfCurrent = (impedance.inverse() * vInitABC).real();
59  **mIntfVoltage = vInitABC.real();
60  // Initialization of virtual node
61  // Initial voltage of phase B,C is set after A
62  MatrixComp vInitTerm0 = MatrixComp::Zero(3, 1);
63  vInitTerm0(0, 0) = initialSingleVoltage(0);
64  vInitTerm0(1, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_B;
65  vInitTerm0(2, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_C;
66 
67  mVirtualNodes[0]->setInitialVoltage(vInitTerm0 +
68  **mSeriesRes * **mIntfCurrent);
69 
70  // Default model with virtual node in between
71  mSubResistor =
72  std::make_shared<EMT::Ph3::Resistor>(**mName + "_res", mLogLevel);
73  mSubResistor->setParameters(**mSeriesRes);
74  mSubResistor->connect({mTerminals[0]->node(), mVirtualNodes[0]});
75  mSubResistor->initializeFromNodesAndTerminals(frequency);
76  addMNASubComponent(mSubResistor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
77  MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
78 
79  mSubInductor =
80  std::make_shared<EMT::Ph3::Inductor>(**mName + "_ind", mLogLevel);
81  mSubInductor->setParameters(**mSeriesInd);
82  mSubInductor->connect({mVirtualNodes[0], mTerminals[1]->node()});
83  mSubInductor->initializeFromNodesAndTerminals(frequency);
84  addMNASubComponent(mSubInductor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
85  MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
86 
87  mInitialResistor =
88  std::make_shared<EMT::Ph3::Resistor>(**mName + "_snubber_res", mLogLevel);
89  Matrix defaultSnubRes = Matrix::Zero(3, 1);
90  defaultSnubRes << 1e6, 0, 0, 0, 1e6, 0, 0, 0, 1e6;
91  mInitialResistor->setParameters(defaultSnubRes);
92  mInitialResistor->connect({SimNode::GND, mTerminals[1]->node()});
93  mInitialResistor->initializeFromNodesAndTerminals(frequency);
94  addMNASubComponent(mInitialResistor,
95  MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
96  MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
97 
98  SPDLOG_LOGGER_INFO(mSLog,
99  "\n--- Initialization from powerflow ---"
100  "\nVoltage across: {:s}"
101  "\nCurrent: {:s}"
102  "\nTerminal 0 voltage: {:s}"
103  "\nTerminal 1 voltage: {:s}"
104  "\n--- Initialization from powerflow finished ---",
105  Logger::matrixToString(**mIntfVoltage),
106  Logger::matrixToString(**mIntfCurrent),
107  Logger::phasorToString(initialSingleVoltage(0)),
108  Logger::phasorToString(initialSingleVoltage(1)));
109 }
110 
111 void EMT::Ph3::RxLine::mnaParentAddPreStepDependencies(
112  AttributeBase::List &prevStepDependencies,
113  AttributeBase::List &attributeDependencies,
114  AttributeBase::List &modifiedAttributes) {
115  modifiedAttributes.push_back(mRightVector);
116 };
117 
118 void EMT::Ph3::RxLine::mnaParentAddPostStepDependencies(
119  AttributeBase::List &prevStepDependencies,
120  AttributeBase::List &attributeDependencies,
121  AttributeBase::List &modifiedAttributes,
122  Attribute<Matrix>::Ptr &leftVector) {
123  attributeDependencies.push_back(leftVector);
124  modifiedAttributes.push_back(mIntfCurrent);
125  modifiedAttributes.push_back(mIntfVoltage);
126 };
127 
128 void EMT::Ph3::RxLine::mnaParentPreStep(Real time, Int timeStepCount) {
129  mnaCompApplyRightSideVectorStamp(**mRightVector);
130 }
131 
132 void EMT::Ph3::RxLine::mnaParentPostStep(Real time, Int timeStepCount,
133  Attribute<Matrix>::Ptr &leftVector) {
134  mnaCompUpdateVoltage(**leftVector);
135  mnaCompUpdateCurrent(**leftVector);
136 }
137 
138 void EMT::Ph3::RxLine::mnaCompUpdateVoltage(const Matrix &leftVector) {
139  // v1 - v0
140  **mIntfVoltage = Matrix::Zero(3, 1);
141  if (terminalNotGrounded(1)) {
142  (**mIntfVoltage)(0, 0) =
143  Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 0));
144  (**mIntfVoltage)(1, 0) =
145  Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 1));
146  (**mIntfVoltage)(2, 0) =
147  Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 2));
148  }
149  if (terminalNotGrounded(0)) {
150  (**mIntfVoltage)(0, 0) =
151  (**mIntfVoltage)(0, 0) -
152  Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
153  (**mIntfVoltage)(1, 0) =
154  (**mIntfVoltage)(1, 0) -
155  Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
156  (**mIntfVoltage)(2, 0) =
157  (**mIntfVoltage)(2, 0) -
158  Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
159  }
160 }
161 
162 void EMT::Ph3::RxLine::mnaCompUpdateCurrent(const Matrix &leftVector) {
163  **mIntfCurrent = mSubInductor->intfCurrent();
164 }
Base class for composite power components.
PI-line dynamic phasor model.
RxLine(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, logging level.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre and post step operations.
SimPowerComp< Real >::Ptr clone(String name) override
DEPRECATED: Delete method.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
String type()
Get component type (cross-platform)
Base class for all components that are transmitting power.
Definition: SimPowerComp.h:17
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
Current through component.
Definition: SimPowerComp.h:47
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Voltage between terminals.
Definition: SimPowerComp.h:45
Logger::Log mSLog
Component logger.