DPsim
SP_Ph3_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_Ph3_Inductor.h>
10 
11 using namespace CPS;
12 
13 SP::Ph3::Inductor::Inductor(String uid, String name, Logger::Level logLevel)
14  : MNASimPowerComp<Complex>(uid, name, false, true, logLevel),
15  Base::Ph3::Inductor(mAttributes) {
16  mPhaseType = PhaseType::ABC;
17  setTerminalNumber(2);
18  **mIntfVoltage = MatrixComp::Zero(3, 1);
19  **mIntfCurrent = MatrixComp::Zero(3, 1);
20 }
21 
23  auto copy = Inductor::make(name, mLogLevel);
24  copy->setParameters(**mInductance);
25  return copy;
26 }
27 
29 
30  Real omega = 2 * PI * frequency;
31  MatrixComp reactance = MatrixComp::Zero(3, 3);
32  reactance << Complex(0, omega * (**mInductance)(0, 0)),
33  Complex(0, omega * (**mInductance)(0, 1)),
34  Complex(0, omega * (**mInductance)(0, 2)),
35  Complex(0, omega * (**mInductance)(1, 0)),
36  Complex(0, omega * (**mInductance)(1, 1)),
37  Complex(0, omega * (**mInductance)(1, 2)),
38  Complex(0, omega * (**mInductance)(2, 0)),
39  Complex(0, omega * (**mInductance)(2, 1)),
40  Complex(0, omega * (**mInductance)(2, 2));
41  mSusceptance = reactance.inverse();
42 
43  // IntfVoltage initialization for each phase
44  (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
45  (**mIntfVoltage)(1, 0) = (**mIntfVoltage)(0, 0) *
46  Complex(cos(-2. / 3. * M_PI), sin(-2. / 3. * M_PI));
47  (**mIntfVoltage)(2, 0) = (**mIntfVoltage)(0, 0) *
48  Complex(cos(2. / 3. * M_PI), sin(2. / 3. * M_PI));
49  **mIntfCurrent = mSusceptance * **mIntfVoltage;
50 
51  SPDLOG_LOGGER_INFO(mSLog, "--- Initialize according to power flow ---");
52  /*
53  mLog.info() << "--- Initialize according to power flow ---" << std::endl
54  << "in phase A: " << std::endl
55  << "Voltage across: " << std::abs((**mIntfVoltage)(0, 0))
56  << "<" << Math::phaseDeg((**mIntfVoltage)(0, 0)) << std::endl
57  << "Current: " << std::abs((**mIntfCurrent)(0, 0))
58  << "<" << Math::phaseDeg((**mIntfCurrent)(0, 0)) << std::endl
59  << "Terminal 0 voltage: " << std::abs(initialSingleVoltage(0))
60  << "<" << Math::phaseDeg(initialSingleVoltage(0)) << std::endl
61  << "Terminal 1 voltage: " << std::abs(initialSingleVoltage(1))
62  << "<" << Math::phaseDeg(initialSingleVoltage(1)) << std::endl
63  << "--- Power flow initialization finished ---" << std::endl;
64 */
65 }
66 
67 void SP::Ph3::Inductor::mnaCompInitialize(Real omega, Real timeStep,
68  Attribute<Matrix>::Ptr leftVector) {
69  updateMatrixNodeIndices();
70  // TODO
71  /*
72  mLog.info() << "Initial voltage " << Math::abs((**mIntfVoltage)(0, 0))
73  << "<" << Math::phaseDeg((**mIntfVoltage)(0, 0)) << std::endl
74  << "Initial current " << Math::abs((**mIntfCurrent)(0, 0))
75  << "<" << Math::phaseDeg((**mIntfCurrent)(0, 0)) << std::endl;
76 */
77 }
78 
80  SparseMatrixRow &systemMatrix) {
81  MNAStampUtils::stampAdmittanceMatrix(
82  mSusceptance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
83  terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
84 }
85 
87  AttributeBase::List &prevStepDependencies,
88  AttributeBase::List &attributeDependencies,
89  AttributeBase::List &modifiedAttributes,
90  Attribute<Matrix>::Ptr &leftVector) {
91  attributeDependencies.push_back(leftVector);
92  modifiedAttributes.push_back(mIntfVoltage);
93  modifiedAttributes.push_back(mIntfCurrent);
94 }
95 
96 void SP::Ph3::Inductor::mnaCompPostStep(Real time, Int timeStepCount,
97  Attribute<Matrix>::Ptr &leftVector) {
98  mnaCompUpdateVoltage(**leftVector);
99  mnaCompUpdateCurrent(**leftVector);
100 }
101 
102 void SP::Ph3::Inductor::mnaCompUpdateVoltage(const Matrix &leftVector) {
103  // v1 - v0
104  **mIntfVoltage = Matrix::Zero(3, 1);
105  if (terminalNotGrounded(1)) {
106  (**mIntfVoltage)(0, 0) =
107  Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 0));
108  (**mIntfVoltage)(1, 0) =
109  Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 1));
110  (**mIntfVoltage)(2, 0) =
111  Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 2));
112  }
113  if (terminalNotGrounded(0)) {
114  (**mIntfVoltage)(0, 0) =
115  (**mIntfVoltage)(0, 0) -
116  Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 0));
117  (**mIntfVoltage)(1, 0) =
118  (**mIntfVoltage)(1, 0) -
119  Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 1));
120  (**mIntfVoltage)(2, 0) =
121  (**mIntfVoltage)(2, 0) -
122  Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 2));
123  }
124 }
125 
126 void SP::Ph3::Inductor::mnaCompUpdateCurrent(const Matrix &leftVector) {
127  **mIntfCurrent = mSusceptance * **mIntfVoltage;
128 }
129 
130 // #### Tear Methods ####
131 void SP::Ph3::Inductor::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
132  // TODO
133  Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx,
134  1. / mSusceptance(0, 0));
135  Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx,
136  1. / mSusceptance(1, 0));
137  Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx,
138  1. / mSusceptance(2, 0));
139 }
Base class for all MNA components that are transmitting power.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
Inductor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
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