Commit 4cf169c3 authored by Jan Dinkelbach's avatar Jan Dinkelbach Committed by Markus Mirz
Browse files

remove unused files

parent af0c1b2e
......@@ -31,7 +31,6 @@
#include <cps/SP/SP_Ph3_Resistor.h>
#include <cps/SP/SP_Ph3_VoltageSource.h>
#include <cps/SP/SP_Ph3_ControlledVoltageSource.h>
#include <cps/SP/SP_Ph3_Transformer.h>
#include <cps/DP/DP_Ph1_Capacitor.h>
#include <cps/DP/DP_Ph1_CurrentSource.h>
......
/* Copyright 2017-2020 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 <cps/SimPowerComp.h>
#include <cps/Solver/MNAInterface.h>
#include <cps/SP/SP_Ph3_RxLine.h>
#include <cps/SP/SP_Ph3_Inductor.h>
#include <cps/Base/Base_Ph3_Transformer.h>
namespace CPS {
namespace SP {
namespace Ph3 {
/// Transformer that includes an inductance and resistance
class Transformer :
public SimPowerComp<Real>,
public MNAInterface,
public SharedFactory<Transformer>,
public Base::Ph3::Transformer {
private:
/// Internal inductor to model losses
std::shared_ptr<SP::Ph3::Inductor> mSubInductor;
/// Internal parallel resistance as snubber
std::shared_ptr<SP::Ph3::Resistor> mSubSnubResistor;
std::shared_ptr<SP::Ph3::Resistor> mSubResistor;
public:
/// Defines UID, name and logging level
Transformer(String uid, String name,
Logger::Level logLevel = Logger::Level::off);
/// Defines name and logging level
Transformer(String name, Logger::Level logLevel = Logger::Level::off)
: Transformer(name, name, logLevel) { }
SimPowerComp<Real>::Ptr clone(String name);
// #### General ####
/// Defines component parameters
void setParameters(Real ratioAbs, Real ratioPhase, Matrix resistance, Matrix inductance);
/// Initializes component from power flow data
void initializeFromNodesAndTerminals(Real frequency);
// #### MNA section ####
/// Initializes internal variables of the component
void mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector);
/// Stamps system matrix
void mnaApplySystemMatrixStamp(Matrix& systemMatrix);
/// Stamps right side (source) vector
void mnaApplyRightSideVectorStamp(Matrix& rightVector);
/// Updates internal current variable of the component
void mnaUpdateCurrent(const Matrix& leftVector);
/// Updates internal voltage variable of the component
void mnaUpdateVoltage(const Matrix& leftVector);
class MnaPreStep : public Task {
public:
MnaPreStep(Transformer& transformer) :
Task(transformer.mName + ".MnaPreStep"), mTransformer(transformer) {
mAttributeDependencies.push_back(transformer.mSubSnubResistor->attribute("right_vector"));
mAttributeDependencies.push_back(transformer.mSubInductor->attribute("right_vector"));
if (transformer.mSubResistor)
mAttributeDependencies.push_back(transformer.mSubResistor->attribute("right_vector"));
mModifiedAttributes.push_back(transformer.attribute("right_vector"));
}
void execute(Real time, Int timeStepCount);
private:
Transformer& mTransformer;
};
class MnaPostStep : public Task {
public:
MnaPostStep(Transformer& transformer, Attribute<Matrix>::Ptr leftVector) :
Task(transformer.mName + ".MnaPostStep"), mTransformer(transformer), mLeftVector(leftVector) {
mAttributeDependencies.push_back(transformer.mSubInductor->attribute("i_intf"));
mAttributeDependencies.push_back(leftVector);
mModifiedAttributes.push_back(transformer.attribute("i_intf"));
mModifiedAttributes.push_back(transformer.attribute("v_intf"));
}
void execute(Real time, Int timeStepCount);
private:
Transformer& mTransformer;
Attribute<Matrix>::Ptr mLeftVector;
};
};
}
}
}
/* Copyright 2017-2020 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 <cps/EMT/EMT_Ph3_Transformer.h>
using namespace CPS;
EMT::Ph3::Transformer::Transformer(String uid, String name,
Logger::Level logLevel)
: SimPowerComp<Real>(uid, name, logLevel) {
mPhaseType = PhaseType::ABC;
setTerminalNumber(2);
setVirtualNodeNumber(1);
mIntfVoltage = Matrix::Zero(3, 1);
mIntfCurrent = Matrix::Zero(1, 1);
addAttribute<Complex>("ratio", &mRatio, Flags::write | Flags::read);
addAttribute<Matrix>("R", &mResistance, Flags::write | Flags::read);
addAttribute<Matrix>("L", &mInductance, Flags::write | Flags::read);
}
SimPowerComp<Real>::Ptr EMT::Ph3::Transformer::clone(String name) {
auto copy = Transformer::make(name, mLogLevel);
copy->setParameters(std::abs(mRatio), std::arg(mRatio), mResistance, mInductance);
return copy;
}
void EMT::Ph3::Transformer::setParameters(Real ratioAbs, Real ratioPhase,
Matrix resistance, Matrix inductance) {
Base::Ph3::Transformer::setParameters(ratioAbs, ratioPhase, resistance, inductance);
if (resistance(0, 0) > 0)
setVirtualNodeNumber(3);
else
setVirtualNodeNumber(2);
}
void EMT::Ph3::Transformer::initializeFromNodesAndTerminals(Real frequency) {
// A snubber conductance is added on the low voltage side
Matrix snubberResistance = Matrix::Zero(3, 3);
snubberResistance <<
1e3, 0, 0,
0, 1e3, 0,
0, 0, 1e3;
// Component parameters are referred to high voltage side.
// Switch terminals if transformer is connected the other way around.
if (Math::abs(mRatio) < 1.) {
mRatio = 1. / mRatio;
std::shared_ptr<SimTerminal<Real>> tmp = mTerminals[0];
mTerminals[0] = mTerminals[1];
mTerminals[1] = tmp;
}
// Set initial voltage of virtual node in between
mVirtualNodes[0]->setInitialVoltage(initialSingleVoltage(1) * mRatio);
// Static calculations from load flow data
Real omega = 2. * PI * frequency;
MatrixComp impedance = MatrixComp::Zero(3, 3);
impedance <<
Complex(mResistance(0, 0), omega * mInductance(0, 0)), Complex(mResistance(0, 1), omega * mInductance(0, 1)), Complex(mResistance(0, 2), omega * mInductance(0, 2)),
Complex(mResistance(1, 0), omega * mInductance(1, 0)), Complex(mResistance(1, 1), omega * mInductance(1, 1)), Complex(mResistance(1, 2), omega * mInductance(1, 2)),
Complex(mResistance(2, 0), omega * mInductance(2, 0)), Complex(mResistance(2, 1), omega * mInductance(2, 1)), Complex(mResistance(2, 2), omega * mInductance(2, 2));
MatrixComp vInitABC = MatrixComp::Zero(3, 1);
vInitABC(0, 0) = mVirtualNodes[0]->initialSingleVoltage() - initialSingleVoltage(0);
vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
MatrixComp iInit = impedance.inverse() * vInitABC;
mIntfCurrent = iInit.real();
mIntfVoltage = vInitABC.real();
// Create series sub components
mSubInductor = std::make_shared<EMT::Ph3::Inductor>(mName + "_ind", mLogLevel);
mSubInductor->setParameters(mInductance);
if (mNumVirtualNodes == 3) {
mVirtualNodes[2]->setInitialVoltage(initialSingleVoltage(0));
mSubResistor = std::make_shared<EMT::Ph3::Resistor>(mName + "_res", mLogLevel);
mSubResistor->setParameters(mResistance);
mSubResistor->connect({ node(0), mVirtualNodes[2] });
mSubResistor->initialize(mFrequencies);
mSubResistor->initializeFromNodesAndTerminals(frequency);
mSubInductor->connect({ mVirtualNodes[2], mVirtualNodes[0] });
}
else {
mSubInductor->connect({ node(0), mVirtualNodes[0] });
}
mSubInductor->initialize(mFrequencies);
mSubInductor->initializeFromNodesAndTerminals(frequency);
// Create parallel sub components
mSubSnubResistor = std::make_shared<EMT::Ph3::Resistor>(mName + "_snub_res", mLogLevel);
mSubSnubResistor->setParameters(snubberResistance);
mSubSnubResistor->connect({ node(1), EMT::SimNode::GND });
mSubSnubResistor->initialize(mFrequencies);
mSubSnubResistor->initializeFromNodesAndTerminals(frequency);
mSLog->info(
"\n--- Initialization from powerflow ---"
"\nVoltage across: {:s}"
"\nCurrent: {:s}"
"\nTerminal 0 voltage: {:s}"
"\nTerminal 1 voltage: {:s}"
"\nVirtual Node 1 voltage: {:s}"
"\n--- Initialization from powerflow finished ---",
Logger::matrixToString(mIntfVoltage),
Logger::matrixToString(mIntfCurrent),
Logger::phasorToString(initialSingleVoltage(0)),
Logger::phasorToString(initialSingleVoltage(1)),
Logger::phasorToString(mVirtualNodes[0]->initialSingleVoltage()));
}
void EMT::Ph3::Transformer::mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
MNAInterface::mnaInitialize(omega, timeStep);
updateMatrixNodeIndices();
mRightVector = Matrix::Zero(leftVector->get().rows(), 1);
auto subComponents = MNAInterface::List({ mSubInductor, mSubSnubResistor });
if (mSubResistor)
subComponents.push_back(mSubResistor);
for (auto comp : subComponents) {
comp->mnaInitialize(omega, timeStep, leftVector);
for (auto task : comp->mnaTasks()) {
mMnaTasks.push_back(task);
}
}
mMnaTasks.push_back(std::make_shared<MnaPreStep>(*this));
mMnaTasks.push_back(std::make_shared<MnaPostStep>(*this, leftVector));
mSLog->info(
"\nTerminal 0 connected to {:s} = sim node {:d}"
"\nTerminal 1 connected to {:s} = sim node {:d}",
mTerminals[0]->node()->name(), mTerminals[0]->node()->matrixNodeIndex(),
mTerminals[1]->node()->name(), mTerminals[1]->node()->matrixNodeIndex());
}
void EMT::Ph3::Transformer::mnaApplySystemMatrixStamp(Matrix& systemMatrix) {
// Ideal transformer equations
if (terminalNotGrounded(0)) {
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), mVirtualNodes[1]->matrixNodeIndex(PhaseType::A), -1.);
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), mVirtualNodes[1]->matrixNodeIndex(PhaseType::B), -1.);
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), mVirtualNodes[1]->matrixNodeIndex(PhaseType::C), -1.);
Math::setMatrixElement(systemMatrix, mVirtualNodes[1]->matrixNodeIndex(PhaseType::A), mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), 1.);
Math::setMatrixElement(systemMatrix, mVirtualNodes[1]->matrixNodeIndex(PhaseType::B), mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), 1.);
Math::setMatrixElement(systemMatrix, mVirtualNodes[1]->matrixNodeIndex(PhaseType::C), mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), 1.);
}
if (terminalNotGrounded(1)) {
Math::setMatrixElement(systemMatrix, matrixNodeIndex(1, 0), mVirtualNodes[1]->matrixNodeIndex(PhaseType::A), mRatio.real());
Math::setMatrixElement(systemMatrix, matrixNodeIndex(1, 1), mVirtualNodes[1]->matrixNodeIndex(PhaseType::B), mRatio.real());
Math::setMatrixElement(systemMatrix, matrixNodeIndex(1, 2), mVirtualNodes[1]->matrixNodeIndex(PhaseType::C), mRatio.real());
Math::setMatrixElement(systemMatrix, mVirtualNodes[1]->matrixNodeIndex(PhaseType::A), matrixNodeIndex(1, 0), -mRatio.real());
Math::setMatrixElement(systemMatrix, mVirtualNodes[1]->matrixNodeIndex(PhaseType::B), matrixNodeIndex(1, 1), -mRatio.real());
Math::setMatrixElement(systemMatrix, mVirtualNodes[1]->matrixNodeIndex(PhaseType::C), matrixNodeIndex(1, 2), -mRatio.real());
}
// Add inductive part to system matrix
mSubInductor->mnaApplySystemMatrixStamp(systemMatrix);
mSubSnubResistor->mnaApplySystemMatrixStamp(systemMatrix);
if (mNumVirtualNodes == 3) {
mSubResistor->mnaApplySystemMatrixStamp(systemMatrix);
}
if (terminalNotGrounded(0)) {
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(Complex(-1.0, 0)),
mVirtualNodes[0]->matrixNodeIndex(PhaseType::A), mVirtualNodes[1]->matrixNodeIndex(PhaseType::A));
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(Complex(-1.0, 0)),
mVirtualNodes[0]->matrixNodeIndex(PhaseType::B), mVirtualNodes[1]->matrixNodeIndex(PhaseType::B));
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(Complex(-1.0, 0)),
mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), mVirtualNodes[1]->matrixNodeIndex(PhaseType::C));
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(Complex(1.0, 0)),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::A), mVirtualNodes[0]->matrixNodeIndex(PhaseType::A));
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(Complex(1.0, 0)),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::B), mVirtualNodes[0]->matrixNodeIndex(PhaseType::B));
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(Complex(1.0, 0)),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::C), mVirtualNodes[0]->matrixNodeIndex(PhaseType::C));
}
if (terminalNotGrounded(1)) {
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(mRatio),
matrixNodeIndex(1, 0), mVirtualNodes[1]->matrixNodeIndex(PhaseType::A));
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(mRatio),
matrixNodeIndex(1, 1), mVirtualNodes[1]->matrixNodeIndex(PhaseType::B));
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(mRatio),
matrixNodeIndex(1, 2), mVirtualNodes[1]->matrixNodeIndex(PhaseType::C));
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(-mRatio),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::A), matrixNodeIndex(1, 0));
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(-mRatio),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::B), matrixNodeIndex(1, 1));
mSLog->info("Add {:s} to system at ({:d},{:d})", Logger::complexToString(-mRatio),
mVirtualNodes[1]->matrixNodeIndex(PhaseType::C), matrixNodeIndex(1, 2));
}
}
void EMT::Ph3::Transformer::mnaApplyRightSideVectorStamp(Matrix& rightVector) {
mSubInductor->mnaApplyRightSideVectorStamp(rightVector);
}
void EMT::Ph3::Transformer::MnaPreStep::execute(Real time, Int timeStepCount) {
mTransformer.mnaApplyRightSideVectorStamp(mTransformer.mRightVector);
}
void EMT::Ph3::Transformer::MnaPostStep::execute(Real time, Int timeStepCount) {
mTransformer.mnaUpdateVoltage(*mLeftVector);
mTransformer.mnaUpdateCurrent(*mLeftVector);
}
void EMT::Ph3::Transformer::mnaUpdateCurrent(const Matrix& leftVector) {
mIntfCurrent = mSubInductor->intfCurrent();
}
void EMT::Ph3::Transformer::mnaUpdateVoltage(const Matrix& leftVector) {
// v1 - v0
mIntfVoltage = Matrix::Zero(3, 1);
if (terminalNotGrounded(1)) {
mIntfVoltage(0, 0) = Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 0));
mIntfVoltage(1, 0) = Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 1));
mIntfVoltage(2, 0) = Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 2));
}
if (terminalNotGrounded(0)) {
mIntfVoltage(0, 0) = mIntfVoltage(0, 0) - Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
mIntfVoltage(1, 0) = mIntfVoltage(1, 0) - Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
mIntfVoltage(2, 0) = mIntfVoltage(2, 0) - Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment