Skip to content

Commit 959899f

Browse files
committed
implemetnation of branch outage minimal
1 parent f559083 commit 959899f

19 files changed

Lines changed: 137 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## v.03
44

5+
- Added `enable` and `disable` solver events that put a branch in or out of service.
56

67
## v0.2
78

‎GridKit/Model/PhasorDynamics/Branch/Branch.hpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ namespace GridKit
7474
virtual int evaluateJacobian() override final;
7575
virtual int verify() const override final;
7676

77+
int setEnabled(bool enabled);
78+
7779
void setR(RealT R)
7880
{
7981
R_ = R;
@@ -195,6 +197,7 @@ namespace GridKit
195197
RealT Bmag_{0.0};
196198
RealT tap_{1.0};
197199
RealT phase_{0.0};
200+
RealT enabled_{1.0}; ///< 1 in service, 0 out of service
198201
IdxT bus1_id_{0};
199202
IdxT bus2_id_{0};
200203

‎GridKit/Model/PhasorDynamics/Branch/BranchImpl.hpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,19 @@ namespace GridKit
184184
return ret;
185185
}
186186

187+
/// Put the branch in or out of service; out of service, it injects no current.
188+
template <typename scalar_type, typename index_type>
189+
int Branch<scalar_type, index_type>::setEnabled(bool enabled)
190+
{
191+
enabled_ = ZERO<RealT>;
192+
if (enabled)
193+
{
194+
enabled_ = ONE<RealT>;
195+
}
196+
setDerivedParams();
197+
return 0;
198+
}
199+
187200
template <typename scalar_type, typename index_type>
188201
__attribute__((always_inline)) inline void Branch<scalar_type, index_type>::addAdmittanceContribution(
189202
const RealT G,
@@ -514,6 +527,16 @@ namespace GridKit
514527

515528
g22_ = g_diag - RealT{0.5} * G_;
516529
b22_ = b_diag - RealT{0.5} * B_;
530+
531+
// An out-of-service branch has zero admittance
532+
g11_ *= enabled_;
533+
b11_ *= enabled_;
534+
g12_ *= enabled_;
535+
b12_ *= enabled_;
536+
g21_ *= enabled_;
537+
b21_ *= enabled_;
538+
g22_ *= enabled_;
539+
b22_ *= enabled_;
517540
}
518541

519542
} // namespace PhasorDynamics

‎GridKit/Model/PhasorDynamics/Branch/README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,23 @@ The off-nominal transformer transformation uses bus 1 as the tap side:
9494
\end{aligned}
9595
```
9696

97-
The magnetizing and line shunts are added outside the transformation:
97+
The magnetizing and line shunts are added outside the transformation, and the
98+
service status $u$ scales the whole branch:
9899

99100
```math
100101
\begin{aligned}
101102
\mathbf{Y}
102103
&=
104+
u
105+
\left(
103106
\mathbf{M}^{\dagger}
104107
\mathbf{Y}_0
105108
\mathbf{M}
106109
+
107110
\mathbf{Y}_\mathrm{mag}
108111
+
109112
\mathbf{Y}_\mathrm{sh}
113+
\right)
110114
\end{aligned}
111115
```
112116

‎GridKit/Model/PhasorDynamics/SystemModel.hpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <map>
44
#include <memory>
5+
#include <string>
56

67
#include <GridKit/Model/PhasorDynamics/Component.hpp>
78
#include <GridKit/Model/PhasorDynamics/SignalNode/SignalNodeSet.hpp>
@@ -25,6 +26,9 @@ namespace GridKit
2526
template <typename scalar_type, typename index_type>
2627
class BusFault;
2728

29+
template <typename scalar_type, typename index_type>
30+
class Branch;
31+
2832
template <typename scalar_type, typename index_type>
2933
class SignalNode;
3034

@@ -105,6 +109,7 @@ namespace GridKit
105109
BusT* getBus(IdxT bus_id);
106110
SignalNodeT* getSignalNode(IdxT signal_id);
107111
ComponentT* getComponent(IdxT gridkit_component_id);
112+
Branch<ScalarT, IdxT>* getBranch(const std::string& id);
108113
BusFault<ScalarT, IdxT>* getBusFault(IdxT fault_id);
109114

110115
private:
@@ -115,6 +120,8 @@ namespace GridKit
115120
std::map<IdxT, IdxT> gridkit_bus_indices_; ///< Map between gridkit_bus_id and bus_id
116121
std::map<IdxT, IdxT> gridkit_fault_indices_; ///< Map between fault_id and component_id
117122

123+
std::map<std::string, IdxT> gridkit_branch_indices_; ///< Map between branch id and gridkit_component_id
124+
118125
bool owns_components_{false};
119126

120127
/// Variable monitor

‎GridKit/Model/PhasorDynamics/SystemModelImpl.hpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ namespace GridKit
110110
auto* branch = new Branch<ScalarT, IdxT>(getBus(bus1_index),
111111
getBus(bus2_index),
112112
branchdata);
113+
114+
gridkit_branch_indices_[branchdata.disambiguation_string] = static_cast<IdxT>(components_.size());
113115
addComponent(branch);
114116
}
115117

@@ -830,6 +832,17 @@ namespace GridKit
830832
return components_[gridkit_component_id];
831833
}
832834

835+
/**
836+
* @brief Return pointer to a branch by case-file `id`
837+
*/
838+
template <typename scalar_type, typename index_type>
839+
Branch<scalar_type, index_type>*
840+
SystemModel<scalar_type, index_type>::getBranch(const std::string& id)
841+
{
842+
// Should fail if user-provided id is incorrect
843+
return dynamic_cast<Branch<ScalarT, IdxT>*>(components_[gridkit_branch_indices_.at(id)]);
844+
}
845+
833846
/**
834847
* @brief Return pointer to a bus fault model
835848
*

‎application/PhasorDynamics/AnalysisUtilities.hpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <magic_enum/magic_enum.hpp>
1212
#include <nlohmann/json.hpp>
1313

14+
#include <GridKit/Constants.hpp>
1415
#include <GridKit/Model/PhasorDynamics/SystemModelData.hpp>
1516
#include <GridKit/Solver/Dynamic/Ida.hpp>
1617
#include <GridKit/Testing/TestHelpers.hpp>
@@ -34,7 +35,9 @@ namespace GridKit
3435
enum class Type
3536
{
3637
FAULT_ON,
37-
FAULT_OFF
38+
FAULT_OFF,
39+
ENABLE,
40+
DISABLE
3841
};
3942

4043
/// Time event takes place
@@ -43,6 +46,8 @@ namespace GridKit
4346
Type type;
4447
/// ID of element used in event (e.g., bus fault id)
4548
std::size_t element_id;
49+
/// Case-file `id` of the device to enable or disable
50+
std::string device;
4651
};
4752

4853
/**
@@ -130,7 +135,8 @@ namespace GridKit
130135
{
131136
auto& event = c.events.emplace_back();
132137
raw_event.at("time").get_to(event.time);
133-
raw_event.at("element_id").get_to(event.element_id);
138+
event.element_id = raw_event.value("element_id", INVALID_INDEX<std::size_t>);
139+
event.device = raw_event.value("device", std::string{});
134140

135141
auto type_str = raw_event.at("type").get<std::string>();
136142
using EventType = SystemEvent::Type;

‎application/PhasorDynamics/ContingencyAnalysis.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <omp.h>
88
#endif
99

10+
#include <GridKit/Model/PhasorDynamics/Branch/Branch.hpp>
1011
#include <GridKit/Model/PhasorDynamics/BusFault/BusFault.hpp>
1112
#include <GridKit/Model/PhasorDynamics/SystemModel.hpp>
1213
#include <GridKit/Solver/Dynamic/Ida.hpp>
@@ -64,6 +65,12 @@ TestStatus runStudy(StudyData study_data)
6465
case EventType::FAULT_OFF:
6566
sys.getBusFault(event.element_id)->setStatus(false);
6667
break;
68+
case EventType::ENABLE:
69+
sys.getBranch(event.device)->setEnabled(true);
70+
break;
71+
case EventType::DISABLE:
72+
sys.getBranch(event.device)->setEnabled(false);
73+
break;
6774
}
6875

6976
// Re-initialize simulation at event time

‎application/PhasorDynamics/DynamicSimulation.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <filesystem>
33
#include <fstream>
44

5+
#include <GridKit/Model/PhasorDynamics/Branch/Branch.hpp>
56
#include <GridKit/Model/PhasorDynamics/BusFault/BusFault.hpp>
67
#include <GridKit/Model/PhasorDynamics/SystemModel.hpp>
78
#include <GridKit/Solver/Dynamic/Ida.hpp>
@@ -63,6 +64,12 @@ int runApplication(int argc, const char* argv[])
6364
case EventType::FAULT_OFF:
6465
sys.getBusFault(event.element_id)->setStatus(false);
6566
break;
67+
case EventType::ENABLE:
68+
sys.getBranch(event.device)->setEnabled(true);
69+
break;
70+
case EventType::DISABLE:
71+
sys.getBranch(event.device)->setEnabled(false);
72+
break;
6673
}
6774

6875
// Re-initialize simulation at event time

‎application/PhasorDynamics/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ Each event group describes a system event that occurs at a given time point
2929
Name | Value
3030
--------------------|-------------------------------------------------------
3131
`time` | A floating point value for time event occurs
32-
`type` | Event type (one of { "fault_on", "fault_off" })
32+
`type` | Event type (one of { "fault_on", "fault_off", "enable", "disable" })
3333
`element_id` | An integer value referencing the element associated with the event (e.g., bus fault id)
34+
`device` | `id` of the branch to put in service ("enable") or take out of service ("disable")

0 commit comments

Comments
 (0)