From 4a70522dad2f695e4ed6a0fbb8b1863eb7398d24 Mon Sep 17 00:00:00 2001 From: Philip Fackler Date: Thu, 23 Apr 2026 15:04:06 -0500 Subject: [PATCH 1/2] Add ConstituentModel as base for components and buses; removed SignalNode from evaluator tree --- GridKit/Model/PhasorDynamics/BusBase.hpp | 291 +---------------- GridKit/Model/PhasorDynamics/BusBaseImpl.hpp | 9 - GridKit/Model/PhasorDynamics/CMakeLists.txt | 2 + GridKit/Model/PhasorDynamics/Component.hpp | 303 +----------------- .../Model/PhasorDynamics/ConstituentModel.hpp | 302 +++++++++++++++++ .../PhasorDynamics/SignalNode/SignalNode.hpp | 271 +--------------- .../SignalNodeDependencyTracking.cpp | 2 + .../SignalNode/SignalNodeImpl.hpp | 34 +- GridKit/Utilities/CMakeLists.txt | 1 + GridKit/Utilities/Errors.hpp | 19 ++ 10 files changed, 354 insertions(+), 880 deletions(-) create mode 100644 GridKit/Model/PhasorDynamics/ConstituentModel.hpp create mode 100644 GridKit/Utilities/Errors.hpp diff --git a/GridKit/Model/PhasorDynamics/BusBase.hpp b/GridKit/Model/PhasorDynamics/BusBase.hpp index b2fc397d2..7ca3fc113 100644 --- a/GridKit/Model/PhasorDynamics/BusBase.hpp +++ b/GridKit/Model/PhasorDynamics/BusBase.hpp @@ -6,8 +6,8 @@ #include #include -#include #include +#include #include #include @@ -22,11 +22,11 @@ namespace GridKit * */ template - class BusBase : public Model::Evaluator + class BusBase : public ConstituentModel { public: - using RealT = typename Model::Evaluator::RealT; - using MatrixT = typename Model::Evaluator::MatrixT; + using RealT = typename ConstituentModel::RealT; + using MatrixT = typename ConstituentModel::MatrixT; using BusTypeT = typename BusData::BusType; using MonitorT = Model::VariableMonitor; @@ -36,43 +36,27 @@ namespace GridKit virtual ~BusBase(); - /// Pure virtual function, returns bus type (DEFAULT or SLACK). - virtual BusTypeT BusType() const + int verify() const override { - return BusTypeT::DEFAULT; - } - - virtual IdxT size() override - { - return size_; + return 0; } - virtual IdxT nnz() override + /// Pure virtual function, returns bus type (DEFAULT or SLACK). + virtual BusTypeT BusType() const { - return nnz_; + return BusTypeT::DEFAULT; } - virtual bool hasJacobian() override + bool hasJacobian() override { return false; } - virtual void updateTime(RealT /* t */, RealT /* a */) override + void updateTime(RealT /* t */, RealT /* a */) override { // No time to update in bus models } - virtual void setTolerances(RealT& rtol, RealT& atol) const override - { - rtol = rtol_; - atol = atol_; - } - - virtual void setMaxSteps(IdxT& msa) const override - { - msa = max_steps_; - } - virtual ScalarT& Vr() = 0; virtual const ScalarT& Vr() const = 0; virtual ScalarT& Vi() = 0; @@ -82,46 +66,6 @@ namespace GridKit virtual ScalarT& Ii() = 0; virtual const ScalarT& Ii() const = 0; - std::vector& y() override - { - return y_; - } - - const std::vector& y() const override - { - return y_; - } - - std::vector& yp() override - { - return yp_; - } - - const std::vector& yp() const override - { - return yp_; - } - - std::vector& tag() override - { - return tag_; - } - - const std::vector& tag() const override - { - return tag_; - } - - MatrixT& getJacobian() override - { - return J_; - } - - const MatrixT& getJacobian() const override - { - return J_; - } - virtual int setBusID(IdxT) = 0; virtual const IdxT busID() const @@ -129,226 +73,13 @@ namespace GridKit return bus_id_; } - int setVariableIndex(IdxT local_index, IdxT global_index) - { - variable_indices_[static_cast(local_index)] = global_index; - return 0; - } - - IdxT getVariableIndex(IdxT local_index) const - { - return variable_indices_[static_cast(local_index)]; - } - - const std::vector& getVariableIndices() const - { - return variable_indices_; - } - - int setResidualIndex(IdxT local_index, IdxT global_index) - { - residual_indices_[static_cast(local_index)] = global_index; - return 0; - } - - IdxT getResidualIndex(IdxT local_index) const - { - return residual_indices_[static_cast(local_index)]; - } - - const std::vector& getResidualIndices() const - { - return residual_indices_; - } - const Model::VariableMonitorBase* getMonitor() const override; protected: IdxT bus_id_{INVALID_INDEX}; - IdxT size_{0}; - IdxT nnz_{0}; - std::vector variable_indices_; ///< Global (system-level) variable indices - std::vector residual_indices_; ///< Global (system-level) residual indices - /// Variable monitor std::unique_ptr monitor_; - - std::vector y_; - std::vector yp_; - std::vector tag_; - std::vector f_; - - MatrixT J_; - IdxT* J_rows_buffer_{nullptr}; - IdxT* J_cols_buffer_{nullptr}; - RealT* J_vals_buffer_{nullptr}; - - RealT rtol_; - RealT atol_; - - IdxT max_steps_; - - // - // Adjoint sensitivity members - // - - std::vector g_{}; - std::vector yB_{}; - std::vector ypB_{}; - std::vector fB_{}; - std::vector gB_{}; - - std::vector param_{}; - std::vector param_up_{}; - std::vector param_lo_{}; - - // - // Public adjoint sensitivity methods (not yet implemented in components) - // - - public: - virtual IdxT sizeQuadrature() override - { - throw "ERROR: Method not implemented!\n"; - return 0; - } - - virtual IdxT sizeParams() override - { - throw "ERROR: Method not implemented!\n"; - return 0; - } - - std::vector& yB() override - { - throw "ERROR: Method not implemented!\n"; - return yB_; - } - - const std::vector& yB() const override - { - throw "ERROR: Method not implemented!\n"; - return yB_; - } - - std::vector& ypB() override - { - throw "ERROR: Method not implemented!\n"; - return ypB_; - } - - const std::vector& ypB() const override - { - throw "ERROR: Method not implemented!\n"; - return ypB_; - } - - std::vector& param() override - { - throw "ERROR: Method not implemented!\n"; - return param_; - } - - const std::vector& param() const override - { - throw "ERROR: Method not implemented!\n"; - return param_; - } - - std::vector& param_up() override - { - throw "ERROR: Method not implemented!\n"; - return param_up_; - } - - const std::vector& param_up() const override - { - throw "ERROR: Method not implemented!\n"; - return param_up_; - } - - std::vector& param_lo() override - { - throw "ERROR: Method not implemented!\n"; - return param_lo_; - } - - const std::vector& param_lo() const override - { - throw "ERROR: Method not implemented!\n"; - return param_lo_; - } - - int evaluateIntegrand() override - { - throw "ERROR: Method not implemented!\n"; - return 1; - } - - int initializeAdjoint() override - { - throw "ERROR: Method not implemented!\n"; - return 1; - } - - int evaluateAdjointResidual() override - { - throw "ERROR: Method not implemented!\n"; - return 1; - } - - int evaluateAdjointIntegrand() override - { - throw "ERROR: Method not implemented!\n"; - return 1; - } - - std::vector& getResidual() override - { - return f_; - } - - const std::vector& getResidual() const override - { - return f_; - } - - std::vector& getIntegrand() override - { - throw "ERROR: Method not implemented!\n"; - return g_; - } - - const std::vector& getIntegrand() const override - { - throw "ERROR: Method not implemented!\n"; - return g_; - } - - std::vector& getAdjointResidual() override - { - throw "ERROR: Method not implemented!\n"; - return fB_; - } - - const std::vector& getAdjointResidual() const override - { - throw "ERROR: Method not implemented!\n"; - return fB_; - } - - std::vector& getAdjointIntegrand() override - { - throw "ERROR: Method not implemented!\n"; - return gB_; - } - - const std::vector& getAdjointIntegrand() const override - { - throw "ERROR: Method not implemented!\n"; - return gB_; - } }; } // namespace PhasorDynamics diff --git a/GridKit/Model/PhasorDynamics/BusBaseImpl.hpp b/GridKit/Model/PhasorDynamics/BusBaseImpl.hpp index 5611b8597..aa06537a9 100644 --- a/GridKit/Model/PhasorDynamics/BusBaseImpl.hpp +++ b/GridKit/Model/PhasorDynamics/BusBaseImpl.hpp @@ -26,15 +26,6 @@ namespace GridKit template BusBase::~BusBase() { - if (J_rows_buffer_ != nullptr) - { - delete[] J_rows_buffer_; - delete[] J_cols_buffer_; - delete[] J_vals_buffer_; - J_rows_buffer_ = nullptr; - J_cols_buffer_ = nullptr; - J_vals_buffer_ = nullptr; - } } template diff --git a/GridKit/Model/PhasorDynamics/CMakeLists.txt b/GridKit/Model/PhasorDynamics/CMakeLists.txt index b83192684..68a244938 100644 --- a/GridKit/Model/PhasorDynamics/CMakeLists.txt +++ b/GridKit/Model/PhasorDynamics/CMakeLists.txt @@ -11,10 +11,12 @@ gridkit_add_library(phasor_dynamics_core SystemModelData.cpp HEADERS BusBase.hpp + BusBaseImpl.hpp Component.hpp ComponentData.hpp ComponentLibrary.hpp ComponentSignals.hpp + ConstituentModel.hpp SystemModel.hpp SystemModelData.hpp LINK_LIBRARIES diff --git a/GridKit/Model/PhasorDynamics/Component.hpp b/GridKit/Model/PhasorDynamics/Component.hpp index 53de53b38..8f750bd92 100644 --- a/GridKit/Model/PhasorDynamics/Component.hpp +++ b/GridKit/Model/PhasorDynamics/Component.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include namespace GridKit @@ -17,114 +17,28 @@ namespace GridKit * @brief Component model implementation base class. */ template - class Component : public Model::Evaluator + class Component : public ConstituentModel { public: - using RealT = typename Model::Evaluator::RealT; - using MatrixT = typename Model::Evaluator::MatrixT; + using RealT = typename ConstituentModel::RealT; + using MatrixT = typename ConstituentModel::MatrixT; - Component() - : size_(0) - { - } + Component() = default; virtual ~Component() { - if (J_rows_buffer_ != nullptr) - { - delete[] J_rows_buffer_; - delete[] J_cols_buffer_; - delete[] J_vals_buffer_; - J_rows_buffer_ = nullptr; - J_cols_buffer_ = nullptr; - J_vals_buffer_ = nullptr; - } - } - - virtual int verify() const = 0; - - virtual IdxT size() override - { - return size_; - } - - virtual IdxT nnz() override - { - return nnz_; } /// @todo Remove this method. It should be part of DynamicSolver class. - virtual bool hasJacobian() override + bool hasJacobian() override { return true; } - virtual void updateTime(RealT t, RealT a) override + void updateTime(RealT t, RealT a) override { time_ = t; alpha_ = a; - // std::cout << "updateTime: t = " << time_ << ", alpha = " << alpha_ << "\n"; - } - - virtual void setTolerances(RealT& rtol, RealT& atol) const override - { - rtol = rel_tol_; - atol = abs_tol_; - } - - virtual void setMaxSteps(IdxT& msa) const override - { - msa = max_steps_; - } - - std::vector& y() override - { - return y_; - } - - const std::vector& y() const override - { - return y_; - } - - std::vector& yp() override - { - return yp_; - } - - const std::vector& yp() const override - { - return yp_; - } - - std::vector& tag() override - { - return tag_; - } - - const std::vector& tag() const override - { - return tag_; - } - - std::vector& getResidual() override - { - return f_; - } - - const std::vector& getResidual() const override - { - return f_; - } - - MatrixT& getJacobian() override - { - return J_; - } - - const MatrixT& getJacobian() const override - { - return J_; } virtual int setGridKitComponentID(IdxT) = 0; @@ -134,66 +48,15 @@ namespace GridKit return gridkit_component_id_; } - int setVariableIndex(IdxT local_index, IdxT global_index) - { - variable_indices_[static_cast(local_index)] = global_index; - return 0; - } - - IdxT& getVariableIndex(IdxT local_index) - { - return variable_indices_[static_cast(local_index)]; - } - - const std::vector& getVariableIndices() const - { - return variable_indices_; - } - - int setResidualIndex(IdxT local_index, IdxT global_index) - { - residual_indices_[static_cast(local_index)] = global_index; - return 0; - } - - IdxT& getResidualIndex(IdxT local_index) - { - return residual_indices_[static_cast(local_index)]; - } - - const std::vector& getResidualIndices() const - { - return residual_indices_; - } - protected: - IdxT gridkit_component_id_{0}; - IdxT size_{0}; - IdxT nnz_{0}; - std::vector variable_indices_; ///< Global (system-level) variable indices - std::vector residual_indices_; ///< Global (system-level) residual indices + IdxT gridkit_component_id_{0}; - std::vector y_; - std::vector yp_; - std::vector tag_; - std::vector f_; - std::vector g_; std::vector wb_; std::vector h_; - MatrixT J_; - IdxT* J_rows_buffer_{nullptr}; - IdxT* J_cols_buffer_{nullptr}; - RealT* J_vals_buffer_{nullptr}; - RealT time_; RealT alpha_; - RealT rel_tol_; - RealT abs_tol_; - - IdxT max_steps_; - /* ------ WARNING: Temporary ------ @@ -205,156 +68,6 @@ namespace GridKit */ RealT mva_system_base_{100.0}; - - // - // Adjoint sensitivity members - // - - std::vector yB_{}; - std::vector ypB_{}; - std::vector fB_{}; - std::vector gB_{}; - - std::vector param_{}; - std::vector param_up_{}; - std::vector param_lo_{}; - - // - // Public adjoint sensitivity methods (not yet implemented in components) - // - - public: - virtual IdxT sizeQuadrature() override - { - throw "ERROR: Method not implemented!\n"; - return 0; - } - - virtual IdxT sizeParams() override - { - throw "ERROR: Method not implemented!\n"; - return 0; - } - - std::vector& yB() override - { - throw "ERROR: Method not implemented!\n"; - return yB_; - } - - const std::vector& yB() const override - { - throw "ERROR: Method not implemented!\n"; - return yB_; - } - - std::vector& ypB() override - { - throw "ERROR: Method not implemented!\n"; - return ypB_; - } - - const std::vector& ypB() const override - { - throw "ERROR: Method not implemented!\n"; - return ypB_; - } - - std::vector& param() override - { - throw "ERROR: Method not implemented!\n"; - return param_; - } - - const std::vector& param() const override - { - throw "ERROR: Method not implemented!\n"; - return param_; - } - - std::vector& param_up() override - { - throw "ERROR: Method not implemented!\n"; - return param_up_; - } - - const std::vector& param_up() const override - { - throw "ERROR: Method not implemented!\n"; - return param_up_; - } - - std::vector& param_lo() override - { - throw "ERROR: Method not implemented!\n"; - return param_lo_; - } - - const std::vector& param_lo() const override - { - throw "ERROR: Method not implemented!\n"; - return param_lo_; - } - - int evaluateIntegrand() override - { - throw "ERROR: Method not implemented!\n"; - return 1; - } - - int initializeAdjoint() override - { - throw "ERROR: Method not implemented!\n"; - return 1; - } - - int evaluateAdjointResidual() override - { - throw "ERROR: Method not implemented!\n"; - return 1; - } - - int evaluateAdjointIntegrand() override - { - throw "ERROR: Method not implemented!\n"; - return 1; - } - - std::vector& getIntegrand() override - { - throw "ERROR: Method not implemented!\n"; - return g_; - } - - const std::vector& getIntegrand() const override - { - throw "ERROR: Method not implemented!\n"; - return g_; - } - - std::vector& getAdjointResidual() override - { - throw "ERROR: Method not implemented!\n"; - return fB_; - } - - const std::vector& getAdjointResidual() const override - { - throw "ERROR: Method not implemented!\n"; - return fB_; - } - - std::vector& getAdjointIntegrand() override - { - throw "ERROR: Method not implemented!\n"; - return gB_; - } - - const std::vector& getAdjointIntegrand() const override - { - throw "ERROR: Method not implemented!\n"; - return gB_; - } }; } // namespace PhasorDynamics diff --git a/GridKit/Model/PhasorDynamics/ConstituentModel.hpp b/GridKit/Model/PhasorDynamics/ConstituentModel.hpp new file mode 100644 index 000000000..f488d1303 --- /dev/null +++ b/GridKit/Model/PhasorDynamics/ConstituentModel.hpp @@ -0,0 +1,302 @@ +#pragma once + +#include + +#include +#include +#include +#include +#include + +namespace GridKit +{ + namespace PhasorDynamics + { + using Log = ::GridKit::Utilities::Logger; + + /** + * @brief Model base class for all system constituents + */ + template + class ConstituentModel : public Model::Evaluator + { + public: + using RealT = typename Model::Evaluator::RealT; + using MatrixT = typename Model::Evaluator::MatrixT; + + ConstituentModel() + : size_{0} + { + } + + virtual ~ConstituentModel() + { + if (J_rows_buffer_ != nullptr) + { + delete[] J_rows_buffer_; + delete[] J_cols_buffer_; + delete[] J_vals_buffer_; + J_rows_buffer_ = nullptr; + J_cols_buffer_ = nullptr; + J_vals_buffer_ = nullptr; + } + } + + virtual int verify() const = 0; + + IdxT size() override final + { + return size_; + } + + IdxT nnz() override final + { + return nnz_; + } + + void setTolerances(RealT& rtol, RealT& atol) const override + { + rtol = rel_tol_; + atol = abs_tol_; + } + + void setMaxSteps(IdxT& msa) const override + { + msa = max_steps_; + } + + std::vector& y() override + { + return y_; + } + + const std::vector& y() const override + { + return y_; + } + + std::vector& yp() override + { + return yp_; + } + + const std::vector& yp() const override + { + return yp_; + } + + std::vector& tag() override + { + return tag_; + } + + const std::vector& tag() const override + { + return tag_; + } + + std::vector& getResidual() override + { + return f_; + } + + const std::vector& getResidual() const override + { + return f_; + } + + MatrixT& getJacobian() override + { + return J_; + } + + const MatrixT& getJacobian() const override + { + return J_; + } + + int setVariableIndex(IdxT local_index, IdxT global_index) + { + variable_indices_[static_cast(local_index)] = global_index; + return 0; + } + + IdxT& getVariableIndex(IdxT local_index) + { + return variable_indices_[static_cast(local_index)]; + } + + const std::vector& getVariableIndices() const + { + return variable_indices_; + } + + int setResidualIndex(IdxT local_index, IdxT global_index) + { + residual_indices_[static_cast(local_index)] = global_index; + return 0; + } + + IdxT& getResidualIndex(IdxT local_index) + { + return residual_indices_[static_cast(local_index)]; + } + + const std::vector& getResidualIndices() const + { + return residual_indices_; + } + + protected: + IdxT size_{0}; + IdxT nnz_{0}; + /// Global (system-level) variable indices + std::vector variable_indices_; + /// Global (system-level) residual indices + std::vector residual_indices_; + + std::vector y_; + std::vector yp_; + std::vector tag_; + std::vector f_; + std::vector g_; + + MatrixT J_; + IdxT* J_rows_buffer_{nullptr}; + IdxT* J_cols_buffer_{nullptr}; + RealT* J_vals_buffer_{nullptr}; + + RealT rel_tol_; + RealT abs_tol_; + + IdxT max_steps_; + + // + // Adjoint sensitivity members + // + + std::vector yB_{}; + std::vector ypB_{}; + std::vector fB_{}; + std::vector gB_{}; + + std::vector param_{}; + std::vector param_up_{}; + std::vector param_lo_{}; + + using NotImplementedError = GridKit::Utilities::NotImplementedError; + + public: + [[noreturn]] IdxT sizeQuadrature() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] IdxT sizeParams() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] std::vector& yB() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] const std::vector& yB() const override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] std::vector& ypB() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] const std::vector& ypB() const override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] std::vector& param() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] const std::vector& param() const override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] std::vector& param_up() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] const std::vector& param_up() const override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] std::vector& param_lo() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] const std::vector& param_lo() const override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] int evaluateIntegrand() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] int initializeAdjoint() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] int evaluateAdjointResidual() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] int evaluateAdjointIntegrand() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] std::vector& getIntegrand() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] const std::vector& getIntegrand() const override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] std::vector& getAdjointResidual() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] const std::vector& getAdjointResidual() const override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] std::vector& getAdjointIntegrand() override + { + throw NotImplementedError(__func__); + } + + [[noreturn]] const std::vector& getAdjointIntegrand() const override + { + throw NotImplementedError(__func__); + } + }; + + } // namespace PhasorDynamics +} // namespace GridKit diff --git a/GridKit/Model/PhasorDynamics/SignalNode/SignalNode.hpp b/GridKit/Model/PhasorDynamics/SignalNode/SignalNode.hpp index f285fb152..148631194 100644 --- a/GridKit/Model/PhasorDynamics/SignalNode/SignalNode.hpp +++ b/GridKit/Model/PhasorDynamics/SignalNode/SignalNode.hpp @@ -1,9 +1,7 @@ #pragma once -#include - -#include -#include +#include +#include namespace GridKit { @@ -23,23 +21,16 @@ namespace GridKit * */ template - class SignalNode : public Model::Evaluator + class SignalNode { public: - using RealT = typename Model::Evaluator::RealT; - using MatrixT = typename Model::Evaluator::MatrixT; + using RealT = typename GridKit::ScalarTraits::RealT; SignalNode(); SignalNode(const SignalNodeData& data); virtual ~SignalNode() = default; - virtual int allocate() override final; - virtual int initialize() override final; - virtual int tagDifferentiable() override final; - virtual int evaluateResidual() override final; - virtual int evaluateJacobian() override final; - void set(ScalarT* signal_in, IdxT* global_index); bool linked() const; ScalarT read() const; @@ -50,80 +41,14 @@ namespace GridKit return signal_id_; } - virtual IdxT size() override final - { - return size_; - } - - virtual IdxT nnz() override final - { - return nnz_; - } - - virtual bool hasJacobian() override final - { - return false; - } - - virtual void updateTime(RealT /* t */, RealT /* a */) override final - { - // No time to update in signal nodes - } - - virtual void setTolerances(RealT& rtol, RealT& atol) const override final - { - rtol = rtol_; - atol = atol_; - } - - virtual void setMaxSteps(IdxT& msa) const override final - { - msa = max_steps_; - } - - std::vector& y() override final - { - return y_; - } - - const std::vector& y() const override final - { - return y_; - } - - std::vector& yp() override final - { - return yp_; - } - - const std::vector& yp() const override final - { - return yp_; - } - - std::vector& tag() override final - { - return tag_; - } - - const std::vector& tag() const override final - { - return tag_; - } - - MatrixT& getJacobian() override final - { - return J_; - } - - const MatrixT& getJacobian() const override final + IdxT getVariableIndex() const { - return J_; + return *variable_index_; } - IdxT getVariableIndex() const + virtual const IdxT busID() const { - return *variable_index_; + return bus_id_; } private: @@ -133,187 +58,7 @@ namespace GridKit protected: const IdxT bus_id_{INVALID_INDEX}; - IdxT size_{0}; - IdxT nnz_{0}; IdxT* variable_index_{nullptr}; - - std::vector y_; - std::vector yp_; - std::vector tag_; - std::vector f_; - - MatrixT J_; - - RealT rtol_; - RealT atol_; - - IdxT max_steps_; - - // - // Adjoint sensitivity members - // - - std::vector g_{}; - std::vector yB_{}; - std::vector ypB_{}; - std::vector fB_{}; - std::vector gB_{}; - - std::vector param_{}; - std::vector param_up_{}; - std::vector param_lo_{}; - - // - // Public adjoint sensitivity methods (not yet implemented in components) - // - - public: - virtual IdxT sizeQuadrature() override final - { - throw "ERROR: Method not implemented!\n"; - return 0; - } - - virtual IdxT sizeParams() override final - { - throw "ERROR: Method not implemented!\n"; - return 0; - } - - std::vector& yB() override final - { - throw "ERROR: Method not implemented!\n"; - return yB_; - } - - const std::vector& yB() const override final - { - throw "ERROR: Method not implemented!\n"; - return yB_; - } - - std::vector& ypB() override final - { - throw "ERROR: Method not implemented!\n"; - return ypB_; - } - - const std::vector& ypB() const override final - { - throw "ERROR: Method not implemented!\n"; - return ypB_; - } - - std::vector& param() override final - { - throw "ERROR: Method not implemented!\n"; - return param_; - } - - const std::vector& param() const override final - { - throw "ERROR: Method not implemented!\n"; - return param_; - } - - std::vector& param_up() override final - { - throw "ERROR: Method not implemented!\n"; - return param_up_; - } - - const std::vector& param_up() const override final - { - throw "ERROR: Method not implemented!\n"; - return param_up_; - } - - std::vector& param_lo() override final - { - throw "ERROR: Method not implemented!\n"; - return param_lo_; - } - - const std::vector& param_lo() const override final - { - throw "ERROR: Method not implemented!\n"; - return param_lo_; - } - - int evaluateIntegrand() override final - { - throw "ERROR: Method not implemented!\n"; - return 1; - } - - int initializeAdjoint() override final - { - throw "ERROR: Method not implemented!\n"; - return 1; - } - - int evaluateAdjointResidual() override final - { - throw "ERROR: Method not implemented!\n"; - return 1; - } - - int evaluateAdjointIntegrand() override final - { - throw "ERROR: Method not implemented!\n"; - return 1; - } - - std::vector& getResidual() override final - { - return f_; - } - - const std::vector& getResidual() const override final - { - return f_; - } - - std::vector& getIntegrand() override final - { - throw "ERROR: Method not implemented!\n"; - return g_; - } - - const std::vector& getIntegrand() const override final - { - throw "ERROR: Method not implemented!\n"; - return g_; - } - - std::vector& getAdjointResidual() override final - { - throw "ERROR: Method not implemented!\n"; - return fB_; - } - - const std::vector& getAdjointResidual() const override final - { - throw "ERROR: Method not implemented!\n"; - return fB_; - } - - std::vector& getAdjointIntegrand() override final - { - throw "ERROR: Method not implemented!\n"; - return gB_; - } - - const std::vector& getAdjointIntegrand() const override final - { - throw "ERROR: Method not implemented!\n"; - return gB_; - } - - virtual const IdxT busID() const - { - return bus_id_; - } }; } // namespace PhasorDynamics diff --git a/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeDependencyTracking.cpp b/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeDependencyTracking.cpp index ea9d83ce8..df00cf7a9 100644 --- a/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeDependencyTracking.cpp +++ b/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeDependencyTracking.cpp @@ -1,6 +1,8 @@ /** * @file SignalNode model implementation. */ +#include + #include "SignalNodeImpl.hpp" namespace GridKit diff --git a/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeImpl.hpp b/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeImpl.hpp index c4556d203..5a408ab04 100644 --- a/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeImpl.hpp +++ b/GridKit/Model/PhasorDynamics/SignalNode/SignalNodeImpl.hpp @@ -10,47 +10,15 @@ namespace GridKit { template SignalNode::SignalNode() - : size_(0) { } template SignalNode::SignalNode(const SignalNodeData& data) - : signal_id_(data.signal_id), - size_(0) + : signal_id_(data.signal_id) { } - template - int SignalNode::allocate() - { - return 0; - } - - template - int SignalNode::initialize() - { - return 0; - } - - template - int SignalNode::tagDifferentiable() - { - return 0; - } - - template - int SignalNode::evaluateResidual() - { - return 0; - } - - template - int SignalNode::evaluateJacobian() - { - return 0; - } - template void SignalNode::set(ScalarT* signal, IdxT* variable_index) { diff --git a/GridKit/Utilities/CMakeLists.txt b/GridKit/Utilities/CMakeLists.txt index ad10e4812..afc0badf2 100644 --- a/GridKit/Utilities/CMakeLists.txt +++ b/GridKit/Utilities/CMakeLists.txt @@ -12,6 +12,7 @@ install(TARGETS Utilities EXPORT gridkit-targets) install( FILES Colors.hpp + Errors.hpp FileIO.hpp MapFromCOO.hpp DESTINATION diff --git a/GridKit/Utilities/Errors.hpp b/GridKit/Utilities/Errors.hpp new file mode 100644 index 000000000..06e430461 --- /dev/null +++ b/GridKit/Utilities/Errors.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +namespace GridKit +{ + namespace Utilities + { + class NotImplementedError : public std::runtime_error + { + public: + NotImplementedError(const std::string& funcname) + : std::runtime_error("ERROR: Function not implemented: " + funcname) + { + } + }; + } // namespace Utilities +} // namespace GridKit From 7230d20c5c144009211ac23991701ad60f51c14e Mon Sep 17 00:00:00 2001 From: Philip Fackler Date: Mon, 27 Apr 2026 17:01:32 -0500 Subject: [PATCH 2/2] Changed class name --- GridKit/Model/PhasorDynamics/BusBase.hpp | 8 ++++---- GridKit/Model/PhasorDynamics/CMakeLists.txt | 2 +- GridKit/Model/PhasorDynamics/Component.hpp | 8 ++++---- .../{ConstituentModel.hpp => GridElement.hpp} | 8 +++++--- 4 files changed, 14 insertions(+), 12 deletions(-) rename GridKit/Model/PhasorDynamics/{ConstituentModel.hpp => GridElement.hpp} (97%) diff --git a/GridKit/Model/PhasorDynamics/BusBase.hpp b/GridKit/Model/PhasorDynamics/BusBase.hpp index 7ca3fc113..ce37eaf9e 100644 --- a/GridKit/Model/PhasorDynamics/BusBase.hpp +++ b/GridKit/Model/PhasorDynamics/BusBase.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include @@ -22,11 +22,11 @@ namespace GridKit * */ template - class BusBase : public ConstituentModel + class BusBase : public GridElement { public: - using RealT = typename ConstituentModel::RealT; - using MatrixT = typename ConstituentModel::MatrixT; + using RealT = typename GridElement::RealT; + using MatrixT = typename GridElement::MatrixT; using BusTypeT = typename BusData::BusType; using MonitorT = Model::VariableMonitor; diff --git a/GridKit/Model/PhasorDynamics/CMakeLists.txt b/GridKit/Model/PhasorDynamics/CMakeLists.txt index 68a244938..b586b2fd7 100644 --- a/GridKit/Model/PhasorDynamics/CMakeLists.txt +++ b/GridKit/Model/PhasorDynamics/CMakeLists.txt @@ -16,7 +16,7 @@ gridkit_add_library(phasor_dynamics_core ComponentData.hpp ComponentLibrary.hpp ComponentSignals.hpp - ConstituentModel.hpp + GridElement.hpp SystemModel.hpp SystemModelData.hpp LINK_LIBRARIES diff --git a/GridKit/Model/PhasorDynamics/Component.hpp b/GridKit/Model/PhasorDynamics/Component.hpp index 8f750bd92..14bf7ca12 100644 --- a/GridKit/Model/PhasorDynamics/Component.hpp +++ b/GridKit/Model/PhasorDynamics/Component.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include namespace GridKit @@ -17,11 +17,11 @@ namespace GridKit * @brief Component model implementation base class. */ template - class Component : public ConstituentModel + class Component : public GridElement { public: - using RealT = typename ConstituentModel::RealT; - using MatrixT = typename ConstituentModel::MatrixT; + using RealT = typename GridElement::RealT; + using MatrixT = typename GridElement::MatrixT; Component() = default; diff --git a/GridKit/Model/PhasorDynamics/ConstituentModel.hpp b/GridKit/Model/PhasorDynamics/GridElement.hpp similarity index 97% rename from GridKit/Model/PhasorDynamics/ConstituentModel.hpp rename to GridKit/Model/PhasorDynamics/GridElement.hpp index f488d1303..aa961bfc7 100644 --- a/GridKit/Model/PhasorDynamics/ConstituentModel.hpp +++ b/GridKit/Model/PhasorDynamics/GridElement.hpp @@ -18,18 +18,18 @@ namespace GridKit * @brief Model base class for all system constituents */ template - class ConstituentModel : public Model::Evaluator + class GridElement : public Model::Evaluator { public: using RealT = typename Model::Evaluator::RealT; using MatrixT = typename Model::Evaluator::MatrixT; - ConstituentModel() + GridElement() : size_{0} { } - virtual ~ConstituentModel() + virtual ~GridElement() { if (J_rows_buffer_ != nullptr) { @@ -187,6 +187,8 @@ namespace GridKit using NotImplementedError = GridKit::Utilities::NotImplementedError; public: + // TODO: evaluate how this complies with xSDK guidelines + [[noreturn]] IdxT sizeQuadrature() override { throw NotImplementedError(__func__);