DPsim
Loading...
Searching...
No Matches
DecouplingLine.h
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
9#pragma once
10
11#include <vector>
12
13#include <dpsim-models/DP/DP_Ph1_CurrentSource.h>
14#include <dpsim-models/DP/DP_Ph1_Resistor.h>
15#include <dpsim-models/SimPowerComp.h>
16#include <dpsim-models/SimSignalComp.h>
17#include <dpsim-models/Task.h>
18
19namespace CPS {
20namespace Signal {
21class DecouplingLine : public SimSignalComp,
22 public SharedFactory<DecouplingLine> {
23protected:
24 Real mDelay;
25 Real mResistance;
26 Real mInductance, mCapacitance;
27 Real mSurgeImpedance;
28
29 std::shared_ptr<DP::SimNode> mNode1, mNode2;
30 std::shared_ptr<DP::Ph1::Resistor> mRes1, mRes2;
31 std::shared_ptr<DP::Ph1::CurrentSource> mSrc1, mSrc2;
32 Attribute<Complex>::Ptr mSrcCur1, mSrcCur2;
33
34 // Ringbuffers for the values of previous timesteps
35 // TODO make these matrix attributes
36 std::vector<Complex> mVolt1, mVolt2, mCur1, mCur2;
37 UInt mBufIdx = 0;
38 UInt mBufSize;
39 Real mAlpha;
40
41 Complex interpolate(std::vector<Complex> &data);
42
43public:
44 typedef std::shared_ptr<DecouplingLine> Ptr;
45
46 const Attribute<Complex>::Ptr mSrcCur1Ref;
47 const Attribute<Complex>::Ptr mSrcCur2Ref;
48
50 const Attribute<Matrix>::Ptr mStates;
51
52 DecouplingLine(String name, SimNode<Complex>::Ptr node1,
53 SimNode<Complex>::Ptr node2, Real resistance, Real inductance,
54 Real capacitance,
55 Logger::Level logLevel = Logger::Level::info);
56
57 DecouplingLine(String name, Logger::Level logLevel = Logger::Level::info);
58
59 void setParameters(SimNode<Complex>::Ptr node1, SimNode<Complex>::Ptr node2,
60 Real resistance, Real inductance, Real capacitance);
61 void initialize(Real omega, Real timeStep);
62 void step(Real time, Int timeStepCount);
63 void postStep();
64 Task::List getTasks();
65 IdentifiedObject::List getLineComponents();
66
67 class PreStep : public Task {
68 public:
69 PreStep(DecouplingLine &line)
70 : Task(**line.mName + ".MnaPreStep"), mLine(line) {
71 mPrevStepDependencies.push_back(mLine.mStates);
72 mModifiedAttributes.push_back(mLine.mSrc1->mCurrentRef);
73 mModifiedAttributes.push_back(mLine.mSrc2->mCurrentRef);
74 }
75
76 void execute(Real time, Int timeStepCount);
77
78 private:
79 DecouplingLine &mLine;
80 };
81
82 class PostStep : public Task {
83 public:
84 PostStep(DecouplingLine &line)
85 : Task(**line.mName + ".PostStep"), mLine(line) {
86 mAttributeDependencies.push_back(mLine.mRes1->mIntfVoltage);
87 mAttributeDependencies.push_back(mLine.mRes1->mIntfCurrent);
88 mAttributeDependencies.push_back(mLine.mRes2->mIntfVoltage);
89 mAttributeDependencies.push_back(mLine.mRes2->mIntfCurrent);
90 mModifiedAttributes.push_back(mLine.mStates);
91 }
92
93 void execute(Real time, Int timeStepCount);
94
95 private:
96 DecouplingLine &mLine;
97 };
98};
99} // namespace Signal
100} // 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.