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