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);
33 copy->setParameters(**mNominalVoltageEnd1, **mNominalVoltageEnd2,
34 std::abs(**mRatio), std::arg(**mRatio), **mResistance,
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]",
50 **mNominalVoltageEnd1, **mNominalVoltageEnd2);
53 "Resistance={} [Ohm] Inductance={} [Ohm] (referred to primary side)",
54 **mResistance, **mInductance);
55 SPDLOG_LOGGER_INFO(mSLog,
"Tap Ratio={} [ ] Phase Shift={} [deg]",
56 std::abs(**mRatio), std::arg(**mRatio));
57 SPDLOG_LOGGER_INFO(mSLog,
"Rated Power ={} [W]", **mRatedPower);
59 mParametersSet =
true;
63 Real nomVoltageEnd2, Real ratedPower,
64 Real ratioAbs, Real ratioPhase,
65 Real resistance, Real inductance) {
67 **mRatedPower = ratedPower;
68 SPDLOG_LOGGER_INFO(mSLog,
"Rated Power ={} [W]", **mRatedPower);
71 ratioPhase, resistance, inductance);
79 if (Math::abs(**mRatio) < 1.) {
80 **mRatio = 1. / **mRatio;
81 std::shared_ptr<SimTerminal<Complex>> tmp = mTerminals[0];
82 mTerminals[0] = mTerminals[1];
84 Real tmpVolt = **mNominalVoltageEnd1;
85 **mNominalVoltageEnd1 = **mNominalVoltageEnd2;
86 **mNominalVoltageEnd2 = tmpVolt;
87 SPDLOG_LOGGER_INFO(mSLog,
"Switching terminals to have first terminal at "
88 "higher voltage side. Updated parameters: ");
90 mSLog,
"Nominal Voltage End 1 = {} [V] Nominal Voltage End 2 = {} [V]",
91 **mNominalVoltageEnd1, **mNominalVoltageEnd2);
92 SPDLOG_LOGGER_INFO(mSLog,
"Tap Ratio = {} [ ] Phase Shift = {} [deg]",
93 std::abs(**mRatio), std::arg(**mRatio));
97 mVirtualNodes[0]->setInitialVoltage(initialSingleVoltage(1) * **mRatio);
100 Real omega = 2. * PI * frequency;
101 Complex impedance = {**mResistance, omega * **mInductance};
102 SPDLOG_LOGGER_INFO(mSLog,
"Reactance={} [Ohm] (referred to primary side)",
103 omega * **mInductance);
104 (**mIntfVoltage)(0, 0) =
105 mVirtualNodes[0]->initialSingleVoltage() - initialSingleVoltage(0);
106 (**mIntfCurrent)(0, 0) = (**mIntfVoltage)(0, 0) / impedance;
110 std::make_shared<DP::Ph1::Inductor>(**mName +
"_ind", mLogLevel);
111 mSubInductor->setParameters(**mInductance);
112 addMNASubComponent(mSubInductor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
113 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
115 if (mNumVirtualNodes == 3) {
116 mVirtualNodes[2]->setInitialVoltage(initialSingleVoltage(0));
118 std::make_shared<DP::Ph1::Resistor>(**mName +
"_res", mLogLevel);
119 mSubResistor->setParameters(**mResistance);
120 mSubResistor->connect({node(0), mVirtualNodes[2]});
121 mSubInductor->connect({mVirtualNodes[2], mVirtualNodes[0]});
122 addMNASubComponent(mSubResistor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
123 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
125 mSubInductor->connect({node(0), mVirtualNodes[0]});
129 Real pSnub = P_SNUB_TRANSFORMER * **mRatedPower;
130 Real qSnub = Q_SNUB_TRANSFORMER * **mRatedPower;
133 mSnubberResistance1 = std::pow(std::abs(**mNominalVoltageEnd1), 2) / pSnub;
135 std::make_shared<DP::Ph1::Resistor>(**mName +
"_snub_res1", mLogLevel);
136 mSubSnubResistor1->setParameters(mSnubberResistance1);
137 mSubSnubResistor1->connect({node(0), DP::SimNode::GND});
140 "Snubber Resistance 1 (connected to higher voltage side {}) = {} [Ohm]",
141 node(0)->name(), Logger::realToString(mSnubberResistance1));
142 addMNASubComponent(mSubSnubResistor1,
143 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
144 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
147 mSnubberResistance2 = std::pow(std::abs(**mNominalVoltageEnd2), 2) / pSnub;
149 std::make_shared<DP::Ph1::Resistor>(**mName +
"_snub_res2", mLogLevel);
150 mSubSnubResistor2->setParameters(mSnubberResistance2);
151 mSubSnubResistor2->connect({node(1), DP::SimNode::GND});
154 "Snubber Resistance 2 (connected to lower voltage side {}) = {} [Ohm]",
155 node(1)->name(), Logger::realToString(mSnubberResistance2));
156 addMNASubComponent(mSubSnubResistor2,
157 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
158 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
169 mSnubberCapacitance2 =
170 qSnub / std::pow(std::abs(**mNominalVoltageEnd2), 2) / omega;
172 std::make_shared<DP::Ph1::Capacitor>(**mName +
"_snub_cap2", mLogLevel);
173 mSubSnubCapacitor2->setParameters(mSnubberCapacitance2);
174 mSubSnubCapacitor2->connect({node(1), DP::SimNode::GND});
177 "Snubber Capacitance 2 (connected to lower voltage side {}) = {} [F]",
178 node(1)->name(), Logger::realToString(mSnubberCapacitance2));
179 addMNASubComponent(mSubSnubCapacitor2,
180 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
181 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
184 SPDLOG_LOGGER_INFO(mSLog,
"Electrical subcomponents: ");
185 for (
auto subcomp : mSubComponents) {
186 SPDLOG_LOGGER_INFO(mSLog,
"- {}", subcomp->name());
187 subcomp->initialize(mFrequencies);
188 subcomp->initializeFromNodesAndTerminals(frequency);
193 "\n--- Initialization from powerflow ---"
194 "\nVoltage across: {:s}"
196 "\nTerminal 0 voltage: {:s}"
197 "\nTerminal 1 voltage: {:s}"
198 "\nVirtual Node 1 voltage: {:s}"
199 "\n--- Initialization from powerflow finished ---",
200 Logger::phasorToString((**mIntfVoltage)(0, 0)),
201 Logger::phasorToString((**mIntfCurrent)(0, 0)),
202 Logger::phasorToString(initialSingleVoltage(0)),
203 Logger::phasorToString(initialSingleVoltage(1)),
204 Logger::phasorToString(mVirtualNodes[0]->initialSingleVoltage()));
211 "\nTerminal 0 connected to {:s} = sim node {:d}"
212 "\nTerminal 1 connected to {:s} = sim node {:d}",
213 mTerminals[0]->node()->name(), mTerminals[0]->node()->matrixNodeIndex(),
214 mTerminals[1]->node()->name(), mTerminals[1]->node()->matrixNodeIndex());
218 SparseMatrixRow &systemMatrix) {
220 if (terminalNotGrounded(0)) {
221 Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->matrixNodeIndex(),
222 mVirtualNodes[1]->matrixNodeIndex(),
224 Math::setMatrixElement(systemMatrix, mVirtualNodes[1]->matrixNodeIndex(),
225 mVirtualNodes[0]->matrixNodeIndex(),
228 if (terminalNotGrounded(1)) {
229 Math::setMatrixElement(systemMatrix, matrixNodeIndex(1),
230 mVirtualNodes[1]->matrixNodeIndex(), **mRatio);
231 Math::setMatrixElement(systemMatrix, mVirtualNodes[1]->matrixNodeIndex(),
232 matrixNodeIndex(1), -**mRatio);
236 for (
auto subcomp : mSubComponents)
237 if (
auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
238 mnasubcomp->mnaApplySystemMatrixStamp(systemMatrix);
240 if (terminalNotGrounded(0)) {
241 SPDLOG_LOGGER_INFO(mSLog,
"Add {:s} to system at ({:d},{:d})",
242 Logger::complexToString(Complex(-1.0, 0)),
243 mVirtualNodes[0]->matrixNodeIndex(),
244 mVirtualNodes[1]->matrixNodeIndex());
245 SPDLOG_LOGGER_INFO(mSLog,
"Add {:s} to system at ({:d},{:d})",
246 Logger::complexToString(Complex(1.0, 0)),
247 mVirtualNodes[1]->matrixNodeIndex(),
248 mVirtualNodes[0]->matrixNodeIndex());
250 if (terminalNotGrounded(1)) {
251 SPDLOG_LOGGER_INFO(mSLog,
"Add {:s} to system at ({:d},{:d})",
252 Logger::complexToString(**mRatio), matrixNodeIndex(1),
253 mVirtualNodes[1]->matrixNodeIndex());
254 SPDLOG_LOGGER_INFO(mSLog,
"Add {:s} to system at ({:d},{:d})",
255 Logger::complexToString(-**mRatio),
256 mVirtualNodes[1]->matrixNodeIndex(), matrixNodeIndex(1));
261 AttributeBase::List &prevStepDependencies,
262 AttributeBase::List &attributeDependencies,
263 AttributeBase::List &modifiedAttributes) {
264 prevStepDependencies.push_back(mIntfCurrent);
265 prevStepDependencies.push_back(mIntfVoltage);
266 modifiedAttributes.push_back(mRightVector);
270 this->mnaApplyRightSideVectorStamp(**this->mRightVector);
274 AttributeBase::List &prevStepDependencies,
275 AttributeBase::List &attributeDependencies,
276 AttributeBase::List &modifiedAttributes,
278 attributeDependencies.push_back(leftVector);
279 modifiedAttributes.push_back(mIntfVoltage);
280 modifiedAttributes.push_back(mIntfCurrent);
285 this->mnaUpdateVoltage(**leftVector);
286 this->mnaUpdateCurrent(**leftVector);
290 (**mIntfCurrent)(0, 0) = mSubInductor->intfCurrent()(0, 0);
295 (**mIntfVoltage)(0, 0) = 0;
296 (**mIntfVoltage)(0, 0) =
297 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
298 (**mIntfVoltage)(0, 0) = (**mIntfVoltage)(0, 0) -
299 Math::complexFromVectorElement(
300 leftVector, mVirtualNodes[0]->matrixNodeIndex());
301 SPDLOG_LOGGER_DEBUG(mSLog,
"Voltage {:s}",
302 Logger::phasorToString((**mIntfVoltage)(0, 0)));
Base class for composite power components.
String type()
Get component type (cross-platform)
Base class for all components that are transmitting power.
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Voltage between terminals.
Logger::Log mSLog
Component logger.