DPsim
DecouplingLineEMT.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/EMT/EMT_Ph1_CurrentSource.h>
14 #include <dpsim-models/EMT/EMT_Ph1_Resistor.h>
15 #include <dpsim-models/SimSignalComp.h>
16 #include <dpsim-models/Task.h>
17 
18 namespace CPS {
19 namespace Signal {
21  public SharedFactory<DecouplingLineEMT> {
22 protected:
23  Real mDelay;
24  Real mResistance;
25  Real mInductance;
26  Real mCapacitance;
27  Real mSurgeImpedance;
28 
29  std::shared_ptr<EMT::SimNode> mNode1, mNode2;
30  std::shared_ptr<EMT::Ph1::Resistor> mRes1, mRes2;
31  std::shared_ptr<EMT::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<Real> mVolt1, mVolt2, mCur1, mCur2;
37  UInt mBufIdx = 0;
38  UInt mBufSize;
39  Real mAlpha;
40 
41  Real interpolate(std::vector<Real> &data);
42 
43 public:
44  typedef std::shared_ptr<DecouplingLineEMT> Ptr;
45 
46  const Attribute<Real>::Ptr mSrcCur1Ref;
47  const Attribute<Real>::Ptr mSrcCur2Ref;
48 
51 
52  DecouplingLineEMT(String name, Logger::Level logLevel = Logger::Level::info);
53 
54  void setParameters(SimNode<Real>::Ptr node1, SimNode<Real>::Ptr node2,
55  Real resistance, Real inductance, Real capacitance);
56  void initialize(Real omega, Real timeStep);
57  void step(Real time, Int timeStepCount);
58  void postStep();
59  Task::List getTasks();
60  IdentifiedObject::List getLineComponents();
61 
62  class PreStep : public Task {
63  public:
65  : Task(**line.mName + ".MnaPreStep"), mLine(line) {
66  mPrevStepDependencies.push_back(mLine.mStates);
67  mModifiedAttributes.push_back(mLine.mSrc1->mCurrentRef);
68  mModifiedAttributes.push_back(mLine.mSrc2->mCurrentRef);
69  }
70 
71  void execute(Real time, Int timeStepCount);
72 
73  private:
74  DecouplingLineEMT &mLine;
75  };
76 
77  class PostStep : public Task {
78  public:
80  : Task(**line.mName + ".PostStep"), mLine(line) {
81  mAttributeDependencies.push_back(mLine.mRes1->mIntfVoltage);
82  mAttributeDependencies.push_back(mLine.mRes1->mIntfCurrent);
83  mAttributeDependencies.push_back(mLine.mRes2->mIntfVoltage);
84  mAttributeDependencies.push_back(mLine.mRes2->mIntfCurrent);
85  mModifiedAttributes.push_back(mLine.mStates);
86  }
87 
88  void execute(Real time, Int timeStepCount);
89 
90  private:
91  DecouplingLineEMT &mLine;
92  };
93 };
94 } // namespace Signal
95 } // 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.
Tasks to be defined by every component.
Definition: Task.h:25