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

refactor task definition of slack and vs in sp1ph and use vs as subcomp in slack

parent 7f36c83b
......@@ -34,9 +34,9 @@ namespace Ph1 {
std::vector<const Matrix*> mRightVectorStamps;
public:
/// Defines UID, name, component parameters and logging level
/// Defines UID, name and logging level
NetworkInjection(String uid, String name, Logger::Level loglevel = Logger::Level::off);
/// Defines UID, name, component parameters and logging level
/// Defines name and logging level
NetworkInjection(String name, Logger::Level logLevel = Logger::Level::off)
: NetworkInjection(name, name, logLevel) { }
/// Defines name, component parameters and logging level
......
......@@ -12,11 +12,14 @@
#include <cps/Solver/PFSolverInterfaceBus.h>
#include <cps/Solver/MNAInterface.h>
#include <cps/Solver/DAEInterface.h>
#include <cps/SP/SP_Ph1_VoltageSource.h>
namespace CPS {
namespace SP {
namespace Ph1 {
/// \brief Network injection model
///
/// This model represents network injections by an ideal voltage source.
class NetworkInjection:
public SimPowerComp<Complex>,
public SharedFactory<NetworkInjection>,
......@@ -25,14 +28,13 @@ namespace Ph1 {
public DAEInterface {
private:
// ### Electrical Subcomponents ###
/// Voltage source
std::shared_ptr<SP::Ph1::VoltageSource> mSubVoltageSource;
// #### MNA ####
///
void updateVoltage(Real time);
///
Attribute<Complex>::Ptr mVoltageRef;
///
Attribute<Real>::Ptr mSrcFreq;
// #### solver ####
/// Vector to collect subcomponent right vector stamps
std::vector<const Matrix*> mRightVectorStamps;
// #### Powerflow section ####
/// Voltage set point [V]
......@@ -51,22 +53,21 @@ namespace Ph1 {
Real mVoltageSetPointPerUnit=1.0;
public:
// #### General ####
/// Defines UID, name and logging level
NetworkInjection(String uid, String name, Logger::Level logLevel = Logger::Level::off);
/// Defines name and logging level
NetworkInjection(String name, Logger::Level logLevel = Logger::Level::off)
: NetworkInjection(name, name, logLevel) { }
/// Initializes component from power flow data
void initializeFromNodesAndTerminals(Real frequency) override;
///
void setSourceValue(Complex voltage);
///
void setParameters(Real vSetPointPerUnit);
///
SimPowerComp<Complex>::Ptr clone(String name) override;
// #### General ####
/// Initializes component from power flow data
void initializeFromNodesAndTerminals(Real frequency) override;
// #### Powerflow section ####
/// Set parameters relevant for PF solver
void setParameters(Real vSetPointPerUnit);
/// Set base voltage
void setBaseVoltage(Real baseVoltage);
/// Calculates component's parameters in specified per-unit system
......@@ -87,35 +88,42 @@ namespace Ph1 {
void mnaApplyRightSideVectorStamp(Matrix& rightVector) override;
/// Returns current through the component
void mnaUpdateCurrent(const Matrix& leftVector) override;
class MnaPreStep : public Task {
/// Updates voltage across 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 CPS::Task {
public:
MnaPreStep(NetworkInjection& networkInjection) :
Task(networkInjection.mName + ".MnaPreStep"), mNetworkInjection(networkInjection) {
mAttributeDependencies.push_back(mNetworkInjection.attribute("V_ref"));
mModifiedAttributes.push_back(mNetworkInjection.attribute("right_vector"));
mModifiedAttributes.push_back(mNetworkInjection.attribute("v_intf"));
mNetworkInjection.mnaAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) { mNetworkInjection.mnaPreStep(time, timeStepCount); };
private:
NetworkInjection& mNetworkInjection;
};
class MnaPostStep : public Task {
class MnaPostStep : public CPS::Task {
public:
MnaPostStep(NetworkInjection& networkInjection, Attribute<Matrix>::Ptr leftVector) :
Task(networkInjection.mName + ".MnaPostStep"),
mNetworkInjection(networkInjection), mLeftVector(leftVector) {
mAttributeDependencies.push_back(mLeftVector);
mModifiedAttributes.push_back(mNetworkInjection.attribute("i_intf"));
Task(networkInjection.mName + ".MnaPostStep"), mNetworkInjection(networkInjection), mLeftVector(leftVector) {
mNetworkInjection.mnaAddPostStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes, mLeftVector);
}
void execute(Real time, Int timeStepCount);
void execute(Real time, Int timeStepCount) { mNetworkInjection.mnaPostStep(time, timeStepCount, mLeftVector); };
private:
NetworkInjection& mNetworkInjection;
Attribute<Matrix>::Ptr mLeftVector;
};
// #### DAE Section ####
/// Residual function for DAE Solver
void daeResidual(double ttime, const double state[], const double dstate_dt[], double resid[], std::vector<int>& off) override;
......
......@@ -13,91 +13,96 @@
#include <cps/Solver/DAEInterface.h>
namespace CPS {
namespace SP {
namespace Ph1 {
/// \brief Ideal Voltage source model
///
/// This model uses modified nodal analysis to represent an ideal voltage source.
/// For a voltage source between nodes j and k, a new variable
/// (current across the voltage source) is added to the left side vector
/// as unkown and it is taken into account for the equation of node j as
/// positve and for the equation of node k as negative. Moreover
/// a new equation ej - ek = V is added to the problem.
class VoltageSource :
public SimPowerComp<Complex>,
public MNAInterface,
public DAEInterface,
public SharedFactory<VoltageSource> {
private:
void updateVoltage(Real time);
namespace SP {
namespace Ph1 {
/// \brief Ideal Voltage source model
///
/// This model uses modified nodal analysis to represent an ideal voltage source.
/// For a voltage source between nodes j and k, a new variable
/// (current across the voltage source) is added to the left side vector
/// as unkown and it is taken into account for the equation of node j as
/// positve and for the equation of node k as negative. Moreover
/// a new equation ej - ek = V is added to the problem.
class VoltageSource :
public SimPowerComp<Complex>,
public MNAInterface,
public DAEInterface,
public SharedFactory<VoltageSource> {
private:
///
void updateVoltage(Real time);
///
Attribute<Complex>::Ptr mVoltageRef;
///
Attribute<Real>::Ptr mSrcFreq;
public:
/// Defines UID, name, component parameters and logging level
VoltageSource(String uid, String name, Logger::Level loglevel = Logger::Level::off);
/// Defines UID, name, component parameters and logging level
VoltageSource(String name, Logger::Level logLevel = Logger::Level::off)
: VoltageSource(name, name, logLevel) { }
/// Defines name, component parameters and logging level
VoltageSource(String name,
Complex voltage, Logger::Level logLevel = Logger::Level::off);
///
SimPowerComp<Complex>::Ptr clone(String name);
Attribute<Complex>::Ptr mVoltageRef;
public:
/// Defines UID, name, component parameters and logging level
VoltageSource(String uid, String name, Logger::Level loglevel = Logger::Level::off);
/// Defines UID, name, component parameters and logging level
VoltageSource(String name, Logger::Level logLevel = Logger::Level::off)
: VoltageSource(name, name, logLevel) { }
/// Defines name, component parameters and logging level
VoltageSource(String name,
Complex voltage, Logger::Level logLevel = Logger::Level::off);
// #### General ####
/// Initializes component from power flow data
void initializeFromNodesAndTerminals(Real frequency);
///
void setSourceValue(Complex voltage);
///
void setParameters(Complex voltageRef, Real srcFreq = -1);
SimPowerComp<Complex>::Ptr clone(String name);
// #### 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 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);
void setParameters(Complex voltageRef);
// #### General ####
/// Initializes component from power flow data
void initializeFromNodesAndTerminals(Real frequency);
///
void setSourceValue(Complex voltage);
class MnaPreStep : public Task {
public:
MnaPreStep(VoltageSource& voltageSource) :
Task(voltageSource.mName + ".MnaPreStep"), mVoltageSource(voltageSource) {
mVoltageSource.mnaAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount) { mVoltageSource.mnaPreStep(time, timeStepCount); };
private:
VoltageSource& mVoltageSource;
};
// #### MNA Section ####
///
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);
class MnaPostStep : public Task {
public:
MnaPostStep(VoltageSource& voltageSource, Attribute<Matrix>::Ptr leftVector) :
Task(voltageSource.mName + ".MnaPostStep"),
mVoltageSource(voltageSource), mLeftVector(leftVector) {
mVoltageSource.mnaAddPostStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes, mLeftVector);
}
void execute(Real time, Int timeStepCount) { mVoltageSource.mnaPostStep(time, timeStepCount, mLeftVector); };
private:
VoltageSource& mVoltageSource;
Attribute<Matrix>::Ptr mLeftVector;
};
class MnaPreStep : public CPS::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"));
}
void execute(Real time, Int timeStepCount);
private:
VoltageSource& mVoltageSource;
};
class MnaPostStep : public CPS::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"));
}
void execute(Real time, Int timeStepCount);
private:
VoltageSource& mVoltageSource;
Attribute<Matrix>::Ptr mLeftVector;
};
// #### DAE Section ####
/// Residual function for DAE Solver
void daeResidual(double ttime, const double state[], const double dstate_dt[], double resid[], std::vector<int>& off);
///Voltage Getter
Complex daeInitialize();
};
}
}
// #### DAE Section ####
/// Residual function for DAE Solver
void daeResidual(double ttime, const double state[], const double dstate_dt[], double resid[], std::vector<int>& off);
///Voltage Getter
Complex daeInitialize();
};
}
}
}
......@@ -18,17 +18,24 @@ SP::Ph1::NetworkInjection::NetworkInjection(String uid, String name,
mSLog->flush();
mIntfVoltage = MatrixComp::Zero(1, 1);
mIntfCurrent = MatrixComp::Zero(1, 1);
setVirtualNodeNumber(1);
setVirtualNodeNumber(0);
setTerminalNumber(1);
// Create electrical sub components
mSubVoltageSource = std::make_shared<SP::Ph1::VoltageSource>(mName + "_vs", mLogLevel);
mSubComponents.push_back(mSubVoltageSource);
mSLog->info("Electrical subcomponents: ");
for (auto subcomp: mSubComponents)
mSLog->info("- {}", subcomp->name());
addAttribute<Real>("V_set", &mVoltageSetPoint, Flags::read | Flags::write);
addAttribute<Real>("V_set_pu", &mVoltageSetPointPerUnit, Flags::read | Flags::write);
addAttribute<Real>("p_inj", &mActivePowerInjection, Flags::read | Flags::write);
addAttribute<Real>("q_inj", &mReactivePowerInjection, Flags::read | Flags::write);
// MNA attributes
addAttribute<Complex>("V_ref", Flags::read | Flags::write);
addAttribute<Real>("f_src", Flags::read | Flags::write);
addAttributeRef<Complex>("V_ref", mSubVoltageSource->attribute<Complex>("V_ref"), Flags::read | Flags::write);
addAttributeRef<Real>("f_src", mSubVoltageSource->attribute<Real>("f_src"), Flags::read | Flags::write);
}
// #### Powerflow section ####
......@@ -68,9 +75,14 @@ void SP::Ph1::NetworkInjection::updatePowerInjection(Complex powerInj) {
// #### MNA Section ####
void SP::Ph1::NetworkInjection::setParameters(Complex voltageRef, Real srcFreq) {
attribute<Complex>("V_ref")->set(voltageRef);
attribute<Real>("f_src")->set(srcFreq);
mParametersSet = true;
mSubVoltageSource->setParameters(voltageRef, srcFreq);
mSLog->info("\nVoltage Ref={:s} [V]"
"\nFrequency={:s} [Hz]",
Logger::phasorToString(voltageRef),
Logger::realToString(srcFreq));
}
SimPowerComp<Complex>::Ptr SP::Ph1::NetworkInjection::clone(String name) {
......@@ -80,18 +92,14 @@ SimPowerComp<Complex>::Ptr SP::Ph1::NetworkInjection::clone(String name) {
}
void SP::Ph1::NetworkInjection::initializeFromNodesAndTerminals(Real frequency) {
mVoltageRef = attribute<Complex>("V_ref");
mSrcFreq = attribute<Real>("f_src");
if (mVoltageRef->get() == Complex(0, 0))
//mVoltageRef->set(Complex(std::abs(initialSingleVoltage(0).real()), std::abs(initialSingleVoltage(0).imag())));
mVoltageRef->set(initialSingleVoltage(0));
mSLog->info(
"\n--- Initialization from node voltages ---"
"\nVoltage across: {:e}<{:e}"
"\nTerminal 0 voltage: {:e}<{:e}"
"\n--- Initialization from node voltages ---",
std::abs(mVoltageRef->get()), std::arg(mVoltageRef->get()),
std::abs(initialSingleVoltage(0)), std::arg(initialSingleVoltage(0)));
// Connect electrical subcomponents
mSubVoltageSource->connect({ SimNode::GND, node(0) });
// Initialize electrical subcomponents
for (auto subcomp: mSubComponents) {
subcomp->initialize(mFrequencies);
subcomp->initializeFromNodesAndTerminals(frequency);
}
}
// #### MNA functions ####
......@@ -100,51 +108,83 @@ void SP::Ph1::NetworkInjection::mnaInitialize(Real omega, Real timeStep, Attribu
MNAInterface::mnaInitialize(omega, timeStep);
updateMatrixNodeIndices();
mIntfVoltage(0, 0) = mVoltageRef->get();
// initialize electrical subcomponents
for (auto subcomp: mSubComponents)
if (auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
mnasubcomp->mnaInitialize(omega, timeStep, leftVector);
// collect right side vectors of subcomponents
mRightVectorStamps.push_back(&mSubVoltageSource->attribute<Matrix>("right_vector")->get());
// collect tasks
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 SP::Ph1::NetworkInjection::mnaApplySystemMatrixStamp(Matrix& systemMatrix) {
Math::setMatrixElement(systemMatrix, mVirtualNodes[0]->matrixNodeIndex(), matrixNodeIndex(0), Complex(1, 0));
Math::setMatrixElement(systemMatrix, matrixNodeIndex(0), mVirtualNodes[0]->matrixNodeIndex(), Complex(1, 0));
mSLog->info("-- Matrix Stamp ---");
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));
for (auto subcomp: mSubComponents)
if (auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
mnasubcomp->mnaApplySystemMatrixStamp(systemMatrix);
}
void SP::Ph1::NetworkInjection::mnaApplyRightSideVectorStamp(Matrix& rightVector) {
// TODO: Is this correct with two nodes not gnd?
Math::setVectorElement(rightVector, mVirtualNodes[0]->matrixNodeIndex(), mIntfVoltage(0, 0));
SPDLOG_LOGGER_DEBUG(mSLog, "Add {:s} to source vector at {:d}",
Logger::complexToString(mIntfVoltage(0, 0)), mVirtualNodes[0]->matrixNodeIndex());
rightVector.setZero();
for (auto stamp : mRightVectorStamps)
rightVector += *stamp;
mSLog->debug("Right Side Vector: {:s}",
Logger::matrixToString(rightVector));
}
void SP::Ph1::NetworkInjection::updateVoltage(Real time) {
if (mSrcFreq->get() < 0) {
mIntfVoltage(0, 0) = mVoltageRef->get();
}
else {
mIntfVoltage(0, 0) = Complex(
Math::abs(mVoltageRef->get()) * cos(time * 2. * PI * mSrcFreq->get() + Math::phase(mVoltageRef->get())),
Math::abs(mVoltageRef->get()) * sin(time * 2. * PI * mSrcFreq->get() + Math::phase(mVoltageRef->get())));
}
void SP::Ph1::NetworkInjection::mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
// add pre-step dependencies of subcomponents
for (auto subcomp: mSubComponents)
if (auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
mnasubcomp->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 SP::Ph1::NetworkInjection::MnaPreStep::execute(Real time, Int timeStepCount) {
mNetworkInjection.updateVoltage(time);
mNetworkInjection.mnaApplyRightSideVectorStamp(mNetworkInjection.mRightVector);
void SP::Ph1::NetworkInjection::mnaPreStep(Real time, Int timeStepCount) {
// pre-step of subcomponents
for (auto subcomp: mSubComponents)
if (auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
mnasubcomp->mnaPreStep(time, timeStepCount);
// pre-step of component itself
mnaApplyRightSideVectorStamp(mRightVector);
}
void SP::Ph1::NetworkInjection::mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) {
// add post-step dependencies of subcomponents
for (auto subcomp: mSubComponents)
if (auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
mnasubcomp->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 SP::Ph1::NetworkInjection::mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
// post-step of subcomponents
for (auto subcomp: mSubComponents)
if (auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
mnasubcomp->mnaPostStep(time, timeStepCount, leftVector);
// post-step of component itself
mnaUpdateCurrent(*leftVector);
mnaUpdateVoltage(*leftVector);
}
void SP::Ph1::NetworkInjection::MnaPostStep::execute(Real time, Int timeStepCount) {
mNetworkInjection.mnaUpdateCurrent(*mLeftVector);
void SP::Ph1::NetworkInjection::mnaUpdateVoltage(const Matrix& leftVector) {
mIntfVoltage = mSubVoltageSource->attribute<MatrixComp>("v_intf")->get();
}
void SP::Ph1::NetworkInjection::mnaUpdateCurrent(const Matrix& leftVector) {
mIntfCurrent(0, 0) = Math::complexFromVectorElement(leftVector, mVirtualNodes[0]->matrixNodeIndex());
mIntfCurrent = mSubVoltageSource->attribute<MatrixComp>("i_intf")->get();
}
void SP::Ph1::NetworkInjection::daeResidual(double ttime, const double state[], const double dstate_dt[], double resid[], std::vector<int>& off) {
......@@ -173,6 +213,6 @@ void SP::Ph1::NetworkInjection::daeResidual(double ttime, const double state[],
}
Complex SP::Ph1::NetworkInjection::daeInitialize() {
mIntfVoltage(0, 0) = mVoltageRef->get();
return mVoltageRef->get();
mIntfVoltage(0,0) = mSubVoltageSource->attribute<Complex>("v_intf")->get();
return mSubVoltageSource->attribute<Complex>("v_intf")->get();
}
......@@ -18,6 +18,7 @@ SP::Ph1::VoltageSource::VoltageSource(String uid, String name, Logger::Level log
mIntfCurrent = MatrixComp::Zero(1, 1);
addAttribute<Complex>("V_ref", Flags::read | Flags::write);
addAttribute<Real>("f_src", Flags::read | Flags::write);
}
SimPowerComp<Complex>::Ptr SP::Ph1::VoltageSource::clone(String name) {
......@@ -26,64 +27,119 @@ SimPowerComp<Complex>::Ptr SP::Ph1::VoltageSource::clone(String name) {
return copy;
}
void SP::Ph1::VoltageSource::setParameters(Complex voltageRef) {
void SP::Ph1::VoltageSource::setParameters(Complex voltageRef, Real srcFreq) {
attribute<Complex>("V_ref")->set(voltageRef);
attribute<Real>("f_src")->set(srcFreq);
mParametersSet = true;
}
void SP::Ph1::VoltageSource::initializeFromNodesAndTerminals(Real frequency) {
mVoltageRef = attribute<Complex>("V_ref");
mSrcFreq = attribute<Real>("f_src");
if (mVoltageRef->get() == Complex(0, 0))
// TODO: find more explicit way, e.g. make dependend on mParametersSet or other flag
if (mVoltageRef->get() == Complex(0, 0))
mVoltageRef->set(initialSingleVoltage(1) - initialSingleVoltage(0));
mSLog->info(
"\n--- Initialization from node voltages ---"
"\nVoltage across: {:s}"
"\nTerminal 0 voltage: {:s}"
"\nTerminal 1 voltage: {:s}"
"\n--- Initialization from node voltages ---",
Logger::phasorToString(mVoltageRef->get()),
Logger::phasorToString(initialSingleVoltage(0)),
Logger::phasorToString(initialSingleVoltage(1)));
}
// #### MNA functions ####
void SP::Ph1::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 SP::Ph1::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 SP::Ph1::VoltageSource::mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
MNAInterface::mnaInitialize(omega, timeStep);
updateMatrixNodeIndices();
mIntfVoltage(0, 0) = mVoltageRef->get();
mIntfVoltage(0,0) = mVoltageRef->get();
mMnaTasks.push_back(std::make_shared<MnaPreStep>(*this));
mMnaTasks.push_back(std::make_shared<MnaPostStep>(*this, leftVector));
mRightVector = Matrix::Zero(leftVector->get().rows(), 1);
mSLog->info(
"\n--- MNA initialization ---"
"\nInitial voltage {:s}"
"\nInitial current {:s}"
"\n--- MNA initialization finished ---",
Logger::phasorToString(mIntfVoltage(0,0)),
Logger::phasorToString(mIntfCurrent(0,0)));
}
void SP::Ph1::VoltageSource::mnaApplySystemMatrixStamp(Matrix& systemMatrix