DPsim
Loading...
Searching...
No Matches
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
11using 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
16EMT::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
31SimPowerComp<Real>::Ptr EMT::Ph3::RxLine::clone(String name) {
32 auto copy = RxLine::make(name, mLogLevel);
33 copy->setParameters(**mSeriesRes, **mSeriesInd);
34 return copy;
35}
36
39 return;
40 mSubCompCreated = true;
41
42 // Default model with virtual node in between
44 std::make_shared<EMT::Ph3::Resistor>(**mName + "_res", mLogLevel);
45 mSubResistor->setParameters(**mSeriesRes);
46 mSubResistor->connect({mTerminals[0]->node(), mVirtualNodes[0]});
47 addMNASubComponent(mSubResistor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
48 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
49
51 std::make_shared<EMT::Ph3::Inductor>(**mName + "_ind", mLogLevel);
52 mSubInductor->setParameters(**mSeriesInd);
53 mSubInductor->connect({mVirtualNodes[0], mTerminals[1]->node()});
54 addMNASubComponent(mSubInductor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
55 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
56
58 std::make_shared<EMT::Ph3::Resistor>(**mName + "_snubber_res", mLogLevel);
59 Matrix defaultSnubRes = Matrix::Zero(3, 3);
60 defaultSnubRes << 1e6, 0, 0, 0, 1e6, 0, 0, 0, 1e6;
61 mInitialResistor->setParameters(defaultSnubRes);
62 mInitialResistor->connect({SimNode::GND, mTerminals[1]->node()});
64 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
65 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
66}
67
69 // Static calculation
70 Real omega = 2. * PI * frequency;
71 MatrixComp impedance = MatrixComp::Zero(3, 3);
72 impedance << Complex((**mSeriesRes)(0, 0), omega * (**mSeriesInd)(0, 0)),
73 Complex((**mSeriesRes)(0, 1), omega * (**mSeriesInd)(0, 1)),
74 Complex((**mSeriesRes)(0, 2), omega * (**mSeriesInd)(0, 2)),
75 Complex((**mSeriesRes)(1, 0), omega * (**mSeriesInd)(1, 0)),
76 Complex((**mSeriesRes)(1, 1), omega * (**mSeriesInd)(1, 1)),
77 Complex((**mSeriesRes)(1, 2), omega * (**mSeriesInd)(1, 2)),
78 Complex((**mSeriesRes)(2, 0), omega * (**mSeriesInd)(2, 0)),
79 Complex((**mSeriesRes)(2, 1), omega * (**mSeriesInd)(2, 1)),
80 Complex((**mSeriesRes)(2, 2), omega * (**mSeriesInd)(2, 2));
81
82 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
83 vInitABC(0, 0) =
84 mVirtualNodes[0]->initialSingleVoltage() - initialSingleVoltage(0);
85 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
86 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
87
88 **mIntfCurrent = (impedance.inverse() * vInitABC).real();
89 **mIntfVoltage = vInitABC.real();
90 // Initialization of virtual node
91 // Initial voltage of phase B,C is set after A
92 MatrixComp vInitTerm0 = MatrixComp::Zero(3, 1);
93 vInitTerm0(0, 0) = initialSingleVoltage(0);
94 vInitTerm0(1, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_B;
95 vInitTerm0(2, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_C;
96
97 mVirtualNodes[0]->setInitialVoltage(vInitTerm0 +
99
100 SPDLOG_LOGGER_INFO(mSLog,
101 "\n--- Initialization from powerflow ---"
102 "\nVoltage across: {:s}"
103 "\nCurrent: {:s}"
104 "\nTerminal 0 voltage: {:s}"
105 "\nTerminal 1 voltage: {:s}"
106 "\n--- Initialization from powerflow finished ---",
107 Logger::matrixToString(**mIntfVoltage),
108 Logger::matrixToString(**mIntfCurrent),
109 Logger::phasorToString(initialSingleVoltage(0)),
110 Logger::phasorToString(initialSingleVoltage(1)));
111}
112
113void EMT::Ph3::RxLine::mnaParentAddPreStepDependencies(
114 AttributeBase::List &prevStepDependencies,
115 AttributeBase::List &attributeDependencies,
116 AttributeBase::List &modifiedAttributes) {
117 modifiedAttributes.push_back(mRightVector);
118};
119
120void EMT::Ph3::RxLine::mnaParentAddPostStepDependencies(
121 AttributeBase::List &prevStepDependencies,
122 AttributeBase::List &attributeDependencies,
123 AttributeBase::List &modifiedAttributes,
124 Attribute<Matrix>::Ptr &leftVector) {
125 attributeDependencies.push_back(leftVector);
126 modifiedAttributes.push_back(mIntfCurrent);
127 modifiedAttributes.push_back(mIntfVoltage);
128};
129
133
134void EMT::Ph3::RxLine::mnaParentPostStep(Real time, Int timeStepCount,
135 Attribute<Matrix>::Ptr &leftVector) {
136 mnaCompUpdateVoltage(**leftVector);
137 mnaCompUpdateCurrent(**leftVector);
138}
139
140void EMT::Ph3::RxLine::mnaCompUpdateVoltage(const Matrix &leftVector) {
141 // v1 - v0
142 **mIntfVoltage = Matrix::Zero(3, 1);
143 if (terminalNotGrounded(1)) {
144 (**mIntfVoltage)(0, 0) =
145 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 0));
146 (**mIntfVoltage)(1, 0) =
147 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 1));
148 (**mIntfVoltage)(2, 0) =
149 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 2));
150 }
151 if (terminalNotGrounded(0)) {
152 (**mIntfVoltage)(0, 0) =
153 (**mIntfVoltage)(0, 0) -
154 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
155 (**mIntfVoltage)(1, 0) =
156 (**mIntfVoltage)(1, 0) -
157 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
158 (**mIntfVoltage)(2, 0) =
159 (**mIntfVoltage)(2, 0) -
160 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
161 }
162}
163
164void EMT::Ph3::RxLine::mnaCompUpdateCurrent(const Matrix &leftVector) {
165 **mIntfCurrent = mSubInductor->intfCurrent();
166}
const Attribute< Matrix >::Ptr mSeriesRes
Resistance along the line [ohms].
const Attribute< Matrix >::Ptr mSeriesInd
Inductance along the line [H].
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)
std::shared_ptr< Resistor > mSubResistor
Resistor submodel.
std::shared_ptr< Inductor > mSubInductor
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 createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
std::shared_ptr< Resistor > mInitialResistor
Inductor end to ground resistor to facilitate initialization.
void initializeParentFromNodesAndTerminals(Real frequency) override
Derives values from power flow data and pushes them to subcomponents.
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.