From 44bc562ed4acd6d931e96dccbc60a195ac821d3e Mon Sep 17 00:00:00 2001 From: Philip Fackler Date: Wed, 20 May 2026 16:00:46 -0500 Subject: [PATCH] Fix template formatting issues in phasor dynamics --- GridKit/Model/Evaluator.hpp | 4 +- .../Model/PhasorDynamics/Branch/Branch.cpp | 6 +- .../Model/PhasorDynamics/Branch/Branch.hpp | 78 +++---- .../PhasorDynamics/Branch/BranchData.hpp | 10 +- .../Branch/BranchDependencyTracking.cpp | 6 +- .../PhasorDynamics/Branch/BranchEnzyme.cpp | 6 +- .../PhasorDynamics/Branch/BranchImpl.hpp | 108 +++++---- GridKit/Model/PhasorDynamics/Bus/Bus.cpp | 6 +- GridKit/Model/PhasorDynamics/Bus/Bus.hpp | 38 ++-- GridKit/Model/PhasorDynamics/Bus/BusData.hpp | 9 +- .../Bus/BusDependencyTracking.cpp | 6 +- .../Model/PhasorDynamics/Bus/BusEnzyme.cpp | 6 +- .../Model/PhasorDynamics/Bus/BusFactory.hpp | 4 +- GridKit/Model/PhasorDynamics/Bus/BusImpl.hpp | 38 ++-- .../Model/PhasorDynamics/Bus/BusInfinite.hpp | 30 +-- .../PhasorDynamics/Bus/BusInfiniteImpl.hpp | 44 ++-- GridKit/Model/PhasorDynamics/BusBase.hpp | 6 +- GridKit/Model/PhasorDynamics/BusBaseImpl.hpp | 12 +- .../PhasorDynamics/BusFault/BusFault.cpp | 6 +- .../PhasorDynamics/BusFault/BusFault.hpp | 60 ++--- .../PhasorDynamics/BusFault/BusFaultData.hpp | 10 +- .../BusFault/BusFaultDependencyTracking.cpp | 6 +- .../BusFault/BusFaultEnzyme.cpp | 6 +- .../PhasorDynamics/BusFault/BusFaultImpl.hpp | 70 +++--- .../Model/PhasorDynamics/ComponentData.hpp | 13 +- .../Model/PhasorDynamics/ComponentSignals.hpp | 11 +- .../PhasorDynamics/Exciter/IEEET1/Ieeet1.cpp | 6 +- .../PhasorDynamics/Exciter/IEEET1/Ieeet1.hpp | 78 +++---- .../Exciter/IEEET1/Ieeet1Data.hpp | 10 +- .../IEEET1/Ieeet1DependencyTracking.cpp | 6 +- .../Exciter/IEEET1/Ieeet1Enzyme.cpp | 6 +- .../Exciter/IEEET1/Ieeet1Impl.hpp | 131 +++++------ .../Exciter/SEXS-PTI/SexsPti.cpp | 4 +- .../Exciter/SEXS-PTI/SexsPti.hpp | 64 +++--- .../Exciter/SEXS-PTI/SexsPtiData.hpp | 6 +- .../SEXS-PTI/SexsPtiDependencyTracking.cpp | 4 +- .../Exciter/SEXS-PTI/SexsPtiEnzyme.cpp | 4 +- .../Exciter/SEXS-PTI/SexsPtiImpl.hpp | 58 ++--- .../PhasorDynamics/Governor/Tgov1/Tgov1.cpp | 6 +- .../PhasorDynamics/Governor/Tgov1/Tgov1.hpp | 60 ++--- .../Governor/Tgov1/Tgov1Data.hpp | 12 +- .../Tgov1/Tgov1DependencyTracking.cpp | 6 +- .../Governor/Tgov1/Tgov1Enzyme.cpp | 6 +- .../Governor/Tgov1/Tgov1Impl.hpp | 74 +++--- GridKit/Model/PhasorDynamics/GridElement.hpp | 6 +- GridKit/Model/PhasorDynamics/Load/Load.cpp | 6 +- GridKit/Model/PhasorDynamics/Load/Load.hpp | 66 +++--- .../Model/PhasorDynamics/Load/LoadData.hpp | 10 +- .../Load/LoadDependencyTracking.cpp | 6 +- .../Model/PhasorDynamics/Load/LoadEnzyme.cpp | 6 +- .../Model/PhasorDynamics/Load/LoadImpl.hpp | 68 +++--- .../Model/PhasorDynamics/LoadZIP/LoadZIP.cpp | 6 +- .../Model/PhasorDynamics/LoadZIP/LoadZIP.hpp | 72 +++--- .../PhasorDynamics/LoadZIP/LoadZIPData.hpp | 10 +- .../LoadZIP/LoadZIPDependencyTracking.cpp | 6 +- .../PhasorDynamics/LoadZIP/LoadZIPEnzyme.cpp | 6 +- .../PhasorDynamics/LoadZIP/LoadZIPImpl.hpp | 76 +++---- .../PhasorDynamics/SignalNode/SignalNode.hpp | 8 +- .../SignalNode/SignalNodeData.hpp | 8 +- .../SignalNode/SignalNodeImpl.hpp | 24 +- .../Stabilizer/IEEEST/Ieeest.cpp | 6 +- .../Stabilizer/IEEEST/Ieeest.hpp | 56 ++--- .../Stabilizer/IEEEST/IeeestData.hpp | 10 +- .../IEEEST/IeeestDependencyTracking.cpp | 4 +- .../Stabilizer/IEEEST/IeeestEnzyme.cpp | 4 +- .../Stabilizer/IEEEST/IeeestImpl.hpp | 126 +++++------ .../SynchronousMachine/GENROUwS/Genrou.cpp | 6 +- .../SynchronousMachine/GENROUwS/Genrou.hpp | 132 +++++------ .../GENROUwS/GenrouDependencyTracking.cpp | 6 +- .../GENROUwS/GenrouEnzyme.cpp | 4 +- .../GENROUwS/GenrouImpl.hpp | 210 +++++++++--------- .../GenClassical/GenClassical.cpp | 6 +- .../GenClassical/GenClassical.hpp | 84 +++---- .../GenClassical/GenClassicalData.hpp | 10 +- .../GenClassicalDependencyTracking.cpp | 6 +- .../GenClassical/GenClassicalEnzyme.cpp | 6 +- .../GenClassical/GenClassicalImpl.hpp | 112 +++++----- GridKit/Model/PhasorDynamics/SystemModel.hpp | 68 +++--- .../Model/PhasorDynamics/SystemModelData.hpp | 4 +- GridKit/Model/VariableMonitor.hpp | 4 +- GridKit/Model/VariableMonitorController.hpp | 8 +- GridKit/Model/VariableMonitorImpl.hpp | 18 +- 82 files changed, 1200 insertions(+), 1214 deletions(-) diff --git a/GridKit/Model/Evaluator.hpp b/GridKit/Model/Evaluator.hpp index d932f6565..3635c7027 100644 --- a/GridKit/Model/Evaluator.hpp +++ b/GridKit/Model/Evaluator.hpp @@ -17,10 +17,12 @@ namespace GridKit * @brief Abstract class describing a model. * */ - template + template class Evaluator { public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename GridKit::ScalarTraits::RealT; using MatrixT = GridKit::LinearAlgebra::COO_Matrix; //\todo Use CsrMatrix using CsrMatrixT = GridKit::LinearAlgebra::CsrMatrix; diff --git a/GridKit/Model/PhasorDynamics/Branch/Branch.cpp b/GridKit/Model/PhasorDynamics/Branch/Branch.cpp index b2aff31fe..ad18621f3 100644 --- a/GridKit/Model/PhasorDynamics/Branch/Branch.cpp +++ b/GridKit/Model/PhasorDynamics/Branch/Branch.cpp @@ -13,12 +13,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int Branch::evaluateJacobian() + template + int Branch::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Branch..." << std::endl; Log::misc() << "Jacobian evaluation is not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Branch/Branch.hpp b/GridKit/Model/PhasorDynamics/Branch/Branch.hpp index 5355b0b8a..a93420654 100644 --- a/GridKit/Model/PhasorDynamics/Branch/Branch.hpp +++ b/GridKit/Model/PhasorDynamics/Branch/Branch.hpp @@ -18,10 +18,10 @@ namespace GridKit { namespace PhasorDynamics { - template + template class BusBase; - template + template struct BranchData; } // namespace PhasorDynamics } // namespace GridKit @@ -37,36 +37,38 @@ namespace GridKit * direction is into the busses. * */ - template - class Branch : public Component + template + class Branch : public Component { - using Component::gridkit_component_id_; - using Component::size_; - using Component::nnz_; - using Component::time_; - using Component::alpha_; - using Component::y_; - using Component::yp_; - using Component::tag_; - using Component::f_; - using Component::wb_; - using Component::h_; - using Component::J_; - using Component::J_rows_buffer_; - using Component::J_cols_buffer_; - using Component::J_vals_buffer_; - using Component::variable_indices_; - using Component::residual_indices_; + using Component::gridkit_component_id_; + using Component::size_; + using Component::nnz_; + using Component::time_; + using Component::alpha_; + using Component::y_; + using Component::yp_; + using Component::tag_; + using Component::f_; + using Component::wb_; + using Component::h_; + using Component::J_; + using Component::J_rows_buffer_; + using Component::J_cols_buffer_; + using Component::J_vals_buffer_; + using Component::variable_indices_; + using Component::residual_indices_; public: - using RealT = typename Component::RealT; - using bus_type = BusBase; - using model_data_type = BranchData; - using MonitorT = Model::VariableMonitor; - - Branch(bus_type* bus1, bus_type* bus2); - Branch(bus_type* bus1, bus_type* bus2, RealT R, RealT X, RealT G, RealT B); - Branch(bus_type* bus1, bus_type* bus2, const model_data_type& data); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename Component::RealT; + using BusT = BusBase; + using ModelDataT = BranchData; + using MonitorT = Model::VariableMonitor; + + Branch(BusT* bus1, BusT* bus2); + Branch(BusT* bus1, BusT* bus2, RealT R, RealT X, RealT G, RealT B); + Branch(BusT* bus1, BusT* bus2, const ModelDataT& data); virtual ~Branch(); virtual int setGridKitComponentID(IdxT) override final; @@ -109,7 +111,7 @@ namespace GridKit const Model::VariableMonitorBase* getMonitor() const override; private: - void initializeParameters(const model_data_type& data); + void initializeParameters(const ModelDataT& data); void initializeMonitor(); void setDerivedParams(); @@ -160,14 +162,14 @@ namespace GridKit __attribute__((always_inline)) inline int evaluateBusResidual22(ScalarT*, ScalarT*, ScalarT*, ScalarT*); private: - bus_type* bus1_; - bus_type* bus2_; - RealT R_{0.0}; - RealT X_{0.0}; - RealT G_{0.0}; - RealT B_{0.0}; - IdxT bus1_id_{0}; - IdxT bus2_id_{0}; + BusT* bus1_; + BusT* bus2_; + RealT R_{0.0}; + RealT X_{0.0}; + RealT G_{0.0}; + RealT B_{0.0}; + IdxT bus1_id_{0}; + IdxT bus2_id_{0}; /* Derived parameters */ RealT b_; diff --git a/GridKit/Model/PhasorDynamics/Branch/BranchData.hpp b/GridKit/Model/PhasorDynamics/Branch/BranchData.hpp index 98528c3d1..c0c93107a 100644 --- a/GridKit/Model/PhasorDynamics/Branch/BranchData.hpp +++ b/GridKit/Model/PhasorDynamics/Branch/BranchData.hpp @@ -46,14 +46,14 @@ namespace GridKit /** * @brief Contains modeling data for a Branch * - * @tparam RealT Real parameter data type - * @tparam IdxT Integer parameter data type + * @tparam real_type Real parameter data type + * @tparam index_type Integer parameter data type * * Integer parameters are of the same type as matrix and vector indices. */ - template - struct BranchData : public ComponentData + struct BranchData : public ComponentData diff --git a/GridKit/Model/PhasorDynamics/Branch/BranchDependencyTracking.cpp b/GridKit/Model/PhasorDynamics/Branch/BranchDependencyTracking.cpp index 5f384af29..c06da9396 100644 --- a/GridKit/Model/PhasorDynamics/Branch/BranchDependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/Branch/BranchDependencyTracking.cpp @@ -13,12 +13,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int Branch::evaluateJacobian() + template + int Branch::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Branch..." << std::endl; Log::misc() << "Jacobian evaluation is not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Branch/BranchEnzyme.cpp b/GridKit/Model/PhasorDynamics/Branch/BranchEnzyme.cpp index 535d944cd..a6cd306b2 100644 --- a/GridKit/Model/PhasorDynamics/Branch/BranchEnzyme.cpp +++ b/GridKit/Model/PhasorDynamics/Branch/BranchEnzyme.cpp @@ -15,12 +15,10 @@ namespace GridKit /** * @brief Jacobian evaluation experimental * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int Branch::evaluateJacobian() + template + int Branch::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Branch..." << std::endl; Log::misc() << "Jacobian evaluation is experimental!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Branch/BranchImpl.hpp b/GridKit/Model/PhasorDynamics/Branch/BranchImpl.hpp index bcb0c268d..b1743deda 100644 --- a/GridKit/Model/PhasorDynamics/Branch/BranchImpl.hpp +++ b/GridKit/Model/PhasorDynamics/Branch/BranchImpl.hpp @@ -26,8 +26,8 @@ namespace GridKit * - Number of equations = 0 * - Number of internal variables = 0 */ - template - Branch::Branch(bus_type* bus1, bus_type* bus2) + template + Branch::Branch(BusT* bus1, BusT* bus2) : bus1_(bus1), bus2_(bus2), R_(0.0), @@ -44,8 +44,6 @@ namespace GridKit /** * @brief Construct a new Branch * - * @tparam ScalarT - scalar type - * @tparam IdxT - matrix/vector index type * @param bus1 - pointer to bus-1 * @param bus2 - pointer to bus-2 * @param R - line series resistance @@ -53,13 +51,13 @@ namespace GridKit * @param G - line shunt conductance * @param B - line shunt charging */ - template - Branch::Branch(bus_type* bus1, - bus_type* bus2, - RealT R, - RealT X, - RealT G, - RealT B) + template + Branch::Branch(BusT* bus1, + BusT* bus2, + RealT R, + RealT X, + RealT G, + RealT B) : bus1_(bus1), bus2_(bus2), R_(R), @@ -72,8 +70,8 @@ namespace GridKit setDerivedParams(); } - template - Branch::Branch(bus_type* bus1, bus_type* bus2, const model_data_type& data) + template + Branch::Branch(BusT* bus1, BusT* bus2, const ModelDataT& data) : bus1_(bus1), bus2_(bus2), monitor_(std::make_unique(data)) @@ -88,11 +86,9 @@ namespace GridKit /** * @brief Destroy the Branch * - * @tparam ScalarT - * @tparam IdxT */ - template - Branch::~Branch() + template + Branch::~Branch() { // std::cout << "Destroy Branch..." << std::endl; } @@ -100,8 +96,8 @@ namespace GridKit /** * @brief Set the component ID */ - template - int Branch::setGridKitComponentID(IdxT component_id) + template + int Branch::setGridKitComponentID(IdxT component_id) { gridkit_component_id_ = component_id; return 0; @@ -110,8 +106,8 @@ namespace GridKit /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int Branch::allocate() + template + int Branch::allocate() { // std::cout << "Allocate Branch..." << std::endl; @@ -125,8 +121,8 @@ namespace GridKit * Initialization of the branch model * */ - template - int Branch::initialize() + template + int Branch::initialize() { return 0; } @@ -134,8 +130,8 @@ namespace GridKit /** * \brief Identify differential variables. */ - template - int Branch::tagDifferentiable() + template + int Branch::tagDifferentiable() { return 0; } @@ -144,8 +140,8 @@ namespace GridKit * @brief Bus 1 residual contribution from bus 1 variables * */ - template - __attribute__((always_inline)) inline int Branch::evaluateBusResidual11( + template + __attribute__((always_inline)) inline int Branch::evaluateBusResidual11( [[maybe_unused]] ScalarT* y, [[maybe_unused]] ScalarT* yp, ScalarT* wb, @@ -165,8 +161,8 @@ namespace GridKit * @brief Bus 1 residual contribution from bus 2 variables * */ - template - __attribute__((always_inline)) inline int Branch::evaluateBusResidual12( + template + __attribute__((always_inline)) inline int Branch::evaluateBusResidual12( [[maybe_unused]] ScalarT* y, [[maybe_unused]] ScalarT* yp, ScalarT* wb, @@ -186,8 +182,8 @@ namespace GridKit * @brief Bus 2 residual contribution from bus 1 variables * */ - template - __attribute__((always_inline)) int Branch::evaluateBusResidual21( + template + __attribute__((always_inline)) int Branch::evaluateBusResidual21( [[maybe_unused]] ScalarT* y, [[maybe_unused]] ScalarT* yp, ScalarT* wb, @@ -207,8 +203,8 @@ namespace GridKit * @brief Bus 2 residual contribution from bus 2 variables * */ - template - __attribute__((always_inline)) int Branch::evaluateBusResidual22( + template + __attribute__((always_inline)) int Branch::evaluateBusResidual22( [[maybe_unused]] ScalarT* y, [[maybe_unused]] ScalarT* yp, ScalarT* wb, @@ -228,8 +224,8 @@ namespace GridKit * @brief Residual contribution of the branch is computed and pushed to the terminal buses. * */ - template - int Branch::evaluateResidual() + template + int Branch::evaluateResidual() { wb_[0] = Vr1(); wb_[1] = Vi1(); @@ -252,50 +248,50 @@ namespace GridKit return 0; } - template - void Branch::initializeParameters(const model_data_type& data) + template + void Branch::initializeParameters(const ModelDataT& data) { - if (data.parameters.contains(model_data_type::Parameters::R)) + if (data.parameters.contains(ModelDataT::Parameters::R)) { - R_ = std::get(data.parameters.at(model_data_type::Parameters::R)); + R_ = std::get(data.parameters.at(ModelDataT::Parameters::R)); } - if (data.parameters.contains(model_data_type::Parameters::X)) + if (data.parameters.contains(ModelDataT::Parameters::X)) { - X_ = std::get(data.parameters.at(model_data_type::Parameters::X)); + X_ = std::get(data.parameters.at(ModelDataT::Parameters::X)); } - if (data.parameters.contains(model_data_type::Parameters::G)) + if (data.parameters.contains(ModelDataT::Parameters::G)) { - G_ = std::get(data.parameters.at(model_data_type::Parameters::G)); + G_ = std::get(data.parameters.at(ModelDataT::Parameters::G)); } - if (data.parameters.contains(model_data_type::Parameters::B)) + if (data.parameters.contains(ModelDataT::Parameters::B)) { - B_ = std::get(data.parameters.at(model_data_type::Parameters::B)); + B_ = std::get(data.parameters.at(ModelDataT::Parameters::B)); } - if (data.ports.contains(model_data_type::Ports::bus1)) + if (data.ports.contains(ModelDataT::Ports::bus1)) { - bus1_id_ = data.ports.at(model_data_type::Ports::bus1); + bus1_id_ = data.ports.at(ModelDataT::Ports::bus1); } - if (data.ports.contains(model_data_type::Ports::bus2)) + if (data.ports.contains(ModelDataT::Ports::bus2)) { - bus2_id_ = data.ports.at(model_data_type::Ports::bus2); + bus2_id_ = data.ports.at(ModelDataT::Ports::bus2); } } - template - const Model::VariableMonitorBase* Branch::getMonitor() const + template + const Model::VariableMonitorBase* Branch::getMonitor() const { return monitor_.get(); } - template - void Branch::initializeMonitor() + template + void Branch::initializeMonitor() { - using Variable = typename model_data_type::MonitorableVariables; + using Variable = typename ModelDataT::MonitorableVariables; monitor_->set(Variable::ir1, [this] { return Ir1(); }); monitor_->set(Variable::ii1, [this] @@ -322,8 +318,8 @@ namespace GridKit * @brief Derived parameters * */ - template - void Branch::setDerivedParams() + template + void Branch::setDerivedParams() { b_ = -X_ / (R_ * R_ + X_ * X_); g_ = R_ / (R_ * R_ + X_ * X_); diff --git a/GridKit/Model/PhasorDynamics/Bus/Bus.cpp b/GridKit/Model/PhasorDynamics/Bus/Bus.cpp index 0971e2504..1679fa1c4 100644 --- a/GridKit/Model/PhasorDynamics/Bus/Bus.cpp +++ b/GridKit/Model/PhasorDynamics/Bus/Bus.cpp @@ -8,12 +8,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented * - * @tparam ScalarT - data type for Jacobian elements - * @tparam IdxT - data type for matrix indices * @return int - error code */ - template - int Bus::evaluateJacobian() + template + int Bus::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Bus..." << std::endl; Log::misc() << "Jacobian evaluation is not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Bus/Bus.hpp b/GridKit/Model/PhasorDynamics/Bus/Bus.hpp index a94afe863..f8173daeb 100644 --- a/GridKit/Model/PhasorDynamics/Bus/Bus.hpp +++ b/GridKit/Model/PhasorDynamics/Bus/Bus.hpp @@ -15,30 +15,32 @@ namespace GridKit * * */ - template - class Bus : public BusBase + template + class Bus : public BusBase { - using BusBase::bus_id_; - using BusBase::size_; - using BusBase::y_; - using BusBase::yp_; - using BusBase::f_; - using BusBase::J_; - using BusBase::J_rows_buffer_; - using BusBase::J_cols_buffer_; - using BusBase::J_vals_buffer_; - using BusBase::tag_; - using BusBase::variable_indices_; - using BusBase::residual_indices_; + using BusBase::bus_id_; + using BusBase::size_; + using BusBase::y_; + using BusBase::yp_; + using BusBase::f_; + using BusBase::J_; + using BusBase::J_rows_buffer_; + using BusBase::J_cols_buffer_; + using BusBase::J_vals_buffer_; + using BusBase::tag_; + using BusBase::variable_indices_; + using BusBase::residual_indices_; public: - using RealT = typename BusBase::RealT; - using DataT = BusData; - using BusTypeT = typename BusData::BusType; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename BusBase::RealT; + using ModelDataT = BusData; + using BusTypeT = typename BusData::BusType; Bus(); Bus(ScalarT Vr, ScalarT Vi); - Bus(const DataT& data); + Bus(const ModelDataT& data); virtual ~Bus(); virtual int setBusID(IdxT) override final; diff --git a/GridKit/Model/PhasorDynamics/Bus/BusData.hpp b/GridKit/Model/PhasorDynamics/Bus/BusData.hpp index f1c15ef3b..d78e39ec0 100644 --- a/GridKit/Model/PhasorDynamics/Bus/BusData.hpp +++ b/GridKit/Model/PhasorDynamics/Bus/BusData.hpp @@ -27,16 +27,19 @@ namespace GridKit /** * @brief Contains modeling data for a Bus * - * @tparam RealT Real parameter data type - * @tparam IdxT Integer parameter data type + * @tparam real_type Real parameter data type + * @tparam index_type Integer parameter data type * * Integer parameters are of the same type as matrix and vector indices. * * @todo Decide on naming scheme for model parameters. */ - template + template struct BusData { + using RealT = real_type; + using IdxT = index_type; + std::string name; ///< A name given to this bus RealT Vr0{1.0}; ///< Initial value for the real bus voltage diff --git a/GridKit/Model/PhasorDynamics/Bus/BusDependencyTracking.cpp b/GridKit/Model/PhasorDynamics/Bus/BusDependencyTracking.cpp index fe116cf7c..93745aded 100644 --- a/GridKit/Model/PhasorDynamics/Bus/BusDependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/Bus/BusDependencyTracking.cpp @@ -8,12 +8,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented * - * @tparam ScalarT - data type for Jacobian elements - * @tparam IdxT - data type for matrix indices * @return int - error code */ - template - int Bus::evaluateJacobian() + template + int Bus::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Bus..." << std::endl; Log::misc() << "Jacobian evaluation is not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Bus/BusEnzyme.cpp b/GridKit/Model/PhasorDynamics/Bus/BusEnzyme.cpp index a315622c2..1a99a11b6 100644 --- a/GridKit/Model/PhasorDynamics/Bus/BusEnzyme.cpp +++ b/GridKit/Model/PhasorDynamics/Bus/BusEnzyme.cpp @@ -17,12 +17,10 @@ namespace GridKit * @warning This implementation assumes bus Jacobians are always evaluated * _before_ component model Jacobians. * - * @tparam ScalarT - data type for Jacobian elements - * @tparam IdxT - data type for matrix indices * @return int - error code */ - template - int Bus::evaluateJacobian() + template + int Bus::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Bus..." << std::endl; Log::misc() << "Jacobian evaluation is experimental!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Bus/BusFactory.hpp b/GridKit/Model/PhasorDynamics/Bus/BusFactory.hpp index c9898a5d2..f8511db93 100644 --- a/GridKit/Model/PhasorDynamics/Bus/BusFactory.hpp +++ b/GridKit/Model/PhasorDynamics/Bus/BusFactory.hpp @@ -9,10 +9,12 @@ namespace GridKit { namespace PhasorDynamics { - template + template class BusFactory { public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename Model::Evaluator::RealT; using BusData = GridKit::PhasorDynamics::BusData; using BusTypeT = typename GridKit::PhasorDynamics::BusData::BusType; diff --git a/GridKit/Model/PhasorDynamics/Bus/BusImpl.hpp b/GridKit/Model/PhasorDynamics/Bus/BusImpl.hpp index 77fe6ecf0..f5a18aa01 100644 --- a/GridKit/Model/PhasorDynamics/Bus/BusImpl.hpp +++ b/GridKit/Model/PhasorDynamics/Bus/BusImpl.hpp @@ -22,8 +22,8 @@ namespace GridKit * - Number of quadratures = 0 * - Number of optimization parameters = 0 */ - template - Bus::Bus() + template + Bus::Bus() : Vr0_(0.0), Vi0_(0.0) { size_ = 2; @@ -40,8 +40,8 @@ namespace GridKit * - Number of quadratures = 0 * - Number of optimization parameters = 0 */ - template - Bus::Bus(ScalarT Vr, ScalarT Vi) + template + Bus::Bus(ScalarT Vr, ScalarT Vi) : Vr0_(Vr), Vi0_(Vi) { size_ = 2; @@ -50,12 +50,10 @@ namespace GridKit /** * @brief Construct a new Bus * - * @tparam ScalarT - type of scalar variables - * @tparam IdxT - type for vector/matrix indices * @param[in] data - structure with bus data */ - template - Bus::Bus(const DataT& data) + template + Bus::Bus(const ModelDataT& data) : BusBase(data), Vr0_(data.Vr0), Vi0_(data.Vi0) @@ -66,8 +64,8 @@ namespace GridKit size_ = 2; } - template - Bus::~Bus() + template + Bus::~Bus() { // std::cout << "Destroy PQ bus ..." << std::endl; } @@ -75,8 +73,8 @@ namespace GridKit /*! * @brief allocate method resizes local solution and residual vectors. */ - template - int Bus::allocate() + template + int Bus::allocate() { // Temporary while we use std::vector in the code size_t size = static_cast(size_); @@ -102,8 +100,8 @@ namespace GridKit /** * @brief Set the bus ID */ - template - int Bus::setBusID(IdxT bus_id) + template + int Bus::setBusID(IdxT bus_id) { bus_id_ = bus_id; return 0; @@ -112,8 +110,8 @@ namespace GridKit /*! * @brief Bus variables are algebraic. */ - template - int Bus::tagDifferentiable() + template + int Bus::tagDifferentiable() { tag_[0] = false; tag_[1] = false; @@ -123,8 +121,8 @@ namespace GridKit /*! * @brief initialize method sets bus variables to stored initial values. */ - template - int Bus::initialize() + template + int Bus::initialize() { // std::cout << "Initialize Bus..." << std::endl; y_[0] = Vr0_; @@ -142,8 +140,8 @@ namespace GridKit * _before_ component model residuals. * */ - template - int Bus::evaluateResidual() + template + int Bus::evaluateResidual() { // std::cout << "Evaluating residual of a PQ bus ...\n"; f_[0] = 0.0; diff --git a/GridKit/Model/PhasorDynamics/Bus/BusInfinite.hpp b/GridKit/Model/PhasorDynamics/Bus/BusInfinite.hpp index 9f9866994..c398de501 100644 --- a/GridKit/Model/PhasorDynamics/Bus/BusInfinite.hpp +++ b/GridKit/Model/PhasorDynamics/Bus/BusInfinite.hpp @@ -13,26 +13,28 @@ namespace GridKit * * */ - template - class BusInfinite : public BusBase + template + class BusInfinite : public BusBase { - using BusBase::bus_id_; - using BusBase::size_; - using BusBase::y_; - using BusBase::yp_; - using BusBase::f_; - using BusBase::J_; - using BusBase::variable_indices_; - using BusBase::residual_indices_; + using BusBase::bus_id_; + using BusBase::size_; + using BusBase::y_; + using BusBase::yp_; + using BusBase::f_; + using BusBase::J_; + using BusBase::variable_indices_; + using BusBase::residual_indices_; public: - using RealT = typename BusBase::RealT; - using DataT = BusData; - using BusTypeT = typename BusData::BusType; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename BusBase::RealT; + using ModelDataT = BusData; + using BusTypeT = typename BusData::BusType; BusInfinite(); BusInfinite(ScalarT Vr, ScalarT Vi); - BusInfinite(const DataT& data); + BusInfinite(const ModelDataT& data); virtual ~BusInfinite(); virtual int setBusID(IdxT) override final; diff --git a/GridKit/Model/PhasorDynamics/Bus/BusInfiniteImpl.hpp b/GridKit/Model/PhasorDynamics/Bus/BusInfiniteImpl.hpp index 56d05d82a..86381b826 100644 --- a/GridKit/Model/PhasorDynamics/Bus/BusInfiniteImpl.hpp +++ b/GridKit/Model/PhasorDynamics/Bus/BusInfiniteImpl.hpp @@ -20,8 +20,8 @@ namespace GridKit * - Number of equations = 0 (size_) * - Number of variables = 0 (size_) */ - template - BusInfinite::BusInfinite() + template + BusInfinite::BusInfinite() { size_ = 0; } @@ -35,8 +35,8 @@ namespace GridKit * - Number of equations = 0 (size_) * - Number of variables = 0 (size_) */ - template - BusInfinite::BusInfinite(ScalarT Vr, ScalarT Vi) + template + BusInfinite::BusInfinite(ScalarT Vr, ScalarT Vi) : Vr_(Vr), Vi_(Vi) { size_ = 0; @@ -49,12 +49,10 @@ namespace GridKit * - Number of equations = 0 (size_) * - Number of variables = 0 (size_) - * @tparam ScalarT - type of scalar variables - * @tparam IdxT - type for vector/matrix indices * @param[in] data - structure with bus data */ - template - BusInfinite::BusInfinite(const DataT& data) + template + BusInfinite::BusInfinite(const ModelDataT& data) : BusBase(data), Vr_(data.Vr0), Vi_(data.Vi0) @@ -62,16 +60,16 @@ namespace GridKit size_ = 0; } - template - BusInfinite::~BusInfinite() + template + BusInfinite::~BusInfinite() { } /** * @brief Set the bus ID */ - template - int BusInfinite::setBusID(IdxT bus_id) + template + int BusInfinite::setBusID(IdxT bus_id) { bus_id_ = bus_id; return 0; @@ -80,8 +78,8 @@ namespace GridKit /*! * @brief allocate method resizes local solution and residual vectors. */ - template - int BusInfinite::allocate() + template + int BusInfinite::allocate() { return 0; } @@ -89,8 +87,8 @@ namespace GridKit /** * @brief Tag differentiable variables */ - template - int BusInfinite::tagDifferentiable() + template + int BusInfinite::tagDifferentiable() { return 0; } @@ -98,8 +96,8 @@ namespace GridKit /*! * @brief initialize method sets bus variables to stored initial values. */ - template - int BusInfinite::initialize() + template + int BusInfinite::initialize() { return 0; } @@ -116,8 +114,8 @@ namespace GridKit * _before_ component model residuals. * */ - template - int BusInfinite::evaluateResidual() + template + int BusInfinite::evaluateResidual() { Ir_ = 0.0; Ii_ = 0.0; @@ -127,12 +125,10 @@ namespace GridKit /** * @brief There is no Jacobian for slack variables * - * @tparam ScalarT - data type for Jacobian elements - * @tparam IdxT - data type for matrix indices * @return int - error code */ - template - int BusInfinite::evaluateJacobian() + template + int BusInfinite::evaluateJacobian() { return 0; } diff --git a/GridKit/Model/PhasorDynamics/BusBase.hpp b/GridKit/Model/PhasorDynamics/BusBase.hpp index ce37eaf9e..714c53946 100644 --- a/GridKit/Model/PhasorDynamics/BusBase.hpp +++ b/GridKit/Model/PhasorDynamics/BusBase.hpp @@ -21,10 +21,12 @@ namespace GridKit * @brief BusBase model implementation base class. * */ - template - class BusBase : public GridElement + template + class BusBase : public GridElement { public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename GridElement::RealT; using MatrixT = typename GridElement::MatrixT; using BusTypeT = typename BusData::BusType; diff --git a/GridKit/Model/PhasorDynamics/BusBaseImpl.hpp b/GridKit/Model/PhasorDynamics/BusBaseImpl.hpp index aa06537a9..1a2edad7a 100644 --- a/GridKit/Model/PhasorDynamics/BusBaseImpl.hpp +++ b/GridKit/Model/PhasorDynamics/BusBaseImpl.hpp @@ -7,8 +7,8 @@ namespace GridKit { namespace PhasorDynamics { - template - BusBase::BusBase(const BusData& data) + template + BusBase::BusBase(const BusData& data) : bus_id_(data.bus_id), monitor_(std::make_unique("Bus_" + data.name, data.monitored_variables)) { @@ -23,13 +23,13 @@ namespace GridKit { return std::atan2(Vi(), Vr()); }); } - template - BusBase::~BusBase() + template + BusBase::~BusBase() { } - template - inline const Model::VariableMonitorBase* BusBase::getMonitor() const + template + inline const Model::VariableMonitorBase* BusBase::getMonitor() const { return monitor_.get(); } diff --git a/GridKit/Model/PhasorDynamics/BusFault/BusFault.cpp b/GridKit/Model/PhasorDynamics/BusFault/BusFault.cpp index 9f8124c53..3498fd062 100644 --- a/GridKit/Model/PhasorDynamics/BusFault/BusFault.cpp +++ b/GridKit/Model/PhasorDynamics/BusFault/BusFault.cpp @@ -15,12 +15,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented yet * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int BusFault::evaluateJacobian() + template + int BusFault::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for BusFault..." << std::endl; Log::misc() << "Jacobian evaluation not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/BusFault/BusFault.hpp b/GridKit/Model/PhasorDynamics/BusFault/BusFault.hpp index ba0d4784f..3b559fd1b 100644 --- a/GridKit/Model/PhasorDynamics/BusFault/BusFault.hpp +++ b/GridKit/Model/PhasorDynamics/BusFault/BusFault.hpp @@ -11,7 +11,7 @@ namespace GridKit { namespace PhasorDynamics { - template + template struct BusFaultData; } } // namespace GridKit @@ -20,32 +20,34 @@ namespace GridKit { namespace PhasorDynamics { - template - class BusFault : public Component + template + class BusFault : public Component { - using Component::gridkit_component_id_; - using Component::alpha_; - using Component::nnz_; - using Component::size_; - using Component::tag_; - using Component::time_; - using Component::y_; - using Component::yp_; - using Component::wb_; - using Component::h_; - using Component::J_rows_buffer_; - using Component::J_cols_buffer_; - using Component::J_vals_buffer_; + using Component::gridkit_component_id_; + using Component::alpha_; + using Component::nnz_; + using Component::size_; + using Component::tag_; + using Component::time_; + using Component::y_; + using Component::yp_; + using Component::wb_; + using Component::h_; + using Component::J_rows_buffer_; + using Component::J_cols_buffer_; + using Component::J_vals_buffer_; public: - using bus_type = BusBase; - using RealT = typename Component::RealT; - using DataT = BusFaultData; - using MonitorT = Model::VariableMonitor; - - BusFault(bus_type* bus); - BusFault(bus_type* bus, RealT R, RealT X, int status); - BusFault(bus_type* bus, const DataT& data); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename Component::RealT; + using BusT = BusBase; + using ModelDataT = BusFaultData; + using MonitorT = Model::VariableMonitor; + + BusFault(BusT* bus); + BusFault(BusT* bus, RealT R, RealT X, int status); + BusFault(BusT* bus, const ModelDataT& data); ~BusFault(); int setGridKitComponentID(IdxT) override final; @@ -111,11 +113,11 @@ namespace GridKit __attribute__((always_inline)) inline int evaluateBusResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*); private: - bus_type* bus_; - RealT R_{0.0}; - RealT X_{0.0}; - bool status_{false}; - IdxT bus_id_{0}; + BusT* bus_; + RealT R_{0.0}; + RealT X_{0.0}; + bool status_{false}; + IdxT bus_id_{0}; /* Derivied parameters */ RealT B_; diff --git a/GridKit/Model/PhasorDynamics/BusFault/BusFaultData.hpp b/GridKit/Model/PhasorDynamics/BusFault/BusFaultData.hpp index 4ace959f5..c4042f990 100644 --- a/GridKit/Model/PhasorDynamics/BusFault/BusFaultData.hpp +++ b/GridKit/Model/PhasorDynamics/BusFault/BusFaultData.hpp @@ -38,14 +38,14 @@ namespace GridKit /** * @brief Contains modeling data for a short-to-ground fault * - * @tparam RealT Real parameter data type - * @tparam IdxT Integer parameter data type + * @tparam real_type Real parameter data type + * @tparam index_type Integer parameter data type * * Integer parameters are of the same type as matrix and vector indices. */ - template - struct BusFaultData : public ComponentData + struct BusFaultData : public ComponentData diff --git a/GridKit/Model/PhasorDynamics/BusFault/BusFaultDependencyTracking.cpp b/GridKit/Model/PhasorDynamics/BusFault/BusFaultDependencyTracking.cpp index 6dc1173cb..097a97d14 100644 --- a/GridKit/Model/PhasorDynamics/BusFault/BusFaultDependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/BusFault/BusFaultDependencyTracking.cpp @@ -7,12 +7,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented yet * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int BusFault::evaluateJacobian() + template + int BusFault::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for BusFault..." << std::endl; Log::misc() << "Jacobian evaluation not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/BusFault/BusFaultEnzyme.cpp b/GridKit/Model/PhasorDynamics/BusFault/BusFaultEnzyme.cpp index d607ead65..9d3c45854 100644 --- a/GridKit/Model/PhasorDynamics/BusFault/BusFaultEnzyme.cpp +++ b/GridKit/Model/PhasorDynamics/BusFault/BusFaultEnzyme.cpp @@ -15,12 +15,10 @@ namespace GridKit /** * @brief Jacobian evaluation experimental * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int BusFault::evaluateJacobian() + template + int BusFault::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for BusFault..." << std::endl; Log::misc() << "Jacobian evaluation is experimental!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/BusFault/BusFaultImpl.hpp b/GridKit/Model/PhasorDynamics/BusFault/BusFaultImpl.hpp index 97761a533..8c1212d4a 100644 --- a/GridKit/Model/PhasorDynamics/BusFault/BusFaultImpl.hpp +++ b/GridKit/Model/PhasorDynamics/BusFault/BusFaultImpl.hpp @@ -19,8 +19,8 @@ namespace GridKit * - Number of equations = 0 * - Number of independent variables = 0 */ - template - BusFault::BusFault(bus_type* bus) + template + BusFault::BusFault(BusT* bus) : bus_(bus), R_(0), X_(0.01), status_(0), bus_id_(0) { (void) bus_id_; @@ -31,8 +31,6 @@ namespace GridKit /** * @brief Construct a new BusFault * - * @tparam ScalarT - scalar type - * @tparam IdxT - matrix/vector index type * @param bus1 - pointer to bus-1 * @param bus2 - pointer to bus-2 * @param R - line series resistance @@ -40,8 +38,8 @@ namespace GridKit * @param G - line shunt conductance * @param B - line shunt charging */ - template - BusFault::BusFault(bus_type* bus, RealT R, RealT X, int status) + template + BusFault::BusFault(BusT* bus, RealT R, RealT X, int status) : bus_(bus), R_(R), X_(X), status_(status), bus_id_(0) { size_ = 0; @@ -51,37 +49,35 @@ namespace GridKit /** * @brief Construct a new BusFault * - * @tparam ScalarT - scalar type - * @tparam IdxT - matrix/vector index type * @param bus1 - pointer to bus-1 * @param bus2 - pointer to bus-2 */ - template - BusFault::BusFault(bus_type* bus, const DataT& data) + template + BusFault::BusFault(BusT* bus, const ModelDataT& data) : bus_(bus), monitor_(std::make_unique(data)) { - if (data.parameters.contains(DataT::Parameters::R)) + if (data.parameters.contains(ModelDataT::Parameters::R)) { - R_ = std::get(data.parameters.at(DataT::Parameters::R)); + R_ = std::get(data.parameters.at(ModelDataT::Parameters::R)); } - if (data.parameters.contains(DataT::Parameters::X)) + if (data.parameters.contains(ModelDataT::Parameters::X)) { - X_ = std::get(data.parameters.at(DataT::Parameters::X)); + X_ = std::get(data.parameters.at(ModelDataT::Parameters::X)); } - if (data.parameters.contains(DataT::Parameters::state0)) + if (data.parameters.contains(ModelDataT::Parameters::state0)) { - status_ = std::get(data.parameters.at(DataT::Parameters::state0)); + status_ = std::get(data.parameters.at(ModelDataT::Parameters::state0)); } - if (data.ports.contains(DataT::Ports::bus)) + if (data.ports.contains(ModelDataT::Ports::bus)) { - bus_id_ = data.ports.at(DataT::Ports::bus); + bus_id_ = data.ports.at(ModelDataT::Ports::bus); } - using Variable = typename DataT::MonitorableVariables; + using Variable = typename ModelDataT::MonitorableVariables; monitor_->set(Variable::state, [this] { return status_; }); monitor_->set(Variable::ir, [this] @@ -93,16 +89,16 @@ namespace GridKit setDerivedParams(); } - template - BusFault::~BusFault() + template + BusFault::~BusFault() { } /** * @brief Set the component ID */ - template - int BusFault::setGridKitComponentID(IdxT component_id) + template + int BusFault::setGridKitComponentID(IdxT component_id) { gridkit_component_id_ = component_id; return 0; @@ -111,8 +107,8 @@ namespace GridKit /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int BusFault::allocate() + template + int BusFault::allocate() { // std::cout << "Allocate BusFault..." << std::endl; @@ -126,8 +122,8 @@ namespace GridKit * Initialization of the branch model * */ - template - int BusFault::initialize() + template + int BusFault::initialize() { return 0; } @@ -135,8 +131,8 @@ namespace GridKit /** * \brief Identify differential variables. */ - template - int BusFault::tagDifferentiable() + template + int BusFault::tagDifferentiable() { return 0; } @@ -145,8 +141,8 @@ namespace GridKit * @brief Bus residual * */ - template - __attribute__((always_inline)) int BusFault::evaluateBusResidual( + template + __attribute__((always_inline)) int BusFault::evaluateBusResidual( [[maybe_unused]] ScalarT* y, [[maybe_unused]] ScalarT* yp, ScalarT* wb, ScalarT* h) { ScalarT Vr = wb[0]; @@ -164,8 +160,8 @@ namespace GridKit * two terminal buses. * */ - template - int BusFault::evaluateResidual() + template + int BusFault::evaluateResidual() { if (status_) { @@ -178,8 +174,8 @@ namespace GridKit return 0; } - template - const Model::VariableMonitorBase* BusFault::getMonitor() const + template + const Model::VariableMonitorBase* BusFault::getMonitor() const { return monitor_.get(); } @@ -188,8 +184,8 @@ namespace GridKit * @brief Derived parameters * */ - template - void BusFault::setDerivedParams() + template + void BusFault::setDerivedParams() { B_ = -X_ / (X_ * X_ + R_ * R_); G_ = R_ / (X_ * X_ + R_ * R_); diff --git a/GridKit/Model/PhasorDynamics/ComponentData.hpp b/GridKit/Model/PhasorDynamics/ComponentData.hpp index c6f83559a..9e15f0eb8 100644 --- a/GridKit/Model/PhasorDynamics/ComponentData.hpp +++ b/GridKit/Model/PhasorDynamics/ComponentData.hpp @@ -14,11 +14,11 @@ namespace GridKit /** * @brief Unified interface for `Component` data containers * - * @tparam RealT Real parameter data type - * @tparam IdxT Integer parameter data type + * @tparam real_type Real parameter data type + * @tparam index_type Integer parameter data type */ - template @@ -27,6 +27,11 @@ namespace GridKit && std::is_enum_v struct ComponentData { + /// Real value type + using RealT = real_type; + /// Index type + using IdxT = index_type; + /// Class of device this is for std::string device_class; diff --git a/GridKit/Model/PhasorDynamics/ComponentSignals.hpp b/GridKit/Model/PhasorDynamics/ComponentSignals.hpp index cebe9167c..827181346 100644 --- a/GridKit/Model/PhasorDynamics/ComponentSignals.hpp +++ b/GridKit/Model/PhasorDynamics/ComponentSignals.hpp @@ -31,8 +31,8 @@ namespace GridKit /// This is used by adding an instance in a field to your class and /// exposing this field to others /// - /// @tparam ScalarT Scalar value type - /// @tparam IdxT Index type + /// @tparam scalar_type Scalar value type + /// @tparam index_type Index type /// @tparam InternalVariables An enumeration satisfying /// `EnumHasMaximumValueAndIsSizeT` enumerating internal variables /// for the component @@ -43,12 +43,17 @@ namespace GridKit /// integer value of the enum /// @invariant ExternalVariables::MAXIMUM is the greatest attainable /// integer value of the enum - template + template requires EnumHasMaximumValueAndIsSizeT && EnumHasMaximumValueAndIsSizeT class ComponentSignals { public: + /// Scalar value type + using ScalarT = scalar_type; + /// Index type + using IdxT = index_type; + /// Attaches a signal node to an external variable on this component /// /// @tparam variable The external variable to attach the provided diff --git a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1.cpp b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1.cpp index da21cd779..181ea4920 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1.cpp +++ b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1.cpp @@ -18,12 +18,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented yet * - * @tparam ScalarT - Scalar data type - * @tparam IdxT - Index data type * @return int - error code, 0 = success */ - template - int Ieeet1::evaluateJacobian() + template + int Ieeet1::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Ieeet1..." << std::endl; Log::misc() << "Jacobian evaluation not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1.hpp b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1.hpp index 507ee52b1..add41ad66 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1.hpp +++ b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1.hpp @@ -20,14 +20,14 @@ namespace GridKit { namespace Exciter { - template + template struct Ieeet1Data; } // namespace Exciter - template + template class BusBase; - template + template class SignalNode; } // namespace PhasorDynamics @@ -64,40 +64,42 @@ namespace GridKit MAXIMUM, }; - template - class Ieeet1 : public Component + template + class Ieeet1 : public Component { - using Component::gridkit_component_id_; - using Component::alpha_; - using Component::f_; - using Component::nnz_; - using Component::size_; - using Component::tag_; - using Component::time_; - using Component::y_; - using Component::yp_; - using Component::wb_; - using Component::J_; - using Component::J_rows_buffer_; - using Component::J_cols_buffer_; - using Component::J_vals_buffer_; - using Component::variable_indices_; - using Component::residual_indices_; + using Component::gridkit_component_id_; + using Component::alpha_; + using Component::f_; + using Component::nnz_; + using Component::size_; + using Component::tag_; + using Component::time_; + using Component::y_; + using Component::yp_; + using Component::wb_; + using Component::J_; + using Component::J_rows_buffer_; + using Component::J_cols_buffer_; + using Component::J_vals_buffer_; + using Component::variable_indices_; + using Component::residual_indices_; public: - using RealT = typename Component::RealT; - using model_data_type = Ieeet1Data; - using signal_type = SignalNode; - using bus_type = BusBase; - using MonitorT = Model::VariableMonitor; - - Ieeet1(bus_type* bus); - Ieeet1(signal_type* efd_signal, - signal_type* speed_signal, - bus_type* bus, - const model_data_type& data); - Ieeet1(bus_type* bus, - const model_data_type& data); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename Component::RealT; + using BusT = BusBase; + using ModelDataT = Ieeet1Data; + using SignalT = SignalNode; + using MonitorT = Model::VariableMonitor; + + Ieeet1(BusT* bus); + Ieeet1(SignalT* efd_signal, + SignalT* speed_signal, + BusT* bus, + const ModelDataT& data); + Ieeet1(BusT* bus, + const ModelDataT& data); ~Ieeet1(); int setGridKitComponentID(IdxT) override final; @@ -124,9 +126,9 @@ namespace GridKit private: // Signal pointers - signal_type* efd_signal_; - signal_type* speed_signal_; - bus_type* bus_; + SignalT* efd_signal_; + SignalT* speed_signal_; + BusT* bus_; // Model Input parameters RealT Tr_; ///< Time constant for voltage sensing @@ -164,7 +166,7 @@ namespace GridKit std::unique_ptr monitor_; // Parameter initialization function - void initModelParams(const model_data_type& data); + void initModelParams(const ModelDataT& data); /// Associate variable getter functions with enum values void initializeMonitor(); diff --git a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Data.hpp b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Data.hpp index 99d0febc5..0fdfe9874 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Data.hpp +++ b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Data.hpp @@ -53,14 +53,14 @@ namespace GridKit /** * @brief Contains modeling data for a IEEET1 Exciter model. * - * @tparam RealT Real parameter data type - * @tparam IdxT Integer parameter data type + * @tparam real_type Real parameter data type + * @tparam index_type Integer parameter data type * * Integer parameters are of the same type as matrix and vector indices. */ - template - struct Ieeet1Data : public ComponentData + struct Ieeet1Data : public ComponentData diff --git a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1DependencyTracking.cpp b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1DependencyTracking.cpp index 9346fabb3..6638f952b 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1DependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1DependencyTracking.cpp @@ -18,12 +18,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented yet * - * @tparam ScalarT - Scalar data type - * @tparam IdxT - Index data type * @return int - error code, 0 = success */ - template - int Ieeet1::evaluateJacobian() + template + int Ieeet1::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Ieeet1..." << std::endl; Log::misc() << "Jacobian evaluation not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Enzyme.cpp b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Enzyme.cpp index 9bb4496d6..31ef04039 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Enzyme.cpp +++ b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Enzyme.cpp @@ -17,12 +17,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented yet * - * @tparam ScalarT - Scalar data type - * @tparam IdxT - Index data type * @return int - error code, 0 = success */ - template - int Ieeet1::evaluateJacobian() + template + int Ieeet1::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Ieeet1..." << std::endl; Log::misc() << "Jacobian evaluation is experimental!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Impl.hpp b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Impl.hpp index e2fa7dab5..688e1574a 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Impl.hpp +++ b/GridKit/Model/PhasorDynamics/Exciter/IEEET1/Ieeet1Impl.hpp @@ -29,12 +29,9 @@ namespace GridKit /** * @brief Constructor for IEEET1 Exciter - * - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - Ieeet1::Ieeet1(bus_type* bus) + template + Ieeet1::Ieeet1(BusT* bus) : bus_(bus) { size_ = 9; @@ -47,14 +44,12 @@ namespace GridKit * @param bus Signal used for terminal reference vmag * @param speed Signal used for machine relative speed * @param efd Signal used for E field - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - Ieeet1::Ieeet1(signal_type* efd_signal, - signal_type* speed_signal, - bus_type* bus, - const model_data_type& data) + template + Ieeet1::Ieeet1(SignalT* efd_signal, + SignalT* speed_signal, + BusT* bus, + const ModelDataT& data) : efd_signal_(efd_signal), speed_signal_(speed_signal), bus_(bus), @@ -75,12 +70,10 @@ namespace GridKit * * @param bus Signal used for terminal reference vmag * @param data Data object to store parameters - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type */ - template - Ieeet1::Ieeet1(bus_type* bus, - const model_data_type& data) + template + Ieeet1::Ieeet1(BusT* bus, + const ModelDataT& data) : bus_(bus), monitor_(std::make_unique(data)) { @@ -94,16 +87,16 @@ namespace GridKit size_ = 9; } - template - Ieeet1::~Ieeet1() + template + Ieeet1::~Ieeet1() { } /** * @brief Set the component ID */ - template - int Ieeet1::setGridKitComponentID(IdxT component_id) + template + int Ieeet1::setGridKitComponentID(IdxT component_id) { gridkit_component_id_ = component_id; return 0; @@ -113,8 +106,8 @@ namespace GridKit * @brief Allocate memory for model * */ - template - int Ieeet1::allocate() + template + int Ieeet1::allocate() { // Resize component model data auto size = static_cast(size_); // avoid compiler warnings @@ -155,8 +148,8 @@ namespace GridKit /** * @brief verify method checks that attached signals are also linked */ - template - int Ieeet1::verify() const + template + int Ieeet1::verify() const { static constexpr auto OMEGA = Ieeet1ExternalVariables::OMEGA; static constexpr auto VS = Ieeet1ExternalVariables::VS; @@ -197,8 +190,8 @@ namespace GridKit * * Saturation is included via ksat computed from efdp and SA, SB. */ - template - int Ieeet1::initialize() + template + int Ieeet1::initialize() { // External Variables @@ -263,12 +256,10 @@ namespace GridKit /** * @brief Identify differential variables. * - * @tparam ScalarT Scalar data type - * @tparam IdxT Index data type * @return int 0 */ - template - int Ieeet1::tagDifferentiable() + template + int Ieeet1::tagDifferentiable() { tag_[0] = true; // y0 - vts - Sensed term volt @@ -288,8 +279,8 @@ namespace GridKit * @brief Internal Residual * */ - template - __attribute__((always_inline)) inline int Ieeet1::evaluateInternalResidual( + template + __attribute__((always_inline)) inline int Ieeet1::evaluateInternalResidual( ScalarT* y, ScalarT* yp, ScalarT* wb, @@ -349,8 +340,8 @@ namespace GridKit * @brief Residual evaluation * */ - template - int Ieeet1::evaluateResidual() + template + int Ieeet1::evaluateResidual() { // Set Input Variables // Meta PR Note: This seems to be very slow, @@ -389,65 +380,65 @@ namespace GridKit /** * @brief Initialization Exciter Parameters from data structure */ - template - void Ieeet1::initModelParams(const model_data_type& data) + template + void Ieeet1::initModelParams(const ModelDataT& data) { - if (data.parameters.contains(model_data_type::Parameters::Tr)) + if (data.parameters.contains(ModelDataT::Parameters::Tr)) { - Tr_ = std::get(data.parameters.at(model_data_type::Parameters::Tr)); + Tr_ = std::get(data.parameters.at(ModelDataT::Parameters::Tr)); } - if (data.parameters.contains(model_data_type::Parameters::Ka)) + if (data.parameters.contains(ModelDataT::Parameters::Ka)) { - Ka_ = std::get(data.parameters.at(model_data_type::Parameters::Ka)); + Ka_ = std::get(data.parameters.at(ModelDataT::Parameters::Ka)); } - if (data.parameters.contains(model_data_type::Parameters::Ta)) + if (data.parameters.contains(ModelDataT::Parameters::Ta)) { - Ta_ = std::get(data.parameters.at(model_data_type::Parameters::Ta)); + Ta_ = std::get(data.parameters.at(ModelDataT::Parameters::Ta)); } - if (data.parameters.contains(model_data_type::Parameters::Ke)) + if (data.parameters.contains(ModelDataT::Parameters::Ke)) { - Ke_ = std::get(data.parameters.at(model_data_type::Parameters::Ke)); + Ke_ = std::get(data.parameters.at(ModelDataT::Parameters::Ke)); } - if (data.parameters.contains(model_data_type::Parameters::Te)) + if (data.parameters.contains(ModelDataT::Parameters::Te)) { - Te_ = std::get(data.parameters.at(model_data_type::Parameters::Te)); + Te_ = std::get(data.parameters.at(ModelDataT::Parameters::Te)); } - if (data.parameters.contains(model_data_type::Parameters::Kf)) + if (data.parameters.contains(ModelDataT::Parameters::Kf)) { - Kf_ = std::get(data.parameters.at(model_data_type::Parameters::Kf)); + Kf_ = std::get(data.parameters.at(ModelDataT::Parameters::Kf)); } - if (data.parameters.contains(model_data_type::Parameters::Tf)) + if (data.parameters.contains(ModelDataT::Parameters::Tf)) { - Tf_ = std::get(data.parameters.at(model_data_type::Parameters::Tf)); + Tf_ = std::get(data.parameters.at(ModelDataT::Parameters::Tf)); } - if (data.parameters.contains(model_data_type::Parameters::Vrmin)) + if (data.parameters.contains(ModelDataT::Parameters::Vrmin)) { - Vrmin_ = std::get(data.parameters.at(model_data_type::Parameters::Vrmin)); + Vrmin_ = std::get(data.parameters.at(ModelDataT::Parameters::Vrmin)); } - if (data.parameters.contains(model_data_type::Parameters::Vrmax)) + if (data.parameters.contains(ModelDataT::Parameters::Vrmax)) { - Vrmax_ = std::get(data.parameters.at(model_data_type::Parameters::Vrmax)); + Vrmax_ = std::get(data.parameters.at(ModelDataT::Parameters::Vrmax)); } - if (data.parameters.contains(model_data_type::Parameters::E1)) + if (data.parameters.contains(ModelDataT::Parameters::E1)) { - E1_ = std::get(data.parameters.at(model_data_type::Parameters::E1)); + E1_ = std::get(data.parameters.at(ModelDataT::Parameters::E1)); } - if (data.parameters.contains(model_data_type::Parameters::E2)) + if (data.parameters.contains(ModelDataT::Parameters::E2)) { - E2_ = std::get(data.parameters.at(model_data_type::Parameters::E2)); + E2_ = std::get(data.parameters.at(ModelDataT::Parameters::E2)); } - if (data.parameters.contains(model_data_type::Parameters::Se1)) + if (data.parameters.contains(ModelDataT::Parameters::Se1)) { - Se1_ = std::get(data.parameters.at(model_data_type::Parameters::Se1)); + Se1_ = std::get(data.parameters.at(ModelDataT::Parameters::Se1)); } - if (data.parameters.contains(model_data_type::Parameters::Se2)) + if (data.parameters.contains(ModelDataT::Parameters::Se2)) { - Se2_ = std::get(data.parameters.at(model_data_type::Parameters::Se2)); + Se2_ = std::get(data.parameters.at(ModelDataT::Parameters::Se2)); } - if (data.parameters.contains(model_data_type::Parameters::Ispdlim)) + if (data.parameters.contains(ModelDataT::Parameters::Ispdlim)) { - Ispdlim_ = std::get(data.parameters.at(model_data_type::Parameters::Ispdlim)); + Ispdlim_ = std::get(data.parameters.at(ModelDataT::Parameters::Ispdlim)); } // Derived Parameters @@ -458,16 +449,16 @@ namespace GridKit SB_ = Se1_ / (E1_ - SA_) / (E1_ - SA_); } - template - const Model::VariableMonitorBase* Ieeet1::getMonitor() const + template + const Model::VariableMonitorBase* Ieeet1::getMonitor() const { return monitor_.get(); } - template - void Ieeet1::initializeMonitor() + template + void Ieeet1::initializeMonitor() { - using Variable = model_data_type::MonitorableVariables; + using Variable = ModelDataT::MonitorableVariables; monitor_->set(Variable::efd, [this] { return efd_signal_->read(); }); monitor_->set(Variable::ksat, [this] diff --git a/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPti.cpp b/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPti.cpp index 6bcd4ace6..9daaa0a36 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPti.cpp +++ b/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPti.cpp @@ -12,8 +12,8 @@ namespace GridKit { namespace Exciter { - template - int SexsPti::evaluateJacobian() + template + int SexsPti::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for SexsPti..." << std::endl; Log::misc() << "Jacobian evaluation not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPti.hpp b/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPti.hpp index 87c143070..8f169a3d0 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPti.hpp +++ b/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPti.hpp @@ -16,14 +16,14 @@ namespace GridKit { namespace Exciter { - template + template struct SexsPtiData; } // namespace Exciter - template + template class BusBase; - template + template class SignalNode; } // namespace PhasorDynamics @@ -51,35 +51,37 @@ namespace GridKit MAXIMUM, }; - template - class SexsPti : public Component + template + class SexsPti : public Component { - using Component::gridkit_component_id_; - using Component::alpha_; - using Component::f_; - using Component::nnz_; - using Component::size_; - using Component::tag_; - using Component::time_; - using Component::y_; - using Component::yp_; - using Component::wb_; - using Component::J_; - using Component::J_rows_buffer_; - using Component::J_cols_buffer_; - using Component::J_vals_buffer_; - using Component::variable_indices_; - using Component::residual_indices_; + using Component::gridkit_component_id_; + using Component::alpha_; + using Component::f_; + using Component::nnz_; + using Component::size_; + using Component::tag_; + using Component::time_; + using Component::y_; + using Component::yp_; + using Component::wb_; + using Component::J_; + using Component::J_rows_buffer_; + using Component::J_cols_buffer_; + using Component::J_vals_buffer_; + using Component::variable_indices_; + using Component::residual_indices_; public: - using RealT = typename Component::RealT; - using model_data_type = SexsPtiData; - using signal_type = SignalNode; - using bus_type = BusBase; - using MonitorT = Model::VariableMonitor; - - SexsPti(bus_type* bus); - SexsPti(bus_type* bus, const model_data_type& data); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename Component::RealT; + using BusT = BusBase; + using ModelDataT = SexsPtiData; + using SignalT = SignalNode; + using MonitorT = Model::VariableMonitor; + + SexsPti(BusT* bus); + SexsPti(BusT* bus, const ModelDataT& data); ~SexsPti(); int setGridKitComponentID(IdxT) override final; @@ -105,7 +107,7 @@ namespace GridKit ScalarT*, ScalarT*, ScalarT*, ScalarT*, ScalarT*); private: - bus_type* bus_{nullptr}; + BusT* bus_{nullptr}; RealT Ta_{0}; RealT Tb_{0}; @@ -124,7 +126,7 @@ namespace GridKit std::unique_ptr monitor_; - void initModelParams(const model_data_type& data); + void initModelParams(const ModelDataT& data); void initializeMonitor(); std::vector ws_; diff --git a/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiData.hpp b/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiData.hpp index 40ca45f4c..a22bd5be8 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiData.hpp +++ b/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiData.hpp @@ -39,9 +39,9 @@ namespace GridKit efd ///< Field voltage output }; - template - struct SexsPtiData : public ComponentData + struct SexsPtiData : public ComponentData diff --git a/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiDependencyTracking.cpp b/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiDependencyTracking.cpp index 2db2f5172..705734f27 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiDependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiDependencyTracking.cpp @@ -12,8 +12,8 @@ namespace GridKit { namespace Exciter { - template - int SexsPti::evaluateJacobian() + template + int SexsPti::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for SexsPti..." << std::endl; Log::misc() << "Jacobian evaluation not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiEnzyme.cpp b/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiEnzyme.cpp index 41610a891..2cc959481 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiEnzyme.cpp +++ b/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiEnzyme.cpp @@ -14,8 +14,8 @@ namespace GridKit { namespace Exciter { - template - int SexsPti::evaluateJacobian() + template + int SexsPti::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for SexsPti..." << std::endl; Log::misc() << "Jacobian evaluation is experimental!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiImpl.hpp b/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiImpl.hpp index ceebbac4a..121ff60c3 100644 --- a/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiImpl.hpp +++ b/GridKit/Model/PhasorDynamics/Exciter/SEXS-PTI/SexsPtiImpl.hpp @@ -24,16 +24,16 @@ namespace GridKit { using Log = ::GridKit::Utilities::Logger; - template - SexsPti::SexsPti(bus_type* bus) + template + SexsPti::SexsPti(BusT* bus) : bus_(bus) { size_ = 3; } - template - SexsPti::SexsPti(bus_type* bus, - const model_data_type& data) + template + SexsPti::SexsPti(BusT* bus, + const ModelDataT& data) : bus_(bus), monitor_(std::make_unique(data)) { @@ -42,20 +42,20 @@ namespace GridKit size_ = 3; } - template - SexsPti::~SexsPti() + template + SexsPti::~SexsPti() { } - template - int SexsPti::setGridKitComponentID(IdxT component_id) + template + int SexsPti::setGridKitComponentID(IdxT component_id) { gridkit_component_id_ = component_id; return 0; } - template - int SexsPti::allocate() + template + int SexsPti::allocate() { auto size = static_cast(size_); f_.resize(size); @@ -87,8 +87,8 @@ namespace GridKit return 0; } - template - int SexsPti::verify() const + template + int SexsPti::verify() const { int ret = missing_param_count_; @@ -141,8 +141,8 @@ namespace GridKit return ret; } - template - int SexsPti::initialize() + template + int SexsPti::initialize() { ScalarT efd0{0.0}; if (signals_.template isAssigned()) @@ -170,8 +170,8 @@ namespace GridKit return 0; } - template - int SexsPti::tagDifferentiable() + template + int SexsPti::tagDifferentiable() { tag_[0] = true; tag_[1] = true; @@ -180,8 +180,8 @@ namespace GridKit return 0; } - template - __attribute__((always_inline)) inline int SexsPti::evaluateInternalResidual( + template + __attribute__((always_inline)) inline int SexsPti::evaluateInternalResidual( ScalarT* y, ScalarT* yp, ScalarT* wb, @@ -208,8 +208,8 @@ namespace GridKit return 0; } - template - int SexsPti::evaluateResidual() + template + int SexsPti::evaluateResidual() { ws_[0] = 0.0; ws_indices_[0] = INVALID_INDEX; @@ -227,10 +227,10 @@ namespace GridKit return 0; } - template - void SexsPti::initModelParams(const model_data_type& data) + template + void SexsPti::initModelParams(const ModelDataT& data) { - using Params = typename model_data_type::Parameters; + using Params = typename ModelDataT::Parameters; missing_param_count_ = 0; @@ -255,16 +255,16 @@ namespace GridKit load(Params::Efdmin, Efdmin_, "Efdmin"); } - template - const Model::VariableMonitorBase* SexsPti::getMonitor() const + template + const Model::VariableMonitorBase* SexsPti::getMonitor() const { return monitor_.get(); } - template - void SexsPti::initializeMonitor() + template + void SexsPti::initializeMonitor() { - using Variable = typename model_data_type::MonitorableVariables; + using Variable = typename ModelDataT::MonitorableVariables; monitor_->set(Variable::efd, [this] { return y_[1]; }); } diff --git a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1.cpp b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1.cpp index 048f058a8..8737b8265 100644 --- a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1.cpp +++ b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1.cpp @@ -14,12 +14,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented yet * - * @tparam ScalarT - Scalar data type - * @tparam IdxT - Index data type * @return int - error code, 0 = success */ - template - int Tgov1::evaluateJacobian() + template + int Tgov1::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Tgov1..." << std::endl; Log::misc() << "Jacobian evaluation not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1.hpp b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1.hpp index 2b2a86ad7..f8ceb7207 100644 --- a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1.hpp +++ b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1.hpp @@ -19,14 +19,14 @@ namespace GridKit { namespace Governor { - template + template struct Tgov1Data; } // namespace Governor - template + template class Genrou; - template + template class SignalNode; } // namespace PhasorDynamics @@ -55,35 +55,37 @@ namespace GridKit MAXIMUM, }; - template - class Tgov1 : public Component + template + class Tgov1 : public Component { - using Component::gridkit_component_id_; - using Component::alpha_; - using Component::f_; - using Component::nnz_; - using Component::size_; - using Component::tag_; - using Component::time_; - using Component::y_; - using Component::yp_; - using Component::wb_; - using Component::h_; - using Component::J_; - using Component::J_rows_buffer_; - using Component::J_cols_buffer_; - using Component::J_vals_buffer_; - using Component::variable_indices_; - using Component::residual_indices_; - - using RealT = typename Component::RealT; - using model_data_type = Tgov1Data; - using signal_type = SignalNode; + using Component::gridkit_component_id_; + using Component::alpha_; + using Component::f_; + using Component::nnz_; + using Component::size_; + using Component::tag_; + using Component::time_; + using Component::y_; + using Component::yp_; + using Component::wb_; + using Component::h_; + using Component::J_; + using Component::J_rows_buffer_; + using Component::J_cols_buffer_; + using Component::J_vals_buffer_; + using Component::variable_indices_; + using Component::residual_indices_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename Component::RealT; + using ModelDataT = Tgov1Data; + using SignalT = SignalNode; + Tgov1(); - Tgov1(signal_type*, signal_type*); - Tgov1(const model_data_type&); + Tgov1(SignalT*, SignalT*); + Tgov1(const ModelDataT&); ~Tgov1() = default; int setGridKitComponentID(IdxT) override final; @@ -126,7 +128,7 @@ namespace GridKit ComponentSignals signals_; // Parameter initialization function - void initializeParameters(const model_data_type& data); + void initializeParameters(const ModelDataT& data); /* Local copies of signal variables */ std::vector ws_; diff --git a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Data.hpp b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Data.hpp index 51edd0474..91a19e20d 100644 --- a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Data.hpp +++ b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Data.hpp @@ -52,11 +52,15 @@ namespace GridKit /** * @brief Modeling data for TGOV1 Governor using ComponentData base. * - * @tparam RealT Real number type (e.g., double) - * @tparam IdxT Index type (e.g., size_t) + * @tparam real_type Real number type (e.g., double) + * @tparam index_type Index type (e.g., size_t) */ - template - struct Tgov1Data : public ComponentData + template + struct Tgov1Data : public ComponentData { Tgov1Data() = default; diff --git a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1DependencyTracking.cpp b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1DependencyTracking.cpp index 63476a79b..278641e18 100644 --- a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1DependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1DependencyTracking.cpp @@ -14,12 +14,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented yet * - * @tparam ScalarT - Scalar data type - * @tparam IdxT - Index data type * @return int - error code, 0 = success */ - template - int Tgov1::evaluateJacobian() + template + int Tgov1::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Tgov1..." << std::endl; Log::misc() << "Jacobian evaluation not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Enzyme.cpp b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Enzyme.cpp index 14472f8aa..115670d4f 100644 --- a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Enzyme.cpp +++ b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Enzyme.cpp @@ -17,12 +17,10 @@ namespace GridKit /** * @brief Jacobian evaluation experimental * - * @tparam ScalarT - Scalar data type - * @tparam IdxT - Index data type * @return int - error code, 0 = success */ - template - int Tgov1::evaluateJacobian() + template + int Tgov1::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Tgov1..." << std::endl; Log::misc() << "Jacobian evaluation is experimental!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Impl.hpp b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Impl.hpp index 2d7c7d87a..2a6e1d6c6 100644 --- a/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Impl.hpp +++ b/GridKit/Model/PhasorDynamics/Governor/Tgov1/Tgov1Impl.hpp @@ -30,8 +30,8 @@ namespace GridKit * @brief Constructs a Tgov1 governor model without setting its parameters * */ - template - Tgov1::Tgov1() + template + Tgov1::Tgov1() { size_ = 3; } @@ -42,8 +42,8 @@ namespace GridKit * @param pmech $P_m$ internal variable signal node * @param omega $\Delta_\omega$ external variable signal node */ - template - Tgov1::Tgov1(signal_type* pmech, signal_type* omega) + template + Tgov1::Tgov1(SignalT* pmech, SignalT* omega) : R_(0.05), Pvmin_(0), Pvmax_(1), @@ -64,8 +64,8 @@ namespace GridKit * * @param data Data to initialize the model from. */ - template - Tgov1::Tgov1(const model_data_type& data) + template + Tgov1::Tgov1(const ModelDataT& data) { initializeParameters(data); size_ = 3; @@ -74,55 +74,55 @@ namespace GridKit /** * @brief Helper function to extract and assign model parameters. * - * Parses values from the model_data_type and assigns them to internal + * Parses values from the ModelDataT and assigns them to internal * parameters. * * @param data Structure containing model parameters. */ - template - void Tgov1::initializeParameters(const model_data_type& data) + template + void Tgov1::initializeParameters(const ModelDataT& data) { - if (data.parameters.contains(model_data_type::Parameters::R)) + if (data.parameters.contains(ModelDataT::Parameters::R)) { - R_ = std::get(data.parameters.at(model_data_type::Parameters::R)); + R_ = std::get(data.parameters.at(ModelDataT::Parameters::R)); } - if (data.parameters.contains(model_data_type::Parameters::Pvmin)) + if (data.parameters.contains(ModelDataT::Parameters::Pvmin)) { - Pvmin_ = std::get(data.parameters.at(model_data_type::Parameters::Pvmin)); + Pvmin_ = std::get(data.parameters.at(ModelDataT::Parameters::Pvmin)); } - if (data.parameters.contains(model_data_type::Parameters::Pvmax)) + if (data.parameters.contains(ModelDataT::Parameters::Pvmax)) { - Pvmax_ = std::get(data.parameters.at(model_data_type::Parameters::Pvmax)); + Pvmax_ = std::get(data.parameters.at(ModelDataT::Parameters::Pvmax)); } - if (data.parameters.contains(model_data_type::Parameters::T1)) + if (data.parameters.contains(ModelDataT::Parameters::T1)) { - T1_ = std::get(data.parameters.at(model_data_type::Parameters::T1)); + T1_ = std::get(data.parameters.at(ModelDataT::Parameters::T1)); } - if (data.parameters.contains(model_data_type::Parameters::T2)) + if (data.parameters.contains(ModelDataT::Parameters::T2)) { - T2_ = std::get(data.parameters.at(model_data_type::Parameters::T2)); + T2_ = std::get(data.parameters.at(ModelDataT::Parameters::T2)); } - if (data.parameters.contains(model_data_type::Parameters::T3)) + if (data.parameters.contains(ModelDataT::Parameters::T3)) { - T3_ = std::get(data.parameters.at(model_data_type::Parameters::T3)); + T3_ = std::get(data.parameters.at(ModelDataT::Parameters::T3)); } - if (data.parameters.contains(model_data_type::Parameters::Dt)) + if (data.parameters.contains(ModelDataT::Parameters::Dt)) { - Dt_ = std::get(data.parameters.at(model_data_type::Parameters::Dt)); + Dt_ = std::get(data.parameters.at(ModelDataT::Parameters::Dt)); } } /** * @brief Set the component ID */ - template - int Tgov1::setGridKitComponentID(IdxT component_id) + template + int Tgov1::setGridKitComponentID(IdxT component_id) { gridkit_component_id_ = component_id; return 0; @@ -131,8 +131,8 @@ namespace GridKit /*! * @brief Allocate memory for model */ - template - int Tgov1::allocate() + template + int Tgov1::allocate() { // Allocate local component data auto size = static_cast(size_); // avoid compiler warnings @@ -168,8 +168,8 @@ namespace GridKit /** * @brief verify method checks that attached signals are also linked */ - template - int Tgov1::verify() const + template + int Tgov1::verify() const { static constexpr auto DELTAOMEGA = Tgov1ExternalVariables::DELTAOMEGA; @@ -191,8 +191,8 @@ namespace GridKit * @brief Initialization of the Governor * */ - template - int Tgov1::initialize() + template + int Tgov1::initialize() { ScalarT p0{0}; @@ -221,8 +221,8 @@ namespace GridKit /** * @brief Identify differential variables. */ - template - int Tgov1::tagDifferentiable() + template + int Tgov1::tagDifferentiable() { tag_[0] = true; // Pv @@ -236,8 +236,8 @@ namespace GridKit * @brief Internal residuals * */ - template - __attribute__((always_inline)) inline int Tgov1::evaluateInternalResidual( + template + __attribute__((always_inline)) inline int Tgov1::evaluateInternalResidual( ScalarT* y, ScalarT* yp, [[maybe_unused]] ScalarT* wb, @@ -274,8 +274,8 @@ namespace GridKit * @brief Residuals of system equations * */ - template - int Tgov1::evaluateResidual() + template + int Tgov1::evaluateResidual() { // Input Variables if (signals_.template isAttached()) diff --git a/GridKit/Model/PhasorDynamics/GridElement.hpp b/GridKit/Model/PhasorDynamics/GridElement.hpp index aa961bfc7..919216368 100644 --- a/GridKit/Model/PhasorDynamics/GridElement.hpp +++ b/GridKit/Model/PhasorDynamics/GridElement.hpp @@ -17,10 +17,12 @@ namespace GridKit /** * @brief Model base class for all system constituents */ - template - class GridElement : public Model::Evaluator + template + class GridElement : public Model::Evaluator { public: + using ScalarT = scalar_type; + using IdxT = index_type; using RealT = typename Model::Evaluator::RealT; using MatrixT = typename Model::Evaluator::MatrixT; diff --git a/GridKit/Model/PhasorDynamics/Load/Load.cpp b/GridKit/Model/PhasorDynamics/Load/Load.cpp index 324b0af88..85ca93c3c 100644 --- a/GridKit/Model/PhasorDynamics/Load/Load.cpp +++ b/GridKit/Model/PhasorDynamics/Load/Load.cpp @@ -8,12 +8,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int Load::evaluateJacobian() + template + int Load::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Load..." << std::endl; Log::misc() << "Jacobian evaluation is not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Load/Load.hpp b/GridKit/Model/PhasorDynamics/Load/Load.hpp index 6dd8390d5..33ce3cc1e 100644 --- a/GridKit/Model/PhasorDynamics/Load/Load.hpp +++ b/GridKit/Model/PhasorDynamics/Load/Load.hpp @@ -10,10 +10,10 @@ namespace GridKit { namespace PhasorDynamics { - template + template class BusBase; - template + template struct LoadData; } // namespace PhasorDynamics } // namespace GridKit @@ -26,36 +26,38 @@ namespace GridKit * @brief Implementation of a constant load. * */ - template - class Load : public Component + template + class Load : public Component { - using Component::gridkit_component_id_; - using Component::size_; - using Component::nnz_; - using Component::time_; - using Component::alpha_; - using Component::y_; - using Component::yp_; - using Component::tag_; - using Component::wb_; - using Component::h_; - using Component::f_; - using Component::J_; - using Component::J_rows_buffer_; - using Component::J_cols_buffer_; - using Component::J_vals_buffer_; - using Component::variable_indices_; - using Component::residual_indices_; + using Component::gridkit_component_id_; + using Component::size_; + using Component::nnz_; + using Component::time_; + using Component::alpha_; + using Component::y_; + using Component::yp_; + using Component::tag_; + using Component::wb_; + using Component::h_; + using Component::f_; + using Component::J_; + using Component::J_rows_buffer_; + using Component::J_cols_buffer_; + using Component::J_vals_buffer_; + using Component::variable_indices_; + using Component::residual_indices_; public: - using RealT = typename Component::RealT; - using bus_type = BusBase; - using model_data_type = LoadData; - using MonitorT = Model::VariableMonitor; - - Load(bus_type* bus); - Load(bus_type* bus, RealT R, RealT X); - Load(bus_type* bus, const model_data_type& data); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename Component::RealT; + using BusT = BusBase; + using ModelDataT = LoadData; + using MonitorT = Model::VariableMonitor; + + Load(BusT* bus); + Load(BusT* bus, RealT R, RealT X); + Load(BusT* bus, const ModelDataT& data); virtual ~Load(); virtual int setGridKitComponentID(IdxT) override final; @@ -112,9 +114,9 @@ namespace GridKit __attribute__((always_inline)) inline int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*); private: - bus_type* bus_{nullptr}; - RealT R_{0.1}; - RealT X_{0.01}; + BusT* bus_{nullptr}; + RealT R_{0.1}; + RealT X_{0.01}; /* Derivied parameters */ RealT b_; diff --git a/GridKit/Model/PhasorDynamics/Load/LoadData.hpp b/GridKit/Model/PhasorDynamics/Load/LoadData.hpp index ccddccfae..959201fe3 100644 --- a/GridKit/Model/PhasorDynamics/Load/LoadData.hpp +++ b/GridKit/Model/PhasorDynamics/Load/LoadData.hpp @@ -35,14 +35,14 @@ namespace GridKit /** * @brief Contains modeling data for a load * - * @tparam RealT Real parameter data type - * @tparam IdxT Integer parameter data type + * @tparam real_type Real parameter data type + * @tparam index_type Integer parameter data type * * Integer parameters are of the same type as matrix and vector indices. */ - template - struct LoadData : public ComponentData + struct LoadData : public ComponentData diff --git a/GridKit/Model/PhasorDynamics/Load/LoadDependencyTracking.cpp b/GridKit/Model/PhasorDynamics/Load/LoadDependencyTracking.cpp index 37e9f0238..9f1336755 100644 --- a/GridKit/Model/PhasorDynamics/Load/LoadDependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/Load/LoadDependencyTracking.cpp @@ -8,12 +8,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int Load::evaluateJacobian() + template + int Load::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Load..." << std::endl; Log::misc() << "Jacobian evaluation is not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Load/LoadEnzyme.cpp b/GridKit/Model/PhasorDynamics/Load/LoadEnzyme.cpp index 1344a9b18..58ea9c1f5 100644 --- a/GridKit/Model/PhasorDynamics/Load/LoadEnzyme.cpp +++ b/GridKit/Model/PhasorDynamics/Load/LoadEnzyme.cpp @@ -15,12 +15,10 @@ namespace GridKit /** * @brief Jacobian evaluation experimental * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int Load::evaluateJacobian() + template + int Load::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Load..." << std::endl; Log::misc() << "Jacobian evaluation is experimental!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Load/LoadImpl.hpp b/GridKit/Model/PhasorDynamics/Load/LoadImpl.hpp index e774074ea..e124bc375 100644 --- a/GridKit/Model/PhasorDynamics/Load/LoadImpl.hpp +++ b/GridKit/Model/PhasorDynamics/Load/LoadImpl.hpp @@ -19,17 +19,17 @@ namespace GridKit * - Number of equations = 2 * - Number of independent variables = 2 */ - template - Load::Load(bus_type* bus) + template + Load::Load(BusT* bus) : bus_(bus) { size_ = 2; } - template - Load::Load(bus_type* bus, - RealT R, - RealT X) + template + Load::Load(BusT* bus, + RealT R, + RealT X) : bus_(bus), R_(R), X_(X) @@ -38,22 +38,22 @@ namespace GridKit setDerivedParams(); } - template - Load::Load(bus_type* bus, - const model_data_type& data) + template + Load::Load(BusT* bus, + const ModelDataT& data) : bus_(bus) { - if (data.parameters.contains(model_data_type::Parameters::R)) + if (data.parameters.contains(ModelDataT::Parameters::R)) { - R_ = std::get(data.parameters.at(model_data_type::Parameters::R)); + R_ = std::get(data.parameters.at(ModelDataT::Parameters::R)); } - if (data.parameters.contains(model_data_type::Parameters::X)) + if (data.parameters.contains(ModelDataT::Parameters::X)) { - X_ = std::get(data.parameters.at(model_data_type::Parameters::X)); + X_ = std::get(data.parameters.at(ModelDataT::Parameters::X)); } - // using Variable = typename model_data_type::MonitorableVariables; + // using Variable = typename ModelDataT::MonitorableVariables; // monitor_->set(Variable::p, [this] { return ?; }); // monitor_->set(Variable::q, [this] { return ?; }); @@ -61,8 +61,8 @@ namespace GridKit setDerivedParams(); } - template - Load::~Load() + template + Load::~Load() { // std::cout << "Destroy Load..." << std::endl; } @@ -70,8 +70,8 @@ namespace GridKit /** * @brief Set the component ID */ - template - int Load::setGridKitComponentID(IdxT component_id) + template + int Load::setGridKitComponentID(IdxT component_id) { gridkit_component_id_ = component_id; return 0; @@ -80,8 +80,8 @@ namespace GridKit /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int Load::allocate() + template + int Load::allocate() { // std::cout << "Allocate Load..." << std::endl; @@ -111,8 +111,8 @@ namespace GridKit * Initialization of the load model * */ - template - int Load::initialize() + template + int Load::initialize() { ScalarT vr = Vr(); ScalarT vi = Vi(); @@ -131,8 +131,8 @@ namespace GridKit /** * \brief Identify differential variables. */ - template - int Load::tagDifferentiable() + template + int Load::tagDifferentiable() { tag_[0] = false; tag_[1] = false; @@ -144,8 +144,8 @@ namespace GridKit * @brief Bus residual * */ - template - __attribute__((always_inline)) int Load::evaluateBusResidual( + template + __attribute__((always_inline)) int Load::evaluateBusResidual( ScalarT* y, [[maybe_unused]] ScalarT* yp, [[maybe_unused]] ScalarT* wb, @@ -163,8 +163,8 @@ namespace GridKit * @brief Internal residual * */ - template - __attribute__((always_inline)) int Load::evaluateInternalResidual( + template + __attribute__((always_inline)) int Load::evaluateInternalResidual( ScalarT* y, [[maybe_unused]] ScalarT* yp, ScalarT* wb, @@ -184,8 +184,8 @@ namespace GridKit * @brief Residual contribution of the load is pushed to the bus. * */ - template - int Load::evaluateResidual() + template + int Load::evaluateResidual() { wb_[0] = Vr(); wb_[1] = Vi(); @@ -201,15 +201,15 @@ namespace GridKit * @brief Derived parameters * */ - template - void Load::setDerivedParams() + template + void Load::setDerivedParams() { b_ = -X_ / (R_ * R_ + X_ * X_); g_ = R_ / (R_ * R_ + X_ * X_); } - template - const Model::VariableMonitorBase* Load::getMonitor() const + template + const Model::VariableMonitorBase* Load::getMonitor() const { return monitor_.get(); } diff --git a/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIP.cpp b/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIP.cpp index 476593a53..095d25437 100644 --- a/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIP.cpp +++ b/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIP.cpp @@ -8,12 +8,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int LoadZIP::evaluateJacobian() + template + int LoadZIP::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for LoadZIP..." << std::endl; Log::misc() << "Jacobian evaluation is not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIP.hpp b/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIP.hpp index 6ebfbd029..ebe3a9be2 100644 --- a/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIP.hpp +++ b/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIP.hpp @@ -10,10 +10,10 @@ namespace GridKit { namespace PhasorDynamics { - template + template class BusBase; - template + template struct LoadZIPData; } // namespace PhasorDynamics } // namespace GridKit @@ -26,36 +26,38 @@ namespace GridKit * @brief Implementation of a ZIP load. * */ - template - class LoadZIP : public Component + template + class LoadZIP : public Component { - using Component::gridkit_component_id_; - using Component::size_; - using Component::nnz_; - using Component::time_; - using Component::alpha_; - using Component::y_; - using Component::yp_; - using Component::tag_; - using Component::wb_; - using Component::h_; - using Component::f_; - using Component::J_; - using Component::J_rows_buffer_; - using Component::J_cols_buffer_; - using Component::J_vals_buffer_; - using Component::variable_indices_; - using Component::residual_indices_; + using Component::gridkit_component_id_; + using Component::size_; + using Component::nnz_; + using Component::time_; + using Component::alpha_; + using Component::y_; + using Component::yp_; + using Component::tag_; + using Component::wb_; + using Component::h_; + using Component::f_; + using Component::J_; + using Component::J_rows_buffer_; + using Component::J_cols_buffer_; + using Component::J_vals_buffer_; + using Component::variable_indices_; + using Component::residual_indices_; public: - using RealT = typename Component::RealT; - using bus_type = BusBase; - using model_data_type = LoadZIPData; - using MonitorT = Model::VariableMonitor; - - LoadZIP(bus_type* bus); - LoadZIP(bus_type* bus, RealT P0, RealT Q0, RealT V0, RealT alphaI, RealT alphaP); - LoadZIP(bus_type* bus, const model_data_type& data); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename Component::RealT; + using BusT = BusBase; + using ModelDataT = LoadZIPData; + using MonitorT = Model::VariableMonitor; + + LoadZIP(BusT* bus); + LoadZIP(BusT* bus, RealT P0, RealT Q0, RealT V0, RealT alphaI, RealT alphaP); + LoadZIP(BusT* bus, const ModelDataT& data); ~LoadZIP(); int setGridKitComponentID(IdxT) override final; @@ -126,12 +128,12 @@ namespace GridKit __attribute__((always_inline)) inline int evaluateInternalResidual(ScalarT*, ScalarT*, ScalarT*, ScalarT*); private: - bus_type* bus_{nullptr}; - RealT P0_{0}; - RealT Q0_{0}; - RealT V0_{1.0}; - RealT alphaI_{0}; - RealT alphaP_{0}; + BusT* bus_{nullptr}; + RealT P0_{0}; + RealT Q0_{0}; + RealT V0_{1.0}; + RealT alphaI_{0}; + RealT alphaP_{0}; std::unique_ptr monitor_; }; diff --git a/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPData.hpp b/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPData.hpp index 442ac8e6c..cfefff260 100644 --- a/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPData.hpp +++ b/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPData.hpp @@ -36,14 +36,14 @@ namespace GridKit /** * @brief Contains modeling data for a load * - * @tparam RealT Real parameter data type - * @tparam IdxT Integer parameter data type + * @tparam real_type Real parameter data type + * @tparam index_type Integer parameter data type * * Integer parameters are of the same type as matrix and vector indices. */ - template - struct LoadZIPData : public ComponentData + struct LoadZIPData : public ComponentData diff --git a/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPDependencyTracking.cpp b/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPDependencyTracking.cpp index 7c01f6b1e..514ead2e9 100644 --- a/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPDependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPDependencyTracking.cpp @@ -8,12 +8,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int LoadZIP::evaluateJacobian() + template + int LoadZIP::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for LoadZIP..." << std::endl; Log::misc() << "Jacobian evaluation is not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPEnzyme.cpp b/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPEnzyme.cpp index 4cc1d0b47..a5f7e6dfc 100644 --- a/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPEnzyme.cpp +++ b/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPEnzyme.cpp @@ -10,12 +10,10 @@ namespace GridKit /** * @brief Jacobian evaluation experimental * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int LoadZIP::evaluateJacobian() + template + int LoadZIP::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for LoadZIP..." << std::endl; Log::misc() << "Jacobian evaluation is experimental!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPImpl.hpp b/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPImpl.hpp index 6896662d1..8dc38dc83 100644 --- a/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPImpl.hpp +++ b/GridKit/Model/PhasorDynamics/LoadZIP/LoadZIPImpl.hpp @@ -19,15 +19,15 @@ namespace GridKit * - Number of equations = 2 * - Number of independent variables = 2 */ - template - LoadZIP::LoadZIP(bus_type* bus) + template + LoadZIP::LoadZIP(BusT* bus) : bus_(bus) { size_ = 2; } - template - LoadZIP::LoadZIP(bus_type* bus, RealT P0, RealT Q0, RealT V0, RealT alphaI, RealT alphaP) + template + LoadZIP::LoadZIP(BusT* bus, RealT P0, RealT Q0, RealT V0, RealT alphaI, RealT alphaP) : bus_(bus), P0_(P0), Q0_(Q0), @@ -39,37 +39,37 @@ namespace GridKit setDerivedParams(); } - template - LoadZIP::LoadZIP(bus_type* bus, - const model_data_type& data) + template + LoadZIP::LoadZIP(BusT* bus, + const ModelDataT& data) : bus_(bus) { - if (data.parameters.contains(model_data_type::Parameters::P0)) + if (data.parameters.contains(ModelDataT::Parameters::P0)) { - P0_ = std::get(data.parameters.at(model_data_type::Parameters::P0)); + P0_ = std::get(data.parameters.at(ModelDataT::Parameters::P0)); } - if (data.parameters.contains(model_data_type::Parameters::Q0)) + if (data.parameters.contains(ModelDataT::Parameters::Q0)) { - Q0_ = std::get(data.parameters.at(model_data_type::Parameters::Q0)); + Q0_ = std::get(data.parameters.at(ModelDataT::Parameters::Q0)); } - if (data.parameters.contains(model_data_type::Parameters::V0)) + if (data.parameters.contains(ModelDataT::Parameters::V0)) { - V0_ = std::get(data.parameters.at(model_data_type::Parameters::V0)); + V0_ = std::get(data.parameters.at(ModelDataT::Parameters::V0)); } - if (data.parameters.contains(model_data_type::Parameters::alphaI)) + if (data.parameters.contains(ModelDataT::Parameters::alphaI)) { - alphaI_ = std::get(data.parameters.at(model_data_type::Parameters::alphaI)); + alphaI_ = std::get(data.parameters.at(ModelDataT::Parameters::alphaI)); } - if (data.parameters.contains(model_data_type::Parameters::alphaP)) + if (data.parameters.contains(ModelDataT::Parameters::alphaP)) { - alphaP_ = std::get(data.parameters.at(model_data_type::Parameters::alphaP)); + alphaP_ = std::get(data.parameters.at(ModelDataT::Parameters::alphaP)); } - // using Variable = typename model_data_type::MonitorableVariables; + // using Variable = typename ModelDataT::MonitorableVariables; // monitor_->set(Variable::p, [this] { return ?; }); // monitor_->set(Variable::q, [this] { return ?; }); @@ -77,8 +77,8 @@ namespace GridKit setDerivedParams(); } - template - LoadZIP::~LoadZIP() + template + LoadZIP::~LoadZIP() { // std::cout << "Destroy LoadZIP..." << std::endl; } @@ -86,8 +86,8 @@ namespace GridKit /** * @brief Set the component ID */ - template - int LoadZIP::setGridKitComponentID(IdxT component_id) + template + int LoadZIP::setGridKitComponentID(IdxT component_id) { gridkit_component_id_ = component_id; return 0; @@ -96,8 +96,8 @@ namespace GridKit /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int LoadZIP::allocate() + template + int LoadZIP::allocate() { // std::cout << "Allocate Load..." << std::endl; @@ -127,8 +127,8 @@ namespace GridKit * Initialization of the load model * */ - template - int LoadZIP::initialize() + template + int LoadZIP::initialize() { ScalarT vr = Vr(); ScalarT vi = Vi(); @@ -150,8 +150,8 @@ namespace GridKit /** * \brief Identify differential variables. */ - template - int LoadZIP::tagDifferentiable() + template + int LoadZIP::tagDifferentiable() { tag_[0] = false; tag_[1] = false; @@ -162,8 +162,8 @@ namespace GridKit * @brief Bus residual * */ - template - __attribute__((always_inline)) int LoadZIP::evaluateBusResidual( + template + __attribute__((always_inline)) int LoadZIP::evaluateBusResidual( ScalarT* y, [[maybe_unused]] ScalarT* yp, [[maybe_unused]] ScalarT* wb, @@ -181,8 +181,8 @@ namespace GridKit * @brief Residual contribution of the load is pushed to the bus. * */ - template - int LoadZIP::evaluateResidual() + template + int LoadZIP::evaluateResidual() { wb_[0] = Vr(); wb_[1] = Vi(); @@ -198,8 +198,8 @@ namespace GridKit * @brief Internal residual * */ - template - __attribute__((always_inline)) int LoadZIP::evaluateInternalResidual( + template + __attribute__((always_inline)) int LoadZIP::evaluateInternalResidual( ScalarT* y, [[maybe_unused]] ScalarT* yp, ScalarT* wb, @@ -223,14 +223,14 @@ namespace GridKit * @brief Derived parameters * */ - template - void LoadZIP::setDerivedParams() + template + void LoadZIP::setDerivedParams() { return; } - template - const Model::VariableMonitorBase* LoadZIP::getMonitor() const + template + const Model::VariableMonitorBase* LoadZIP::getMonitor() const { return monitor_.get(); } diff --git a/GridKit/Model/PhasorDynamics/SignalNode/SignalNode.hpp b/GridKit/Model/PhasorDynamics/SignalNode/SignalNode.hpp index 148631194..e86e973fa 100644 --- a/GridKit/Model/PhasorDynamics/SignalNode/SignalNode.hpp +++ b/GridKit/Model/PhasorDynamics/SignalNode/SignalNode.hpp @@ -7,7 +7,7 @@ namespace GridKit { namespace PhasorDynamics { - template + template struct SignalNodeData; } // namespace PhasorDynamics } // namespace GridKit @@ -20,11 +20,13 @@ namespace GridKit * @brief SignalNode model implementation base class. * */ - template + template class SignalNode { public: - using RealT = typename GridKit::ScalarTraits::RealT; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename GridKit::ScalarTraits::RealT; SignalNode(); SignalNode(const SignalNodeData& data); diff --git a/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeData.hpp b/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeData.hpp index 3a5854666..3e15b984d 100644 --- a/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeData.hpp +++ b/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeData.hpp @@ -18,16 +18,18 @@ namespace GridKit /** * @brief Contains modeling data for a Bus * - * @tparam RealT Real parameter data type - * @tparam IdxT Integer parameter data type + * @tparam real_type Real parameter data type + * @tparam index_type Integer parameter data type * * Integer parameters are of the same type as matrix and vector indices. * * @todo Decide on naming scheme for model parameters. */ - template + template struct SignalNodeData { + using IdxT = index_type; + std::string name; ///< A name given to this bus IdxT signal_id{0}; ///< The unique ID of the signal node }; diff --git a/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeImpl.hpp b/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeImpl.hpp index 5a408ab04..c3eba4e2f 100644 --- a/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeImpl.hpp +++ b/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeImpl.hpp @@ -8,38 +8,38 @@ namespace GridKit { namespace PhasorDynamics { - template - SignalNode::SignalNode() + template + SignalNode::SignalNode() { } - template - SignalNode::SignalNode(const SignalNodeData& data) + template + SignalNode::SignalNode(const SignalNodeData& data) : signal_id_(data.signal_id) { } - template - void SignalNode::set(ScalarT* signal, IdxT* variable_index) + template + void SignalNode::set(ScalarT* signal, IdxT* variable_index) { signal_ = signal; variable_index_ = variable_index; } - template - bool SignalNode::linked() const + template + bool SignalNode::linked() const { return (signal_) && (variable_index_); } - template - ScalarT SignalNode::read() const + template + scalar_type SignalNode::read() const { return *signal_; } - template - void SignalNode::init(ScalarT signal) + template + void SignalNode::init(ScalarT signal) { *signal_ = signal; } diff --git a/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/Ieeest.cpp b/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/Ieeest.cpp index dad12b933..045fac991 100644 --- a/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/Ieeest.cpp +++ b/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/Ieeest.cpp @@ -15,12 +15,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented yet * - * @tparam ScalarT - Scalar data type - * @tparam IdxT - Index data type * @return int - error code, 0 = success */ - template - int Ieeest::evaluateJacobian() + template + int Ieeest::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Ieeest..." << std::endl; Log::misc() << "Jacobian evaluation not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/Ieeest.hpp b/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/Ieeest.hpp index b495a49d3..b2c86e55d 100644 --- a/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/Ieeest.hpp +++ b/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/Ieeest.hpp @@ -16,11 +16,11 @@ namespace GridKit { namespace Stabilizer { - template + template struct IeeestData; } // namespace Stabilizer - template + template class SignalNode; } // namespace PhasorDynamics @@ -59,35 +59,37 @@ namespace GridKit MAXIMUM, }; - template - class Ieeest : public Component + template + class Ieeest : public Component { - using Component::gridkit_component_id_; - using Component::alpha_; - using Component::f_; - using Component::nnz_; - using Component::size_; - using Component::tag_; - using Component::time_; - using Component::y_; - using Component::yp_; - using Component::wb_; - using Component::h_; - using Component::J_; - using Component::J_rows_buffer_; - using Component::J_cols_buffer_; - using Component::J_vals_buffer_; - using Component::variable_indices_; - using Component::residual_indices_; + using Component::gridkit_component_id_; + using Component::alpha_; + using Component::f_; + using Component::nnz_; + using Component::size_; + using Component::tag_; + using Component::time_; + using Component::y_; + using Component::yp_; + using Component::wb_; + using Component::h_; + using Component::J_; + using Component::J_rows_buffer_; + using Component::J_cols_buffer_; + using Component::J_vals_buffer_; + using Component::variable_indices_; + using Component::residual_indices_; public: - using RealT = typename Component::RealT; - using model_data_type = IeeestData; - using signal_type = SignalNode; - using MonitorT = Model::VariableMonitor; + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename Component::RealT; + using ModelDataT = IeeestData; + using SignalT = SignalNode; + using MonitorT = Model::VariableMonitor; Ieeest(); - Ieeest(const model_data_type& data); + Ieeest(const ModelDataT& data); ~Ieeest(); int setGridKitComponentID(IdxT) override final; @@ -168,7 +170,7 @@ namespace GridKit std::unique_ptr monitor_; - void initializeParameters(const model_data_type& data); + void initializeParameters(const ModelDataT& data); void initializeMonitor(); std::vector ws_; diff --git a/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestData.hpp b/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestData.hpp index 00d728a58..6bdc38743 100644 --- a/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestData.hpp +++ b/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestData.hpp @@ -60,12 +60,12 @@ namespace GridKit /** * @brief Contains modeling data for a IEEEST Stabilizer model. * - * @tparam RealT Real parameter data type - * @tparam IdxT Integer parameter data type + * @tparam real_type Real parameter data type + * @tparam index_type Integer parameter data type */ - template - struct IeeestData : public ComponentData + struct IeeestData : public ComponentData diff --git a/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestDependencyTracking.cpp b/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestDependencyTracking.cpp index b61781f56..34b01b85c 100644 --- a/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestDependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestDependencyTracking.cpp @@ -19,8 +19,8 @@ namespace GridKit * @tparam IdxT - Index data type * @return int - error code, 0 = success */ - template - int Ieeest::evaluateJacobian() + template + int Ieeest::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Ieeest..." << std::endl; Log::misc() << "Jacobian evaluation not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestEnzyme.cpp b/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestEnzyme.cpp index 71c8a086e..1ea9e6434 100644 --- a/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestEnzyme.cpp +++ b/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestEnzyme.cpp @@ -21,8 +21,8 @@ namespace GridKit * @tparam IdxT - Index data type * @return int - error code, 0 = success */ - template - int Ieeest::evaluateJacobian() + template + int Ieeest::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Ieeest..." << std::endl; Log::misc() << "Jacobian evaluation is experimental!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestImpl.hpp b/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestImpl.hpp index b0c815d90..718f93c63 100644 --- a/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestImpl.hpp +++ b/GridKit/Model/PhasorDynamics/Stabilizer/IEEEST/IeeestImpl.hpp @@ -23,14 +23,14 @@ namespace GridKit { using Log = ::GridKit::Utilities::Logger; - template - Ieeest::Ieeest() + template + Ieeest::Ieeest() { size_ = 13; } - template - Ieeest::Ieeest(const model_data_type& data) + template + Ieeest::Ieeest(const ModelDataT& data) : monitor_(std::make_unique(data)) { initializeParameters(data); @@ -38,85 +38,85 @@ namespace GridKit size_ = 13; } - template - Ieeest::~Ieeest() + template + Ieeest::~Ieeest() { } - template - void Ieeest::initializeParameters(const model_data_type& data) + template + void Ieeest::initializeParameters(const ModelDataT& data) { - if (data.parameters.contains(model_data_type::Parameters::A1)) + if (data.parameters.contains(ModelDataT::Parameters::A1)) { - A1_ = std::get(data.parameters.at(model_data_type::Parameters::A1)); + A1_ = std::get(data.parameters.at(ModelDataT::Parameters::A1)); } - if (data.parameters.contains(model_data_type::Parameters::A2)) + if (data.parameters.contains(ModelDataT::Parameters::A2)) { - A2_ = std::get(data.parameters.at(model_data_type::Parameters::A2)); + A2_ = std::get(data.parameters.at(ModelDataT::Parameters::A2)); } - if (data.parameters.contains(model_data_type::Parameters::A3)) + if (data.parameters.contains(ModelDataT::Parameters::A3)) { - A3_ = std::get(data.parameters.at(model_data_type::Parameters::A3)); + A3_ = std::get(data.parameters.at(ModelDataT::Parameters::A3)); } - if (data.parameters.contains(model_data_type::Parameters::A4)) + if (data.parameters.contains(ModelDataT::Parameters::A4)) { - A4_ = std::get(data.parameters.at(model_data_type::Parameters::A4)); + A4_ = std::get(data.parameters.at(ModelDataT::Parameters::A4)); } - if (data.parameters.contains(model_data_type::Parameters::A5)) + if (data.parameters.contains(ModelDataT::Parameters::A5)) { - A5_ = std::get(data.parameters.at(model_data_type::Parameters::A5)); + A5_ = std::get(data.parameters.at(ModelDataT::Parameters::A5)); } - if (data.parameters.contains(model_data_type::Parameters::A6)) + if (data.parameters.contains(ModelDataT::Parameters::A6)) { - A6_ = std::get(data.parameters.at(model_data_type::Parameters::A6)); + A6_ = std::get(data.parameters.at(ModelDataT::Parameters::A6)); } - if (data.parameters.contains(model_data_type::Parameters::T1)) + if (data.parameters.contains(ModelDataT::Parameters::T1)) { - T1_ = std::get(data.parameters.at(model_data_type::Parameters::T1)); + T1_ = std::get(data.parameters.at(ModelDataT::Parameters::T1)); } - if (data.parameters.contains(model_data_type::Parameters::T2)) + if (data.parameters.contains(ModelDataT::Parameters::T2)) { - T2_ = std::get(data.parameters.at(model_data_type::Parameters::T2)); + T2_ = std::get(data.parameters.at(ModelDataT::Parameters::T2)); } - if (data.parameters.contains(model_data_type::Parameters::T3)) + if (data.parameters.contains(ModelDataT::Parameters::T3)) { - T3_ = std::get(data.parameters.at(model_data_type::Parameters::T3)); + T3_ = std::get(data.parameters.at(ModelDataT::Parameters::T3)); } - if (data.parameters.contains(model_data_type::Parameters::T4)) + if (data.parameters.contains(ModelDataT::Parameters::T4)) { - T4_ = std::get(data.parameters.at(model_data_type::Parameters::T4)); + T4_ = std::get(data.parameters.at(ModelDataT::Parameters::T4)); } - if (data.parameters.contains(model_data_type::Parameters::T5)) + if (data.parameters.contains(ModelDataT::Parameters::T5)) { - T5_ = std::get(data.parameters.at(model_data_type::Parameters::T5)); + T5_ = std::get(data.parameters.at(ModelDataT::Parameters::T5)); } - if (data.parameters.contains(model_data_type::Parameters::T6)) + if (data.parameters.contains(ModelDataT::Parameters::T6)) { - T6_ = std::get(data.parameters.at(model_data_type::Parameters::T6)); + T6_ = std::get(data.parameters.at(ModelDataT::Parameters::T6)); } - if (data.parameters.contains(model_data_type::Parameters::Ks)) + if (data.parameters.contains(ModelDataT::Parameters::Ks)) { - Ks_ = std::get(data.parameters.at(model_data_type::Parameters::Ks)); + Ks_ = std::get(data.parameters.at(ModelDataT::Parameters::Ks)); } - if (data.parameters.contains(model_data_type::Parameters::Lsmin)) + if (data.parameters.contains(ModelDataT::Parameters::Lsmin)) { - Lsmin_ = std::get(data.parameters.at(model_data_type::Parameters::Lsmin)); + Lsmin_ = std::get(data.parameters.at(ModelDataT::Parameters::Lsmin)); } - if (data.parameters.contains(model_data_type::Parameters::Lsmax)) + if (data.parameters.contains(ModelDataT::Parameters::Lsmax)) { - Lsmax_ = std::get(data.parameters.at(model_data_type::Parameters::Lsmax)); + Lsmax_ = std::get(data.parameters.at(ModelDataT::Parameters::Lsmax)); } - if (data.parameters.contains(model_data_type::Parameters::Vcl)) + if (data.parameters.contains(ModelDataT::Parameters::Vcl)) { - Vcl_ = std::get(data.parameters.at(model_data_type::Parameters::Vcl)); + Vcl_ = std::get(data.parameters.at(ModelDataT::Parameters::Vcl)); } - if (data.parameters.contains(model_data_type::Parameters::Vcu)) + if (data.parameters.contains(ModelDataT::Parameters::Vcu)) { - Vcu_ = std::get(data.parameters.at(model_data_type::Parameters::Vcu)); + Vcu_ = std::get(data.parameters.at(ModelDataT::Parameters::Vcu)); } - if (data.parameters.contains(model_data_type::Parameters::Tdelay)) + if (data.parameters.contains(ModelDataT::Parameters::Tdelay)) { - Tdelay_ = std::get(data.parameters.at(model_data_type::Parameters::Tdelay)); + Tdelay_ = std::get(data.parameters.at(ModelDataT::Parameters::Tdelay)); } a0_ = 1; @@ -153,15 +153,15 @@ namespace GridKit bypass_cutout_ = 1.0 - use_cutout_; } - template - int Ieeest::setGridKitComponentID(IdxT component_id) + template + int Ieeest::setGridKitComponentID(IdxT component_id) { gridkit_component_id_ = component_id; return 0; } - template - int Ieeest::allocate() + template + int Ieeest::allocate() { auto size = static_cast(size_); f_.resize(size); @@ -193,8 +193,8 @@ namespace GridKit return 0; } - template - int Ieeest::verify() const + template + int Ieeest::verify() const { int ret = 0; @@ -230,8 +230,8 @@ namespace GridKit return ret; } - template - int Ieeest::initialize() + template + int Ieeest::initialize() { for (IdxT i = 0; i < size_; ++i) { @@ -242,8 +242,8 @@ namespace GridKit return 0; } - template - int Ieeest::tagDifferentiable() + template + int Ieeest::tagDifferentiable() { tag_[0] = true; tag_[1] = true; @@ -262,8 +262,8 @@ namespace GridKit return 0; } - template - __attribute__((always_inline)) inline int Ieeest::evaluateInternalResidual( + template + __attribute__((always_inline)) inline int Ieeest::evaluateInternalResidual( ScalarT* y, ScalarT* yp, [[maybe_unused]] ScalarT* wb, @@ -321,8 +321,8 @@ namespace GridKit return 0; } - template - int Ieeest::evaluateResidual() + template + int Ieeest::evaluateResidual() { if (signals_.template isAttached()) { @@ -342,16 +342,16 @@ namespace GridKit return 0; } - template - const Model::VariableMonitorBase* Ieeest::getMonitor() const + template + const Model::VariableMonitorBase* Ieeest::getMonitor() const { return monitor_.get(); } - template - void Ieeest::initializeMonitor() + template + void Ieeest::initializeMonitor() { - using Variable = typename model_data_type::MonitorableVariables; + using Variable = typename ModelDataT::MonitorableVariables; monitor_->set(Variable::vs, [this] { return y_[12]; }); } diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/Genrou.cpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/Genrou.cpp index efcea4fc6..72499c959 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/Genrou.cpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/Genrou.cpp @@ -14,12 +14,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented yet * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int Genrou::evaluateJacobian() + template + int Genrou::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Genrou..." << std::endl; Log::misc() << "Jacobian evaluation not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/Genrou.hpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/Genrou.hpp index e0bccb2c0..73b6f764d 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/Genrou.hpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/Genrou.hpp @@ -18,13 +18,13 @@ namespace GridKit { namespace PhasorDynamics { - template + template class BusBase; - template + template class SignalNode; - template + template struct GenrouData; } // namespace PhasorDynamics } // namespace GridKit @@ -66,67 +66,69 @@ namespace GridKit MAXIMUM, }; - template - class Genrou : public Component + template + class Genrou : public Component { - using Component::gridkit_component_id_; - using Component::alpha_; - using Component::f_; - using Component::nnz_; - using Component::size_; - using Component::tag_; - using Component::time_; - using Component::y_; - using Component::yp_; - using Component::wb_; - using Component::h_; - using Component::J_; - using Component::J_rows_buffer_; - using Component::J_cols_buffer_; - using Component::J_vals_buffer_; - using Component::freq_system_base_; - using Component::va_system_base_; - using Component::variable_indices_; - using Component::residual_indices_; + using Component::gridkit_component_id_; + using Component::alpha_; + using Component::f_; + using Component::nnz_; + using Component::size_; + using Component::tag_; + using Component::time_; + using Component::y_; + using Component::yp_; + using Component::wb_; + using Component::h_; + using Component::J_; + using Component::J_rows_buffer_; + using Component::J_cols_buffer_; + using Component::J_vals_buffer_; + using Component::freq_system_base_; + using Component::va_system_base_; + using Component::variable_indices_; + using Component::residual_indices_; public: - using RealT = typename Component::RealT; - using bus_type = BusBase; - using model_data_type = GenrouData; - using signal_type = SignalNode; - using MonitorT = Model::VariableMonitor; - - Genrou(bus_type* bus, IdxT unit_id); - Genrou(bus_type* bus, - signal_type* omega, - signal_type* pmech, - const model_data_type& data); - Genrou(bus_type* bus, - signal_type* omega, - signal_type* pmech, - signal_type* efd, - const model_data_type& data); - Genrou(bus_type* bus, const model_data_type& data); - Genrou(bus_type* bus, - IdxT unit_id, - RealT p0, - RealT q0, - RealT H, - RealT D, - RealT Ra, - RealT Tdop, - RealT Tdopp, - RealT Tqopp, - RealT Tqop, - RealT Xd, - RealT Xdp, - RealT Xdpp, - RealT Xq, - RealT Xqp, - RealT Xqpp, - RealT Xl, - RealT S10, - RealT S12); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename Component::RealT; + using BusT = BusBase; + using ModelDataT = GenrouData; + using SignalT = SignalNode; + using MonitorT = Model::VariableMonitor; + + Genrou(BusT* bus, IdxT unit_id); + Genrou(BusT* bus, + SignalT* omega, + SignalT* pmech, + const ModelDataT& data); + Genrou(BusT* bus, + SignalT* omega, + SignalT* pmech, + SignalT* efd, + const ModelDataT& data); + Genrou(BusT* bus, const ModelDataT& data); + Genrou(BusT* bus, + IdxT unit_id, + RealT p0, + RealT q0, + RealT H, + RealT D, + RealT Ra, + RealT Tdop, + RealT Tdopp, + RealT Tqopp, + RealT Tqop, + RealT Xd, + RealT Xdp, + RealT Xdpp, + RealT Xq, + RealT Xqp, + RealT Xqpp, + RealT Xl, + RealT S10, + RealT S12); ~Genrou(); int setGridKitComponentID(IdxT) override final; @@ -157,7 +159,7 @@ namespace GridKit const Model::VariableMonitorBase* getMonitor() const override; private: - void initializeParameters(const model_data_type& data); + void initializeParameters(const ModelDataT& data); /// Associate variable getter functions with enum values void initializeMonitor(); void setDerivedParams(); @@ -208,9 +210,9 @@ namespace GridKit private: /* Identification */ - bus_type* bus_; - IdxT bus_id_{0}; - IdxT unit_id_; //< @todo this should be removed + BusT* bus_; + IdxT bus_id_{0}; + IdxT unit_id_; //< @todo this should be removed /// Component signal extension ComponentSignals signals_; diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GenrouDependencyTracking.cpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GenrouDependencyTracking.cpp index 8d4c004ca..7d5001b5e 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GenrouDependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GenrouDependencyTracking.cpp @@ -7,12 +7,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented yet * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int Genrou::evaluateJacobian() + template + int Genrou::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Genrou..." << std::endl; Log::misc() << "Jacobian evaluation not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GenrouEnzyme.cpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GenrouEnzyme.cpp index 18c4cbb36..5347d4b9a 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GenrouEnzyme.cpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GenrouEnzyme.cpp @@ -19,8 +19,8 @@ namespace GridKit * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int Genrou::evaluateJacobian() + template + int Genrou::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for Genrou..." << std::endl; Log::misc() << "Jacobian evaluation is experimental!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GenrouImpl.hpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GenrouImpl.hpp index b7ccac6d5..710937377 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GenrouImpl.hpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROUwS/GenrouImpl.hpp @@ -27,8 +27,8 @@ namespace GridKit * - Number of quadratures = 0 * - Number of optimization parameters = 0 */ - template - Genrou::Genrou(bus_type* bus, IdxT unit_id) + template + Genrou::Genrou(BusT* bus, IdxT unit_id) : bus_(bus), bus_id_(0), unit_id_(unit_id), @@ -59,27 +59,27 @@ namespace GridKit /** * @brief Constructor for a GENROU generator model with saturation */ - template - Genrou::Genrou(bus_type* bus, - IdxT unit_id, - RealT p0, - RealT q0, - RealT H, - RealT D, - RealT Ra, - RealT Tdop, - RealT Tdopp, - RealT Tqopp, - RealT Tqop, - RealT Xd, - RealT Xdp, - RealT Xdpp, - RealT Xq, - RealT Xqp, - RealT Xqpp, - RealT Xl, - RealT S10, - RealT S12) + template + Genrou::Genrou(BusT* bus, + IdxT unit_id, + RealT p0, + RealT q0, + RealT H, + RealT D, + RealT Ra, + RealT Tdop, + RealT Tdopp, + RealT Tqopp, + RealT Tqop, + RealT Xd, + RealT Xdp, + RealT Xdpp, + RealT Xq, + RealT Xqp, + RealT Xqpp, + RealT Xl, + RealT S10, + RealT S12) : bus_(bus), bus_id_(0), unit_id_(unit_id), @@ -110,8 +110,8 @@ namespace GridKit /** * @brief Constructor for a GENROU generator model with saturation */ - template - Genrou::Genrou(bus_type* bus, const model_data_type& data) + template + Genrou::Genrou(BusT* bus, const ModelDataT& data) : bus_(bus), unit_id_(1), monitor_(std::make_unique(data)) @@ -126,8 +126,8 @@ namespace GridKit /** * @brief Constructor for a GENROU generator model with saturation */ - template - Genrou::Genrou(bus_type* bus, signal_type* omega, signal_type* pmech, const model_data_type& data) + template + Genrou::Genrou(BusT* bus, SignalT* omega, SignalT* pmech, const ModelDataT& data) : bus_(bus), unit_id_(1), monitor_(std::make_unique(data)) @@ -144,8 +144,8 @@ namespace GridKit /** * @brief Constructor for a GENROU generator model with saturation */ - template - Genrou::Genrou(bus_type* bus, signal_type* omega, signal_type* pmech, signal_type* efd, const model_data_type& data) + template + Genrou::Genrou(BusT* bus, SignalT* omega, SignalT* pmech, SignalT* efd, const ModelDataT& data) : bus_(bus), unit_id_(1), monitor_(std::make_unique(data)) @@ -160,139 +160,139 @@ namespace GridKit setDerivedParams(); } - template - Genrou::~Genrou() + template + Genrou::~Genrou() { } /// Helper function to extract and assign model parameters from the model's associated /// data structure. - template - void Genrou::initializeParameters(const model_data_type& data) + template + void Genrou::initializeParameters(const ModelDataT& data) { - if (data.parameters.contains(model_data_type::Parameters::p0)) + if (data.parameters.contains(ModelDataT::Parameters::p0)) { - p0_ = std::get(data.parameters.at(model_data_type::Parameters::p0)); + p0_ = std::get(data.parameters.at(ModelDataT::Parameters::p0)); } - if (data.parameters.contains(model_data_type::Parameters::q0)) + if (data.parameters.contains(ModelDataT::Parameters::q0)) { - q0_ = std::get(data.parameters.at(model_data_type::Parameters::q0)); + q0_ = std::get(data.parameters.at(ModelDataT::Parameters::q0)); } - if (data.parameters.contains(model_data_type::Parameters::H)) + if (data.parameters.contains(ModelDataT::Parameters::H)) { - H_ = std::get(data.parameters.at(model_data_type::Parameters::H)); + H_ = std::get(data.parameters.at(ModelDataT::Parameters::H)); } - if (data.parameters.contains(model_data_type::Parameters::D)) + if (data.parameters.contains(ModelDataT::Parameters::D)) { - D_ = std::get(data.parameters.at(model_data_type::Parameters::D)); + D_ = std::get(data.parameters.at(ModelDataT::Parameters::D)); } - if (data.parameters.contains(model_data_type::Parameters::Ra)) + if (data.parameters.contains(ModelDataT::Parameters::Ra)) { - Ra_ = std::get(data.parameters.at(model_data_type::Parameters::Ra)); + Ra_ = std::get(data.parameters.at(ModelDataT::Parameters::Ra)); } - if (data.parameters.contains(model_data_type::Parameters::Tdop)) + if (data.parameters.contains(ModelDataT::Parameters::Tdop)) { - Tdop_ = std::get(data.parameters.at(model_data_type::Parameters::Tdop)); + Tdop_ = std::get(data.parameters.at(ModelDataT::Parameters::Tdop)); } - if (data.parameters.contains(model_data_type::Parameters::Tdopp)) + if (data.parameters.contains(ModelDataT::Parameters::Tdopp)) { - Tdopp_ = std::get(data.parameters.at(model_data_type::Parameters::Tdopp)); + Tdopp_ = std::get(data.parameters.at(ModelDataT::Parameters::Tdopp)); } - if (data.parameters.contains(model_data_type::Parameters::Tqopp)) + if (data.parameters.contains(ModelDataT::Parameters::Tqopp)) { - Tqopp_ = std::get(data.parameters.at(model_data_type::Parameters::Tqopp)); + Tqopp_ = std::get(data.parameters.at(ModelDataT::Parameters::Tqopp)); } - if (data.parameters.contains(model_data_type::Parameters::Tqop)) + if (data.parameters.contains(ModelDataT::Parameters::Tqop)) { - Tqop_ = std::get(data.parameters.at(model_data_type::Parameters::Tqop)); + Tqop_ = std::get(data.parameters.at(ModelDataT::Parameters::Tqop)); } - if (data.parameters.contains(model_data_type::Parameters::Xd)) + if (data.parameters.contains(ModelDataT::Parameters::Xd)) { - Xd_ = std::get(data.parameters.at(model_data_type::Parameters::Xd)); + Xd_ = std::get(data.parameters.at(ModelDataT::Parameters::Xd)); } - if (data.parameters.contains(model_data_type::Parameters::Xdp)) + if (data.parameters.contains(ModelDataT::Parameters::Xdp)) { - Xdp_ = std::get(data.parameters.at(model_data_type::Parameters::Xdp)); + Xdp_ = std::get(data.parameters.at(ModelDataT::Parameters::Xdp)); } - if (data.parameters.contains(model_data_type::Parameters::Xdpp)) + if (data.parameters.contains(ModelDataT::Parameters::Xdpp)) { - Xdpp_ = std::get(data.parameters.at(model_data_type::Parameters::Xdpp)); + Xdpp_ = std::get(data.parameters.at(ModelDataT::Parameters::Xdpp)); } - if (data.parameters.contains(model_data_type::Parameters::Xq)) + if (data.parameters.contains(ModelDataT::Parameters::Xq)) { - Xq_ = std::get(data.parameters.at(model_data_type::Parameters::Xq)); + Xq_ = std::get(data.parameters.at(ModelDataT::Parameters::Xq)); } - if (data.parameters.contains(model_data_type::Parameters::Xqp)) + if (data.parameters.contains(ModelDataT::Parameters::Xqp)) { - Xqp_ = std::get(data.parameters.at(model_data_type::Parameters::Xqp)); + Xqp_ = std::get(data.parameters.at(ModelDataT::Parameters::Xqp)); } - if (data.parameters.contains(model_data_type::Parameters::Xqpp)) + if (data.parameters.contains(ModelDataT::Parameters::Xqpp)) { - Xqpp_ = std::get(data.parameters.at(model_data_type::Parameters::Xqpp)); + Xqpp_ = std::get(data.parameters.at(ModelDataT::Parameters::Xqpp)); } - if (data.parameters.contains(model_data_type::Parameters::Xl)) + if (data.parameters.contains(ModelDataT::Parameters::Xl)) { - Xl_ = std::get(data.parameters.at(model_data_type::Parameters::Xl)); + Xl_ = std::get(data.parameters.at(ModelDataT::Parameters::Xl)); } - if (data.parameters.contains(model_data_type::Parameters::S10)) + if (data.parameters.contains(ModelDataT::Parameters::S10)) { - S10_ = std::get(data.parameters.at(model_data_type::Parameters::S10)); + S10_ = std::get(data.parameters.at(ModelDataT::Parameters::S10)); } - if (data.parameters.contains(model_data_type::Parameters::S12)) + if (data.parameters.contains(ModelDataT::Parameters::S12)) { - S12_ = std::get(data.parameters.at(model_data_type::Parameters::S12)); + S12_ = std::get(data.parameters.at(ModelDataT::Parameters::S12)); } - if (data.parameters.contains(model_data_type::Parameters::mva_base)) + if (data.parameters.contains(ModelDataT::Parameters::mva_base)) { - mva_base_ = std::get(data.parameters.at(model_data_type::Parameters::mva_base)); + mva_base_ = std::get(data.parameters.at(ModelDataT::Parameters::mva_base)); } - if (data.ports.contains(model_data_type::Ports::bus)) + if (data.ports.contains(ModelDataT::Ports::bus)) { - bus_id_ = data.ports.at(model_data_type::Ports::bus); + bus_id_ = data.ports.at(ModelDataT::Ports::bus); } } - template - const Model::VariableMonitorBase* Genrou::getMonitor() const + template + const Model::VariableMonitorBase* Genrou::getMonitor() const { return monitor_.get(); } - template - ScalarT Genrou::toMachineBase(ScalarT value) const + template + Genrou::ScalarT Genrou::toMachineBase(ScalarT value) const { return value * va_system_base_ / va_machine_base_; } - template - ScalarT Genrou::toSystemBase(ScalarT value) const + template + Genrou::ScalarT Genrou::toSystemBase(ScalarT value) const { return value / toMachineBase(static_cast(ONE)); } - template - void Genrou::initializeMonitor() + template + void Genrou::initializeMonitor() { - using Variable = typename model_data_type::MonitorableVariables; + using Variable = typename ModelDataT::MonitorableVariables; monitor_->set(Variable::ir, [this] { return toSystemBase(y_[15]); }); monitor_->set(Variable::ii, [this] @@ -312,8 +312,8 @@ namespace GridKit /** * @brief Set the component ID */ - template - int Genrou::setGridKitComponentID(IdxT component_id) + template + int Genrou::setGridKitComponentID(IdxT component_id) { gridkit_component_id_ = component_id; return 0; @@ -322,8 +322,8 @@ namespace GridKit /*! * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int Genrou::allocate() + template + int Genrou::allocate() { // Resize component model data auto size = static_cast(size_); @@ -363,8 +363,8 @@ namespace GridKit /** * @brief verify method checks that attached signals are also linked */ - template - int Genrou::verify() const + template + int Genrou::verify() const { static constexpr auto PM = GenrouExternalVariables::PM; static constexpr auto EFD = GenrouExternalVariables::EFD; @@ -396,8 +396,8 @@ namespace GridKit * Initialization of the branch model * */ - template - int Genrou::initialize() + template + int Genrou::initialize() { // Saturated initialization with ksat iteration. // See README "With Saturation" and plan for derivation. @@ -513,8 +513,8 @@ namespace GridKit /** * \brief Identify differential variables. */ - template - int Genrou::tagDifferentiable() + template + int Genrou::tagDifferentiable() { for (IdxT i = 0; i < size_; ++i) { @@ -527,8 +527,8 @@ namespace GridKit * @brief Internal residual * */ - template - __attribute__((always_inline)) inline int Genrou::evaluateInternalResidual( + template + __attribute__((always_inline)) inline int Genrou::evaluateInternalResidual( ScalarT* y, ScalarT* yp, ScalarT* wb, @@ -605,8 +605,8 @@ namespace GridKit * @brief Bus residual * */ - template - __attribute__((always_inline)) inline int Genrou::evaluateBusResidual( + template + __attribute__((always_inline)) inline int Genrou::evaluateBusResidual( ScalarT* y, [[maybe_unused]] ScalarT* yp, ScalarT* wb, @@ -627,8 +627,8 @@ namespace GridKit * \brief Residual evaluation and contribution to the connected bus * */ - template - int Genrou::evaluateResidual() + template + int Genrou::evaluateResidual() { // Mechanical Power ws_[0] = pmech_set_; @@ -664,24 +664,22 @@ namespace GridKit /** * @brief Access generator relative speed * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - ScalarT Genrou::getSpeed() + template + scalar_type Genrou::getSpeed() { return y_[1]; } - template - ScalarT Genrou::getTorque() + template + scalar_type Genrou::getTorque() { return y_[12]; } - template - void Genrou::setDerivedParams() + template + void Genrou::setDerivedParams() { SA_ = 0; SB_ = 0; diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassical.cpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassical.cpp index b13b66247..2f83c80b5 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassical.cpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassical.cpp @@ -8,12 +8,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int GenClassical::evaluateJacobian() + template + int GenClassical::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for GenClassical..." << std::endl; Log::misc() << "Jacobian evaluation is not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassical.hpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassical.hpp index 2bf77e2ce..a2696fc0d 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassical.hpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassical.hpp @@ -17,10 +17,10 @@ namespace GridKit { namespace PhasorDynamics { - template + template class BusBase; - template + template struct GenClassicalData; } // namespace PhasorDynamics } // namespace GridKit @@ -30,45 +30,47 @@ namespace GridKit namespace PhasorDynamics { - template - class GenClassical : public Component + template + class GenClassical : public Component { - using Component::gridkit_component_id_; - using Component::alpha_; - using Component::f_; - using Component::nnz_; - using Component::size_; - using Component::tag_; - using Component::time_; - using Component::y_; - using Component::yp_; - using Component::wb_; - using Component::h_; - using Component::J_; - using Component::J_rows_buffer_; - using Component::J_cols_buffer_; - using Component::J_vals_buffer_; - using Component::freq_system_base_; - using Component::va_system_base_; - using Component::variable_indices_; - using Component::residual_indices_; + using Component::gridkit_component_id_; + using Component::alpha_; + using Component::f_; + using Component::nnz_; + using Component::size_; + using Component::tag_; + using Component::time_; + using Component::y_; + using Component::yp_; + using Component::wb_; + using Component::h_; + using Component::J_; + using Component::J_rows_buffer_; + using Component::J_cols_buffer_; + using Component::J_vals_buffer_; + using Component::freq_system_base_; + using Component::va_system_base_; + using Component::variable_indices_; + using Component::residual_indices_; public: - using bus_type = BusBase; - using RealT = typename Component::RealT; - using DataT = GenClassicalData; - using MonitorT = Model::VariableMonitor; - - GenClassical(bus_type* bus, int unit_id); - GenClassical(bus_type* bus, - int unit_id, - RealT p0, - RealT q0, - RealT H, - RealT D, - RealT Ra, - RealT Xdp); - GenClassical(bus_type* bus, const DataT& data); + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename Component::RealT; + using BusT = BusBase; + using ModelDataT = GenClassicalData; + using MonitorT = Model::VariableMonitor; + + GenClassical(BusT* bus, int unit_id); + GenClassical(BusT* bus, + int unit_id, + RealT p0, + RealT q0, + RealT H, + RealT D, + RealT Ra, + RealT Xdp); + GenClassical(BusT* bus, const ModelDataT& data); ~GenClassical(); int setGridKitComponentID(IdxT) override final; @@ -147,9 +149,9 @@ namespace GridKit private: /* Identification */ - bus_type* bus_; - IdxT bus_id_{0}; - int unit_id_; //< @todo this should be removed + BusT* bus_; + IdxT bus_id_{0}; + int unit_id_; //< @todo this should be removed /* Initial terminal conditions */ RealT p0_{0.0}; diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalData.hpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalData.hpp index ab7491445..bf1bd0a58 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalData.hpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalData.hpp @@ -51,16 +51,16 @@ namespace GridKit /** * @brief Contains modeling data for a GenClassical generator model. * - * @tparam RealT Real parameter data type - * @tparam IdxT Integer parameter data type + * @tparam real_type Real parameter data type + * @tparam index_type Integer parameter data type * * Integer parameters are of the same type as matrix and vector indices. * * @todo Decide on naming scheme for model parameters. */ - template - struct GenClassicalData : public ComponentData + struct GenClassicalData : public ComponentData diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalDependencyTracking.cpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalDependencyTracking.cpp index 1fa1a7036..7a173534a 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalDependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalDependencyTracking.cpp @@ -8,12 +8,10 @@ namespace GridKit /** * @brief Jacobian evaluation not implemented * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int GenClassical::evaluateJacobian() + template + int GenClassical::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for GenClassical..." << std::endl; Log::misc() << "Jacobian evaluation is not implemented!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalEnzyme.cpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalEnzyme.cpp index c38a88931..f5f664035 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalEnzyme.cpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalEnzyme.cpp @@ -15,12 +15,10 @@ namespace GridKit /** * @brief Jacobian evaluation experimental * - * @tparam ScalarT - scalar data type - * @tparam IdxT - matrix index data type * @return int - error code, 0 = success */ - template - int GenClassical::evaluateJacobian() + template + int GenClassical::evaluateJacobian() { Log::misc() << "Evaluate Jacobian for GenClassical..." << std::endl; Log::misc() << "Jacobian evaluation is experimental!" << std::endl; diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalImpl.hpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalImpl.hpp index e3836912f..582a59d70 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalImpl.hpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GenClassical/GenClassicalImpl.hpp @@ -22,8 +22,8 @@ namespace GridKit /** * @brief Constructor for a classical generator model */ - template - GenClassical::GenClassical(bus_type* bus, int unit_id) + template + GenClassical::GenClassical(BusT* bus, int unit_id) : bus_(bus), bus_id_(0), unit_id_(unit_id), @@ -42,15 +42,15 @@ namespace GridKit /** * @brief Constructor for a classical generator model */ - template - GenClassical::GenClassical(bus_type* bus, - int unit_id, - RealT p0, - RealT q0, - RealT H, - RealT D, - RealT Ra, - RealT Xdp) + template + GenClassical::GenClassical(BusT* bus, + int unit_id, + RealT p0, + RealT q0, + RealT H, + RealT D, + RealT Ra, + RealT Xdp) : bus_(bus), bus_id_(0), unit_id_(unit_id), @@ -69,50 +69,50 @@ namespace GridKit /** * @brief Constructor for a classical generator model */ - template - GenClassical::GenClassical(bus_type* bus, const DataT& data) + template + GenClassical::GenClassical(BusT* bus, const ModelDataT& data) : bus_(bus), unit_id_(1), monitor_(std::make_unique(data)) { - if (data.parameters.contains(DataT::Parameters::p0)) + if (data.parameters.contains(ModelDataT::Parameters::p0)) { - p0_ = std::get(data.parameters.at(DataT::Parameters::p0)); + p0_ = std::get(data.parameters.at(ModelDataT::Parameters::p0)); } - if (data.parameters.contains(DataT::Parameters::q0)) + if (data.parameters.contains(ModelDataT::Parameters::q0)) { - q0_ = std::get(data.parameters.at(DataT::Parameters::q0)); + q0_ = std::get(data.parameters.at(ModelDataT::Parameters::q0)); } - if (data.parameters.contains(DataT::Parameters::H)) + if (data.parameters.contains(ModelDataT::Parameters::H)) { - H_ = std::get(data.parameters.at(DataT::Parameters::H)); + H_ = std::get(data.parameters.at(ModelDataT::Parameters::H)); } - if (data.parameters.contains(DataT::Parameters::D)) + if (data.parameters.contains(ModelDataT::Parameters::D)) { - D_ = std::get(data.parameters.at(DataT::Parameters::D)); + D_ = std::get(data.parameters.at(ModelDataT::Parameters::D)); } - if (data.parameters.contains(DataT::Parameters::Ra)) + if (data.parameters.contains(ModelDataT::Parameters::Ra)) { - Ra_ = std::get(data.parameters.at(DataT::Parameters::Ra)); + Ra_ = std::get(data.parameters.at(ModelDataT::Parameters::Ra)); } - if (data.parameters.contains(DataT::Parameters::Xdp)) + if (data.parameters.contains(ModelDataT::Parameters::Xdp)) { - Xdp_ = std::get(data.parameters.at(DataT::Parameters::Xdp)); + Xdp_ = std::get(data.parameters.at(ModelDataT::Parameters::Xdp)); } - if (data.parameters.contains(DataT::Parameters::mva_base)) + if (data.parameters.contains(ModelDataT::Parameters::mva_base)) { - mva_base_ = std::get(data.parameters.at(DataT::Parameters::mva_base)); + mva_base_ = std::get(data.parameters.at(ModelDataT::Parameters::mva_base)); } - if (data.ports.contains(DataT::Ports::bus)) + if (data.ports.contains(ModelDataT::Ports::bus)) { - bus_id_ = data.ports.at(DataT::Ports::bus); + bus_id_ = data.ports.at(ModelDataT::Ports::bus); } initializeMonitor(); @@ -121,33 +121,33 @@ namespace GridKit setDerivedParams(); } - template - GenClassical::~GenClassical() + template + GenClassical::~GenClassical() { } - template - const Model::VariableMonitorBase* GenClassical::getMonitor() const + template + const Model::VariableMonitorBase* GenClassical::getMonitor() const { return monitor_.get(); } - template - ScalarT GenClassical::toMachineBase(ScalarT value) const + template + GenClassical::ScalarT GenClassical::toMachineBase(ScalarT value) const { return value * va_system_base_ / va_machine_base_; } - template - ScalarT GenClassical::toSystemBase(ScalarT value) const + template + GenClassical::ScalarT GenClassical::toSystemBase(ScalarT value) const { return value / toMachineBase(static_cast(ONE)); } - template - void GenClassical::initializeMonitor() + template + void GenClassical::initializeMonitor() { - using Variable = typename DataT::MonitorableVariables; + using Variable = typename ModelDataT::MonitorableVariables; monitor_->set(Variable::ir, [this] { return toSystemBase(y_[3]); }); monitor_->set(Variable::ii, [this] @@ -165,8 +165,8 @@ namespace GridKit /** * @brief Set the component ID */ - template - int GenClassical::setGridKitComponentID(IdxT component_id) + template + int GenClassical::setGridKitComponentID(IdxT component_id) { gridkit_component_id_ = component_id; return 0; @@ -175,8 +175,8 @@ namespace GridKit /** * @brief allocate method computes sparsity pattern of the Jacobian. */ - template - int GenClassical::allocate() + template + int GenClassical::allocate() { // Resize component model data auto size = static_cast(size_); @@ -204,8 +204,8 @@ namespace GridKit /** * Initialization of the generator model */ - template - int GenClassical::initialize() + template + int GenClassical::initialize() { ScalarT vr = Vr(); ScalarT vi = Vi(); @@ -238,8 +238,8 @@ namespace GridKit /** * \brief Identify differential variables. */ - template - int GenClassical::tagDifferentiable() + template + int GenClassical::tagDifferentiable() { for (IdxT i = 0; i < size_; ++i) { @@ -252,8 +252,8 @@ namespace GridKit * @brief Internal residual * */ - template - __attribute__((always_inline)) int GenClassical::evaluateInternalResidual( + template + __attribute__((always_inline)) int GenClassical::evaluateInternalResidual( ScalarT* y, ScalarT* yp, ScalarT* wb, @@ -293,8 +293,8 @@ namespace GridKit * @brief Bus residual * */ - template - __attribute__((always_inline)) int GenClassical::evaluateBusResidual( + template + __attribute__((always_inline)) int GenClassical::evaluateBusResidual( ScalarT* y, [[maybe_unused]] ScalarT* yp, [[maybe_unused]] ScalarT* wb, @@ -312,8 +312,8 @@ namespace GridKit * \brief Residual for the generator model. * */ - template - int GenClassical::evaluateResidual() + template + int GenClassical::evaluateResidual() { wb_[0] = Vr(); wb_[1] = Vi(); @@ -327,8 +327,8 @@ namespace GridKit return 0; } - template - void GenClassical::setDerivedParams() + template + void GenClassical::setDerivedParams() { G_ = Ra_ / (Ra_ * Ra_ + Xdp_ * Xdp_); B_ = -Xdp_ / (Ra_ * Ra_ + Xdp_ * Xdp_); diff --git a/GridKit/Model/PhasorDynamics/SystemModel.hpp b/GridKit/Model/PhasorDynamics/SystemModel.hpp index 53f2d990e..b7c340766 100644 --- a/GridKit/Model/PhasorDynamics/SystemModel.hpp +++ b/GridKit/Model/PhasorDynamics/SystemModel.hpp @@ -29,31 +29,33 @@ namespace GridKit * @todo Address thread safety for the system model methods. * */ - template - class SystemModel : public PhasorDynamics::Component + template + class SystemModel : public PhasorDynamics::Component { - using bus_type = PhasorDynamics::BusBase; - using signal_type = PhasorDynamics::SignalNode; - using component_type = PhasorDynamics::Component; - using RealT = typename Model::Evaluator::RealT; - using CsrMatrixT = typename Model::Evaluator::CsrMatrixT; - - using PhasorDynamics::Component::gridkit_component_id_; - using PhasorDynamics::Component::size_; - using PhasorDynamics::Component::nnz_; - using PhasorDynamics::Component::time_; - using PhasorDynamics::Component::alpha_; - using PhasorDynamics::Component::y_; - using PhasorDynamics::Component::yp_; - using PhasorDynamics::Component::tag_; - using PhasorDynamics::Component::f_; - using PhasorDynamics::Component::J_; - using PhasorDynamics::Component::rel_tol_; - using PhasorDynamics::Component::abs_tol_; - using PhasorDynamics::Component::variable_indices_; - using PhasorDynamics::Component::residual_indices_; + using PhasorDynamics::Component::gridkit_component_id_; + using PhasorDynamics::Component::size_; + using PhasorDynamics::Component::nnz_; + using PhasorDynamics::Component::time_; + using PhasorDynamics::Component::alpha_; + using PhasorDynamics::Component::y_; + using PhasorDynamics::Component::yp_; + using PhasorDynamics::Component::tag_; + using PhasorDynamics::Component::f_; + using PhasorDynamics::Component::J_; + using PhasorDynamics::Component::rel_tol_; + using PhasorDynamics::Component::abs_tol_; + using PhasorDynamics::Component::variable_indices_; + using PhasorDynamics::Component::residual_indices_; public: + using ScalarT = scalar_type; + using IdxT = index_type; + using RealT = typename Model::Evaluator::RealT; + using CsrMatrixT = typename Model::Evaluator::CsrMatrixT; + using BusT = PhasorDynamics::BusBase; + using SignalT = PhasorDynamics::SignalNode; + using ComponentT = PhasorDynamics::Component; + /** * @brief Constructor for the system model */ @@ -918,7 +920,7 @@ namespace GridKit * Add bus at the end of the bus array and map bus ID with GridKit's ID for the bus * */ - void addBus(bus_type* bus) + void addBus(BusT* bus) { IdxT gridkit_bus_id = static_cast(buses_.size()); gridkit_bus_indices_[bus->busID()] = gridkit_bus_id; @@ -931,7 +933,7 @@ namespace GridKit * Add signal at the end of the signals array and map signal ID with GridKit's ID for the signal * */ - void addSignal(signal_type* signal) + void addSignal(SignalT* signal) { IdxT gridkit_signal_id = static_cast(signals_.size()); gridkit_signal_indices_[signal->signalId()] = gridkit_signal_id; @@ -946,7 +948,7 @@ namespace GridKit */ void setSystemBase(RealT freq_system_base, RealT va_system_base) { - component_type::setSystemBase(freq_system_base, va_system_base); + ComponentT::setSystemBase(freq_system_base, va_system_base); for (auto* component : components_) { @@ -963,7 +965,7 @@ namespace GridKit * component ID to the disambiguation_string * */ - void addComponent(component_type* component) + void addComponent(ComponentT* component) { IdxT gridkit_component_id = static_cast(components_.size()); component->setGridKitComponentID(gridkit_component_id); @@ -979,7 +981,7 @@ namespace GridKit * location, so it can easily be accessed. * */ - void addFault(component_type* component) + void addFault(ComponentT* component) { IdxT gridkit_component_id = static_cast(components_.size()); IdxT gridkit_fault_id = static_cast(gridkit_fault_indices_.size()); @@ -991,7 +993,7 @@ namespace GridKit * @brief Return pointer to a bus * */ - bus_type* getBus(IdxT bus_id) + BusT* getBus(IdxT bus_id) { // Should fail if user-provided bus_id is incorrect IdxT gridkit_bus_id = gridkit_bus_indices_.at(bus_id); @@ -1003,7 +1005,7 @@ namespace GridKit * @brief Return pointer to a signal * */ - signal_type* getSignal(IdxT signal_id) + SignalT* getSignal(IdxT signal_id) { // Should fail if user-provided signal_id is incorrect IdxT gridkit_signal_id = gridkit_signal_indices_.at(signal_id); @@ -1015,7 +1017,7 @@ namespace GridKit * @brief Return pointer to a component * */ - component_type* getComponent(IdxT gridkit_component_id) + ComponentT* getComponent(IdxT gridkit_component_id) { // gridkit_component_id_ is set by System model and guarantied to be unique return components_[gridkit_component_id]; @@ -1035,9 +1037,9 @@ namespace GridKit } private: - std::vector buses_; - std::vector signals_; - std::vector components_; + std::vector buses_; + std::vector signals_; + std::vector components_; std::map gridkit_bus_indices_; ///< Map between gridkit_bus_id and bus_id std::map gridkit_signal_indices_; ///< Map between gridkit_signal_id and signal_id diff --git a/GridKit/Model/PhasorDynamics/SystemModelData.hpp b/GridKit/Model/PhasorDynamics/SystemModelData.hpp index a655d3b59..4961029b6 100644 --- a/GridKit/Model/PhasorDynamics/SystemModelData.hpp +++ b/GridKit/Model/PhasorDynamics/SystemModelData.hpp @@ -30,9 +30,11 @@ namespace GridKit /// /// In particular, this structure is modeled after the grid dynamics /// case format, which is described within `INPUT_FORMAT.md` - template + template struct SystemModelData { + using RealT = real_type; + using IdxT = index_type; using BranchDataT = BranchData; using BusDataT = BusData; using BusFaultDataT = BusFaultData; diff --git a/GridKit/Model/VariableMonitor.hpp b/GridKit/Model/VariableMonitor.hpp index 3aa064554..435b6d73d 100644 --- a/GridKit/Model/VariableMonitor.hpp +++ b/GridKit/Model/VariableMonitor.hpp @@ -21,7 +21,7 @@ namespace GridKit { namespace Model { - template + template class VariableMonitorController; /** @@ -137,7 +137,7 @@ namespace GridKit ///@} }; - template typename DataT> + template typename model_data_type> class VariableMonitor; } // namespace Model diff --git a/GridKit/Model/VariableMonitorController.hpp b/GridKit/Model/VariableMonitorController.hpp index 79db154ca..adc631296 100644 --- a/GridKit/Model/VariableMonitorController.hpp +++ b/GridKit/Model/VariableMonitorController.hpp @@ -18,10 +18,12 @@ namespace GridKit * High-level print functions (without parameters) manage printing for all * monitors for multiple output sinks. */ - template + template class VariableMonitorController : public VariableMonitorBase { public: + /// Underlying scalar value type + using ScalarT = scalar_type; /// Underlying real value type using RealT = typename GridKit::ScalarTraits::RealT; ///@{ @@ -307,9 +309,11 @@ namespace GridKit /** * @brief Define sink for a specific output format */ - template + template struct Sink { + using FormatT = format_type; + Sink() = delete; /** diff --git a/GridKit/Model/VariableMonitorImpl.hpp b/GridKit/Model/VariableMonitorImpl.hpp index eda73332e..a262191b6 100644 --- a/GridKit/Model/VariableMonitorImpl.hpp +++ b/GridKit/Model/VariableMonitorImpl.hpp @@ -8,7 +8,7 @@ namespace GridKit { namespace Model { - template + template class VariableMonitorController; using magic_enum::enum_count; @@ -25,21 +25,25 @@ namespace GridKit * break. That way other monitors can print likewise on the same line, and * the line can be ended by the control monitor. */ - template typename EvalT, - template typename DataT> - class VariableMonitor, DataT> + template typename eval_type, + template typename model_data_type> + class VariableMonitor, model_data_type> : public VariableMonitorBase { template friend class VariableMonitorController; public: + /// Underlying scalar value type + using ScalarT = scalar_type; + /// Index type + using IdxT = index_type; /// Underlying real value type using RealT = typename GridKit::ScalarTraits::RealT; /// Type of (EvalT)Data class expected to have MonitorableVariables enum - using ObjData = DataT; + using ObjData = model_data_type; /// Enum of valid monitorable variables using VariableEnum = typename ObjData::MonitorableVariables; ///@{