66#pragma once
77
88#include < array>
9+ #include < cstddef>
910
1011#include < GridKit/Model/OptimalPowerFlow/Branch/BranchData.hpp>
1112#include < GridKit/Model/OptimalPowerFlow/Bus/Bus.hpp>
@@ -15,6 +16,31 @@ namespace GridKit
1516{
1617 namespace OptimalPowerFlow
1718 {
19+ // / External variables of a `Branch`, the voltages at its ports
20+ enum class BranchExternalVariables : size_t
21+ {
22+ VR1 , // /< \f$V_{\mathrm{r}1}\f$ Bus-1 real voltage [p.u.]
23+ VI1 , // /< \f$V_{\mathrm{i}1}\f$ Bus-1 imaginary voltage [p.u.]
24+ VR2 , // /< \f$V_{\mathrm{r}2}\f$ Bus-2 real voltage [p.u.]
25+ VI2 , // /< \f$V_{\mathrm{i}2}\f$ Bus-2 imaginary voltage [p.u.]
26+ };
27+
28+ // / External equality contributions of a `Branch`, the power into the buses at its ports
29+ enum class BranchExternalEqualities : size_t
30+ {
31+ DP1 , // /< \f$\Delta P_1^\mathrm{bus}\f$ Active power into bus 1 [p.u.]
32+ DQ1 , // /< \f$\Delta Q_1^\mathrm{bus}\f$ Reactive power into bus 1 [p.u.]
33+ DP2 , // /< \f$\Delta P_2^\mathrm{bus}\f$ Active power into bus 2 [p.u.]
34+ DQ2 , // /< \f$\Delta Q_2^\mathrm{bus}\f$ Reactive power into bus 2 [p.u.]
35+ };
36+
37+ // / Inequality rows of a `Branch`
38+ enum class BranchInequalities : size_t
39+ {
40+ S1 , // /< \f$P_1^2 + Q_1^2\f$ Squared apparent power at bus 1 [p.u.]
41+ S2 , // /< \f$P_2^2 + Q_2^2\f$ Squared apparent power at bus 2 [p.u.]
42+ };
43+
1844 /* *
1945 * @brief Line or off-nominal transformer between two buses
2046 *
@@ -24,65 +50,71 @@ namespace GridKit
2450 class Branch final : public Component<scalar_type, index_type>
2551 {
2652 using ComponentT = Component<scalar_type, index_type>;
27- using BusT = Bus<scalar_type, index_type>;
2853 using ScalarT = scalar_type;
2954 using IdxT = index_type;
3055 using RealT = typename ComponentT::RealT;
3156 using ModelDataT = BranchData<RealT, IdxT>;
57+ using BusT = Bus<scalar_type, index_type>;
3258
3359 using ComponentT::d_upper_;
3460
3561 public:
36- static constexpr IdxT NUM_PORTS = 2 ;
37- static constexpr IdxT NUM_INTERNAL_VARIABLES = 0 ;
38- static constexpr IdxT NUM_INTERNAL_EQUALITIES = 0 ;
39- static constexpr IdxT NUM_INTERNAL_INEQUALITIES = 2 ;
62+ using InternalVariablesT = Utilities::EmptyEnum;
63+ using ExternalVariablesT = BranchExternalVariables;
64+ using InternalEqualitiesT = Utilities::EmptyEnum;
65+ using ExternalEqualitiesT = BranchExternalEqualities;
66+ using InequalitiesT = BranchInequalities;
4067
41- static constexpr std::array<IdxT, NUM_PORTS > NUM_PORT_VARIABLES {BusT::NUM_INTERNAL_VARIABLES ,
42- BusT::NUM_INTERNAL_VARIABLES };
43- static constexpr std::array<IdxT, NUM_PORTS > NUM_PORT_EQUALITIES {BusT::NUM_INTERNAL_EQUALITIES ,
44- BusT::NUM_INTERNAL_EQUALITIES };
68+ static constexpr std::array<IdxT, Utilities::enum_size<BranchPorts>()> NUM_PORT_VARIABLES {
69+ Utilities::enum_size<typename BusT::InternalVariablesT>(),
70+ Utilities::enum_size<typename BusT::InternalVariablesT>()};
71+ static constexpr std::array<IdxT, Utilities::enum_size<BranchPorts>()> NUM_PORT_EQUALITIES {
72+ Utilities::enum_size<typename BusT::InternalEqualitiesT>(),
73+ Utilities::enum_size<typename BusT::InternalEqualitiesT>()};
4574
4675 explicit Branch (const ModelDataT& data);
4776
4877 Model::ConfigurationChecks verify () const override ;
49- int allocate () override ;
78+ int initialize () override ;
5079
80+ int evaluateGradient () override ;
5181 int evaluateEqualityJacobian () override ;
5282 int evaluateInequalityJacobian () override ;
5383 int evaluateHessian (RealT sigma, const RealT* lambda_c, const RealT* lambda_d) override ;
5484
55- [[gnu::always_inline]] void externalEqualities (const ScalarT* x, ScalarT* c) const override ;
56- [[gnu::always_inline]] void internalInequalities (const ScalarT* x, ScalarT* d) const override ;
85+ [[gnu::always_inline]] void externalEqualities (const ScalarT* x, const ScalarT* external, ScalarT* c) const override ;
86+ [[gnu::always_inline]] void inequalities (const ScalarT* x, const ScalarT* external , ScalarT* d) const override ;
5787
5888 bool inService () const
5989 {
60- return in_service_ > ZERO <RealT> ;
90+ return in_service_;
6191 }
6292
6393 private:
64- [[gnu::always_inline]] void power (const ScalarT* x, ScalarT* s) const ;
65- void setDerivedParams ();
66-
67- RealT in_service_{ONE <RealT>};
68- RealT R_ {0.0 };
69- RealT X_ {0.0 };
70- RealT G_ {0.0 };
71- RealT B_ {0.0 };
72- RealT Gmag_{0.0 };
73- RealT Bmag_{0.0 };
74- RealT tap_{1.0 };
75- RealT phase_{0.0 };
76- RealT Smax_{0.0 };
77-
78- RealT g11_{0.0 };
79- RealT b11_{0.0 };
80- RealT g12_{0.0 };
81- RealT b12_{0.0 };
82- RealT g21_{0.0 };
83- RealT b21_{0.0 };
84- RealT g22_{0.0 };
85- RealT b22_{0.0 };
94+ void initializeParameters (const ModelDataT& data);
95+ void setDerivedParameters ();
96+
97+ [[gnu::always_inline]] void power (const ScalarT* external, ScalarT* s) const ;
98+
99+ RealT R_ {ZERO <RealT>};
100+ RealT X_ {ZERO <RealT>};
101+ RealT G_ {ZERO <RealT>};
102+ RealT B_ {ZERO <RealT>};
103+ RealT Gmag_{ZERO <RealT>};
104+ RealT Bmag_{ZERO <RealT>};
105+ RealT tap_{ONE <RealT>};
106+ RealT phase_{ZERO <RealT>};
107+ RealT Smax_{UNBOUNDED <RealT>};
108+ bool in_service_{true };
109+
110+ RealT g11_{ZERO <RealT>};
111+ RealT b11_{ZERO <RealT>};
112+ RealT g12_{ZERO <RealT>};
113+ RealT b12_{ZERO <RealT>};
114+ RealT g21_{ZERO <RealT>};
115+ RealT b21_{ZERO <RealT>};
116+ RealT g22_{ZERO <RealT>};
117+ RealT b22_{ZERO <RealT>};
86118 };
87119 } // namespace OptimalPowerFlow
88120} // namespace GridKit
0 commit comments