DPsim
SP_Ph1_NetworkInjection.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 <dpsim-models/CompositePowerComp.h>
12 #include <dpsim-models/SP/SP_Ph1_VoltageSource.h>
13 #include <dpsim-models/Solver/DAEInterface.h>
14 #include <dpsim-models/Solver/PFSolverInterfaceBus.h>
15 
16 namespace CPS {
17 namespace SP {
18 namespace Ph1 {
26 class NetworkInjection : public CompositePowerComp<Complex>,
27  public SharedFactory<NetworkInjection>,
28  public PFSolverInterfaceBus,
29  public DAEInterface {
30 
31 private:
32  // ### Electrical Subcomponents ###
34  std::shared_ptr<SP::Ph1::VoltageSource> mSubVoltageSource;
35 
36  // #### solver ####
38  std::vector<const Matrix *> mRightVectorStamps;
39 
40  // #### Powerflow section ####
42  Real mBaseVoltage;
43 
44 public:
45  const Attribute<Complex>::Ptr mVoltageRef;
46  const Attribute<Real>::Ptr mSrcFreq;
47 
48  // #### Powerflow section ####
57 
59  NetworkInjection(String uid, String name,
60  Logger::Level logLevel = Logger::Level::off);
62  NetworkInjection(String name, Logger::Level logLevel = Logger::Level::off)
63  : NetworkInjection(name, name, logLevel) {}
65  SimPowerComp<Complex>::Ptr clone(String name) override;
66 
67  // #### General ####
69  void initializeFromNodesAndTerminals(Real frequency) override;
70 
71  // #### Powerflow section ####
73  void setParameters(Real vSetPointPerUnit);
75  void setBaseVoltage(Real baseVoltage);
77  void calculatePerUnitParameters(Real baseApparentPower, Real baseOmega);
79  void modifyPowerFlowBusType(PowerflowBusType powerflowBusType) override;
81  void updatePowerInjection(Complex powerInj);
82 
83  // #### MNA Section ####
87  void setParameters(Complex voltageRef, Real srcFreq = 0.0);
90  void setParameters(Complex initialPhasor, Real freqStart, Real rocof,
91  Real timeStart, Real duration, bool smoothRamp = true);
94  void setParameters(Complex initialPhasor, Real modulationFrequency,
95  Real modulationAmplitude, Real baseFrequency = 0.0,
96  bool zigzag = false);
97 
99  void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override;
101  void mnaCompUpdateCurrent(const Matrix &leftVector) override;
103  void mnaCompUpdateVoltage(const Matrix &leftVector) override;
105  void mnaParentPreStep(Real time, Int timeStepCount) override;
107  void mnaParentPostStep(Real time, Int timeStepCount,
108  Attribute<Matrix>::Ptr &leftVector) override;
111  AttributeBase::List &prevStepDependencies,
112  AttributeBase::List &attributeDependencies,
113  AttributeBase::List &modifiedAttributes) override;
115  void
116  mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
117  AttributeBase::List &attributeDependencies,
118  AttributeBase::List &modifiedAttributes,
119  Attribute<Matrix>::Ptr &leftVector) override;
120 
121  // #### DAE Section ####
123  void daeResidual(double ttime, const double state[], const double dstate_dt[],
124  double resid[], std::vector<int> &off) override;
126  Complex daeInitialize() override;
127 };
128 } // namespace Ph1
129 } // namespace SP
130 } // namespace CPS
Base class for composite power components.
String uid()
Returns unique id.
Common base class of all Component templates.
const Attribute< Real >::Ptr mActivePowerInjection
Active Power Injection [W].
void setParameters(Real vSetPointPerUnit)
Set parameters relevant for PF solver.
Complex daeInitialize() override
Voltage Getter.
void daeResidual(double ttime, const double state[], const double dstate_dt[], double resid[], std::vector< int > &off) override
Residual function for DAE Solver.
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void calculatePerUnitParameters(Real baseApparentPower, Real baseOmega)
Calculates component's parameters in specified per-unit system.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
const Attribute< Real >::Ptr mVoltageSetPoint
Voltage set point [V].
NetworkInjection(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates voltage across component.
NetworkInjection(String name, Logger::Level logLevel=Logger::Level::off)
Defines name and logging level.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void setBaseVoltage(Real baseVoltage)
Set base voltage.
const Attribute< Real >::Ptr mVoltageSetPointPerUnit
Voltage set point [pu].
void modifyPowerFlowBusType(PowerflowBusType powerflowBusType) override
Modify powerflow bus type.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Returns current through the component.
void updatePowerInjection(Complex powerInj)
Update power injection.
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
const Attribute< Real >::Ptr mReactivePowerInjection
Reactive Power Injection [Var].
Base class for all components that are transmitting power.
Definition: SimPowerComp.h:17