-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addition of EMT::Ph1::Switch component (#312)
This branch adds: - A simple Ph1::Switch component version for the EMT domain. - A test Notebook for a circuit VS, Switch, RL1 to test and compare the switch components for the domains EMT_1Ph EMT_3Ph DP_1Ph and SP_1Ph
- Loading branch information
Showing
6 changed files
with
860 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* Copyright 2017-2021 Institute for Automation of Complex Power Systems, | ||
* EONERC, RWTH Aachen University | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*********************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <dpsim-models/Base/Base_Ph1_Switch.h> | ||
#include <dpsim-models/Definitions.h> | ||
#include <dpsim-models/Logger.h> | ||
#include <dpsim-models/MNASimPowerComp.h> | ||
#include <dpsim-models/Solver/MNAInterface.h> | ||
#include <dpsim-models/Solver/MNASwitchInterface.h> | ||
|
||
namespace CPS { | ||
namespace EMT { | ||
namespace Ph1 { | ||
/// \brief One phase EMT switch | ||
/// | ||
/// The switch can be opened and closed. | ||
/// Each state has a specific resistance value. | ||
class Switch : public MNASimPowerComp<Real>, | ||
public Base::Ph1::Switch, | ||
public SharedFactory<Switch>, | ||
public MNASwitchInterface { | ||
|
||
public: | ||
/// Defines UID, name, component parameters and logging level | ||
Switch(String uid, String name, Logger::Level loglevel = Logger::Level::off); | ||
/// Defines name, component parameters and logging level | ||
Switch(String name, Logger::Level logLevel = Logger::Level::off) | ||
: Switch(name, name, logLevel) {} | ||
|
||
SimPowerComp<Real>::Ptr clone(String name) override; | ||
|
||
// #### General #### | ||
/// Initializes component from power flow data | ||
void initializeFromNodesAndTerminals(Real frequency) override; | ||
|
||
// #### General MNA section #### | ||
void mnaCompInitialize(Real omega, Real timeStep, | ||
Attribute<Matrix>::Ptr leftVector) override; | ||
/// Stamps system matrix | ||
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override; | ||
/// Stamps right side (source) vector | ||
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override; | ||
/// Update interface voltage from MNA system result | ||
void mnaCompUpdateVoltage(const Matrix &leftVector) override; | ||
/// Update interface current from MNA system result | ||
void mnaCompUpdateCurrent(const Matrix &leftVector) override; | ||
|
||
// #### MNA section for switches #### | ||
/// Check if switch is closed | ||
Bool mnaIsClosed() override; | ||
/// Stamps system matrix considering the defined switch position | ||
void mnaCompApplySwitchSystemMatrixStamp(Bool closed, | ||
SparseMatrixRow &systemMatrix, | ||
Int freqIdx) override; | ||
/// MNA post step operations | ||
void mnaCompPostStep(Real time, Int timeStepCount, | ||
Attribute<Matrix>::Ptr &leftVector) override; | ||
|
||
/// Add MNA post step dependencies | ||
void | ||
mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, | ||
AttributeBase::List &attributeDependencies, | ||
AttributeBase::List &modifiedAttributes, | ||
Attribute<Matrix>::Ptr &leftVector) override; | ||
}; | ||
} // namespace Ph1 | ||
} // namespace EMT | ||
} // namespace CPS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* Copyright 2017-2021 Institute for Automation of Complex Power Systems, | ||
* EONERC, RWTH Aachen University | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*********************************************************************************/ | ||
|
||
#include <dpsim-models/EMT/EMT_Ph1_Switch.h> | ||
|
||
using namespace CPS; | ||
|
||
EMT::Ph1::Switch::Switch(String uid, String name, Logger::Level logLevel) | ||
: MNASimPowerComp<Real>(uid, name, false, true, logLevel), | ||
Base::Ph1::Switch(mAttributes) { | ||
setTerminalNumber(2); | ||
**mIntfVoltage = Matrix::Zero(1, 1); | ||
**mIntfCurrent = Matrix::Zero(1, 1); | ||
} | ||
|
||
SimPowerComp<Real>::Ptr EMT::Ph1::Switch::clone(String name) { | ||
auto copy = Switch::make(name, mLogLevel); | ||
copy->setParameters(**mOpenResistance, **mClosedResistance, **mIsClosed); | ||
return copy; | ||
} | ||
|
||
void EMT::Ph1::Switch::initializeFromNodesAndTerminals(Real frequency) { | ||
|
||
Real resistance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance; | ||
|
||
(**mIntfVoltage)(0, 0) = | ||
RMS3PH_TO_PEAK1PH * (initialSingleVoltage(1) - initialSingleVoltage(0)).real(); | ||
(**mIntfCurrent)(0, 0) = (**mIntfVoltage)(0, 0) / resistance; | ||
|
||
SPDLOG_LOGGER_INFO(mSLog, | ||
"\n--- Initialization from powerflow ---" | ||
"\nVoltage across: {:s}" | ||
"\nCurrent: {:s}" | ||
"\nTerminal 0 voltage: {:s}" | ||
"\nTerminal 1 voltage: {:s}" | ||
"\n--- Initialization from powerflow finished ---", | ||
Logger::matrixToString(**mIntfVoltage), | ||
Logger::matrixToString(**mIntfCurrent), | ||
Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(0).real()), | ||
Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(1).real())); | ||
} | ||
|
||
void EMT::Ph1::Switch::mnaCompInitialize(Real omega, Real timeStep, | ||
Attribute<Matrix>::Ptr leftVector) { | ||
updateMatrixNodeIndices(); | ||
mMnaTasks.push_back(std::make_shared<MnaPostStep>(*this, leftVector)); | ||
} | ||
|
||
Bool EMT::Ph1::Switch::mnaIsClosed() { return **mIsClosed; } | ||
|
||
void EMT::Ph1::Switch::mnaCompApplySystemMatrixStamp( | ||
SparseMatrixRow &systemMatrix) { | ||
Real conductance; | ||
|
||
conductance = | ||
(**mIsClosed) ? 1. / (**mClosedResistance) : 1. / (**mOpenResistance); | ||
|
||
MNAStampUtils::stampConductance(conductance, systemMatrix, matrixNodeIndex(0), | ||
matrixNodeIndex(1), terminalNotGrounded(0), | ||
terminalNotGrounded(1), mSLog); | ||
} | ||
|
||
void EMT::Ph1::Switch::mnaCompApplySwitchSystemMatrixStamp( | ||
Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) { | ||
Real conductance; | ||
|
||
conductance = | ||
(closed) ? 1. / (**mClosedResistance) : 1. / (**mOpenResistance); | ||
|
||
MNAStampUtils::stampConductance(conductance, systemMatrix, matrixNodeIndex(0), | ||
matrixNodeIndex(1), terminalNotGrounded(0), | ||
terminalNotGrounded(1), mSLog); | ||
} | ||
|
||
void EMT::Ph1::Switch::mnaCompApplyRightSideVectorStamp(Matrix &rightVector) {} | ||
|
||
void EMT::Ph1::Switch::mnaCompAddPostStepDependencies( | ||
AttributeBase::List &prevStepDependencies, | ||
AttributeBase::List &attributeDependencies, | ||
AttributeBase::List &modifiedAttributes, | ||
Attribute<Matrix>::Ptr &leftVector) { | ||
attributeDependencies.push_back(leftVector); | ||
modifiedAttributes.push_back(mIntfVoltage); | ||
modifiedAttributes.push_back(mIntfCurrent); | ||
} | ||
|
||
void EMT::Ph1::Switch::mnaCompPostStep(Real time, Int timeStepCount, | ||
Attribute<Matrix>::Ptr &leftVector) { | ||
mnaCompUpdateVoltage(**leftVector); | ||
mnaCompUpdateCurrent(**leftVector); | ||
} | ||
|
||
void EMT::Ph1::Switch::mnaCompUpdateVoltage(const Matrix &leftVector) { | ||
// Voltage across component is defined as V1 - V0 | ||
**mIntfVoltage = Matrix::Zero(1, 1); | ||
if (terminalNotGrounded(1)) { | ||
(**mIntfVoltage)(0, 0) = | ||
Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 0)); | ||
} | ||
if (terminalNotGrounded(0)) { | ||
(**mIntfVoltage)(0, 0) = | ||
(**mIntfVoltage)(0, 0) - | ||
Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0)); | ||
} | ||
} | ||
|
||
void EMT::Ph1::Switch::mnaCompUpdateCurrent(const Matrix &leftVector) { | ||
(**mIntfCurrent)(0, 0) = (**mIsClosed) | ||
? (**mIntfVoltage)(0, 0) / (**mClosedResistance) | ||
: (**mIntfVoltage)(0, 0) / (**mOpenResistance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.