From 90a31a81acdd583a0aaed11f3bf92d479c6d94c5 Mon Sep 17 00:00:00 2001 From: Jonas Schroeder Date: Fri, 28 Oct 2022 12:47:00 +0000 Subject: [PATCH] simplify use of mUseOmagaRef in TrStab Generator Signed-off-by: Jonas Schroeder --- .../DP/DP_Ph1_SynchronGeneratorTrStab.h | 2 +- .../SP/SP_Ph1_SynchronGeneratorTrStab.h | 2 +- .../src/DP/DP_Ph1_SynchronGeneratorTrStab.cpp | 18 +++--------------- .../src/SP/SP_Ph1_SynchronGeneratorTrStab.cpp | 17 +++-------------- .../cxx/CIM/SP_WSCC-9bus_CIM_Dyn_Switch.cpp | 6 +++--- .../Circuits/DP_SynGenTrStab_3Bus_Fault.cpp | 2 +- .../Circuits/SP_SynGenTrStab_3Bus_Fault.cpp | 2 +- ..._SynGenTrStab_SMIB_Fault_KundurExample1.cpp | 2 +- dpsim/src/pybind/DPComponents.cpp | 2 +- dpsim/src/pybind/SPComponents.cpp | 2 +- .../DP_SP_SynGenTrStab_3Bus_Fault.ipynb | 6 +++--- .../Grids/SP_WSCC_9-bus_dyn_switch.ipynb | 15 ++++++++++----- .../Grids/WSCC_9-bus_dyn_switch.ipynb | 15 ++++++++++----- 13 files changed, 39 insertions(+), 52 deletions(-) diff --git a/dpsim-models/include/dpsim-models/DP/DP_Ph1_SynchronGeneratorTrStab.h b/dpsim-models/include/dpsim-models/DP/DP_Ph1_SynchronGeneratorTrStab.h index f48c09f674..6e7a3a1556 100644 --- a/dpsim-models/include/dpsim-models/DP/DP_Ph1_SynchronGeneratorTrStab.h +++ b/dpsim-models/include/dpsim-models/DP/DP_Ph1_SynchronGeneratorTrStab.h @@ -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 diff --git a/dpsim-models/include/dpsim-models/SP/SP_Ph1_SynchronGeneratorTrStab.h b/dpsim-models/include/dpsim-models/SP/SP_Ph1_SynchronGeneratorTrStab.h index 2c31b39d4f..5396cc83d0 100644 --- a/dpsim-models/include/dpsim-models/SP/SP_Ph1_SynchronGeneratorTrStab.h +++ b/dpsim-models/include/dpsim-models/SP/SP_Ph1_SynchronGeneratorTrStab.h @@ -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 diff --git a/dpsim-models/src/DP/DP_Ph1_SynchronGeneratorTrStab.cpp b/dpsim-models/src/DP/DP_Ph1_SynchronGeneratorTrStab.cpp index dffcef4884..1fb5aff32f 100644 --- a/dpsim-models/src/DP/DP_Ph1_SynchronGeneratorTrStab.cpp +++ b/dpsim-models/src/DP/DP_Ph1_SynchronGeneratorTrStab.cpp @@ -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) { @@ -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 diff --git a/dpsim-models/src/SP/SP_Ph1_SynchronGeneratorTrStab.cpp b/dpsim-models/src/SP/SP_Ph1_SynchronGeneratorTrStab.cpp index 1326992ddf..053632a321 100644 --- a/dpsim-models/src/SP/SP_Ph1_SynchronGeneratorTrStab.cpp +++ b/dpsim-models/src/SP/SP_Ph1_SynchronGeneratorTrStab.cpp @@ -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) { @@ -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("w_ref")->get(); - refDelta = attribute("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 diff --git a/dpsim/examples/cxx/CIM/SP_WSCC-9bus_CIM_Dyn_Switch.cpp b/dpsim/examples/cxx/CIM/SP_WSCC-9bus_CIM_Dyn_Switch.cpp index 30fb244e26..62b8759953 100644 --- a/dpsim/examples/cxx/CIM/SP_WSCC-9bus_CIM_Dyn_Switch.cpp +++ b/dpsim/examples/cxx/CIM/SP_WSCC-9bus_CIM_Dyn_Switch.cpp @@ -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("GEN1")->setModelFlags(false, false); - sys.component("GEN2")->setModelFlags(false, false); - sys.component("GEN3")->setModelFlags(false, false); + sys.component("GEN1")->setModelFlags(false); + sys.component("GEN2")->setModelFlags(false); + sys.component("GEN3")->setModelFlags(false); // Logging auto logger = DataLogger::make(simName); diff --git a/dpsim/examples/cxx/Circuits/DP_SynGenTrStab_3Bus_Fault.cpp b/dpsim/examples/cxx/Circuits/DP_SynGenTrStab_3Bus_Fault.cpp index 3aee68aaa7..d90163914c 100644 --- a/dpsim/examples/cxx/Circuits/DP_SynGenTrStab_3Bus_Fault.cpp +++ b/dpsim/examples/cxx/Circuits/DP_SynGenTrStab_3Bus_Fault.cpp @@ -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("w_r"), gen1DP->attribute("delta_r")); ///Load diff --git a/dpsim/examples/cxx/Circuits/SP_SynGenTrStab_3Bus_Fault.cpp b/dpsim/examples/cxx/Circuits/SP_SynGenTrStab_3Bus_Fault.cpp index 02f3992f10..d4a352175b 100644 --- a/dpsim/examples/cxx/Circuits/SP_SynGenTrStab_3Bus_Fault.cpp +++ b/dpsim/examples/cxx/Circuits/SP_SynGenTrStab_3Bus_Fault.cpp @@ -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("w_r"), gen1SP->attribute("delta_r")); //Load diff --git a/dpsim/examples/cxx/Circuits/SP_SynGenTrStab_SMIB_Fault_KundurExample1.cpp b/dpsim/examples/cxx/Circuits/SP_SynGenTrStab_SMIB_Fault_KundurExample1.cpp index 7fc29cbbd3..e929a8feda 100644 --- a/dpsim/examples/cxx/Circuits/SP_SynGenTrStab_SMIB_Fault_KundurExample1.cpp +++ b/dpsim/examples/cxx/Circuits/SP_SynGenTrStab_SMIB_Fault_KundurExample1.cpp @@ -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(); diff --git a/dpsim/src/pybind/DPComponents.cpp b/dpsim/src/pybind/DPComponents.cpp index ebba44c0dc..38cb8b2b33 100644 --- a/dpsim/src/pybind/DPComponents.cpp +++ b/dpsim/src/pybind/DPComponents.cpp @@ -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(refOmegaName), refDeltaComp->attribute(refDeltaName)); diff --git a/dpsim/src/pybind/SPComponents.cpp b/dpsim/src/pybind/SPComponents.cpp index 57e6657b8b..1a3c10094d 100644 --- a/dpsim/src/pybind/SPComponents.cpp +++ b/dpsim/src/pybind/SPComponents.cpp @@ -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(refOmegaName), refDeltaComp->attribute(refDeltaName)); diff --git a/examples/Notebooks/Circuits/DP_SP_SynGenTrStab_3Bus_Fault.ipynb b/examples/Notebooks/Circuits/DP_SP_SynGenTrStab_3Bus_Fault.ipynb index 41a84e567e..3b98d8a514 100644 --- a/examples/Notebooks/Circuits/DP_SP_SynGenTrStab_3Bus_Fault.ipynb +++ b/examples/Notebooks/Circuits/DP_SP_SynGenTrStab_3Bus_Fault.ipynb @@ -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", @@ -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", @@ -941,7 +941,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.9.2" }, "tests": { "skip": false diff --git a/examples/Notebooks/Grids/SP_WSCC_9-bus_dyn_switch.ipynb b/examples/Notebooks/Grids/SP_WSCC_9-bus_dyn_switch.ipynb index a45e6986e3..58061f8f3b 100644 --- a/examples/Notebooks/Grids/SP_WSCC_9-bus_dyn_switch.ipynb +++ b/examples/Notebooks/Grids/SP_WSCC_9-bus_dyn_switch.ipynb @@ -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", @@ -397,7 +397,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3.9.2 64-bit", "language": "python", "name": "python3" }, @@ -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, diff --git a/examples/Notebooks/Grids/WSCC_9-bus_dyn_switch.ipynb b/examples/Notebooks/Grids/WSCC_9-bus_dyn_switch.ipynb index 1dd2aa1fbc..1197f064b6 100644 --- a/examples/Notebooks/Grids/WSCC_9-bus_dyn_switch.ipynb +++ b/examples/Notebooks/Grids/WSCC_9-bus_dyn_switch.ipynb @@ -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", @@ -284,7 +284,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3.9.2 64-bit", "language": "python", "name": "python3" }, @@ -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,