DPsim
Integrator.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/SimPowerComp.h>
14 #include <dpsim-models/SimSignalComp.h>
15 #include <dpsim-models/Task.h>
16 
17 namespace CPS {
18 namespace Signal {
19 class Integrator : public SimSignalComp, public SharedFactory<Integrator> {
20 
21 protected:
23  Real mTimeStep;
24 
25 public:
28 
41 
42  Integrator(String name, Logger::Level logLevel = Logger::Level::off);
44  void setParameters(Real timestep);
46  void setInitialValues(Real input_init, Real state_init, Real output_init);
48  void signalPreStep(Real time, Int timeStepCount);
50  void signalStep(Real time, Int timeStepCount);
52  void signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies,
53  AttributeBase::List &attributeDependencies,
54  AttributeBase::List &modifiedAttributes);
56  void signalAddStepDependencies(AttributeBase::List &prevStepDependencies,
57  AttributeBase::List &attributeDependencies,
58  AttributeBase::List &modifiedAttributes);
59 
60  Task::List getTasks();
61 
62  class PreStep : public Task {
63  public:
64  PreStep(Integrator &integrator)
65  : Task(**integrator.mName + ".PreStep"), mIntegrator(integrator) {
66  mIntegrator.signalAddPreStepDependencies(
67  mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
68  }
69  void execute(Real time, Int timeStepCount) {
70  mIntegrator.signalPreStep(time, timeStepCount);
71  };
72 
73  private:
74  Integrator &mIntegrator;
75  };
76 
77  class Step : public Task {
78  public:
79  Step(Integrator &integrator)
80  : Task(**integrator.mName + ".Step"), mIntegrator(integrator) {
81  mIntegrator.signalAddStepDependencies(
82  mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
83  }
84  void execute(Real time, Int timeStepCount) {
85  mIntegrator.signalStep(time, timeStepCount);
86  };
87 
88  private:
89  Integrator &mIntegrator;
90  };
91 };
92 } // namespace Signal
93 } // namespace CPS
const Attribute< String >::Ptr mName
Human readable name.
void setParameters(Real timestep)
Setter for integration step parameter.
Definition: Integrator.cpp:25
const Attribute< Real >::Ptr mInputRef
This is never explicitely set to reference anything, so the outside code is responsible for setting u...
Definition: Integrator.h:27
const Attribute< Real >::Ptr mOutputCurr
Current Output.
Definition: Integrator.h:40
const Attribute< Real >::Ptr mOutputPrev
Previous Output.
Definition: Integrator.h:38
Real mTimeStep
Integration time step.
Definition: Integrator.h:23
const Attribute< Real >::Ptr mStateCurr
Current State.
Definition: Integrator.h:36
void signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
add step dependencies
Definition: Integrator.cpp:59
void signalPreStep(Real time, Int timeStepCount)
pre step operations
Definition: Integrator.cpp:53
const Attribute< Real >::Ptr mInputPrev
Previous Input.
Definition: Integrator.h:30
void setInitialValues(Real input_init, Real state_init, Real output_init)
Setter for initial values.
Definition: Integrator.cpp:31
void signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
pre step dependencies
Definition: Integrator.cpp:43
const Attribute< Real >::Ptr mStatePrev
Previous State.
Definition: Integrator.h:34
void signalStep(Real time, Int timeStepCount)
step operations
Definition: Integrator.cpp:68
const Attribute< Real >::Ptr mInputCurr
Current Input.
Definition: Integrator.h:32
Tasks to be defined by every component.
Definition: Task.h:25