DPsim
SP_Ph1_Inductor.cpp
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 #include <dpsim-models/SP/SP_Ph1_Inductor.h>
10 
11 using namespace CPS;
12 
13 SP::Ph1::Inductor::Inductor(String uid, String name, Logger::Level logLevel)
14  : MNASimPowerComp<Complex>(uid, name, false, true, logLevel),
15  Base::Ph1::Inductor(mAttributes) {
16  **mIntfVoltage = MatrixComp::Zero(1, 1);
17  **mIntfCurrent = MatrixComp::Zero(1, 1);
18  setTerminalNumber(2);
19 }
20 
22  auto copy = Inductor::make(name, mLogLevel);
23  copy->setParameters(**mInductance);
24  return copy;
25 }
26 
28 
29  Real omega = 2 * PI * frequency;
30  mSusceptance = Complex(0, -1 / omega / **mInductance);
31  (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
32  **mIntfCurrent = mSusceptance * **mIntfVoltage;
33 
34  SPDLOG_LOGGER_INFO(mSLog,
35  "\nInductance [H]: {:s}"
36  "\nImpedance [Ohm]: {:s}",
37  Logger::realToString(**mInductance),
38  Logger::complexToString(1. / mSusceptance));
39  SPDLOG_LOGGER_INFO(mSLog,
40  "\n--- Initialization from powerflow ---"
41  "\nVoltage across: {:s}"
42  "\nCurrent: {:s}"
43  "\nTerminal 0 voltage: {:s}"
44  "\nTerminal 1 voltage: {:s}"
45  "\n--- Initialization from powerflow finished ---",
46  Logger::phasorToString((**mIntfVoltage)(0, 0)),
47  Logger::phasorToString((**mIntfCurrent)(0, 0)),
48  Logger::phasorToString(initialSingleVoltage(0)),
49  Logger::phasorToString(initialSingleVoltage(1)));
50 }
51 
52 // #### MNA section ####
53 
54 void SP::Ph1::Inductor::mnaCompInitialize(Real omega, Real timeStep,
55  Attribute<Matrix>::Ptr leftVector) {
56  updateMatrixNodeIndices();
57 
58  SPDLOG_LOGGER_INFO(mSLog,
59  "\n--- MNA initialization ---"
60  "\nInitial voltage {:s}"
61  "\nInitial current {:s}"
62  "\n--- MNA initialization finished ---",
63  Logger::phasorToString((**mIntfVoltage)(0, 0)),
64  Logger::phasorToString((**mIntfCurrent)(0, 0)));
65 }
66 
68  SparseMatrixRow &systemMatrix) {
69  MNAStampUtils::stampAdmittance(mSusceptance, systemMatrix, matrixNodeIndex(0),
70  matrixNodeIndex(1), terminalNotGrounded(0),
71  terminalNotGrounded(1), mSLog);
72 }
73 
75  AttributeBase::List &prevStepDependencies,
76  AttributeBase::List &attributeDependencies,
77  AttributeBase::List &modifiedAttributes,
78  Attribute<Matrix>::Ptr &leftVector) {
79  attributeDependencies.push_back(leftVector);
80  modifiedAttributes.push_back(mIntfVoltage);
81  modifiedAttributes.push_back(mIntfCurrent);
82 }
83 
84 void SP::Ph1::Inductor::mnaCompPostStep(Real time, Int timeStepCount,
85  Attribute<Matrix>::Ptr &leftVector) {
86  this->mnaUpdateVoltage(**leftVector);
87  this->mnaUpdateCurrent(**leftVector);
88 }
89 
90 void SP::Ph1::Inductor::mnaCompUpdateVoltage(const Matrix &leftVector) {
91  // v1 - v0
92  **mIntfVoltage = Matrix::Zero(3, 1);
93  if (terminalNotGrounded(1)) {
94  (**mIntfVoltage)(0, 0) =
95  Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
96  }
97  if (terminalNotGrounded(0)) {
98  (**mIntfVoltage)(0, 0) =
99  (**mIntfVoltage)(0, 0) -
100  Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
101  }
102 }
103 
104 void SP::Ph1::Inductor::mnaCompUpdateCurrent(const Matrix &leftVector) {
105  **mIntfCurrent = mSusceptance * **mIntfVoltage;
106 }
107 
108 // #### Tear Methods ####
109 void SP::Ph1::Inductor::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
110  Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx, 1. / mSusceptance);
111 }
Base class for all MNA components that are transmitting power.
Static phasor inductor model.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector)
Initializes internal variables of the component.
SimPowerComp< Complex >::Ptr clone(String name)
Returns a modified copy of the component with the given suffix added to the name and without.
void initializeFromNodesAndTerminals(Real frequency)
Initializes component from power flow data.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector)
MNA post step operations.
void mnaCompUpdateCurrent(const Matrix &leftVector)
Update interface current from MNA system results.
Inductor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and log level.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
Add MNA post step dependencies.
void mnaCompUpdateVoltage(const Matrix &leftVector)
Update interface voltage from MNA system results.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix)
Stamps system matrix.
Base class for all components that are transmitting power.
Definition: SimPowerComp.h:17
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
Current through component.
Definition: SimPowerComp.h:47
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Voltage between terminals.
Definition: SimPowerComp.h:45