Commit 87bac41c authored by Markus Mirz's avatar Markus Mirz
Browse files

Merge branch 'refactoring-rxload' into 'master'

Refactoring rxload

See merge request acs/public/simulation/dpsim!127

Former-commit-id: b0302279
parents a70ae26e bf042443
......@@ -86,6 +86,8 @@ namespace Ph1 {
void initialize(Matrix frequencies);
/// Initializes component from power flow data
void initializeFromPowerflow(Real frequency);
/// Sets model specific parameters
void setParameters(Real activePower, Real ReactivePower, Real volt);
// #### MNA section ####
/// Initializes internal variables of the component
......
......@@ -51,6 +51,9 @@ namespace CPS {
/// "Cached" flags for whether the connected nodes are grounded
std::vector<bool> mSimNodeIsGround;
/// Flag indicating that parameters are set via setParameters() function
bool parametersSet = false;
public:
typedef VarType Type;
typedef std::shared_ptr<PowerComponent<VarType>> Ptr;
......
......@@ -89,6 +89,8 @@ void DP::Ph1::AvVoltageSourceInverterDQ::setParameters(Real sysOmega, Complex sy
mCf = Cf;
mRf = Rf;
mRc = Rc;
parametersSet = true;
}
......
......@@ -33,6 +33,7 @@ DP::Ph1::ControlledVoltageSource::ControlledVoltageSource(String uid, String nam
void DP::Ph1::ControlledVoltageSource::setParameters(MatrixComp voltageRefABC) {
mIntfVoltage = voltageRefABC;
parametersSet = true;
}
PowerComponent<Complex>::Ptr DP::Ph1::ControlledVoltageSource::clone(String name) {
......
......@@ -39,6 +39,7 @@ DP::Ph1::CurrentSource::CurrentSource(String name, Complex current, Logger::Leve
void DP::Ph1::CurrentSource::setParameters(Complex current) {
attribute<Complex>("I_ref")->set(current);
parametersSet = true;
}
PowerComponent<Complex>::Ptr DP::Ph1::CurrentSource::clone(String name) {
......
......@@ -40,6 +40,8 @@ void DP::Ph1::Inverter::setParameters(std::vector<Int> carrierHarms, std::vector
mVin = inputVoltage;
mModIdx = ratio;
mPhaseMod = phase;
parametersSet= true;
}
void DP::Ph1::Inverter::initializeFromPowerflow(Real frequency) {
......
......@@ -53,6 +53,8 @@ void DP::Ph1::NetworkInjection::initialize(Matrix frequencies) {
void DP::Ph1::NetworkInjection::setParameters(Complex voltageRef, Real srcFreq) {
attribute<Complex>("V_ref")->set(voltageRef);
attribute<Real>("f_src")->set(srcFreq);
parametersSet = true;
}
void DP::Ph1::NetworkInjection::initializeFromPowerflow(Real frequency) {
......
......@@ -59,6 +59,8 @@ void DP::Ph1::PQLoadCS::setParameters(Real activePower, Real reactivePower, Real
attribute<Real>("P")->set(activePower);
attribute<Real>("Q")->set(reactivePower);
attribute<Real>("V_nom")->set(nomVolt);
parametersSet = true;
}
PowerComponent<Complex>::Ptr DP::Ph1::PQLoadCS::clone(String name) {
......@@ -74,7 +76,7 @@ void DP::Ph1::PQLoadCS::initializeFromPowerflow(Real frequency) {
mReactivePower = attribute<Real>("Q");
mNomVoltage = attribute<Real>("V_nom");
// Get power from Terminals if it was not set previously.
if (mActivePower->get() == 0 && mReactivePower->get() == 0) {
if (mActivePower->get() == 0 && mReactivePower->get() == 0 && !parametersSet) {
mActivePower->set(mTerminals[0]->singleActivePower());
mReactivePower->set(mTerminals[0]->singleReactivePower());
mNomVoltage->set(std::abs(mTerminals[0]->initialSingleVoltage()));
......
......@@ -32,6 +32,7 @@ DP::Ph1::RXLoad::RXLoad(String uid, String name,
addAttribute<Real>("P", &mActivePower, Flags::read | Flags::write);
addAttribute<Real>("Q", &mReactivePower, Flags::read | Flags::write);
addAttribute<Real>("V_nom", &mNomVoltage, Flags::read | Flags::write);
}
DP::Ph1::RXLoad::RXLoad(String name,
......@@ -50,8 +51,12 @@ DP::Ph1::RXLoad::RXLoad(String name,
}
PowerComponent<Complex>::Ptr DP::Ph1::RXLoad::clone(String name) {
// TODO: Is this change is needed when "everything set by initializePOwerflow"??
// everything set by initializeFromPowerflow
return RXLoad::make(name, mLogLevel);
//return RXLoad::make(name, mLogLevel);
auto copy = RXLoad::make(name, mLogLevel);
copy->setParameters(mActivePower, mReactivePower, mNomVoltage);
return copy;
}
void DP::Ph1::RXLoad::initialize(Matrix frequencies) {
......@@ -60,11 +65,12 @@ void DP::Ph1::RXLoad::initialize(Matrix frequencies) {
void DP::Ph1::RXLoad::initializeFromPowerflow(Real frequency) {
checkForUnconnectedTerminals();
mActivePower = mTerminals[0]->singleActivePower();
mReactivePower = mTerminals[0]->singleReactivePower();
mPower = { mActivePower, mReactivePower };
mNomVoltage = std::abs(mTerminals[0]->initialSingleVoltage());
if(!parametersSet){
mActivePower = mTerminals[0]->singleActivePower();
mReactivePower = mTerminals[0]->singleReactivePower();
mPower = { mActivePower, mReactivePower };
mNomVoltage = std::abs(mTerminals[0]->initialSingleVoltage());
}
if (mActivePower != 0) {
mResistance = std::pow(mNomVoltage, 2) / mActivePower;
......@@ -113,6 +119,16 @@ void DP::Ph1::RXLoad::initializeFromPowerflow(Real frequency) {
Logger::phasorToString(initialSingleVoltage(0)));
}
void DP::Ph1::RXLoad::setParameters(Real activePower, Real reactivePower, Real volt){
mActivePower = activePower;
mReactivePower = reactivePower;
mPower = { mActivePower, mReactivePower};
mNomVoltage = volt;
parametersSet = true;
}
void DP::Ph1::RXLoad::mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
MNAInterface::mnaInitialize(omega, timeStep);
updateSimNodes();
......
......@@ -49,6 +49,8 @@ void DP::Ph1::Transformer::setParameters(Real ratioAbs, Real ratioPhase,
setVirtualNodeNumber(3);
else
setVirtualNodeNumber(2);
parametersSet = true;
}
void DP::Ph1::Transformer::initialize(Matrix frequencies) {
......
......@@ -46,6 +46,8 @@ void DP::Ph1::VoltageSource::initialize(Matrix frequencies) {
void DP::Ph1::VoltageSource::setParameters(Complex voltageRef, Real srcFreq) {
attribute<Complex>("V_ref")->set(voltageRef);
attribute<Real>("f_src")->set(srcFreq);
parametersSet = true;
}
void DP::Ph1::VoltageSource::initializeFromPowerflow(Real frequency) {
......
......@@ -44,6 +44,8 @@ void DP::Ph1::VoltageSourceNorton::setParameters(Complex voltage, Real srcFreq,
mResistance = resistance;
mConductance = 1. / mResistance;
mEquivCurrent = mVoltageRef / mResistance;
parametersSet = true;
}
void DP::Ph1::VoltageSourceNorton::mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
......
......@@ -48,6 +48,8 @@ void DP::Ph1::VoltageSourceRamp::setParameters(Complex voltage, Complex addVolta
mAddSrcFreq = addSrcFreq;
mSwitchTime = switchTime;
mRampTime = rampTime;
parametersSet = true;
}
void DP::Ph1::VoltageSourceRamp::initialize(Matrix frequencies) {
......
......@@ -89,6 +89,8 @@ void DP::Ph3::AvVoltageSourceInverterDQ::setParameters(Real sysOmega, Complex sy
mRf = Rf;
mRc = Rc;
parametersSet = true;
}
void DP::Ph3::AvVoltageSourceInverterDQ::addMonitoredNodes( std::shared_ptr<Capacitor> cap, std::shared_ptr<Inductor> inductor) {
......
......@@ -35,6 +35,7 @@ DP::Ph3::ControlledVoltageSource::ControlledVoltageSource(String uid, String nam
void DP::Ph3::ControlledVoltageSource::setParameters(MatrixComp voltageRefABC) {
mIntfVoltage = voltageRefABC;
parametersSet = true;
}
PowerComponent<Complex>::Ptr DP::Ph3::ControlledVoltageSource::clone(String name) {
......
......@@ -44,6 +44,7 @@ PowerComponent<Complex>::Ptr DP::Ph3::VoltageSource::clone(String name) {
void DP::Ph3::VoltageSource::setParameters(Complex voltageRef) {
attribute<Complex>("V_ref")->set(voltageRef);
parametersSet = true;
}
void DP::Ph3::VoltageSource::initializeFromPowerflow(Real frequency) {
......
......@@ -42,6 +42,8 @@ PowerComponent<Real>::Ptr EMT::Ph1::CurrentSource::clone(String name) {
void EMT::Ph1::CurrentSource::setParameters(Complex currentRef, Real srcFreq) {
attribute<Complex>("I_ref")->set(currentRef);
attribute<Real>("f_src")->set(srcFreq);
parametersSet = true;
}
void EMT::Ph1::CurrentSource::mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
......
......@@ -36,6 +36,8 @@ EMT::Ph1::VoltageSource::VoltageSource(String uid, String name, Logger::Level lo
void EMT::Ph1::VoltageSource::setParameters(Complex voltageRef, Real srcFreq) {
attribute<Complex>("V_ref")->set(voltageRef);
attribute<Real>("f_src")->set(srcFreq);
parametersSet = true;
}
PowerComponent<Real>::Ptr EMT::Ph1::VoltageSource::clone(String name) {
......
......@@ -43,6 +43,8 @@ void EMT::Ph1::VoltageSourceNorton::setParameters(Complex voltage, Real srcFreq,
mResistance = resistance;
mConductance = 1. / mResistance;
parametersSet = true;
}
void EMT::Ph1::VoltageSourceNorton::mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
......
......@@ -49,6 +49,8 @@ void EMT::Ph1::VoltageSourceRamp::setParameters(Complex voltage, Complex addVolt
mAddSrcFreq = addSrcFreq;
mSwitchTime = switchTime;
mRampTime = rampTime;
parametersSet = true;
}
void EMT::Ph1::VoltageSourceRamp::initialize(Matrix frequencies) {
......
Supports Markdown
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