DPsim
Loading...
Searching...
No Matches
EMT_Ph3_Inductor.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_Inductor.h>
10
11using namespace CPS;
12
13EMT::Ph3::Inductor::Inductor(String uid, String name, Logger::Level logLevel)
14 : MNASimPowerComp<Real>(uid, name, true, true, logLevel),
15 Base::Ph3::Inductor(mAttributes) {
16 mPhaseType = PhaseType::ABC;
17 setTerminalNumber(2);
18 mEquivCurrent = Matrix::Zero(3, 1);
19 **mIntfVoltage = Matrix::Zero(3, 1);
20 **mIntfCurrent = Matrix::Zero(3, 1);
21}
22
23SimPowerComp<Real>::Ptr EMT::Ph3::Inductor::clone(String name) {
24 auto copy = Inductor::make(name, mLogLevel);
25 copy->setParameters(**mInductance);
26 return copy;
27}
28
30
31 Real omega = 2 * PI * frequency;
32 MatrixComp impedance = MatrixComp::Zero(3, 3);
33 impedance << Complex(0, omega * (**mInductance)(0, 0)),
34 Complex(0, omega * (**mInductance)(0, 1)),
35 Complex(0, omega * (**mInductance)(0, 2)),
36 Complex(0, omega * (**mInductance)(1, 0)),
37 Complex(0, omega * (**mInductance)(1, 1)),
38 Complex(0, omega * (**mInductance)(1, 2)),
39 Complex(0, omega * (**mInductance)(2, 0)),
40 Complex(0, omega * (**mInductance)(2, 1)),
41 Complex(0, omega * (**mInductance)(2, 2));
42
43 MatrixComp vInitABC = Matrix::Zero(3, 1);
44 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(1) -
45 RMS3PH_TO_PEAK1PH * initialSingleVoltage(0);
46 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
47 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
48 **mIntfVoltage = vInitABC.real();
49 MatrixComp admittance = impedance.inverse();
50 **mIntfCurrent = (admittance * vInitABC).real();
51
52 SPDLOG_LOGGER_INFO(mSLog,
53 "\nInductance [H]: {:s}"
54 "\nImpedance [Ohm]: {:s}",
55 Logger::matrixToString(**mInductance),
56 Logger::matrixCompToString(impedance));
57 SPDLOG_LOGGER_INFO(
58 mSLog,
59 "\n--- Initialization from powerflow ---"
60 "\nVoltage across: {:s}"
61 "\nCurrent: {:s}"
62 "\nTerminal 0 voltage: {:s}"
63 "\nTerminal 1 voltage: {:s}"
64 "\n--- Initialization from powerflow finished ---",
65 Logger::matrixToString(**mIntfVoltage),
66 Logger::matrixToString(**mIntfCurrent),
67 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(0)),
68 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(1)));
69}
70
71void EMT::Ph3::Inductor::mnaCompInitialize(Real omega, Real timeStep,
72 Attribute<Matrix>::Ptr leftVector) {
73
75 mEquivCond = timeStep / 2. * (**mInductance).inverse();
76 // Update internal state
78
79 SPDLOG_LOGGER_INFO(mSLog,
80 "\n--- MNA initialization ---"
81 "\nInitial voltage {:s}"
82 "\nInitial current {:s}"
83 "\nEquiv. current {:s}"
84 "\n--- MNA initialization finished ---",
85 Logger::matrixToString(**mIntfVoltage),
86 Logger::matrixToString(**mIntfCurrent),
87 Logger::matrixToString(mEquivCurrent));
88 mSLog->flush();
89}
90
92 SparseMatrixRow &systemMatrix) {
93 MNAStampUtils::stampConductanceMatrix(
94 mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
95 terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
96
97 SPDLOG_LOGGER_INFO(mSLog, "\nEquivalent Conductance: {:s}",
98 Logger::matrixToString(mEquivCond));
99}
100
102 // Update internal state
104 if (terminalNotGrounded(0)) {
105 Math::setVectorElement(rightVector, matrixNodeIndex(0, 0),
106 mEquivCurrent(0, 0));
107 Math::setVectorElement(rightVector, matrixNodeIndex(0, 1),
108 mEquivCurrent(1, 0));
109 Math::setVectorElement(rightVector, matrixNodeIndex(0, 2),
110 mEquivCurrent(2, 0));
111 }
112 if (terminalNotGrounded(1)) {
113 Math::setVectorElement(rightVector, matrixNodeIndex(1, 0),
114 -mEquivCurrent(0, 0));
115 Math::setVectorElement(rightVector, matrixNodeIndex(1, 1),
116 -mEquivCurrent(1, 0));
117 Math::setVectorElement(rightVector, matrixNodeIndex(1, 2),
118 -mEquivCurrent(2, 0));
119 }
120 SPDLOG_LOGGER_DEBUG(
121 mSLog, "\nEquivalent Current (mnaCompApplyRightSideVectorStamp): {:s}",
122 Logger::matrixToString(mEquivCurrent));
123 mSLog->flush();
124}
125
127 AttributeBase::List &prevStepDependencies,
128 AttributeBase::List &attributeDependencies,
129 AttributeBase::List &modifiedAttributes) {
130 // actually depends on L, but then we'd have to modify the system matrix anyway
131 prevStepDependencies.push_back(mIntfVoltage);
132 prevStepDependencies.push_back(mIntfCurrent);
133 modifiedAttributes.push_back(mRightVector);
134}
135
139
141 AttributeBase::List &prevStepDependencies,
142 AttributeBase::List &attributeDependencies,
143 AttributeBase::List &modifiedAttributes,
144 Attribute<Matrix>::Ptr &leftVector) {
145 attributeDependencies.push_back(leftVector);
146 modifiedAttributes.push_back(mIntfVoltage);
147 modifiedAttributes.push_back(mIntfCurrent);
148}
149
150void EMT::Ph3::Inductor::mnaCompPostStep(Real time, Int timeStepCount,
151 Attribute<Matrix>::Ptr &leftVector) {
152 mnaCompUpdateVoltage(**leftVector);
153 mnaCompUpdateCurrent(**leftVector);
154}
155
156void EMT::Ph3::Inductor::mnaCompUpdateVoltage(const Matrix &leftVector) {
157 // v1 - v0
158 **mIntfVoltage = Matrix::Zero(3, 1);
159 if (terminalNotGrounded(1)) {
160 (**mIntfVoltage)(0, 0) =
161 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 0));
162 (**mIntfVoltage)(1, 0) =
163 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 1));
164 (**mIntfVoltage)(2, 0) =
165 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 2));
166 }
167 if (terminalNotGrounded(0)) {
168 (**mIntfVoltage)(0, 0) =
169 (**mIntfVoltage)(0, 0) -
170 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
171 (**mIntfVoltage)(1, 0) =
172 (**mIntfVoltage)(1, 0) -
173 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
174 (**mIntfVoltage)(2, 0) =
175 (**mIntfVoltage)(2, 0) -
176 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
177 }
178 SPDLOG_LOGGER_DEBUG(mSLog, "\nUpdate Voltage: {:s}",
179 Logger::matrixToString(**mIntfVoltage));
180}
181
182void EMT::Ph3::Inductor::mnaCompUpdateCurrent(const Matrix &leftVector) {
184 SPDLOG_LOGGER_DEBUG(mSLog, "\nUpdate Current: {:s}",
185 Logger::matrixToString(**mIntfCurrent));
186 mSLog->flush();
187}
const CPS::Attribute< Matrix >::Ptr mInductance
Inductance [H].
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
Matrix mEquivCond
Equivalent conductance [S].
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
Matrix mEquivCurrent
DC equivalent current source [A].
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void mnaCompPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
Inductor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.