diff --git a/examples/PhasorDynamics/Tiny/TwoBus/Tgov1/TwoBusTgov1.cpp b/examples/PhasorDynamics/Tiny/TwoBus/Tgov1/TwoBusTgov1.cpp index 8f8223d2e..cc76cbccd 100644 --- a/examples/PhasorDynamics/Tiny/TwoBus/Tgov1/TwoBusTgov1.cpp +++ b/examples/PhasorDynamics/Tiny/TwoBus/Tgov1/TwoBusTgov1.cpp @@ -23,6 +23,7 @@ int main() { using namespace GridKit::PhasorDynamics; using namespace AnalysisManager::Sundials; + using namespace GridKit::PhasorDynamics::Governor; using scalar_type = double; using real_type = double; @@ -102,13 +103,13 @@ int main() // Set governor data (Default PW values) data.gov.resize(1); - data.gov[0].R = 0.05; - data.gov[0].Pvmin = 0; - data.gov[0].Pvmax = 1.0; - data.gov[0].T1 = 0.5; - data.gov[0].T2 = 2.5; - data.gov[0].T3 = 7.5; - data.gov[0].Dt = 0; + data.gov[0].parameters[Tgov1Parameters::R] = 0.05; + data.gov[0].parameters[Tgov1Parameters::Pvmin] = 0.0; + data.gov[0].parameters[Tgov1Parameters::Pvmax] = 1.0; + data.gov[0].parameters[Tgov1Parameters::T1] = 0.5; + data.gov[0].parameters[Tgov1Parameters::T2] = 2.5; + data.gov[0].parameters[Tgov1Parameters::T3] = 7.5; + data.gov[0].parameters[Tgov1Parameters::Dt] = 0.0; // Manually add components // This is a workaround since signal connections are not implemented in parser @@ -121,6 +122,9 @@ int main() auto* omega = new SignalNode(data.signal[0]); auto* pmech = new SignalNode(data.signal[1]); + // Manual add gen & gov components + // This is a hack since SignalBus not implemented + // Create branch Branch branch(bus0, bus1, data.branch[0]); diff --git a/src/Model/PhasorDynamics/Governor/Tgov1/Tgov1.cpp b/src/Model/PhasorDynamics/Governor/Tgov1/Tgov1.cpp index 1be41020d..69ed796ee 100644 --- a/src/Model/PhasorDynamics/Governor/Tgov1/Tgov1.cpp +++ b/src/Model/PhasorDynamics/Governor/Tgov1/Tgov1.cpp @@ -2,6 +2,7 @@ * @file Tgov1.cpp * @author Luke Lowery (lukel@tamu.edu) * @author Adam Birchfield (abirchfield@tamu.edu) + * @author Wiktoria Zielinska (zielinskawa@ORNL.gov) * @brief Definition of a Turbine Governor Model (IEEET1). * */ @@ -26,22 +27,64 @@ namespace GridKit /** * */ + /** + * @brief Constructs a Tgov1 governor model using signal inputs directly. + * + * Initializes the model parameters and sets the internal model size. + * + * @param pmech Pointer to the mechanical power signal. + * @param omega Pointer to the rotor speed signal. + * @param data Model data containing parameter values for initialization. + */ template Tgov1::Tgov1(signal_type* pmech, signal_type* omega, const model_data_type& data) : pmech_(pmech), - omega_(omega), - R_(data.R), - Pvmin_(data.Pvmin), - Pvmax_(data.Pvmax), - T1_(data.T1), - T2_(data.T2), - T3_(data.T3), - Dt_(data.Dt) + omega_(omega) { - // 3 Internal Variables + initializeParameters(data); size_ = 3; } + /** + * @brief Helper function to extract and assign model parameters. + * + * Parses values from the model_data_type and assigns them to internal parameters. + * + * @param data Structure containing model parameters. + */ + template + void Tgov1::initializeParameters(const model_data_type& data) + { + if (data.parameters.contains(model_data_type::Parameters::R)) + { + R_ = std::get(data.parameters.at(model_data_type::Parameters::R)); + } + if (data.parameters.contains(model_data_type::Parameters::Pvmin)) + { + Pvmin_ = std::get(data.parameters.at(model_data_type::Parameters::Pvmin)); + } + if (data.parameters.contains(model_data_type::Parameters::Pvmax)) + { + Pvmax_ = std::get(data.parameters.at(model_data_type::Parameters::Pvmax)); + } + if (data.parameters.contains(model_data_type::Parameters::T1)) + { + T1_ = std::get(data.parameters.at(model_data_type::Parameters::T1)); + } + if (data.parameters.contains(model_data_type::Parameters::T2)) + { + T2_ = std::get(data.parameters.at(model_data_type::Parameters::T2)); + } + if (data.parameters.contains(model_data_type::Parameters::T3)) + { + T3_ = std::get(data.parameters.at(model_data_type::Parameters::T3)); + } + if (data.parameters.contains(model_data_type::Parameters::Dt)) + { + Dt_ = std::get(data.parameters.at(model_data_type::Parameters::Dt)); + } + } + template Tgov1::Tgov1(signal_type* pmech, signal_type* omega) : pmech_(pmech), @@ -218,18 +261,6 @@ namespace GridKit return 0; } - /** - * @brief The mechanical power output. - * @warning This is not yet accessed by anything. The Genrou class will - * need to access this instead of a constant Pmech. - * @return ScalarT - Mechanical output power value. - */ - template - ScalarT& Tgov1::Pmech() - { - return y_[2]; - } - // Available template instantiations template class Tgov1; template class Tgov1; diff --git a/src/Model/PhasorDynamics/Governor/Tgov1/Tgov1.hpp b/src/Model/PhasorDynamics/Governor/Tgov1/Tgov1.hpp index 63c9c3c0e..c55423798 100644 --- a/src/Model/PhasorDynamics/Governor/Tgov1/Tgov1.hpp +++ b/src/Model/PhasorDynamics/Governor/Tgov1/Tgov1.hpp @@ -2,6 +2,7 @@ * @file Tgov1.hpp * @author Luke Lowery (lukel@tamu.edu) * @author Adam Birchfield (abirchfield@tamu.edu) + * @author Wiktoria Zielinska (zielinskawa@ORNL.gov) * @brief Declaration of a Turbine Governor Model (IEEET1). * */ @@ -9,7 +10,6 @@ #pragma once #include -#include // Forward declarations namespace GridKit @@ -39,7 +39,7 @@ namespace GridKit { template - class Tgov1 : public Component, public GovernorBase + class Tgov1 : public Component { using Component::alpha_; using Component::f_; @@ -71,27 +71,25 @@ namespace GridKit { } - // Read Access to Pmech - ScalarT& Pmech() override; - private: + // Associated Machine Model signal_type* pmech_{nullptr}; signal_type* omega_{nullptr}; // Input parameters - real_type R_; - real_type Pvmin_; - real_type Pvmax_; - real_type T1_; - real_type T2_; - real_type T3_; - real_type Dt_; + real_type R_{0}; + real_type Pvmin_{0}; + real_type Pvmax_{0}; + real_type T1_{0}; + real_type T2_{0}; + real_type T3_{0}; + real_type Dt_{0}; // Input States (which can be parameters) - ScalarT pref_; + ScalarT pref_{0}; // Scale of Sigmoid function (temporary local implementation) - const ScalarT mu_ = 4000.0; + const ScalarT mu_{4000.0}; // Activation function (sigmoid approximation) ScalarT sigmoid(ScalarT x); @@ -100,6 +98,8 @@ namespace GridKit ScalarT indicator_low(ScalarT x, ScalarT f); ScalarT indicator_high(ScalarT x, ScalarT f); ScalarT indicator(ScalarT x, ScalarT f); + + void initializeParameters(const model_data_type& data); }; } // namespace Governor diff --git a/src/Model/PhasorDynamics/Governor/Tgov1/Tgov1Data.hpp b/src/Model/PhasorDynamics/Governor/Tgov1/Tgov1Data.hpp index 55a645033..02a1e4a25 100644 --- a/src/Model/PhasorDynamics/Governor/Tgov1/Tgov1Data.hpp +++ b/src/Model/PhasorDynamics/Governor/Tgov1/Tgov1Data.hpp @@ -1,11 +1,14 @@ /** * @file Tgov1Data.hpp + * @author Wiktoria Zielinska (zielinskawa@ORNL.gov) * @author Luke Lowery (lukel@tamu.edu) * @brief Modeling data for TGOV1 - * */ + #pragma once +#include + namespace GridKit { namespace PhasorDynamics @@ -13,26 +16,51 @@ namespace GridKit namespace Governor { /** - * @brief Contains modeling data for a TGOV1 Governor model. - * - * @tparam RealT Real parameter data type - * @tparam IdxT Integer parameter data type + * @brief Parameter keys for TGOV1 Governor model. * - * Integer parameters are of the same type as matrix and vector indices. + * These enum values serve as keys for the parameters map in ComponentData. + */ + enum class Tgov1Parameters + { + R, ///< Droop Constant + T1, ///< Valve Time Delay + T2, ///< Turbine Numerator Time Constant + T3, ///< Turbine Delay + Pvmax, ///< Max Valve Power + Pvmin, ///< Min Valve Power + Dt ///< Damping Coefficient + }; + + /** + * @brief Placeholder enum for TGOV1 ports. + */ + enum class Tgov1Ports + { + }; + + /** + * @brief Placeholder enum for TGOV1 monitorable variables. + */ + enum class Tgov1MonitorableVariables + { + }; + + /** + * @brief Modeling data for TGOV1 Governor using ComponentData base. * - * @todo Decide on naming scheme for model parameters. + * @tparam RealT Real number type (e.g., double) + * @tparam IdxT Index type (e.g., size_t) */ template - struct Tgov1Data + struct Tgov1Data : public ComponentData { - RealT R{0.05}; ///< Droop Constant - RealT T1{0.5}; ///< Valve Time Delay - RealT T2{2.5}; ///< Turbine Numerator Time Constant - RealT T3{7.5}; ///< Turbine Delay - RealT Pvmax{1.0}; ///< Max Valve Power - RealT Pvmin{0.0}; ///< Min Valve Power - RealT Dt{0.0}; ///< + Tgov1Data() = default; + + using Parameters = Tgov1Parameters; + using Ports = Tgov1Ports; + using MonitorableVariables = Tgov1MonitorableVariables; }; + } // namespace Governor } // namespace PhasorDynamics } // namespace GridKit diff --git a/src/Model/PhasorDynamics/GovernorBase.hpp b/src/Model/PhasorDynamics/GovernorBase.hpp deleted file mode 100644 index 04d85a5f7..000000000 --- a/src/Model/PhasorDynamics/GovernorBase.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include - -namespace GridKit -{ - namespace PhasorDynamics - { - /*! - * @brief GovernorBase model implementation base class. - * - */ - template - class GovernorBase - { - public: - virtual ScalarT& Pmech() = 0; - }; - - } // namespace PhasorDynamics -} // namespace GridKit