DPsim
DP_Ph1_Resistor.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/Base/Base_Ph1_Resistor.h>
12 #include <dpsim-models/MNASimPowerComp.h>
13 #include <dpsim-models/Solver/DAEInterface.h>
14 #include <dpsim-models/Solver/MNATearInterface.h>
15 
16 namespace CPS {
17 namespace DP {
18 namespace Ph1 {
20 class Resistor : public MNASimPowerComp<Complex>,
21  public Base::Ph1::Resistor,
22  public MNATearInterface,
23  public DAEInterface,
24  public SharedFactory<Resistor> {
25 public:
27  Resistor(String uid, String name,
28  Logger::Level loglevel = Logger::Level::off);
30  Resistor(String name, Logger::Level logLevel = Logger::Level::off)
31  : Resistor(name, name, logLevel) {}
32 
33  SimPowerComp<Complex>::Ptr clone(String name);
34 
35  // #### General ####
37  void initializeFromNodesAndTerminals(Real frequency);
38 
39  // #### MNA section ####
40  void mnaCompInitialize(Real omega, Real timeStep,
41  Attribute<Matrix>::Ptr leftVector);
42  void mnaCompInitializeHarm(Real omega, Real timeStep,
43  std::vector<Attribute<Matrix>::Ptr> leftVector);
45  void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix);
47  void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix,
48  Int freqIdx);
50  void mnaCompUpdateVoltage(const Matrix &leftVector);
51  void mnaCompUpdateVoltageHarm(const Matrix &leftVector, Int freqIdx);
53  void mnaCompUpdateCurrent(const Matrix &leftVector);
54  void mnaCompUpdateCurrentHarm();
56  void mnaCompPostStep(Real time, Int timeStepCount,
57  Attribute<Matrix>::Ptr &leftVector);
59  void
60  mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
61  AttributeBase::List &attributeDependencies,
62  AttributeBase::List &modifiedAttributes,
63  Attribute<Matrix>::Ptr &leftVector);
64 
65  class MnaPostStepHarm : public Task {
66  public:
67  MnaPostStepHarm(Resistor &resistor,
68  std::vector<Attribute<Matrix>::Ptr> &leftVectors)
69  : Task(**resistor.mName + ".MnaPostStepHarm"), mResistor(resistor),
70  mLeftVectors(leftVectors) {
71  for (UInt i = 0; i < mLeftVectors.size(); i++)
72  mAttributeDependencies.push_back(mLeftVectors[i]);
73  mModifiedAttributes.push_back(mResistor.attribute("v_intf"));
74  mModifiedAttributes.push_back(mResistor.attribute("i_intf"));
75  }
76  void execute(Real time, Int timeStepCount);
77 
78  private:
79  Resistor &mResistor;
80  std::vector<Attribute<Matrix>::Ptr> mLeftVectors;
81  };
82 
83  // #### MNA Tear Section ####
84  void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix);
85 
86  // #### DAE Section ####
88  void daeResidual(double ttime, const double state[], const double dstate_dt[],
89  double resid[], std::vector<int> &off);
91  Complex daeInitialize();
92 };
93 } // namespace Ph1
94 } // namespace DP
95 } // namespace CPS
Dynamic phasor resistor model.
Complex daeInitialize()
Voltage Getter.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
add MNA pre and post step dependencies
void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix, Int freqIdx)
Stamps system matrix considering the frequency index.
Resistor(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector)
MNA pre and post step operations.
void daeResidual(double ttime, const double state[], const double dstate_dt[], double resid[], std::vector< int > &off)
Residual Function for DAE Solver.
void mnaCompUpdateCurrent(const Matrix &leftVector)
Update interface current from MNA system result.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix)
Stamps system matrix.
SimPowerComp< Complex >::Ptr clone(String name)
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompUpdateVoltage(const Matrix &leftVector)
Update interface voltage from MNA system result.
void initializeFromNodesAndTerminals(Real frequency)
Initializes component from power flow data.
Resistor(String name, Logger::Level logLevel=Logger::Level::off)
Defines name and logging level.
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
AttributeBase::Ptr attribute(const String &name) const
Return pointer to an attribute.
Base class for all MNA components that are transmitting power.
Base class for all components that are transmitting power.
Definition: SimPowerComp.h:17
Tasks to be defined by every component.
Definition: Task.h:25