DPsim
Loading...
Searching...
No Matches
EMT_Ph3_RxLine.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
13// !!! TODO: Adaptions to use in EMT_Ph3 models phase-to-ground peak variables
14// !!! with initialization from phase-to-phase RMS variables
15
18 CompositePowerComp<Real>(uid, name, true, true, logLevel) {
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
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]});
49
51 std::make_shared<EMT::Ph3::Inductor>(**mName + "_ind", mLogLevel);
52 mSubInductor->setParameters(**mSeriesInd);
53 mSubInductor->connect({mVirtualNodes[0], mTerminals[1]->node()});
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()});
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 ---",
111}
112
114 AttributeBase::List &prevStepDependencies,
115 AttributeBase::List &attributeDependencies,
116 AttributeBase::List &modifiedAttributes) {
117 modifiedAttributes.push_back(mRightVector);
118};
119
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
135 Attribute<Matrix>::Ptr &leftVector) {
136 mnaCompUpdateVoltage(**leftVector);
137 mnaCompUpdateCurrent(**leftVector);
138}
139
141 // v1 - v0
142 **mIntfVoltage = Matrix::Zero(3, 1);
143 if (terminalNotGrounded(1)) {
144 (**mIntfVoltage)(0, 0) =
146 (**mIntfVoltage)(1, 0) =
148 (**mIntfVoltage)(2, 0) =
150 }
151 if (terminalNotGrounded(0)) {
152 (**mIntfVoltage)(0, 0) =
153 (**mIntfVoltage)(0, 0) -
155 (**mIntfVoltage)(1, 0) =
156 (**mIntfVoltage)(1, 0) -
158 (**mIntfVoltage)(2, 0) =
159 (**mIntfVoltage)(2, 0) -
161 }
162}
163
165 **mIntfCurrent = mSubInductor->intfCurrent();
166}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
const Attribute< Matrix >::Ptr mSeriesRes
Resistance along the line [ohms].
const Attribute< Matrix >::Ptr mSeriesInd
Inductance along the line [H].
PiLine(CPS::AttributeList::Ptr attributeList)
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)
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
std::shared_ptr< Resistor > mSubResistor
Resistor submodel.
std::shared_ptr< Inductor > mSubInductor
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
void mnaCompUpdateVoltage(const Matrix &leftVector) override
void mnaCompUpdateCurrent(const Matrix &leftVector) override
RxLine(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, logging level.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
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.
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixToString(const Matrix &mat)
Definition Logger.cpp:31
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
Attribute< Matrix >::Ptr mRightVector
static Real realFromVectorElement(const Matrix &mat, Matrix::Index row)
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< RxLine > make(Args &&...args)
Definition PtrFactory.h:19
#define PI
Definition Definitions.h:43
#define SHIFT_TO_PHASE_C
Definition Definitions.h:47
#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