Skip to content

Commit

Permalink
added shunt element in EMT domain
Browse files Browse the repository at this point in the history
Signed-off-by: martin.moraga <[email protected]>
  • Loading branch information
martinmoraga committed Feb 5, 2024
1 parent caddd5d commit 4118686
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 11 deletions.
1 change: 1 addition & 0 deletions dpsim-models/include/dpsim-models/Components.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
#include <dpsim-models/EMT/EMT_Ph3_SeriesResistor.h>
#include <dpsim-models/EMT/EMT_Ph3_ResIndSeries.h>
#include <dpsim-models/EMT/EMT_Ph3_SeriesSwitch.h>
#include <dpsim-models/EMT/EMT_Ph3_Shunt.h>
#include <dpsim-models/EMT/EMT_Ph3_CurrentSource.h>
#include <dpsim-models/EMT/EMT_Ph3_VoltageSource.h>
#include <dpsim-models/EMT/EMT_Ph3_VoltageSourceNorton.h>
Expand Down
2 changes: 1 addition & 1 deletion dpsim-models/include/dpsim-models/DP/DP_Ph1_Shunt.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Ph1 {
: Shunt(name, name, logLevel) { }

// #### General ####
/// Set shunt DPecific parameters
/// Set shunt specific parameters
void setParameters(Real conductance, Real susceptance);

// #### MNA section ####
Expand Down
62 changes: 62 additions & 0 deletions dpsim-models/include/dpsim-models/EMT/EMT_Ph3_Shunt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* 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/CompositePowerComp.h>
#include <dpsim-models/Solver/MNAInterface.h>
#include <dpsim-models/EMT/EMT_Ph3_Capacitor.h>
#include <dpsim-models/EMT/EMT_Ph3_Resistor.h>

namespace CPS {
namespace EMT {
namespace Ph3 {

class Shunt :
public CompositePowerComp<Real>,
public SharedFactory<Shunt>{
private:
/// Conductance [S]
Matrix mConductance;
/// Susceptance [S]
Matrix mSusceptance;

/// Capacitor between terminal and ground
std::shared_ptr<Capacitor> mSubCapacitor;
/// Resistor between terminal and ground
std::shared_ptr<Resistor> mSubResistor;

public:
/// Defines UID, name, component parameters and logging level
Shunt(String uid, String name, Logger::Level logLevel = Logger::Level::off);

/// Defines name and logging level
Shunt(String name, Logger::Level logLevel = Logger::Level::off)
: Shunt(name, name, logLevel) { }

// #### General ####
/// Set shunt specific parameters
void setParameters(Real conductance, Real susceptance);
void setParameters(Matrix conductance, Matrix susceptance);

// #### MNA section ####
/// Initializes component from power flow data
void initializeFromNodesAndTerminals(Real frequency) final;
/// Updates internal current variable of the component
void mnaCompUpdateCurrent(const Matrix& leftVector) final;
/// Updates internal voltage variable of the component
void mnaCompUpdateVoltage(const Matrix& leftVector) final;
/// MNA post-step operations
void mnaParentPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) final;
/// add MNA post-step dependencies
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) final;

};
}
}
}
47 changes: 39 additions & 8 deletions dpsim-models/src/CIM/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,17 +942,37 @@ TopologicalPowerComp::Ptr Reader::mapExternalNetworkInjection(CIMPP::ExternalNet
}

TopologicalPowerComp::Ptr Reader::mapEquivalentShunt(CIMPP::EquivalentShunt* shunt){

SPDLOG_LOGGER_INFO(mSLog, "Found shunt {}", shunt->name);

Real baseVoltage = determineBaseVoltageAssociatedWithEquipment(shunt);
if(mDomain == Domain::SP) {
auto cpsShunt = std::make_shared<SP::Ph1::Shunt>(shunt->mRID, shunt->name, mComponentLogLevel);
Real baseVoltage = determineBaseVoltageAssociatedWithEquipment(shunt);
cpsShunt->setParameters(shunt->g.value, shunt->b.value);
cpsShunt->setBaseVoltage(baseVoltage);
SPDLOG_LOGGER_INFO(mSLog, " Create Shunt in SP domain.");
return cpsShunt;
} else if(mDomain == Domain::DP) {
// TODO: consider number of switched sections
auto cpsShunt = std::make_shared<DP::Ph1::Shunt>(shunt->mRID, shunt->name, mComponentLogLevel);
cpsShunt->setParameters(shunt->g.value, shunt->b.value);
SPDLOG_LOGGER_INFO(mSLog, " Create Shunt in DP domain.");
mSLog->flush();

auto cpsShunt = std::make_shared<SP::Ph1::Shunt>(shunt->mRID, shunt->name, mComponentLogLevel);
cpsShunt->setParameters(shunt->g.value, shunt->b.value);
cpsShunt->setBaseVoltage(baseVoltage);
return cpsShunt;
return cpsShunt;
}
else {
// TODO: consider number of switched sections
auto cpsShunt = std::make_shared<EMT::Ph3::Shunt>(shunt->mRID, shunt->name, mComponentLogLevel);
cpsShunt->setParameters(shunt->g.value, shunt->b.value);
SPDLOG_LOGGER_INFO(mSLog, " Create Shunt in EMT domain.");
mSLog->flush();

return cpsShunt;
}
}

TopologicalPowerComp::Ptr Reader::mapEquivalentLinearShunt(CIMPP::LinearShuntCompensator* linearShunt){
TopologicalPowerComp::Ptr Reader::mapEquivalentLinearShunt(CIMPP::LinearShuntCompensator* linearShunt) {

SPDLOG_LOGGER_INFO(mSLog, "Found linear shunt {}", linearShunt->name);

Expand All @@ -962,7 +982,7 @@ TopologicalPowerComp::Ptr Reader::mapEquivalentLinearShunt(CIMPP::LinearShuntCom
Real baseVoltage = determineBaseVoltageAssociatedWithEquipment(linearShunt);
cpsShunt->setParameters(linearShunt->gPerSection.value, linearShunt->bPerSection.value);
cpsShunt->setBaseVoltage(baseVoltage);
SPDLOG_LOGGER_INFO(mSLog, " Create generator in SP domain.");
SPDLOG_LOGGER_INFO(mSLog, " Create Shunt in SP domain.");
mSLog->flush();

return cpsShunt;
Expand All @@ -971,11 +991,22 @@ TopologicalPowerComp::Ptr Reader::mapEquivalentLinearShunt(CIMPP::LinearShuntCom
// TODO: consider number of switched sections
auto cpsShunt = std::make_shared<DP::Ph1::Shunt>(linearShunt->mRID, linearShunt->name, mComponentLogLevel);
cpsShunt->setParameters(linearShunt->gPerSection.value, linearShunt->bPerSection.value);
SPDLOG_LOGGER_INFO(mSLog, " Create generator in SP domain.");
SPDLOG_LOGGER_INFO(mSLog, " Create Shunt in DP domain.");
mSLog->flush();

return cpsShunt;
}
else {
// TODO: consider number of switched sections
auto cpsShunt = std::make_shared<EMT::Ph3::Shunt>(linearShunt->mRID, linearShunt->name, mComponentLogLevel);
cpsShunt->setParameters(linearShunt->gPerSection.value, linearShunt->bPerSection.value);
SPDLOG_LOGGER_INFO(mSLog, " Create Shunt in EMT domain.");
mSLog->flush();

return cpsShunt;
}

return nullptr;
}

Real Reader::determineBaseVoltageAssociatedWithEquipment(CIMPP::ConductingEquipment* equipment){
Expand Down
1 change: 1 addition & 0 deletions dpsim-models/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ list(APPEND MODELS_SOURCES
EMT/EMT_Ph3_RXLoad.cpp
EMT/EMT_Ph3_NetworkInjection.cpp
EMT/EMT_Ph3_Transformer.cpp
EMT/EMT_Ph3_Shunt.cpp
EMT/EMT_Ph3_Switch.cpp
EMT/EMT_Ph3_ReducedOrderSynchronGeneratorVBR.cpp
EMT/EMT_Ph3_SynchronGenerator3OrderVBR.cpp
Expand Down
4 changes: 2 additions & 2 deletions dpsim-models/src/DP/DP_Ph1_Shunt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void DP::Ph1::Shunt::initializeFromNodesAndTerminals(Real frequency) {
mSubResistor->setParameters(1. / **mConductance);
mSubResistor->initialize(mFrequencies);
mSubResistor->initializeFromNodesAndTerminals(frequency);
addMNASubComponent(mSubResistor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
addMNASubComponent(mSubResistor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
}

if (**mSusceptance>0) {
Expand All @@ -52,7 +52,7 @@ void DP::Ph1::Shunt::initializeFromNodesAndTerminals(Real frequency) {
mSubCapacitor->connect(SimNode::List{ SimNode::GND, mTerminals[0]->node()});
mSubCapacitor->initialize(mFrequencies);
mSubCapacitor->initializeFromNodesAndTerminals(frequency);
addMNASubComponent(mSubCapacitor, MNA_SUBCOMP_TASK_ORDER::NO_TASK, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
addMNASubComponent(mSubCapacitor, MNA_SUBCOMP_TASK_ORDER::NO_TASK, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
}

SPDLOG_LOGGER_INFO(mSLog,
Expand Down
107 changes: 107 additions & 0 deletions dpsim-models/src/EMT/EMT_Ph3_Shunt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* 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_Ph3_Shunt.h>

using namespace CPS;

EMT::Ph3::Shunt::Shunt(String uid, String name, Logger::Level logLevel)
: CompositePowerComp<Real>(uid, name, false, true, logLevel) {

mConductance = Matrix::Zero(3,3);
mSusceptance = Matrix::Zero(3,3);
SPDLOG_LOGGER_INFO(mSLog, "Create {} of type {}", this->type(), name);
setTerminalNumber(1);
}


void EMT::Ph3::Shunt::setParameters(Real conductance, Real susceptance) {
this->setParameters(Math::singlePhaseParameterToThreePhase(conductance),
Math::singlePhaseParameterToThreePhase(susceptance));
}

void EMT::Ph3::Shunt::setParameters(Matrix conductance, Matrix susceptance){
mConductance = conductance;
mSusceptance = susceptance;
SPDLOG_LOGGER_INFO(mSLog, "Conductance={} [S] Susceptance={} [Ohm] ",
Logger::matrixToString(mConductance),
Logger::matrixToString(mSusceptance));
mParametersSet = true;
}

/// MNA Section
void EMT::Ph3::Shunt::initializeFromNodesAndTerminals(Real frequency) {

// Static calculation
Real omega = 2. * PI * frequency;
MatrixComp admittance = Matrix::Zero(3,3);
admittance << Complex(mConductance(0,0), mSusceptance(0,0)), 0, 0,
0, Complex(mConductance(1,1), mSusceptance(1,1)), 0,
0, 0, Complex(mConductance(2,2), mSusceptance(2,2));
MatrixComp vInitABC = MatrixComp::Zero(3, 1);
vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * mTerminals[0]->initialSingleVoltage();
vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
**mIntfVoltage = vInitABC.real();
**mIntfCurrent = (admittance * vInitABC).real();

// Create series rl sub component
if (mConductance(0,0)>0) {
mSubResistor = std::make_shared<EMT::Ph3::Resistor>(**mName + "_Res", mLogLevel);
mSubResistor->connect({ SimNode::GND, mTerminals[0]->node() });
mSubResistor->setParameters(mConductance.inverse());
mSubResistor->initialize(mFrequencies);
mSubResistor->initializeFromNodesAndTerminals(frequency);
addMNASubComponent(mSubResistor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
}

if (mSusceptance(0,0)>0) {
mSubCapacitor = std::make_shared<EMT::Ph3::Capacitor>(**mName + "_cap", mLogLevel);
mSubCapacitor->setParameters(mSusceptance * (1/omega));
mSubCapacitor->connect({ SimNode::GND, mTerminals[0]->node() });
mSubCapacitor->initialize(mFrequencies);
mSubCapacitor->initializeFromNodesAndTerminals(frequency);
addMNASubComponent(mSubCapacitor, MNA_SUBCOMP_TASK_ORDER::NO_TASK, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
}

SPDLOG_LOGGER_INFO(mSLog,
"\n--- Initialization from powerflow ---"
"\nVoltage across: {:s}"
"\nCurrent: {:s}"
"\nTerminal voltage: {:s}"
"\n--- Initialization from powerflow finished ---",
Logger::phasorToString((**mIntfVoltage)(0, 0)),
Logger::phasorToString((**mIntfCurrent)(0, 0)),
Logger::phasorToString(initialSingleVoltage(0)));
}

void EMT::Ph3::Shunt::mnaParentAddPostStepDependencies(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::Ph3::Shunt::mnaParentPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
this->mnaUpdateVoltage(**leftVector);
this->mnaUpdateCurrent(**leftVector);
}

void EMT::Ph3::Shunt::mnaCompUpdateVoltage(const Matrix& leftVector) {
(**mIntfVoltage)(0, 0) = Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
(**mIntfVoltage)(1, 0) = Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
(**mIntfVoltage)(2, 0) = Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
}

void EMT::Ph3::Shunt::mnaCompUpdateCurrent(const Matrix& leftVector) {
**mIntfCurrent = Matrix::Zero(3, 1);

if (mConductance(0,0)>0)
**mIntfCurrent += mSubResistor->intfCurrent();
if (mSusceptance(0,0)>0)
**mIntfCurrent += mSubCapacitor->intfCurrent();
}

0 comments on commit 4118686

Please sign in to comment.