DPsim
Loading...
Searching...
No Matches
DP_Ph1_PiLine.cpp
Go to the documentation of this file.
1/* Author: Christoph Wirtz <christoph.wirtz@fgh-ma.de>
2 * SPDX-FileCopyrightText: 2025 FGH e.V.
3 * SPDX-License-Identifier: MPL-2.0
4 */
5
7
8using namespace CPS;
9
12 CompositePowerComp<Complex>(uid, name, true, true, logLevel) {
15
16 SPDLOG_LOGGER_INFO(mSLog, "Create {} {}", this->type(), name);
17 **mIntfVoltage = MatrixComp::Zero(1, 1);
18 **mIntfCurrent = MatrixComp::Zero(1, 1);
19}
20
23 auto copy = PiLine::make(name, mLogLevel);
24 copy->setParameters(**mSeriesRes, **mSeriesInd, **mParallelCap,
26 return copy;
27}
28
31 return;
32 mSubCompCreated = true;
33
34 // By default there is always a small conductance to ground to
35 // avoid problems with floating nodes.
36 Real defaultParallelCond = 1e-6;
38 (**mParallelCond > 0) ? **mParallelCond : defaultParallelCond;
39
41 std::make_shared<DP::Ph1::Resistor>(**mName + "_res", mLogLevel);
42 mSubSeriesResistor->setParameters(**mSeriesRes);
43 mSubSeriesResistor->connect({mTerminals[0]->node(), mVirtualNodes[0]});
47
49 std::make_shared<DP::Ph1::Inductor>(**mName + "_ind", mLogLevel);
50 mSubSeriesInductor->setParameters(**mSeriesInd);
51 mSubSeriesInductor->connect({mVirtualNodes[0], mTerminals[1]->node()});
55
57 std::make_shared<DP::Ph1::Resistor>(**mName + "_con0", mLogLevel);
58 mSubParallelResistor0->setParameters(2. / **mParallelCond);
59 mSubParallelResistor0->connect(
64
66 std::make_shared<DP::Ph1::Resistor>(**mName + "_con1", mLogLevel);
67 mSubParallelResistor1->setParameters(2. / **mParallelCond);
68 mSubParallelResistor1->connect(
73
74 if (**mParallelCap > 0) {
76 std::make_shared<DP::Ph1::Capacitor>(**mName + "_cap0", mLogLevel);
77 mSubParallelCapacitor0->setParameters(**mParallelCap / 2.);
83
85 std::make_shared<DP::Ph1::Capacitor>(**mName + "_cap1", mLogLevel);
86 mSubParallelCapacitor1->setParameters(**mParallelCap / 2.);
92 }
93}
94
96 // Static calculation
97 Real omega = 2. * PI * frequency;
98 Complex impedance = {**mSeriesRes, omega * **mSeriesInd};
99 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
100 (**mIntfCurrent)(0, 0) = (**mIntfVoltage)(0, 0) / impedance;
101
102 // Initialization of virtual node
103 mVirtualNodes[0]->setInitialVoltage(initialSingleVoltage(0) +
104 (**mIntfCurrent)(0, 0) * **mSeriesRes);
105
106 SPDLOG_LOGGER_INFO(
107 mSLog,
108 "\n--- Initialization from powerflow ---"
109 "\nVoltage across: {:s}"
110 "\nCurrent: {:s}"
111 "\nTerminal 0 voltage: {:s}"
112 "\nTerminal 1 voltage: {:s}"
113 "\nVirtual Node 1 voltage: {:s}"
114 "\n--- Initialization from powerflow finished ---",
120}
121
123 AttributeBase::List &prevStepDependencies,
124 AttributeBase::List &attributeDependencies,
125 AttributeBase::List &modifiedAttributes) {
126 // add pre-step dependencies of component itself
127 prevStepDependencies.push_back(mIntfCurrent);
128 prevStepDependencies.push_back(mIntfVoltage);
129 modifiedAttributes.push_back(mRightVector);
130}
131
132void DP::Ph1::PiLine::mnaParentPreStep(Real time, Int timeStepCount) {
133 // pre-step of component itself
135}
136
138 AttributeBase::List &prevStepDependencies,
139 AttributeBase::List &attributeDependencies,
140 AttributeBase::List &modifiedAttributes,
141 Attribute<Matrix>::Ptr &leftVector) {
142 // add post-step dependencies of component itself
143 attributeDependencies.push_back(leftVector);
144 modifiedAttributes.push_back(mIntfVoltage);
145 modifiedAttributes.push_back(mIntfCurrent);
146}
147
149 Attribute<Matrix>::Ptr &leftVector) {
150 // post-step of component itself
151 this->mnaUpdateVoltage(**leftVector);
152 this->mnaUpdateCurrent(**leftVector);
153}
154
156 (**mIntfVoltage)(0, 0) = 0;
157 if (terminalNotGrounded(1))
158 (**mIntfVoltage)(0, 0) =
160 if (terminalNotGrounded(0))
161 (**mIntfVoltage)(0, 0) =
162 (**mIntfVoltage)(0, 0) -
164}
165
167 (**mIntfCurrent)(0, 0) = mSubSeriesInductor->intfCurrent()(0, 0);
168}
169
170// #### Tear Methods ####
172 MNAInterface::List gndComponents;
173
174 gndComponents.push_back(mSubParallelResistor0);
175 gndComponents.push_back(mSubParallelResistor1);
176
177 if (**mParallelCap > 0) {
178 gndComponents.push_back(mSubParallelCapacitor0);
179 gndComponents.push_back(mSubParallelCapacitor1);
180 }
181
182 return gndComponents;
183}
184
186 mSubSeriesResistor->mnaTearSetIdx(mTearIdx);
187 mSubSeriesResistor->mnaTearInitialize(omega, timeStep);
188 mSubSeriesInductor->mnaTearSetIdx(mTearIdx);
189 mSubSeriesInductor->mnaTearInitialize(omega, timeStep);
190}
191
193 mSubSeriesResistor->mnaTearApplyMatrixStamp(tearMatrix);
194 mSubSeriesInductor->mnaTearApplyMatrixStamp(tearMatrix);
195}
196
198 mSubSeriesInductor->mnaTearApplyVoltageStamp(voltageVector);
199}
200
202 mSubSeriesInductor->mnaTearPostStep(voltage - current * **mSeriesRes,
203 current);
204 (**mIntfCurrent)(0, 0) = mSubSeriesInductor->intfCurrent()(0, 0);
205}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
const Attribute< Real >::Ptr mParallelCap
Capacitance in parallel to the line [F].
const Attribute< Real >::Ptr mParallelCond
Conductance in parallel to the line [S].
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)
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre and post step operations.
std::shared_ptr< Capacitor > mSubParallelCapacitor1
Parallel capacitor submodel at Terminal 1.
SimPowerComp< Complex >::Ptr clone(String copySuffix) override
DEPRECATED: Remove method.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Updates internal current variable of the component.
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
std::shared_ptr< Resistor > mSubParallelResistor1
Parallel resistor submodel at Terminal 1.
std::shared_ptr< Resistor > mSubSeriesResistor
Series Resistor submodel.
std::shared_ptr< Inductor > mSubSeriesInductor
Series Inductance submodel.
PiLine(String uid, String name, Logger::Level logLevel=Logger::Level::off)
True after createSubComponents() runs; prevents double-construction.
std::shared_ptr< Resistor > mSubParallelResistor0
Parallel Resistor submodel at Terminal 0.
MNAInterface::List mnaTearGroundComponents() override
void mnaTearApplyVoltageStamp(Matrix &voltageVector) override
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
void mnaTearPostStep(Complex voltage, Complex current) override
void createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
std::shared_ptr< Capacitor > mSubParallelCapacitor0
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
add MNA pre and post step dependencies
void initializeParentFromNodesAndTerminals(Real frequency) override
Derives values from power flow data and pushes them to subcomponents.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates internal voltage variable of the component.
void mnaTearInitialize(Real omega, Real timeStep) 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
std::vector< Ptr > List
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
Attribute< Matrix >::Ptr mRightVector
void mnaApplyRightSideVectorStamp(Matrix &rightVector) final
static Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
Definition MathUtils.cpp:94
std::vector< Ptr > List
Definition SimNode.h:33
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
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< PiLine > 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: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::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74