9#include <dpsim-models/DP/DP_Ph1_Transformer.h>
14 Logger::Level logLevel,
15 Bool withResistiveLosses)
18 if (withResistiveLosses)
19 setVirtualNodeNumber(3);
21 setVirtualNodeNumber(2);
25 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
32 auto copy = Transformer::make(name,
mLogLevel);
40 Real nomVoltageEnd2, Real ratioAbs,
41 Real ratioPhase, Real resistance,
44 Base::Ph1::Transformer::setParameters(nomVoltageEnd1, nomVoltageEnd2,
45 ratioAbs, ratioPhase, resistance,
49 mSLog,
"Nominal Voltage End 1={} [V] Nominal Voltage End 2={} [V]",
53 "Resistance={} [Ohm] Inductance={} [Ohm] (referred to primary side)",
55 SPDLOG_LOGGER_INFO(
mSLog,
"Tap Ratio={} [ ] Phase Shift={} [deg]",
63 Real nomVoltageEnd2, Real ratedPower,
64 Real ratioAbs, Real ratioPhase,
65 Real resistance, Real inductance) {
71 ratioPhase, resistance, inductance);
81 if (Math::abs(**
mRatio) < 1.) {
83 std::shared_ptr<SimTerminal<Complex>> tmp =
mTerminals[0];
89 SPDLOG_LOGGER_INFO(
mSLog,
"Switching terminals to have first terminal at "
90 "higher voltage side. Updated parameters: ");
92 mSLog,
"Nominal Voltage End 1 = {} [V] Nominal Voltage End 2 = {} [V]",
94 SPDLOG_LOGGER_INFO(
mSLog,
"Tap Ratio = {} [ ] Phase Shift = {} [deg]",
102 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
111 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
121 std::make_shared<DP::Ph1::Resistor>(**
mName +
"_snub_res1",
mLogLevel);
122 mSubSnubResistor1->setParameters(mSnubberResistance1);
123 mSubSnubResistor1->connect({
node(0), DP::SimNode::GND});
126 "Snubber Resistance 1 (connected to higher voltage side {}) = {} [Ohm]",
127 node(0)->name(), Logger::realToString(mSnubberResistance1));
129 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
130 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
134 std::make_shared<DP::Ph1::Resistor>(**
mName +
"_snub_res2",
mLogLevel);
135 mSubSnubResistor2->setParameters(mSnubberResistance2);
136 mSubSnubResistor2->connect({
node(1), DP::SimNode::GND});
139 "Snubber Resistance 2 (connected to lower voltage side {}) = {} [Ohm]",
140 node(1)->name(), Logger::realToString(mSnubberResistance2));
142 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
143 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
147 std::make_shared<DP::Ph1::Capacitor>(**
mName +
"_snub_cap2",
mLogLevel);
148 mSubSnubCapacitor2->connect({
node(1), DP::SimNode::GND});
150 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
151 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
156 Real omega = 2. * PI * frequency;
158 mSnubberCapacitance2 =
160 mSubSnubCapacitor2->setParameters(mSnubberCapacitance2);
163 "Snubber Capacitance 2 (connected to lower voltage side {}) = {} [F]",
164 node(1)->name(), Logger::realToString(mSnubberCapacitance2));
170 mVirtualNodes[2]->setInitialVoltage(initialSingleVoltage(0));
174 SPDLOG_LOGGER_INFO(
mSLog,
"Reactance={} [Ohm] (referred to primary side)",
176 (**mIntfVoltage)(0, 0) =
177 mVirtualNodes[0]->initialSingleVoltage() - initialSingleVoltage(0);
178 (**mIntfCurrent)(0, 0) = (**
mIntfVoltage)(0, 0) / impedance;
182 "\n--- Initialization from powerflow ---"
183 "\nVoltage across: {:s}"
185 "\nTerminal 0 voltage: {:s}"
186 "\nTerminal 1 voltage: {:s}"
187 "\nVirtual Node 1 voltage: {:s}"
188 "\n--- Initialization from powerflow finished ---",
191 Logger::phasorToString(initialSingleVoltage(0)),
192 Logger::phasorToString(initialSingleVoltage(1)),
193 Logger::phasorToString(
mVirtualNodes[0]->initialSingleVoltage()));
197 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
200 "\nTerminal 0 connected to {:s} = sim node {:d}"
201 "\nTerminal 1 connected to {:s} = sim node {:d}",
207 SparseMatrixRow &systemMatrix) {
209 if (terminalNotGrounded(0)) {
210 Math::setMatrixElement(systemMatrix,
mVirtualNodes[0]->matrixNodeIndex(),
213 Math::setMatrixElement(systemMatrix,
mVirtualNodes[1]->matrixNodeIndex(),
217 if (terminalNotGrounded(1)) {
218 Math::setMatrixElement(systemMatrix, matrixNodeIndex(1),
220 Math::setMatrixElement(systemMatrix,
mVirtualNodes[1]->matrixNodeIndex(),
221 matrixNodeIndex(1), -**
mRatio);
226 if (
auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
227 mnasubcomp->mnaApplySystemMatrixStamp(systemMatrix);
229 if (terminalNotGrounded(0)) {
230 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
231 Logger::complexToString(Complex(-1.0, 0)),
234 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
235 Logger::complexToString(Complex(1.0, 0)),
239 if (terminalNotGrounded(1)) {
240 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
241 Logger::complexToString(**
mRatio), matrixNodeIndex(1),
243 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
244 Logger::complexToString(-**
mRatio),
250 AttributeBase::List &prevStepDependencies,
251 AttributeBase::List &attributeDependencies,
252 AttributeBase::List &modifiedAttributes) {
263 AttributeBase::List &prevStepDependencies,
264 AttributeBase::List &attributeDependencies,
265 AttributeBase::List &modifiedAttributes,
266 Attribute<Matrix>::Ptr &leftVector) {
267 attributeDependencies.push_back(leftVector);
273 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
279 (**mIntfCurrent)(0, 0) = mSubInductor->intfCurrent()(0, 0);
284 (**mIntfVoltage)(0, 0) = 0;
285 (**mIntfVoltage)(0, 0) =
286 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
288 Math::complexFromVectorElement(
290 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:s}",
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)
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.
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
Attribute< Matrix >::Ptr mRightVector
void mnaApplyRightSideVectorStamp(Matrix &rightVector) final
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
SimNode< Complex >::Ptr node(UInt index)
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
SimNode< Complex >::List mVirtualNodes
std::vector< std::shared_ptr< SimPowerComp< Complex > > > mSubComponents
Logger::Level mLogLevel
Component logger control for internal variables.
UInt mNumVirtualNodes
Determines the number of virtual or internal Nodes.
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Logger::Log mSLog
Component logger.