DPsim
Loading...
Searching...
No Matches
DP_Ph1_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
11
12using namespace CPS;
13
16
18 Logger::Level logLevel)
20 CompositePowerComp<Complex>(uid, name, true, true, logLevel),
21 mUseSubcomponents(useSubcomponents) {
24
25 SPDLOG_LOGGER_INFO(mSLog, "Create {} {}", this->type(), name);
26 **mIntfVoltage = MatrixComp::Zero(1, 1);
27 **mIntfCurrent = MatrixComp::Zero(1, 1);
28}
29
33 copy->setParameters(**mSeriesRes, **mSeriesInd);
34 return copy;
35}
36
39 return;
41 return;
42 mSubCompCreated = true;
43
45 std::make_shared<DP::Ph1::Resistor>(**mName + "_res", mLogLevel);
46 mSubResistor->setParameters(**mSeriesRes);
47 mSubResistor->connect({mTerminals[0]->node(), mVirtualNodes[0]});
50
52 std::make_shared<DP::Ph1::Inductor>(**mName + "_ind", mLogLevel);
53 mSubInductor->setParameters(**mSeriesInd);
54 mSubInductor->connect({mVirtualNodes[0], mTerminals[1]->node()});
57
59 std::make_shared<DP::Ph1::Resistor>(**mName + "_snubber_res", mLogLevel);
60 mInitialResistor->setParameters(1e6);
61 mInitialResistor->connect({SimNode::GND, mTerminals[1]->node()});
65}
66
68 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
69 (**mIntfCurrent)(0, 0) = 0;
70 mVirtualNodes[0]->setInitialVoltage(initialSingleVoltage(0) +
71 (**mIntfCurrent)(0, 0) * **mSeriesRes);
72
73 SPDLOG_LOGGER_INFO(mSLog,
74 "\n--- Initialization from powerflow ---"
75 "\nVoltage across: {:s}"
76 "\nCurrent: {:s}"
77 "\nTerminal 0 voltage: {:s}"
78 "\nTerminal 1 voltage: {:s}"
79 "\n--- Initialization from powerflow finished ---",
84}
85
87 Attribute<Matrix>::Ptr leftVector) {
89 return;
90 mDirectInductorCond = MatrixComp::Zero(mNumFreqs, 1);
91 mDirectPrevCurrentFactor = MatrixComp::Zero(mNumFreqs, 1);
92 mDirectCurrent = MatrixComp::Zero(mNumFreqs, 1);
93 mDirectVoltage = MatrixComp::Zero(mNumFreqs, 1);
94 mDirectHistory = MatrixComp::Zero(mNumFreqs, 1);
95 for (UInt freq = 0; freq < mNumFreqs; ++freq) {
96 const Real harmonicOmega = 2. * PI * mFrequencies(freq, 0);
97 const Real b = timeStep * harmonicOmega / 2.;
98 const Real a = timeStep / (2. * **mSeriesInd);
99 mDirectInductorCond(freq, 0) =
100 Complex(a / (1. + b * b), -a * b / (1. + b * b));
101 mDirectPrevCurrentFactor(freq, 0) =
102 Complex((1. - b * b) / (1. + b * b), -2. * b / (1. + b * b));
103 if (freq == 0) {
104 mDirectVoltage(freq, 0) =
105 initialSingleVoltage(1) - mVirtualNodes[0]->initialSingleVoltage();
106 const Complex initialCurrent =
107 harmonicOmega != 0. ? mDirectVoltage(freq, 0) /
108 Complex(0., harmonicOmega * **mSeriesInd)
109 : Complex(0., 0.);
110 // Match the DP Inductor's initialization recurrence exactly: initVars()
111 // stores G*v + K*i and then initializes i to G*v + that history.
112 mDirectCurrent(freq, 0) =
113 2. * mDirectInductorCond(freq, 0) * mDirectVoltage(freq, 0) +
114 mDirectPrevCurrentFactor(freq, 0) * initialCurrent;
115 }
116 }
117}
118
120 SparseMatrixRow &systemMatrix) {
122 return;
123 const UInt terminal0 = matrixNodeIndex(0);
124 const UInt terminal1 = matrixNodeIndex(1);
125 const UInt internal = virtualNode(0)->matrixNodeIndex();
126 for (UInt freq = 0; freq < mNumFreqs; ++freq) {
127 MNAStampUtils::stampAdmittance(Complex(1. / **mSeriesRes, 0.), systemMatrix,
128 terminal0, internal, terminalNotGrounded(0),
129 true, mSLog, mNumFreqs, freq);
131 mDirectInductorCond(freq, 0), systemMatrix, internal, terminal1, true,
133 MNAStampUtils::stampAdmittance(Complex(1e-6, 0.), systemMatrix, terminal1,
134 0, terminalNotGrounded(1), false, mSLog,
135 mNumFreqs, freq);
136 }
137}
138
141 return;
142 const UInt terminal1 = matrixNodeIndex(1);
143 const UInt internal = virtualNode(0)->matrixNodeIndex();
144 for (UInt freq = 0; freq < mNumFreqs; ++freq) {
145 mDirectHistory(freq, 0) =
146 mDirectInductorCond(freq, 0) * mDirectVoltage(freq, 0) +
147 mDirectPrevCurrentFactor(freq, 0) * mDirectCurrent(freq, 0);
148 Math::setVectorElement(rightVector, internal, mDirectHistory(freq, 0),
149 mNumFreqs, freq);
150 if (terminalNotGrounded(1))
151 Math::setVectorElement(rightVector, terminal1, -mDirectHistory(freq, 0),
152 mNumFreqs, freq);
153 }
154}
155
159
161 AttributeBase::List &prevStepDependencies,
162 AttributeBase::List &attributeDependencies,
163 AttributeBase::List &modifiedAttributes) {
164 modifiedAttributes.push_back(mRightVector);
165}
166
168 AttributeBase::List &prevStepDependencies,
169 AttributeBase::List &attributeDependencies,
170 AttributeBase::List &modifiedAttributes,
171 Attribute<Matrix>::Ptr &leftVector) {
172 attributeDependencies.push_back(leftVector);
173 modifiedAttributes.push_back(mIntfCurrent);
174 modifiedAttributes.push_back(mIntfVoltage);
175}
176
178 Attribute<Matrix>::Ptr &leftVector) {
179 mnaCompUpdateVoltage(**leftVector);
180 mnaCompUpdateCurrent(**leftVector);
181}
182
184 (**mIntfVoltage)(0, 0) = 0;
185 if (terminalNotGrounded(1))
186 (**mIntfVoltage)(0, 0) =
188 if (terminalNotGrounded(0))
189 (**mIntfVoltage)(0, 0) =
190 (**mIntfVoltage)(0, 0) -
192}
193
195 if (mUseSubcomponents) {
196 (**mIntfCurrent)(0, 0) = mSubInductor->intfCurrent()(0, 0);
197 return;
198 }
199 const UInt internal = virtualNode(0)->matrixNodeIndex();
200 for (UInt freq = 0; freq < mNumFreqs; ++freq) {
201 const Complex internalVoltage =
202 Math::complexFromVectorElement(leftVector, internal, mNumFreqs, freq);
203 const Complex terminalVoltage =
206 mNumFreqs, freq)
207 : Complex(0., 0.);
208 mDirectVoltage(freq, 0) = terminalVoltage - internalVoltage;
209 mDirectCurrent(freq, 0) =
210 mDirectInductorCond(freq, 0) * mDirectVoltage(freq, 0) +
211 mDirectHistory(freq, 0);
212 (**mIntfCurrent)(0, freq) = mDirectCurrent(freq, 0);
213 }
214}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
PiLine(CPS::AttributeList::Ptr attributeList)
const Attribute< Real >::Ptr mSeriesInd
Inductance along the line [H].
const Attribute< Real >::Ptr mSeriesRes
Resistance along the line [ohms].
void addMNASubComponent(typename SimPowerComp< Complex >::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 mnaCompUpdateVoltage(const Matrix &leftVector) override
void initializeParentFromNodesAndTerminals(Real frequency) override
Derives values from power flow data and pushes them to subcomponents.
MatrixComp mDirectInductorCond
MatrixComp mDirectPrevCurrentFactor
std::shared_ptr< Resistor > mSubResistor
Resistor submodel.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
void mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
MatrixComp mDirectHistory
MatrixComp mDirectVoltage
SimPowerComp< Complex >::Ptr clone(String name) override
DEPRECATED: Delete method.
MatrixComp mDirectCurrent
std::shared_ptr< Inductor > mSubInductor
Inductance submodel.
std::shared_ptr< Resistor > mInitialResistor
Inductor end to ground resistor to facilitate initialization.
void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre and post step operations.
void createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
RxLine(String uid, String name, Logger::Level logLevel=Logger::Level::off)
True after createSubComponents() runs; prevents double-construction.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
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 phasorToString(const Complex &num)
Definition Logger.cpp:57
Attribute< Matrix >::Ptr mRightVector
static void stampAdmittance(Complex admittance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog, Int maxFreq=1, Int freqIdx=0)
static Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
SimNode< Complex >::Ptr virtualNode(UInt index)
std::shared_ptr< SimPowerComp< VarType > > Ptr
SimNode< Complex >::List mVirtualNodes
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
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
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:79
std::string String
Definition Definitions.h:63
double Real
Definition Definitions.h:60
int Int
Definition Definitions.h:59
std::complex< Real > Complex
Definition Definitions.h:61
bool Bool
Definition Definitions.h:62
unsigned int UInt
Definition Definitions.h:58
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72