Skip to content

Commit

Permalink
simplify use of mUseOmagaRef in TrStab Generator
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Schroeder <[email protected]>
  • Loading branch information
JTS22 committed Oct 28, 2022
1 parent 24c1e20 commit 90a31a8
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Ph1 {

// #### General Functions ####
/// Flags to modify model behavior
void setModelFlags(Bool useOmegaRef, Bool convertWithOmegaMech);
void setModelFlags(Bool convertWithOmegaMech);
///
void setInitialValues(Complex elecPower, Real mechPower);
/// \brief Initializes the machine parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Ph1 {

// #### General Functions ####
/// Flags to modify model behavior
void setModelFlags(Bool useOmegaRef, Bool convertWithOmegaMech);
void setModelFlags(Bool convertWithOmegaMech);
///
void setInitialValues(Complex elecPower, Real mechPower);
/// \brief Initializes the machine parameters
Expand Down
18 changes: 3 additions & 15 deletions dpsim-models/src/DP/DP_Ph1_SynchronGeneratorTrStab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,11 @@ void DP::Ph1::SynchronGeneratorTrStab::setStandardParametersPU(Real nomPower, Re
"\ndamping: {:f}", mXpd, mLpd, **mInertia, mKd);
}

void DP::Ph1::SynchronGeneratorTrStab::setModelFlags(Bool useOmegaRef, Bool convertWithOmegaMech) {
mUseOmegaRef = useOmegaRef;
void DP::Ph1::SynchronGeneratorTrStab::setModelFlags(Bool convertWithOmegaMech) {
mConvertWithOmegaMech = convertWithOmegaMech;

mSLog->info("\n--- Model flags ---"
"\nuseOmegaRef: {:s}"
"\nconvertWithOmegaMech: {:s}", std::to_string(mUseOmegaRef), std::to_string(mConvertWithOmegaMech));
"\nconvertWithOmegaMech: {:s}", std::to_string(mConvertWithOmegaMech));
}

void DP::Ph1::SynchronGeneratorTrStab::setInitialValues(Complex elecPower, Real mechPower) {
Expand Down Expand Up @@ -232,17 +230,7 @@ void DP::Ph1::SynchronGeneratorTrStab::step(Real time) {

// Derivative of rotor angle at time step k + 1
// if reference omega is set, calculate delta with respect to reference
/// CHECK: This can probably be simplified by utilising the dynamic properties of the reference attributes
Real refOmega;
Real refDelta;
if (mUseOmegaRef) {
refOmega = **mRefOmega;
refDelta = **mRefDelta;
} else {
refOmega = mNomOmega;
refDelta = 0;
}
Real dDelta_p = **mOmMech - refOmega;
Real dDelta_p = **mOmMech - (mUseOmegaRef ? **mRefOmega : mNomOmega);

// Rotor angle at time step k + 1 applying Euler backward
// Update emf - only phase changes
Expand Down
17 changes: 3 additions & 14 deletions dpsim-models/src/SP/SP_Ph1_SynchronGeneratorTrStab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,11 @@ void SP::Ph1::SynchronGeneratorTrStab::setStandardParametersPU(Real nomPower, Re
"\nDamping: {:f}", mXpd, mLpd, **mInertia, mKd);
}

void SP::Ph1::SynchronGeneratorTrStab::setModelFlags(Bool useOmegaRef, Bool convertWithOmegaMech) {
mUseOmegaRef = useOmegaRef;
void SP::Ph1::SynchronGeneratorTrStab::setModelFlags(Bool convertWithOmegaMech) {
mConvertWithOmegaMech = convertWithOmegaMech;

mSLog->info("\n--- Model flags ---"
"\nuseOmegaRef: {:s}"
"\nconvertWithOmegaMech: {:s}", std::to_string(mUseOmegaRef), std::to_string(mConvertWithOmegaMech));
"\nconvertWithOmegaMech: {:s}", std::to_string(mConvertWithOmegaMech));
}

void SP::Ph1::SynchronGeneratorTrStab::setInitialValues(Complex elecPower, Real mechPower) {
Expand Down Expand Up @@ -242,16 +240,7 @@ void SP::Ph1::SynchronGeneratorTrStab::step(Real time) {

// Derivative of rotor angle at time step k + 1
// if reference omega is set, calculate delta with respect to reference
Real refOmega;
Real refDelta;
if (mUseOmegaRef) {
refOmega = attribute<Real>("w_ref")->get();
refDelta = attribute<Real>("delta_ref")->get();
} else {
refOmega = mNomOmega;
refDelta = 0;
}
Real dDelta_p = **mOmMech - refOmega;
Real dDelta_p = **mOmMech - (mUseOmegaRef ? **mRefOmega : mNomOmega);

// Rotor angle at time step k + 1 applying Euler backward
// Update emf - only phase changes
Expand Down
6 changes: 3 additions & 3 deletions dpsim/examples/cxx/CIM/SP_WSCC-9bus_CIM_Dyn_Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ int main(int argc, char *argv[]) {
sys.addComponent(sw);

// Use omegNom for torque conversion in SG models for validation with PSAT
sys.component<Ph1::SynchronGeneratorTrStab>("GEN1")->setModelFlags(false, false);
sys.component<Ph1::SynchronGeneratorTrStab>("GEN2")->setModelFlags(false, false);
sys.component<Ph1::SynchronGeneratorTrStab>("GEN3")->setModelFlags(false, false);
sys.component<Ph1::SynchronGeneratorTrStab>("GEN1")->setModelFlags(false);
sys.component<Ph1::SynchronGeneratorTrStab>("GEN2")->setModelFlags(false);
sys.component<Ph1::SynchronGeneratorTrStab>("GEN3")->setModelFlags(false);

// Logging
auto logger = DataLogger::make(simName);
Expand Down
2 changes: 1 addition & 1 deletion dpsim/examples/cxx/Circuits/DP_SynGenTrStab_3Bus_Fault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void DP_SynGenTrStab_3Bus_Fault(String simName, Real timeStep, Real finalTime, b
Complex initApparentPower_G2= gen2PF->getApparentPower();
gen2DP->setInitialValues(initApparentPower_G2, ThreeBus.initMechPower_G2);

gen2DP->setModelFlags(true, true);
gen2DP->setModelFlags(true);
gen2DP->setReferenceOmega(gen1DP->attribute<Real>("w_r"), gen1DP->attribute<Real>("delta_r"));

///Load
Expand Down
2 changes: 1 addition & 1 deletion dpsim/examples/cxx/Circuits/SP_SynGenTrStab_3Bus_Fault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void SP_SynGenTrStab_3Bus_Fault(String simName, Real timeStep, Real finalTime, b
Complex initApparentPower_G2= gen2PF->getApparentPower();
gen2SP->setInitialValues(initApparentPower_G2, ThreeBus.initMechPower_G2);

gen2SP->setModelFlags(true, true);
gen2SP->setModelFlags(true);
gen2SP->setReferenceOmega(gen1SP->attribute<Real>("w_r"), gen1SP->attribute<Real>("delta_r"));

//Load
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void SP_1ph_SynGenTrStab_Fault(String simName, Real timeStep, Real finalTime, Re

// Xpd is given in p.u of generator base at transfomer primary side and should be transformed to network side
genSP->setStandardParametersPU(syngenNomPower, syngenNomVoltage, nomFreq, syngenXpdPU, cmdInertiaFactor*syngenH, syngenRsPU, syngenD);
genSP->setModelFlags(false, false);
genSP->setModelFlags(false);

// Get actual active and reactive power of generator's Terminal from Powerflow solution
Complex initApparentPower= genPF->getApparentPower();
Expand Down
2 changes: 1 addition & 1 deletion dpsim/src/pybind/DPComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void addDPPh1Components(py::module_ mDPPh1) {
"nom_power"_a, "nom_volt"_a, "nom_freq"_a, "Ll"_a, "Lmd"_a, "Llfd"_a, "H"_a, "D"_a = 0)
.def("set_initial_values", &CPS::DP::Ph1::SynchronGeneratorTrStab::setInitialValues, "elec_power"_a, "mech_power"_a)
.def("connect", &CPS::DP::Ph1::SynchronGeneratorTrStab::connect)
.def("set_model_flags", &CPS::DP::Ph1::SynchronGeneratorTrStab::setModelFlags, "use_omega_ref"_a, "convert_with_omega_mech"_a)
.def("set_model_flags", &CPS::DP::Ph1::SynchronGeneratorTrStab::setModelFlags, "convert_with_omega_mech"_a)
.def("set_reference_omega", [](CPS::DP::Ph1::SynchronGeneratorTrStab &gen, std::string refOmegaName, CPS::IdentifiedObject::Ptr refOmegaComp,
std::string refDeltaName, CPS::IdentifiedObject::Ptr refDeltaComp) {
gen.setReferenceOmega(refOmegaComp->attribute<CPS::Real>(refOmegaName), refDeltaComp->attribute<CPS::Real>(refDeltaName));
Expand Down
2 changes: 1 addition & 1 deletion dpsim/src/pybind/SPComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void addSPPh1Components(py::module_ mSPPh1) {
"nom_power"_a, "nom_volt"_a, "nom_freq"_a, "Xpd"_a, "inertia"_a, "Rs"_a=0, "D"_a=0)
.def("set_initial_values", &CPS::SP::Ph1::SynchronGeneratorTrStab::setInitialValues, "elec_power"_a, "mech_power"_a)
.def("connect", &CPS::SP::Ph1::SynchronGeneratorTrStab::connect)
.def("set_model_flags", &CPS::SP::Ph1::SynchronGeneratorTrStab::setModelFlags, "use_omega_ref"_a, "convert_with_omega_mech"_a)
.def("set_model_flags", &CPS::SP::Ph1::SynchronGeneratorTrStab::setModelFlags, "convert_with_omega_mech"_a)
.def("set_reference_omega", [](CPS::SP::Ph1::SynchronGeneratorTrStab &gen, std::string refOmegaName, CPS::IdentifiedObject::Ptr refOmegaComp,
std::string refDeltaName, CPS::IdentifiedObject::Ptr refDeltaComp) {
gen.setReferenceOmega(refOmegaComp->attribute<CPS::Real>(refOmegaName), refDeltaComp->attribute<CPS::Real>(refDeltaName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
" cmd_damping_G2 * Kd_G2)\n",
"init_apparent_power_G2 = gen2_pf.get_apparent_power()\n",
"gen2_dp.set_initial_values(init_apparent_power_G2, init_mech_power_G2)\n",
"gen2_dp.set_model_flags(use_omega_ref=True, convert_with_omega_mech=True)\n",
"gen2_dp.set_model_flags(convert_with_omega_mech=True)\n",
"gen2_dp.set_reference_omega(\"w_r\", gen1_dp, \"delta_r\", gen1_dp)\n",
"\n",
"# Load\n",
Expand Down Expand Up @@ -580,7 +580,7 @@
" cmd_damping_G2 * Kd_G2)\n",
"init_apparent_power_G2 = gen2_pf.get_apparent_power()\n",
"gen2_sp.set_initial_values(init_apparent_power_G2, init_mech_power_G2)\n",
"gen2_sp.set_model_flags(use_omega_ref=True, convert_with_omega_mech=True)\n",
"gen2_sp.set_model_flags(convert_with_omega_mech=True)\n",
"gen2_sp.set_reference_omega(\"w_r\", gen1_sp, \"delta_r\", gen1_sp)\n",
"\n",
"# Load\n",
Expand Down Expand Up @@ -941,7 +941,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.2"
},
"tests": {
"skip": false
Expand Down
15 changes: 10 additions & 5 deletions examples/Notebooks/Grids/SP_WSCC_9-bus_dyn_switch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
"system.add(sw)\n",
"\n",
"# Use omegNom for torque conversion in SG models for validation with PSAT\n",
"system.component('GEN1').set_model_flags(False, False)\n",
"system.component('GEN2').set_model_flags(False, False)\n",
"system.component('GEN3').set_model_flags(False, False)\n",
"system.component('GEN1').set_model_flags(False)\n",
"system.component('GEN2').set_model_flags(False)\n",
"system.component('GEN3').set_model_flags(False)\n",
"\n",
"logger = dpsimpy.Logger(sim_name)\n",
"\n",
Expand Down Expand Up @@ -397,7 +397,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.9.2 64-bit",
"language": "python",
"name": "python3"
},
Expand All @@ -411,7 +411,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.9.2"
},
"vscode": {
"interpreter": {
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
}
}
},
"nbformat": 4,
Expand Down
15 changes: 10 additions & 5 deletions examples/Notebooks/Grids/WSCC_9-bus_dyn_switch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
"system.add(sw)\n",
"\n",
"# Use omegNom for torque conversion in SG models for validation with PSAT\n",
"system.component('GEN1').set_model_flags(False, False)\n",
"system.component('GEN2').set_model_flags(False, False)\n",
"system.component('GEN3').set_model_flags(False, False)\n",
"system.component('GEN1').set_model_flags(False)\n",
"system.component('GEN2').set_model_flags(False)\n",
"system.component('GEN3').set_model_flags(False)\n",
"\n",
"logger = dpsimpy.Logger(sim_name)\n",
"\n",
Expand Down Expand Up @@ -284,7 +284,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.9.2 64-bit",
"language": "python",
"name": "python3"
},
Expand All @@ -298,7 +298,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.9.2"
},
"vscode": {
"interpreter": {
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
}
}
},
"nbformat": 4,
Expand Down

0 comments on commit 90a31a8

Please sign in to comment.