DPsim
Loading...
Searching...
No Matches
EMT_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<Real>(uid, name, true, true, logLevel) {
15
16 SPDLOG_LOGGER_INFO(mSLog, "Create {} {}", this->type(), name);
17 **mIntfVoltage = Matrix::Zero(1, 1);
18 **mIntfCurrent = Matrix::Zero(1, 1);
19
20 mSLog->flush();
21}
22
25 auto copy = PiLine::make(name, mLogLevel);
26 copy->setParameters(**mSeriesRes, **mSeriesInd, **mParallelCap,
28 return copy;
29}
30
33 return;
34 mSubCompCreated = true;
35
36 // By default there is always a small conductance to ground to
37 // avoid problems with floating nodes.
38 Real defaultParallelCond = 1e-6;
40 (**mParallelCond > 0) ? **mParallelCond : defaultParallelCond;
41
42 // Create series sub components
44 std::make_shared<EMT::Ph1::Resistor>(**mName + "_res", mLogLevel);
45 mSubSeriesResistor->setParameters(**mSeriesRes);
46 mSubSeriesResistor->connect({mTerminals[0]->node(), mVirtualNodes[0]});
50
52 std::make_shared<EMT::Ph1::Inductor>(**mName + "_ind", mLogLevel);
53 mSubSeriesInductor->setParameters(**mSeriesInd);
54 mSubSeriesInductor->connect({mVirtualNodes[0], mTerminals[1]->node()});
58
59 // Create parallel sub components
61 std::make_shared<EMT::Ph1::Resistor>(**mName + "_con0", mLogLevel);
62 mSubParallelResistor0->setParameters(2. / (**mParallelCond));
63 mSubParallelResistor0->connect(
68
70 std::make_shared<EMT::Ph1::Resistor>(**mName + "_con1", mLogLevel);
71 mSubParallelResistor1->setParameters(2. / (**mParallelCond));
72 mSubParallelResistor1->connect(
77
78 if ((**mParallelCap) > 0) {
80 std::make_shared<EMT::Ph1::Capacitor>(**mName + "_cap0", mLogLevel);
81 mSubParallelCapacitor0->setParameters(**mParallelCap / 2.);
87
89 std::make_shared<EMT::Ph1::Capacitor>(**mName + "_cap1", mLogLevel);
90 mSubParallelCapacitor1->setParameters(**mParallelCap / 2.);
96 }
97}
98
100 // Static calculation
101 Real omega = 2. * PI * frequency;
102 Complex impedance = {**mSeriesRes, omega * **mSeriesInd};
103 Complex voltage =
105 Complex current = voltage / impedance;
106 (**mIntfVoltage)(0, 0) = voltage.real();
107 (**mIntfCurrent)(0, 0) = current.real();
108
109 // Initialization of virtual node
110 mVirtualNodes[0]->setInitialVoltage(
112
113 SPDLOG_LOGGER_DEBUG(mSLog,
114 "\n--debug--"
115 "\n seriesRes: {:s}"
116 "\n seriesInd: {:s}"
117 "\n Impedance: {:s}",
120 Logger::complexToString(impedance));
121
122 SPDLOG_LOGGER_INFO(
123 mSLog,
124 "\n--- Initialization from powerflow ---"
125 "\nVoltage across: {:s}"
126 "\nCurrent: {:s}"
127 "\nTerminal 0 voltage: {:s}"
128 "\nTerminal 1 voltage: {:s}"
129 "\nVirtual Node 1 voltage: {:s}"
130 "\n--- Initialization from powerflow finished ---",
136 mSLog->flush();
137}
138
140 AttributeBase::List &prevStepDependencies,
141 AttributeBase::List &attributeDependencies,
142 AttributeBase::List &modifiedAttributes) {
143 prevStepDependencies.push_back(mIntfCurrent);
144 prevStepDependencies.push_back(mIntfVoltage);
145 modifiedAttributes.push_back(mRightVector);
146}
147
151
153 AttributeBase::List &prevStepDependencies,
154 AttributeBase::List &attributeDependencies,
155 AttributeBase::List &modifiedAttributes,
156 Attribute<Matrix>::Ptr &leftVector) {
157 attributeDependencies.push_back(leftVector);
158 modifiedAttributes.push_back(mIntfVoltage);
159 modifiedAttributes.push_back(mIntfCurrent);
160}
161
163 Attribute<Matrix>::Ptr &leftVector) {
164 mnaCompUpdateVoltage(**leftVector);
165 mnaCompUpdateCurrent(**leftVector);
166}
167
169 (**mIntfVoltage)(0, 0) = 0;
170 if (terminalNotGrounded(1))
171 (**mIntfVoltage)(0, 0) =
173 if (terminalNotGrounded(0))
174 (**mIntfVoltage)(0, 0) =
175 (**mIntfVoltage)(0, 0) -
177}
178
180 **mIntfCurrent = mSubSeriesInductor->intfCurrent();
181}
182
183// #### Tear Methods ####
185 MNAInterface::List gndComponents;
186
187 gndComponents.push_back(mSubParallelResistor0);
188 gndComponents.push_back(mSubParallelResistor1);
189
190 if ((**mParallelCap) > 0) {
191 gndComponents.push_back(mSubParallelCapacitor0);
192 gndComponents.push_back(mSubParallelCapacitor1);
193 }
194
195 return gndComponents;
196}
197
199 mSubSeriesResistor->mnaTearSetIdx(mTearIdx);
200 mSubSeriesResistor->mnaTearInitialize(omega, timeStep);
201 mSubSeriesInductor->mnaTearSetIdx(mTearIdx);
202 mSubSeriesInductor->mnaTearInitialize(omega, timeStep);
203}
204
206 mSubSeriesResistor->mnaTearApplyMatrixStamp(tearMatrix);
207 mSubSeriesInductor->mnaTearApplyMatrixStamp(tearMatrix);
208}
209
211 mSubSeriesInductor->mnaTearApplyVoltageStamp(voltageVector);
212}
213
215 mSubSeriesInductor->mnaTearPostStep(voltage - current * **mSeriesRes,
216 current);
217 (**mIntfCurrent) = mSubSeriesInductor->intfCurrent();
218}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
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< 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
MNA post step operations.
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
std::shared_ptr< Inductor > mSubSeriesInductor
MNAInterface::List mnaTearGroundComponents() override
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates internal voltage variable of the component.
std::shared_ptr< Resistor > mSubParallelResistor1
Parallel resistor submodel at Terminal 1.
void mnaTearPostStep(Complex voltage, Complex current) override
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaTearApplyVoltageStamp(Matrix &voltageVector) override
void createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
std::shared_ptr< Capacitor > mSubParallelCapacitor0
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Updates internal current variable of the component.
std::shared_ptr< Resistor > mSubSeriesResistor
Series Resistor submodel.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
SimPowerComp< Real >::Ptr clone(String copySuffix) override
DEPRECATED: Delete method.
std::shared_ptr< Capacitor > mSubParallelCapacitor1
void mnaTearInitialize(Real omega, Real timeStep) override
std::shared_ptr< Resistor > mSubParallelResistor0
Parallel Resistor submodel at Terminal 0.
PiLine(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void initializeParentFromNodesAndTerminals(Real frequency) override
Derives values from power flow data and pushes them to subcomponents.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
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 complexToString(const Complex &num)
Definition Logger.cpp:63
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 PEAK1PH_TO_RMS3PH
Definition Definitions.h:51
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
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72