Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1554aea

Browse files
committed
added unittests for dcpf sensitivities, also added sens_i_mag_u_bound for branches, (not used yet)
1 parent 7f42243 commit 1554aea

5 files changed

Lines changed: 39 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Version 1.3.2
5050
* Fixed bug with treatment of outage branches in PV-PQ switching heuristics.
5151
* Added arrays branch_outages and generator_outages to contingency object to store indices of outage components.
5252
* Added unittests to check that examples run without errors.
53+
* Extended support for storing and retrieving constraint sensitivity information (done).
5354
* Update Python wrapper documentation to show how to install with pip or download/run tests (todo).
5455
* Update examples, documentation (macros, intersphinx) and create release (todo).
5556
* Distribute pfnet python wrapper through pypi (todo).

include/pfnet/branch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ REAL BRANCH_get_sens_ratio_u_bound(Branch* br, int t);
100100
REAL BRANCH_get_sens_ratio_l_bound(Branch* br, int t);
101101
REAL BRANCH_get_sens_phase_u_bound(Branch* br, int t);
102102
REAL BRANCH_get_sens_phase_l_bound(Branch* br, int t);
103+
REAL BRANCH_get_sens_i_mag_u_bound(Branch* br, int t);
103104
int BRANCH_get_index(Branch* br);
104105
int BRANCH_get_index_ratio(Branch* br, int t);
105106
int BRANCH_get_index_phase(Branch* br, int t);
@@ -183,6 +184,7 @@ void BRANCH_set_sens_ratio_u_bound(Branch* br, REAL value, int t);
183184
void BRANCH_set_sens_ratio_l_bound(Branch* br, REAL value, int t);
184185
void BRANCH_set_sens_phase_u_bound(Branch* br, REAL value, int t);
185186
void BRANCH_set_sens_phase_l_bound(Branch* br, REAL value, int t);
187+
void BRANCH_set_sens_i_mag_u_bound(Branch* br, REAL value, int t);
186188
void BRANCH_set_index(Branch* br, int index);
187189
void BRANCH_set_type(Branch* br, int type);
188190
void BRANCH_set_bus_k(Branch* br, Bus* bus_k);

python/lib/pfnet-1.3.2.tar.gz

64 Bytes
Binary file not shown.

python/tests/test_constraints.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3434,6 +3434,25 @@ def test_constr_DCPF(self):
34343434
mis -= br.P_mk_DC[t]
34353435
self.assertLess(np.abs(mismatches1[bus.index+t*net.num_buses]-mis),1e-8)
34363436

3437+
# Sensitivities
3438+
net.clear_sensitivities()
3439+
3440+
lam = np.random.randn(net.num_buses*net.num_periods)
3441+
self.assertEqual(lam.size, constr.A.shape[0])
3442+
3443+
for t in range(net.num_periods):
3444+
for bus in net.buses:
3445+
self.assertEqual(bus.sens_P_balance[t], 0.)
3446+
self.assertEqual(bus.sens_Q_balance[t], 0.)
3447+
3448+
constr.store_sensitivities(lam, None, None, None)
3449+
3450+
for t in range(net.num_periods):
3451+
for bus in net.buses:
3452+
self.assertEqual(bus.sens_P_balance[t], lam[bus.index+t*net.num_buses])
3453+
self.assertNotEqual(bus.sens_P_balance[t], 0.)
3454+
self.assertEqual(bus.sens_Q_balance[t], 0.)
3455+
34373456
def test_constr_DC_FLOW_LIM(self):
34383457

34393458
# Single period

src/net/branch.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct Branch {
8080
REAL* sens_ratio_l_bound; /**< @brief Sensitivity of tap ratio lower bound */
8181
REAL* sens_phase_u_bound; /**< @brief Sensitivity of phase shift upper bound */
8282
REAL* sens_phase_l_bound; /**< @brief Sensitivity of phase shift lower bound */
83+
REAL* sens_i_mag_u_bound; /**< @brief Sensitivity of current magnitude upper bound */
8384

8485
// List
8586
Branch* reg_next; /**< @brief List of branches regulating a bus voltage magnitude */
@@ -110,6 +111,7 @@ void BRANCH_array_del(Branch* br_array, int size) {
110111
free(br->sens_ratio_l_bound);
111112
free(br->sens_phase_u_bound);
112113
free(br->sens_phase_l_bound);
114+
free(br->sens_i_mag_u_bound);
113115
}
114116
free(br_array);
115117
}
@@ -161,6 +163,7 @@ void BRANCH_clear_sensitivities(Branch* br) {
161163
br->sens_ratio_l_bound[t] = 0;
162164
br->sens_phase_u_bound[t] = 0;
163165
br->sens_phase_l_bound[t] = 0;
166+
br->sens_i_mag_u_bound[t] = 0;
164167
}
165168
}
166169
}
@@ -242,6 +245,7 @@ void BRANCH_copy_from_branch(Branch* br, Branch* other) {
242245
memcpy(br->sens_ratio_l_bound,other->sens_ratio_l_bound,num_periods*sizeof(REAL));
243246
memcpy(br->sens_phase_u_bound,other->sens_phase_u_bound,num_periods*sizeof(REAL));
244247
memcpy(br->sens_phase_l_bound,other->sens_phase_l_bound,num_periods*sizeof(REAL));
248+
memcpy(br->sens_i_mag_u_bound,other->sens_i_mag_u_bound,num_periods*sizeof(REAL));
245249

246250
// List
247251
// skip next
@@ -345,6 +349,13 @@ REAL BRANCH_get_sens_phase_l_bound(Branch* br, int t) {
345349
return 0;
346350
}
347351

352+
REAL BRANCH_get_sens_i_mag_u_bound(Branch* br, int t) {
353+
if (br && t >= 0 && t < br->num_periods)
354+
return br->sens_i_mag_u_bound[t];
355+
else
356+
return 0;
357+
}
358+
348359
int BRANCH_get_index(Branch* br) {
349360
if (br)
350361
return br->index;
@@ -1281,6 +1292,7 @@ void BRANCH_init(Branch* br, int num_periods) {
12811292
ARRAY_zalloc(br->sens_ratio_l_bound,REAL,T);
12821293
ARRAY_zalloc(br->sens_phase_u_bound,REAL,T);
12831294
ARRAY_zalloc(br->sens_phase_l_bound,REAL,T);
1295+
ARRAY_zalloc(br->sens_i_mag_u_bound,REAL,T);
12841296

12851297
for (t = 0; t < br->num_periods; t++)
12861298
br->ratio[t] = 1.;
@@ -1436,6 +1448,11 @@ void BRANCH_set_sens_phase_l_bound(Branch* br, REAL value, int t) {
14361448
br->sens_phase_l_bound[t] = value;
14371449
}
14381450

1451+
void BRANCH_set_sens_i_mag_u_bound(Branch* br, REAL value, int t) {
1452+
if (br && t >= 0 && t < br->num_periods)
1453+
br->sens_i_mag_u_bound[t] = value;
1454+
}
1455+
14391456
void BRANCH_set_index(Branch* br, int index) {
14401457
if (br)
14411458
br->index = index;

0 commit comments

Comments
 (0)