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);
79 if (Math::abs(**
mRatio) < 1.) {
81 std::shared_ptr<SimTerminal<Complex>> tmp =
mTerminals[0];
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]",
92 SPDLOG_LOGGER_INFO(
mSLog,
"Tap Ratio = {} [ ] Phase Shift = {} [deg]",
100 Real omega = 2. * PI * frequency;
102 SPDLOG_LOGGER_INFO(
mSLog,
"Reactance={} [Ohm] (referred to primary side)",
104 (**mIntfVoltage)(0, 0) =
105 mVirtualNodes[0]->initialSingleVoltage() - initialSingleVoltage(0);
106 (**mIntfCurrent)(0, 0) = (**
mIntfVoltage)(0, 0) / impedance;
113 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
116 mVirtualNodes[2]->setInitialVoltage(initialSingleVoltage(0));
123 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
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));
143 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
144 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
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));
157 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
158 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
169 mSnubberCapacitance2 =
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));
180 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
181 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
184 SPDLOG_LOGGER_INFO(
mSLog,
"Electrical subcomponents: ");
186 SPDLOG_LOGGER_INFO(
mSLog,
"- {}", subcomp->name());
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 ---",
202 Logger::phasorToString(initialSingleVoltage(0)),
203 Logger::phasorToString(initialSingleVoltage(1)),
204 Logger::phasorToString(
mVirtualNodes[0]->initialSingleVoltage()));
208 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
211 "\nTerminal 0 connected to {:s} = sim node {:d}"
212 "\nTerminal 1 connected to {:s} = sim node {:d}",
218 SparseMatrixRow &systemMatrix) {
220 if (terminalNotGrounded(0)) {
221 Math::setMatrixElement(systemMatrix,
mVirtualNodes[0]->matrixNodeIndex(),
224 Math::setMatrixElement(systemMatrix,
mVirtualNodes[1]->matrixNodeIndex(),
228 if (terminalNotGrounded(1)) {
229 Math::setMatrixElement(systemMatrix, matrixNodeIndex(1),
231 Math::setMatrixElement(systemMatrix,
mVirtualNodes[1]->matrixNodeIndex(),
232 matrixNodeIndex(1), -**
mRatio);
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)),
245 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
246 Logger::complexToString(Complex(1.0, 0)),
250 if (terminalNotGrounded(1)) {
251 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
252 Logger::complexToString(**
mRatio), matrixNodeIndex(1),
254 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
255 Logger::complexToString(-**
mRatio),
261 AttributeBase::List &prevStepDependencies,
262 AttributeBase::List &attributeDependencies,
263 AttributeBase::List &modifiedAttributes) {
274 AttributeBase::List &prevStepDependencies,
275 AttributeBase::List &attributeDependencies,
276 AttributeBase::List &modifiedAttributes,
277 Attribute<Matrix>::Ptr &leftVector) {
278 attributeDependencies.push_back(leftVector);
284 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
290 (**mIntfCurrent)(0, 0) = mSubInductor->intfCurrent()(0, 0);
295 (**mIntfVoltage)(0, 0) = 0;
296 (**mIntfVoltage)(0, 0) =
297 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
299 Math::complexFromVectorElement(
301 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.