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

refactor mna tasks and their attribute dependencies in RLC and PiLine for EMT Ph3

parent f95daada
......@@ -105,7 +105,7 @@ int main(int argc, char* argv[]) {
SystemNodeList{n1EMT, n2EMT},
SystemComponentList{extnetEMT, lineEMT, loadEMT});
// Initialization of dynamic topology (actually necessary here? node objects the same)
// Initialization of dynamic topology
CIM::Reader reader(simNameEMT, Logger::Level::debug);
reader.initDynamicSystemTopologyWithPowerflow(systemPF, systemEMT);
......
......@@ -66,11 +66,13 @@ namespace Ph1 {
/// Update interface current from MNA system result
void mnaUpdateCurrent(const Matrix& leftVector);
void mnaUpdateCurrentHarm();
/// 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 {
......
......@@ -67,11 +67,13 @@ namespace Ph1 {
/// Update interface current from MNA system results
void mnaUpdateCurrent(const Matrix& leftVector);
void mnaUpdateCurrentHarm();
/// 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);
// #### Tearing methods ####
......
......@@ -56,34 +56,33 @@ namespace CPS {
void mnaUpdateVoltage(const Matrix& leftVector);
/// Update interface current from MNA system result
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(Capacitor& capacitor)
: Task(capacitor.mName + ".MnaPreStep"), mCapacitor(capacitor) {
// actually depends on C, but then we'd have to modify the system matrix anyway
mModifiedAttributes.push_back(capacitor.attribute("right_vector"));
mPrevStepDependencies.push_back(mCapacitor.attribute("i_intf"));
mPrevStepDependencies.push_back(mCapacitor.attribute("v_intf"));
mCapacitor.mnaAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) { mCapacitor.mnaPreStep(time, timeStepCount); };
private:
Capacitor& mCapacitor;
};
class MnaPostStep : public CPS::Task {
class MnaPostStep : public Task {
public:
MnaPostStep(Capacitor& capacitor, Attribute<Matrix>::Ptr leftVector)
: Task(capacitor.mName + ".MnaPostStep"), mCapacitor(capacitor), mLeftVector(leftVector) {
mAttributeDependencies.push_back(mLeftVector);
mModifiedAttributes.push_back(mCapacitor.attribute("v_intf"));
mModifiedAttributes.push_back(mCapacitor.attribute("i_intf"));
mCapacitor.mnaAddPostStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes, mLeftVector);
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) { mCapacitor.mnaPostStep(time, timeStepCount, mLeftVector); };
private:
Capacitor& mCapacitor;
Attribute<Matrix>::Ptr mLeftVector;
......
......@@ -56,19 +56,22 @@ namespace CPS {
void mnaUpdateVoltage(const Matrix& leftVector);
/// Update interface current from MNA system result
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 Task {
public:
MnaPreStep(Inductor& inductor) :
Task(inductor.mName + ".MnaPreStep"), mInductor(inductor) {
// actually depends on L, but then we'd have to modify the system matrix anyway
mModifiedAttributes.push_back(inductor.attribute("right_vector"));
mPrevStepDependencies.push_back(inductor.attribute("i_intf"));
mPrevStepDependencies.push_back(inductor.attribute("v_intf"));
mInductor.mnaAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) { mInductor.mnaPreStep(time, timeStepCount); };
private:
Inductor& mInductor;
};
......@@ -76,14 +79,11 @@ namespace CPS {
class MnaPostStep : public Task {
public:
MnaPostStep(Inductor& inductor, Attribute<Matrix>::Ptr leftVector) :
Task(inductor.mName + ".MnaPostStep"), mInductor(inductor), mLeftVector(leftVector) {
mAttributeDependencies.push_back(mLeftVector);
mModifiedAttributes.push_back(mInductor.attribute("v_intf"));
mModifiedAttributes.push_back(mInductor.attribute("i_intf"));
Task(inductor.mName + ".MnaPostStep"),
mInductor(inductor), mLeftVector(leftVector) {
mInductor.mnaAddPostStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes, mLeftVector);
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) { mInductor.mnaPostStep(time, timeStepCount, mLeftVector); };
private:
Inductor& mInductor;
Attribute<Matrix>::Ptr mLeftVector;
......
......@@ -66,27 +66,22 @@ namespace Ph3 {
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(PiLine& line) :
Task(line.mName + ".MnaPreStep"), mLine(line) {
mAttributeDependencies.push_back(line.mSubSeriesResistor->attribute("right_vector"));
mAttributeDependencies.push_back(line.mSubSeriesInductor->attribute("right_vector"));
if (line.mParallelCond(0,0) > 0) {
mAttributeDependencies.push_back(line.mSubParallelResistor0->attribute("right_vector"));
mAttributeDependencies.push_back(line.mSubParallelResistor1->attribute("right_vector"));
mLine.mnaAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
if (line.mParallelCap(0, 0) > 0) {
mAttributeDependencies.push_back(line.mSubParallelCapacitor0->attribute("right_vector"));
mAttributeDependencies.push_back(line.mSubParallelCapacitor1->attribute("right_vector"));
}
mModifiedAttributes.push_back(line.attribute("right_vector"));
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) {mLine.mnaPreStep(time, timeStepCount);};
private:
PiLine& mLine;
};
......@@ -95,14 +90,9 @@ namespace Ph3 {
public:
MnaPostStep(PiLine& line, Attribute<Matrix>::Ptr leftVector) :
Task(line.mName + ".MnaPostStep"), mLine(line), mLeftVector(leftVector) {
mAttributeDependencies.push_back(leftVector);
mAttributeDependencies.push_back(line.mSubSeriesInductor->attribute("i_intf"));
mModifiedAttributes.push_back(line.attribute("i_intf"));
mModifiedAttributes.push_back(line.attribute("v_intf"));
}
void execute(Real time, Int timeStepCount);
mLine.mnaAddPostStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes, mLeftVector);
}
void execute(Real time, Int timeStepCount) { mLine.mnaPostStep(time, timeStepCount, mLeftVector); };
private:
PiLine& mLine;
Attribute<Matrix>::Ptr mLeftVector;
......
......@@ -48,20 +48,19 @@ public:
void mnaUpdateVoltage(const Matrix& leftVector);
/// Update interface current from MNA system result
void mnaUpdateCurrent(const Matrix& leftVector);
/// MNA pre and post step operations
void mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector);
/// add MNA pre and post step dependencies
void mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector);
class MnaPostStep : public Task {
public:
MnaPostStep(Resistor& resistor, Attribute<Matrix>::Ptr leftSideVector) :
Task(resistor.mName + ".MnaPostStep"),
mResistor(resistor), mLeftVector(leftSideVector) {
mAttributeDependencies.push_back(mLeftVector);
mModifiedAttributes.push_back(mResistor.attribute("v_intf"));
mModifiedAttributes.push_back(mResistor.attribute("i_intf"));
mResistor.mnaAddPostStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes, mLeftVector);
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) { mResistor.mnaPostStep(time, timeStepCount, mLeftVector); };
private:
Resistor& mResistor;
Attribute<Matrix>::Ptr mLeftVector;
......
......@@ -141,13 +141,26 @@ void EMT::Ph3::Capacitor::mnaApplyRightSideVectorStamp(Matrix& rightVector) {
Logger::matrixToString(mEquivCurrent));
}
void EMT::Ph3::Capacitor::MnaPreStep::execute(Real time, Int timeStepCount) {
mCapacitor.mnaApplyRightSideVectorStamp(mCapacitor.mRightVector);
void EMT::Ph3::Capacitor::mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
// actually depends on C, but then we'd have to modify the system matrix anyway
prevStepDependencies.push_back(attribute("i_intf"));
prevStepDependencies.push_back(attribute("v_intf"));
modifiedAttributes.push_back(attribute("right_vector"));
}
void EMT::Ph3::Capacitor::MnaPostStep::execute(Real time, Int timeStepCount) {
mCapacitor.mnaUpdateVoltage(*mLeftVector);
mCapacitor.mnaUpdateCurrent(*mLeftVector);
void EMT::Ph3::Capacitor::mnaPreStep(Real time, Int timeStepCount) {
mnaApplyRightSideVectorStamp(mRightVector);
}
void EMT::Ph3::Capacitor::mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) {
attributeDependencies.push_back(leftVector);
modifiedAttributes.push_back(attribute("v_intf"));
modifiedAttributes.push_back(attribute("i_intf"));
}
void EMT::Ph3::Capacitor::mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
mnaUpdateVoltage(*leftVector);
mnaUpdateCurrent(*leftVector);
}
void EMT::Ph3::Capacitor::mnaUpdateVoltage(const Matrix& leftVector) {
......
......@@ -149,13 +149,26 @@ void EMT::Ph3::Inductor::mnaApplyRightSideVectorStamp(Matrix& rightVector) {
mSLog->flush();
}
void EMT::Ph3::Inductor::MnaPreStep::execute(Real time, Int timeStepCount) {
mInductor.mnaApplyRightSideVectorStamp(mInductor.mRightVector);
void EMT::Ph3::Inductor::mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
// actually depends on L, but then we'd have to modify the system matrix anyway
prevStepDependencies.push_back(attribute("v_intf"));
prevStepDependencies.push_back(attribute("i_intf"));
modifiedAttributes.push_back(attribute("right_vector"));
}
void EMT::Ph3::Inductor::MnaPostStep::execute(Real time, Int timeStepCount) {
mInductor.mnaUpdateVoltage(*mLeftVector);
mInductor.mnaUpdateCurrent(*mLeftVector);
void EMT::Ph3::Inductor::mnaPreStep(Real time, Int timeStepCount) {
mnaApplyRightSideVectorStamp(mRightVector);
}
void EMT::Ph3::Inductor::mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) {
attributeDependencies.push_back(leftVector);
modifiedAttributes.push_back(attribute("v_intf"));
modifiedAttributes.push_back(attribute("i_intf"));
}
void EMT::Ph3::Inductor::mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
mnaUpdateVoltage(*leftVector);
mnaUpdateCurrent(*leftVector);
}
void EMT::Ph3::Inductor::mnaUpdateVoltage(const Matrix& leftVector) {
......
......@@ -162,11 +162,6 @@ void EMT::Ph3::PiLine::mnaInitialize(Real omega, Real timeStep, Attribute<Matrix
subComps.push_back(mSubParallelCapacitor0);
subComps.push_back(mSubParallelCapacitor1);
}
for (auto comp : subComps) {
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));
mRightVector = Matrix::Zero(leftVector->get().rows(), 1);
......@@ -191,13 +186,68 @@ void EMT::Ph3::PiLine::mnaApplyRightSideVectorStamp(Matrix& rightVector) {
rightVector += *stamp;
}
void EMT::Ph3::PiLine::MnaPreStep::execute(Real time, Int timeStepCount) {
mLine.mnaApplyRightSideVectorStamp(mLine.mRightVector);
void EMT::Ph3::PiLine::mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes){
// add pre-step dependencies of subcomponents
mSubSeriesResistor->mnaAddPreStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes);
mSubSeriesInductor->mnaAddPreStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes);
if (mParallelCond(0,0) > 0) {
mSubParallelResistor0->mnaAddPreStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes);
mSubParallelResistor1->mnaAddPreStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes);
}
if (mParallelCap(0, 0) > 0) {
mSubParallelCapacitor0->mnaAddPreStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes);
mSubParallelCapacitor1->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::PiLine::mnaPreStep(Real time, Int timeStepCount) {
// pre-step of subcomponents
mSubSeriesInductor->mnaPreStep(time, timeStepCount);
if (mParallelCap(0, 0) > 0) {
mSubParallelCapacitor0->mnaPreStep(time, timeStepCount);
mSubParallelCapacitor1->mnaPreStep(time, timeStepCount);
}
// pre-step of component itself
mnaApplyRightSideVectorStamp(mRightVector);
}
void EMT::Ph3::PiLine::MnaPostStep::execute(Real time, Int timeStepCount) {
mLine.mnaUpdateVoltage(*mLeftVector);
mLine.mnaUpdateCurrent(*mLeftVector);
void EMT::Ph3::PiLine::mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) {
// add post-step dependencies of subcomponents
mSubSeriesResistor->mnaAddPostStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes, leftVector);
mSubSeriesInductor->mnaAddPostStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes, leftVector);
if (mParallelCap(0, 0) > 0) {
mSubParallelCapacitor0->mnaAddPostStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes, leftVector);
mSubParallelCapacitor1->mnaAddPostStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes, leftVector);
}
if (mParallelCond(0,0) > 0) {
mSubParallelResistor0->mnaAddPostStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes, leftVector);
mSubParallelResistor1->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::PiLine::mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
// post-step of subcomponents
mSubSeriesResistor->mnaPostStep(time, timeStepCount, leftVector);
mSubSeriesInductor->mnaPostStep(time, timeStepCount, leftVector);
if (mParallelCap(0, 0) > 0) {
mSubParallelCapacitor0->mnaPostStep(time, timeStepCount, leftVector);
mSubParallelCapacitor1->mnaPostStep(time, timeStepCount, leftVector);
}
if (mParallelCond(0,0) > 0) {
mSubParallelResistor0->mnaPostStep(time, timeStepCount, leftVector);
mSubParallelResistor1->mnaPostStep(time, timeStepCount, leftVector);
}
// post-step of component itself
mnaUpdateVoltage(*leftVector);
mnaUpdateCurrent(*leftVector);
}
void EMT::Ph3::PiLine::mnaUpdateVoltage(const Matrix& leftVector) {
......
......@@ -112,11 +112,18 @@ void EMT::Ph3::Resistor::mnaApplySystemMatrixStamp(Matrix& systemMatrix) {
Logger::matrixToString(mConductance));
}
void EMT::Ph3::Resistor::MnaPostStep::execute(Real time, Int timeStepCount) {
mResistor.mnaUpdateVoltage(*mLeftVector);
mResistor.mnaUpdateCurrent(*mLeftVector);
void EMT::Ph3::Resistor::mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) {
attributeDependencies.push_back(leftVector);
modifiedAttributes.push_back(attribute("v_intf"));
modifiedAttributes.push_back(attribute("i_intf"));
}
void EMT::Ph3::Resistor::mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
mnaUpdateVoltage(*leftVector);
mnaUpdateCurrent(*leftVector);
}
void EMT::Ph3::Resistor::mnaUpdateVoltage(const Matrix& leftVector) {
// v1 - v0
mIntfVoltage = Matrix::Zero(3,1);
......
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