DPsim
Loading...
Searching...
No Matches
EMT_Ph3_PiLine.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
10
11using namespace CPS;
12
15 CompositePowerComp<Real>(uid, name, true, true, logLevel) {
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
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]});
55
57 std::make_shared<EMT::Ph3::Inductor>(**mName + "_ind", mLogLevel);
58 mSubSeriesInductor->setParameters(**mSeriesInd);
59 mSubSeriesInductor->connect({mVirtualNodes[0], mTerminals[1]->node()});
63
64 // Create parallel sub components
66 std::make_shared<EMT::Ph3::Resistor>(**mName + "_con0", mLogLevel);
67 mSubParallelResistor0->setParameters(2. * (**mParallelCond).inverse());
68 mSubParallelResistor0->connect(
73
75 std::make_shared<EMT::Ph3::Resistor>(**mName + "_con1", mLogLevel);
76 mSubParallelResistor1->setParameters(2. * (**mParallelCond).inverse());
77 mSubParallelResistor1->connect(
82
83 if ((**mParallelCap)(0, 0) > 0) {
85 std::make_shared<EMT::Ph3::Capacitor>(**mName + "_cap0", mLogLevel);
86 mSubParallelCapacitor0->setParameters(**mParallelCap / 2.);
92
94 std::make_shared<EMT::Ph3::Capacitor>(**mName + "_cap1", mLogLevel);
95 mSubParallelCapacitor1->setParameters(**mParallelCap / 2.);
101 }
102}
103
105 // Static calculation
106 Real omega = 2. * PI * frequency;
107 MatrixComp impedance = MatrixComp::Zero(3, 3);
108 impedance << Complex((**mSeriesRes)(0, 0), omega * (**mSeriesInd)(0, 0)),
109 Complex((**mSeriesRes)(0, 1), omega * (**mSeriesInd)(0, 1)),
110 Complex((**mSeriesRes)(0, 2), omega * (**mSeriesInd)(0, 2)),
111 Complex((**mSeriesRes)(1, 0), omega * (**mSeriesInd)(1, 0)),
112 Complex((**mSeriesRes)(1, 1), omega * (**mSeriesInd)(1, 1)),
113 Complex((**mSeriesRes)(1, 2), omega * (**mSeriesInd)(1, 2)),
114 Complex((**mSeriesRes)(2, 0), omega * (**mSeriesInd)(2, 0)),
115 Complex((**mSeriesRes)(2, 1), omega * (**mSeriesInd)(2, 1)),
116 Complex((**mSeriesRes)(2, 2), omega * (**mSeriesInd)(2, 2));
117
118 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
119 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(1) -
121 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
122 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
123 MatrixComp iInit = impedance.inverse() * vInitABC;
124 **mIntfCurrent = iInit.real();
125 **mIntfVoltage = vInitABC.real();
126
127 // Initialization of virtual node
128 // Initial voltage of phase B,C is set after A
129 MatrixComp vInitTerm0 = MatrixComp::Zero(3, 1);
130 vInitTerm0(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(0);
131 vInitTerm0(1, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_B;
132 vInitTerm0(2, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_C;
133
134 mVirtualNodes[0]->setInitialVoltage(PEAK1PH_TO_RMS3PH *
135 (vInitTerm0 + **mSeriesRes * iInit));
136
137 SPDLOG_LOGGER_DEBUG(mSLog,
138 "\n--debug--"
139 "\n seriesRes: {:s}"
140 "\n seriesInd: {:s}"
141 "\n Impedance: {:s}"
142 "\n vInit: {:s}"
143 "\n iInit: {:s}",
149
150 SPDLOG_LOGGER_INFO(
151 mSLog,
152 "\n--- Initialization from powerflow ---"
153 "\nVoltage across: {:s}"
154 "\nCurrent: {:s}"
155 "\nTerminal 0 voltage: {:s}"
156 "\nTerminal 1 voltage: {:s}"
157 "\nVirtual Node 1 voltage: {:s}"
158 "\n--- Initialization from powerflow finished ---",
164 mSLog->flush();
165}
166
168 AttributeBase::List &prevStepDependencies,
169 AttributeBase::List &attributeDependencies,
170 AttributeBase::List &modifiedAttributes) {
171 prevStepDependencies.push_back(mIntfCurrent);
172 prevStepDependencies.push_back(mIntfVoltage);
173 modifiedAttributes.push_back(mRightVector);
174}
175
179
181 AttributeBase::List &prevStepDependencies,
182 AttributeBase::List &attributeDependencies,
183 AttributeBase::List &modifiedAttributes,
184 Attribute<Matrix>::Ptr &leftVector) {
185 attributeDependencies.push_back(leftVector);
186 modifiedAttributes.push_back(mIntfVoltage);
187 modifiedAttributes.push_back(mIntfCurrent);
188}
189
191 Attribute<Matrix>::Ptr &leftVector) {
192 mnaCompUpdateVoltage(**leftVector);
193 mnaCompUpdateCurrent(**leftVector);
194}
195
197 // v1 - v0
198 **mIntfVoltage = Matrix::Zero(3, 1);
199 if (terminalNotGrounded(1)) {
200 (**mIntfVoltage)(0, 0) =
202 (**mIntfVoltage)(1, 0) =
204 (**mIntfVoltage)(2, 0) =
206 }
207 if (terminalNotGrounded(0)) {
208 (**mIntfVoltage)(0, 0) =
209 (**mIntfVoltage)(0, 0) -
211 (**mIntfVoltage)(1, 0) =
212 (**mIntfVoltage)(1, 0) -
214 (**mIntfVoltage)(2, 0) =
215 (**mIntfVoltage)(2, 0) -
217 }
218}
219
221 **mIntfCurrent = mSubSeriesInductor->intfCurrent();
222}
223
224// #### Tear Methods ####
226 MNAInterface::List gndComponents;
227
228 gndComponents.push_back(mSubParallelResistor0);
229 gndComponents.push_back(mSubParallelResistor1);
230
231 if ((**mParallelCap)(0, 0) > 0) {
232 gndComponents.push_back(mSubParallelCapacitor0);
233 gndComponents.push_back(mSubParallelCapacitor1);
234 }
235
236 return gndComponents;
237}
238
240 mSubSeriesResistor->mnaTearSetIdx(mTearIdx);
241 mSubSeriesResistor->mnaTearInitialize(omega, timeStep);
242 mSubSeriesInductor->mnaTearSetIdx(mTearIdx);
243 mSubSeriesInductor->mnaTearInitialize(omega, timeStep);
244}
245
247 mSubSeriesResistor->mnaTearApplyMatrixStamp(tearMatrix);
248 mSubSeriesInductor->mnaTearApplyMatrixStamp(tearMatrix);
249}
250
252 mSubSeriesInductor->mnaTearApplyVoltageStamp(voltageVector);
253}
254
256 mSubSeriesInductor->mnaTearPostStep(voltage - (**mSeriesRes * current),
257 current);
258 (**mIntfCurrent) = mSubSeriesInductor->intfCurrent();
259}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
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 mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
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.
MNAInterface::List mnaTearGroundComponents() override
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< Capacitor > mSubParallelCapacitor1
std::shared_ptr< Inductor > mSubSeriesInductor
std::shared_ptr< Capacitor > mSubParallelCapacitor0
void mnaTearApplyVoltageStamp(Matrix &voltageVector) override
std::shared_ptr< Resistor > mSubSeriesResistor
Series Resistor submodel.
void createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
void mnaTearInitialize(Real omega, Real timeStep) override
void mnaTearPostStep(MatrixComp voltage, MatrixComp current) override
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.
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixCompToString(const MatrixComp &mat)
Definition Logger.cpp:37
static String matrixToString(const Matrix &mat)
Definition Logger.cpp:31
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
std::vector< Ptr > List
Attribute< Matrix >::Ptr mRightVector
static Real realFromVectorElement(const Matrix &mat, Matrix::Index row)
std::vector< Ptr > List
Definition SimNode.h:33
static Ptr GND
Definition SimNode.h:35
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::List mTerminals
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< PiLine > 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:81
std::string String
Definition Definitions.h:65
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
std::complex< Real > Complex
Definition Definitions.h:63
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:84
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74