DPsim
Loading...
Searching...
No Matches
DecouplingIdealTransformer_EMT_Ph3.h
1// SPDX-FileCopyrightText: 2026 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University
2// SPDX-License-Identifier: MPL-2.0
3
4#pragma once
5
6#include <vector>
7
8#include "dpsim-models/Definitions.h"
9#include "dpsim-models/EMT/EMT_Ph3_ControlledVoltageSource.h"
10#include "dpsim-models/MathUtils.h"
11#include <dpsim-models/EMT/EMT_Ph3_ControlledCurrentSource.h>
12#include <dpsim-models/EMT/EMT_Ph3_Resistor.h>
13#include <dpsim-models/SimSignalComp.h>
14#include <dpsim-models/Task.h>
15
16namespace CPS {
17namespace Signal {
18
19class DecouplingIdealTransformer_EMT_Ph3
20 : public SimSignalComp,
21 public SharedFactory<DecouplingIdealTransformer_EMT_Ph3> {
22protected:
23 Real mDelay;
24 Matrix mInternalSeriesResistance =
26 Matrix mInternalParallelResistance =
28
29 std::shared_ptr<EMT::SimNode> mNode1, mNode2, mVirtualNode;
30 std::shared_ptr<EMT::Ph3::Resistor> mRes1, mRes2;
31 std::shared_ptr<EMT::Ph3::ControlledCurrentSource> mCurrentSrc;
32 std::shared_ptr<EMT::Ph3::ControlledVoltageSource> mVoltageSrc;
33 Attribute<Matrix>::Ptr mSrcCurrent, mSrcVoltage;
34
35 // Ringbuffers for the values of previous timesteps
36 // TODO make these matrix attributes
37 Matrix mCur1, mVol2;
38
39 // Copy of the most recent elements of the ring buffers
40 // They are used to perform extrapolation
41 Matrix mCur1Extrap, mVol2Extrap;
42 MatrixComp mCurrent1Extrap0;
43
44 UInt mBufIdx = 0;
45 UInt mMacroBufIdx = 0;
46 UInt mBufSize;
47 Real mAlpha;
48 CouplingMethod mCouplingMethod;
49 UInt mExtrapolationDegree = 0;
50 Matrix mVoltageSrcIntfCurr;
51
52 // Get an approximate value of the signal in between steps when the delay is not an integer multiple of the step size
53 Matrix interpolate(Matrix &data);
54
55 // Estimates the value of the input signal in the next step
56 Matrix extrapolate(Matrix &data);
57
58public:
59 typedef std::shared_ptr<DecouplingIdealTransformer_EMT_Ph3> Ptr;
60
61 const Attribute<Matrix>::Ptr mSourceVoltageIntfVoltage;
62 const Attribute<Matrix>::Ptr mSourceVoltageIntfCurrent;
63 const Attribute<Matrix>::Ptr mSrcCurrentRef;
64 const Attribute<Matrix>::Ptr mSrcVoltageRef;
65
67 const Attribute<Matrix>::Ptr mStates;
68
69 DecouplingIdealTransformer_EMT_Ph3(
70 String name, Logger::Level logLevel = Logger::Level::info);
71
72 void setParameters(SimNode<Real>::Ptr node1, SimNode<Real>::Ptr node2,
73 Real delay, Matrix voltageSrcIntfCurr,
74 Matrix current1Extrap0,
75 CouplingMethod method = CouplingMethod::DELAY);
76 void initialize(Real omega, Real timeStep);
77 void step(Real time, Int timeStepCount);
78 void postStep();
79 Task::List getTasks();
80 IdentifiedObject::List getComponents();
81 TopologicalNode::Ptr getVirtualNode();
82
83 class PreStep : public Task {
84 public:
85 PreStep(DecouplingIdealTransformer_EMT_Ph3 &itm)
86 : Task(**itm.mName + ".MnaPreStep"), mITM(itm) {
87 mPrevStepDependencies.push_back(mITM.mStates);
88 mModifiedAttributes.push_back(mITM.mVoltageSrc->mVoltageRef);
89 mModifiedAttributes.push_back(mITM.mCurrentSrc->mCurrentRef);
90 }
91
92 void execute(Real time, Int timeStepCount);
93
94 private:
95 DecouplingIdealTransformer_EMT_Ph3 &mITM;
96 };
97
98 class PostStep : public Task {
99 public:
100 PostStep(DecouplingIdealTransformer_EMT_Ph3 &itm)
101 : Task(**itm.mName + ".PostStep"), mITM(itm) {
102 mAttributeDependencies.push_back(mITM.mVoltageSrc->mIntfVoltage);
103 mAttributeDependencies.push_back(mITM.mVoltageSrc->mIntfCurrent);
104 mAttributeDependencies.push_back(mITM.mCurrentSrc->mIntfVoltage);
105 mAttributeDependencies.push_back(mITM.mCurrentSrc->mIntfCurrent);
106 mModifiedAttributes.push_back(mITM.mStates);
107 }
108
109 void execute(Real time, Int timeStepCount);
110
111 private:
112 DecouplingIdealTransformer_EMT_Ph3 &mITM;
113 };
114};
115} // namespace Signal
116} // namespace CPS
const Attribute< String >::Ptr mName
Human readable name.
static Matrix singlePhaseParameterToThreePhase(Real parameter)
To convert single phase parameters to symmetrical three phase ones.
const Attribute< Matrix >::Ptr mStates
FIXME: workaround for dependency analysis as long as the states aren't attributes.