Commit 41ecaa79 authored by Jan Dinkelbach's avatar Jan Dinkelbach Committed by Markus Mirz
Browse files

remove controlled voltage source from dp1ph

parent 48c9b67a
......@@ -107,7 +107,7 @@ int main(int argc, char* argv[]) {
SystemNodeList{n1DP, n2DP},
SystemComponentList{extnetDP, lineDP, loadDP});
// Initialization of dynamic topology (actually necessary here? node objects the same)
// Initialization of dynamic topology
CIM::Reader reader(simNameDP, Logger::Level::debug);
reader.initDynamicSystemTopologyWithPowerflow(systemPF, systemDP);
......
......@@ -17,7 +17,6 @@
#include <cps/DP/DP_Ph1_VoltageSource.h>
#include <cps/DP/DP_Ph1_Transformer.h>
#include <cps/Base/Base_AvVoltageSourceInverterDQ.h>
#include <cps/PowerProfile.h>
#include <cps/Signal/PLL.h>
#include <cps/Signal/PowerControllerVSI.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>
namespace CPS {
namespace DP {
namespace Ph1 {
class ControlledVoltageSource :
public MNAInterface,
public SimPowerComp<Complex>,
public SharedFactory<ControlledVoltageSource> {
protected:
void updateVoltage(Real time);
public:
/// Defines UID, name and logging level
ControlledVoltageSource(String uid, String name, Logger::Level logLevel = Logger::Level::off);
///
ControlledVoltageSource(String name, Logger::Level logLevel = Logger::Level::off)
: ControlledVoltageSource(name, name, logLevel) { }
void setParameters(MatrixComp voltageRefABC);
SimPowerComp<Complex>::Ptr clone(String name);
// #### General ####
/// 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);
/// Returns current through the component
void mnaUpdateCurrent(const Matrix& leftVector);
/// MNA pre and post step operations
void mnaPreStep(Real time, Int timeStepCount);
void mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector);
/// add MNA pre and post step dependencies
void mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
void mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector);
class MnaPreStep : public CPS::Task {
public:
MnaPreStep(ControlledVoltageSource& ControlledVoltageSource) :
Task(ControlledVoltageSource.mName + ".MnaPreStep"), mControlledVoltageSource(ControlledVoltageSource) {
mControlledVoltageSource.mnaAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount) { mControlledVoltageSource.mnaPreStep(time, timeStepCount); };
private:
ControlledVoltageSource& mControlledVoltageSource;
};
class MnaPostStep : public CPS::Task {
public:
MnaPostStep(ControlledVoltageSource& ControlledVoltageSource, Attribute<Matrix>::Ptr leftVector) :
Task(ControlledVoltageSource.mName + ".MnaPostStep"), mControlledVoltageSource(ControlledVoltageSource), mLeftVector(leftVector) {
mControlledVoltageSource.mnaAddPostStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes, mLeftVector);
}
void execute(Real time, Int timeStepCount) { mControlledVoltageSource.mnaPostStep(time, timeStepCount, mLeftVector); };
private:
ControlledVoltageSource& mControlledVoltageSource;
Attribute<Matrix>::Ptr mLeftVector;
};
class MnaPreStepHarm : public CPS::Task {
public:
MnaPreStepHarm(ControlledVoltageSource& voltageSource) :
Task(voltageSource.mName + ".MnaPreStepHarm"),
mControlledVoltageSource(voltageSource) {
mAttributeDependencies.push_back(voltageSource.attribute("V_ref"));
mModifiedAttributes.push_back(mControlledVoltageSource.attribute("right_vector"));
mModifiedAttributes.push_back(mControlledVoltageSource.attribute("v_intf"));
}
void execute(Real time, Int timeStepCount);
private:
ControlledVoltageSource& mControlledVoltageSource;
};
class MnaPostStepHarm : public CPS::Task {
public:
MnaPostStepHarm(ControlledVoltageSource& voltageSource, std::vector<Attribute<Matrix>::Ptr> leftVectors) :
Task(voltageSource.mName + ".MnaPostStepHarm"),
mControlledVoltageSource(voltageSource), mLeftVectors(leftVectors) {
for (UInt i = 0; i < mLeftVectors.size(); i++)
mAttributeDependencies.push_back(mLeftVectors[i]);
mModifiedAttributes.push_back(mControlledVoltageSource.attribute("i_intf"));
}
void execute(Real time, Int timeStepCount);
private:
ControlledVoltageSource& mControlledVoltageSource;
std::vector< Attribute<Matrix>::Ptr > mLeftVectors;
};
};
}
}
}
......@@ -33,7 +33,6 @@ list(APPEND CPS_SOURCES
DP/DP_Ph1_SynchronGeneratorTrStab.cpp
DP/DP_Ph1_Inverter.cpp
DP/DP_Ph1_AvVoltageSourceInverterDQ.cpp
DP/DP_Ph1_ControlledVoltageSource.cpp
DP/DP_Ph1_NetworkInjection.cpp
DP/DP_Ph3_ControlledVoltageSource.cpp
......
/* 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/DP/DP_Ph1_ControlledVoltageSource.h>
using namespace CPS;
DP::Ph1::ControlledVoltageSource::ControlledVoltageSource(String uid, String name, Logger::Level logLevel)
: SimPowerComp<Complex>(uid, name, logLevel) {
setVirtualNodeNumber(1);
setTerminalNumber(2);
mIntfVoltage = MatrixComp::Zero(1, 1);
mIntfCurrent = MatrixComp::Zero(1, 1);
}
void DP::Ph1::ControlledVoltageSource::setParameters(MatrixComp voltageRefABC) {
mIntfVoltage = voltageRefABC;
mParametersSet = true;
}
SimPowerComp<Complex>::Ptr DP::Ph1::ControlledVoltageSource::clone(String name) {
auto copy = ControlledVoltageSource::make(name, mLogLevel);
copy->setParameters(attribute<MatrixComp>("v_intf")->get());
return copy;
}
void DP::Ph1::ControlledVoltageSource::mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
MNAInterface::mnaInitialize(omega, timeStep);
updateMatrixNodeIndices();
mMnaTasks.push_back(std::make_shared<MnaPreStep>(*this));
mMnaTasks.push_back(std::make_shared<MnaPostStep>(*this, leftVector));
mRightVector = Matrix::Zero(leftVector->get().rows(), 1);
}
void DP::Ph1::ControlledVoltageSource::mnaApplySystemMatrixStamp(Matrix& systemMatrix) {
for (UInt freq = 0; freq < mNumFreqs; freq++) {
if (terminalNotGrounded(0)) {
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(0), Complex(-1, 0), mNumFreqs, freq);
Math::setMatrixElement(systemMatrix, matrixNodeIndex(0), mVirtualNodes[0]->matrixNodeIndex(), Complex(-1, 0), mNumFreqs, freq);
}
if (terminalNotGrounded(1)) {
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(1), Complex(1, 0), mNumFreqs, freq);
Math::setMatrixElement(systemMatrix, matrixNodeIndex(1), mVirtualNodes[0]->matrixNodeIndex(), Complex(1, 0), mNumFreqs, freq);
}
mSLog->info("-- Stamp frequency {:d} ---", freq);
if (terminalNotGrounded(0)) {
mSLog->info("Add {:f} to system at ({:d},{:d})", -1., matrixNodeIndex(0), mVirtualNodes[0]->matrixNodeIndex());
mSLog->info("Add {:f} to system at ({:d},{:d})", -1., mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(0));
}
if (terminalNotGrounded(1)) {
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(1));
mSLog->info("Add {:f} to system at ({:d},{:d})", 1., matrixNodeIndex(1), mVirtualNodes[0]->matrixNodeIndex());
}
}
}
void DP::Ph1::ControlledVoltageSource::mnaApplyRightSideVectorStamp(Matrix& rightVector) {
Math::setVectorElement(rightVector, mVirtualNodes[0]->matrixNodeIndex(), mIntfVoltage(0, 0), mNumFreqs);
SPDLOG_LOGGER_DEBUG(mSLog, "Add {:s} to source vector at {:d}",
Logger::complexToString(mIntfVoltage(0, 0)), mVirtualNodes[0]->matrixNodeIndex());
}
void DP::Ph1::ControlledVoltageSource::mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
attributeDependencies.push_back(this->attribute("v_intf"));
modifiedAttributes.push_back(this->attribute("right_vector"));
}
void DP::Ph1::ControlledVoltageSource::mnaPreStep(Real time, Int timeStepCount) {
this->mnaApplyRightSideVectorStamp(this->mRightVector);
}
void DP::Ph1::ControlledVoltageSource::mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) {
attributeDependencies.push_back(leftVector);
modifiedAttributes.push_back(this->attribute("i_intf"));
}
void DP::Ph1::ControlledVoltageSource::mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
this->mnaUpdateCurrent(*leftVector);
}
void DP::Ph1::ControlledVoltageSource::mnaUpdateCurrent(const Matrix& leftVector) {
for (UInt freq = 0; freq < mNumFreqs; freq++) {
mIntfCurrent(0, freq) = Math::complexFromVectorElement(leftVector, mVirtualNodes[0]->matrixNodeIndex(), mNumFreqs, freq);
}
}
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