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