DPsim
Loading...
Searching...
No Matches
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
11using namespace CPS;
12
13SP::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
21SimPowerComp<Complex>::Ptr SP::Ph1::Inductor::clone(String name) {
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);
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
54void SP::Ph1::Inductor::mnaCompInitialize(Real omega, Real timeStep,
55 Attribute<Matrix>::Ptr leftVector) {
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
84void SP::Ph1::Inductor::mnaCompPostStep(Real time, Int timeStepCount,
85 Attribute<Matrix>::Ptr &leftVector) {
86 this->mnaUpdateVoltage(**leftVector);
87 this->mnaUpdateCurrent(**leftVector);
88}
89
90void 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
104void SP::Ph1::Inductor::mnaCompUpdateCurrent(const Matrix &leftVector) {
106}
107
108// #### Tear Methods ####
109void SP::Ph1::Inductor::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
110 Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx, 1. / mSusceptance);
111}
const CPS::Attribute< Real >::Ptr mInductance
Inductance [H].
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
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.
Complex mSusceptance
susceptance [S]
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.
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.