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

refactor mna tasks of voltage source, controlled voltage source and transformer in em3ph

parent 27afe5f7
......@@ -62,11 +62,13 @@ namespace Ph1 {
void mnaUpdateCurrent(const Matrix& leftVector);
/// Updates internal voltage variable of the component
void mnaUpdateVoltage(const Matrix& leftVector);
/// MNA pre and post step operations
/// MNA pre step operations
void mnaPreStep(Real time, Int timeStepCount);
/// MNA post step operations
void mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector);
/// add MNA pre and post step dependencies
/// Add MNA pre step dependencies
void mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
/// Add MNA post step dependencies
void mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector);
class MnaPreStep : public Task {
......
......@@ -28,7 +28,7 @@ namespace CPS {
ControlledVoltageSource(String name, Logger::Level logLevel = Logger::Level::off)
: ControlledVoltageSource(name, name, logLevel) { }
void setParameters(Matrix voltageRefABC);
void setParameters(const Matrix& voltageRefABC);
SimPowerComp<Real>::Ptr clone(String name);
// #### General ####
......@@ -44,32 +44,34 @@ namespace CPS {
void mnaApplyRightSideVectorStamp(Matrix& rightVector);
/// Returns current through the component
void mnaUpdateCurrent(const Matrix& leftVector);
/// MNA pre step operations
void mnaPreStep(Real time, Int timeStepCount);
/// MNA post step operations
void mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector);
/// Add MNA pre step dependencies
void mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
/// Add MNA post step dependencies
void mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector);
class MnaPreStep : public CPS::Task {
class MnaPreStep : public Task {
public:
MnaPreStep(ControlledVoltageSource& ControlledVoltageSource) :
Task(ControlledVoltageSource.mName + ".MnaPreStep"), mControlledVoltageSource(ControlledVoltageSource) {
mAttributeDependencies.push_back(ControlledVoltageSource.attribute("v_intf"));
mModifiedAttributes.push_back(mControlledVoltageSource.attribute("right_vector"));
MnaPreStep(ControlledVoltageSource& controlledVoltageSource) :
Task(controlledVoltageSource.mName + ".MnaPreStep"), mControlledVoltageSource(controlledVoltageSource) {
mControlledVoltageSource.mnaAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) { mControlledVoltageSource.mnaPreStep(time, timeStepCount); };
private:
ControlledVoltageSource& mControlledVoltageSource;
};
class MnaPostStep : public CPS::Task {
class MnaPostStep : public Task {
public:
MnaPostStep(ControlledVoltageSource& ControlledVoltageSource, Attribute<Matrix>::Ptr leftVector) :
Task(ControlledVoltageSource.mName + ".MnaPostStep"), mControlledVoltageSource(ControlledVoltageSource), mLeftVector(leftVector)
{
mAttributeDependencies.push_back(mLeftVector);
mModifiedAttributes.push_back(mControlledVoltageSource.attribute("i_intf"));
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);
void execute(Real time, Int timeStepCount) { mControlledVoltageSource.mnaPostStep(time, timeStepCount, mLeftVector); };
private:
ControlledVoltageSource& mControlledVoltageSource;
Attribute<Matrix>::Ptr mLeftVector;
......
......@@ -62,20 +62,22 @@ namespace CPS {
void mnaUpdateCurrent(const Matrix& leftVector);
/// Updates internal voltage variable of the component
void mnaUpdateVoltage(const Matrix& leftVector);
/// MNA pre step operations
void mnaPreStep(Real time, Int timeStepCount);
/// MNA post step operations
void mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector);
/// Add MNA pre step dependencies
void mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
/// Add MNA post step dependencies
void mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &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"));
mTransformer.mnaAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) { mTransformer.mnaPreStep(time, timeStepCount); };
private:
Transformer& mTransformer;
};
......@@ -85,13 +87,9 @@ namespace CPS {
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"));
mTransformer.mnaAddPostStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes, mLeftVector);
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) { mTransformer.mnaPostStep(time, timeStepCount, mLeftVector); };
private:
Transformer& mTransformer;
......
......@@ -30,7 +30,9 @@ namespace CPS {
void updateVoltage(Real time);
void updateVoltage(Matrix vabc);
/// Magnitude of the sinusoidal voltage (peak-value, phase-to-ground)
Attribute<Complex>::Ptr mVoltageRef;
/// Frequency of the sinusoidal voltage
Attribute<Real>::Ptr mSrcFreq;
public:
/// Defines UID, name and logging level
......@@ -55,33 +57,34 @@ namespace CPS {
void mnaApplyRightSideVectorStamp(Matrix& rightVector);
/// Returns current through the component
void mnaUpdateCurrent(const Matrix& leftVector);
/// MNA pre step operations
void mnaPreStep(Real time, Int timeStepCount);
/// MNA post step operations
void mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector);
/// Add MNA pre step dependencies
void mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
/// Add MNA post step dependencies
void mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector);
class MnaPreStep : public CPS::Task {
class MnaPreStep : public Task {
public:
MnaPreStep(VoltageSource& voltageSource) :
Task(voltageSource.mName + ".MnaPreStep"), mVoltageSource(voltageSource) {
mAttributeDependencies.push_back(voltageSource.attribute("V_ref"));
mModifiedAttributes.push_back(mVoltageSource.attribute("right_vector"));
mModifiedAttributes.push_back(mVoltageSource.attribute("v_intf"));
mVoltageSource.mnaAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) { mVoltageSource.mnaPreStep(time, timeStepCount); };
private:
VoltageSource& mVoltageSource;
};
class MnaPostStep : public CPS::Task {
class MnaPostStep : public Task {
public:
MnaPostStep(VoltageSource& voltageSource, Attribute<Matrix>::Ptr leftVector) :
Task(voltageSource.mName + ".MnaPostStep"), mVoltageSource(voltageSource), mLeftVector(leftVector)
{
mAttributeDependencies.push_back(mLeftVector);
mModifiedAttributes.push_back(mVoltageSource.attribute("i_intf"));
Task(voltageSource.mName + ".MnaPostStep"),
mVoltageSource(voltageSource), mLeftVector(leftVector) {
mVoltageSource.mnaAddPostStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes, mLeftVector);
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) { mVoltageSource.mnaPostStep(time, timeStepCount, mLeftVector); };
private:
VoltageSource& mVoltageSource;
Attribute<Matrix>::Ptr mLeftVector;
......
......@@ -13,16 +13,17 @@ using namespace CPS;
EMT::Ph3::ControlledVoltageSource::ControlledVoltageSource(String uid, String name, Logger::Level logLevel)
: SimPowerComp<Real>(uid, name, logLevel) {
setVirtualNodeNumber(3);
mPhaseType = PhaseType::ABC;
setVirtualNodeNumber(1);
setTerminalNumber(2);
mIntfVoltage = Matrix::Zero(3, 1);
mIntfCurrent = Matrix::Zero(3, 1);
}
void EMT::Ph3::ControlledVoltageSource::setParameters(Matrix voltageRefABC) {
void EMT::Ph3::ControlledVoltageSource::setParameters(const Matrix& voltageRefABC) {
mIntfVoltage = voltageRefABC;
mSLog->info("Reference voltage: {:s}", Logger::matrixToString(mIntfVoltage));
mParametersSet = true;
}
......@@ -70,13 +71,22 @@ void EMT::Ph3::ControlledVoltageSource::mnaApplyRightSideVectorStamp(Matrix& rig
Math::setVectorElement(rightVector, mVirtualNodes[0]->matrixNodeIndex(PhaseType::C), mIntfVoltage(2, 0));
}
void EMT::Ph3::ControlledVoltageSource::mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
attributeDependencies.push_back(attribute("v_intf"));
modifiedAttributes.push_back(attribute("right_vector"));
}
void EMT::Ph3::ControlledVoltageSource::MnaPreStep::execute(Real time, Int timeStepCount) {
mControlledVoltageSource.mnaApplyRightSideVectorStamp(mControlledVoltageSource.mRightVector);
void EMT::Ph3::ControlledVoltageSource::mnaPreStep(Real time, Int timeStepCount) {
mnaApplyRightSideVectorStamp(mRightVector);
}
void EMT::Ph3::ControlledVoltageSource::MnaPostStep::execute(Real time, Int timeStepCount) {
mControlledVoltageSource.mnaUpdateCurrent(*mLeftVector);
void EMT::Ph3::ControlledVoltageSource::mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) {
attributeDependencies.push_back(leftVector);
modifiedAttributes.push_back(attribute("i_intf"));
};
void EMT::Ph3::ControlledVoltageSource::mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
mnaUpdateCurrent(*leftVector);
}
void EMT::Ph3::ControlledVoltageSource::mnaUpdateCurrent(const Matrix& leftVector) {
......
......@@ -192,5 +192,6 @@ void EMT::Ph3::Inductor::mnaUpdateCurrent(const Matrix& leftVector) {
"\nCurrent: {:s}",
Logger::matrixToString(mIntfCurrent)
);
mSLog->flush();
}
......@@ -141,6 +141,7 @@ void EMT::Ph3::Resistor::mnaUpdateVoltage(const Matrix& leftVector) {
"\nVoltage: {:s}",
Logger::matrixToString(mIntfVoltage)
);
mSLog->flush();
}
void EMT::Ph3::Resistor::mnaUpdateCurrent(const Matrix& leftVector) {
......@@ -149,4 +150,5 @@ void EMT::Ph3::Resistor::mnaUpdateCurrent(const Matrix& leftVector) {
"\nCurrent: {:s}",
Logger::matrixToString(mIntfCurrent)
);
mSLog->flush();
}
......@@ -41,6 +41,8 @@ void EMT::Ph3::Transformer::setParameters(Real ratioAbs, Real ratioPhase,
Matrix resistance, Matrix inductance) {
Base::Ph3::Transformer::setParameters(ratioAbs, ratioPhase, resistance, inductance);
mSLog->info("Resistance={} [Ohm] Inductance={} [Ohm] (referred to primary side)", resistance, inductance);
mSLog->info("Tap Ratio={} [ ] Phase Shift={} [deg]", ratioAbs, ratioPhase);
mParametersSet = true;
}
......@@ -65,6 +67,7 @@ void EMT::Ph3::Transformer::initializeFromNodesAndTerminals(Real frequency) {
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));
mSLog->info("Reactance={} [Ohm] (referred to primary side)", Logger::matrixToString(omega * mInductance));
MatrixComp vInitABC = MatrixComp::Zero(3, 1);
vInitABC(0, 0) = mVirtualNodes[0]->initialSingleVoltage() - RMS3PH_TO_PEAK1PH * initialSingleVoltage(0);
......@@ -102,6 +105,7 @@ void EMT::Ph3::Transformer::initializeFromNodesAndTerminals(Real frequency) {
mSubSnubResistor->connect({ node(1), EMT::SimNode::GND });
mSubSnubResistor->initialize(mFrequencies);
mSubSnubResistor->initializeFromNodesAndTerminals(frequency);
mSLog->info("Snubber Resistance={} [Ohm] (connected to LV side)", Logger::matrixToString(mSnubberResistance));
mSLog->info(
"\n--- Initialization from powerflow ---"
......@@ -115,7 +119,7 @@ void EMT::Ph3::Transformer::initializeFromNodesAndTerminals(Real frequency) {
Logger::matrixToString(mIntfCurrent),
Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(0)),
Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(1)),
Logger::phasorToString(mVirtualNodes[0]->initialSingleVoltage()));
Logger::phasorToString(RMS3PH_TO_PEAK1PH * mVirtualNodes[0]->initialSingleVoltage()));
}
void EMT::Ph3::Transformer::mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
......@@ -207,13 +211,43 @@ 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::mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
// add pre-step dependencies of subcomponents
mSubInductor->mnaAddPreStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes);
// add pre-step dependencies of component itself
prevStepDependencies.push_back(attribute("i_intf"));
prevStepDependencies.push_back(attribute("v_intf"));
modifiedAttributes.push_back(attribute("right_vector"));
}
void EMT::Ph3::Transformer::MnaPostStep::execute(Real time, Int timeStepCount) {
mTransformer.mnaUpdateVoltage(*mLeftVector);
mTransformer.mnaUpdateCurrent(*mLeftVector);
void EMT::Ph3::Transformer::mnaPreStep(Real time, Int timeStepCount) {
// pre-step of subcomponents
mSubInductor->mnaPreStep(time, timeStepCount);
// pre-step of component itself
mnaApplyRightSideVectorStamp(mRightVector);
}
void EMT::Ph3::Transformer::mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) {
// add post-step dependencies of subcomponents
if (mSubResistor)
mSubResistor->mnaAddPostStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes, leftVector);
mSubInductor->mnaAddPostStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes, leftVector);
mSubSnubResistor->mnaAddPostStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes, leftVector);
// add post-step dependencies of component itself
attributeDependencies.push_back(leftVector);
modifiedAttributes.push_back(attribute("v_intf"));
modifiedAttributes.push_back(attribute("i_intf"));
}
void EMT::Ph3::Transformer::mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
// post-step of subcomponents
if (mSubResistor)
mSubResistor->mnaPostStep(time, timeStepCount, leftVector);
mSubInductor->mnaPostStep(time, timeStepCount, leftVector);
mSubSnubResistor->mnaPostStep(time, timeStepCount, leftVector);
// post-step of component itself
mnaUpdateVoltage(*leftVector);
mnaUpdateCurrent(*leftVector);
}
void EMT::Ph3::Transformer::mnaUpdateCurrent(const Matrix& leftVector) {
......
......@@ -11,9 +11,6 @@
using namespace CPS;
// !!! TODO: Adaptions to use in EMT_Ph3 models phase-to-ground peak variables
// !!! with initialization from phase-to-phase RMS variables
EMT::Ph3::VoltageSource::VoltageSource(String uid, String name, Logger::Level logLevel)
: SimPowerComp<Real>(uid, name, logLevel) {
mPhaseType = PhaseType::ABC;
......@@ -112,13 +109,24 @@ void EMT::Ph3::VoltageSource::updateVoltage(Matrix vabc) {
mIntfVoltage=vabc;
}
void EMT::Ph3::VoltageSource::MnaPreStep::execute(Real time, Int timeStepCount) {
mVoltageSource.updateVoltage(time);
mVoltageSource.mnaApplyRightSideVectorStamp(mVoltageSource.mRightVector);
void EMT::Ph3::VoltageSource::mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
attributeDependencies.push_back(attribute("V_ref"));
modifiedAttributes.push_back(attribute("right_vector"));
modifiedAttributes.push_back(attribute("v_intf"));
}
void EMT::Ph3::VoltageSource::mnaPreStep(Real time, Int timeStepCount) {
updateVoltage(time);
mnaApplyRightSideVectorStamp(mRightVector);
}
void EMT::Ph3::VoltageSource::MnaPostStep::execute(Real time, Int timeStepCount) {
mVoltageSource.mnaUpdateCurrent(*mLeftVector);
void EMT::Ph3::VoltageSource::mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) {
attributeDependencies.push_back(leftVector);
modifiedAttributes.push_back(attribute("i_intf"));
};
void EMT::Ph3::VoltageSource::mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
mnaUpdateCurrent(*leftVector);
}
void EMT::Ph3::VoltageSource::mnaUpdateCurrent(const Matrix& leftVector) {
......
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