Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Beginning of AMPL model #231

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f849c3e
Beginning of AMPL model
Hadrien-Godard Nov 18, 2021
55d479e
Git ignore update
Hadrien-Godard Nov 19, 2021
d37c308
Check that controls are local
Hadrien-Godard Nov 19, 2021
1c8822c
Last constraints
Hadrien-Godard Nov 19, 2021
e0955a9
Improvments
Hadrien-Godard Nov 19, 2021
a653b05
Default values for variables,
Hadrien-Godard Nov 26, 2021
3e9502f
Param for power pu
Hadrien-Godard Nov 29, 2021
7ef9a95
New objective function: minimize the difference with the reference vo…
Hadrien-Godard Nov 29, 2021
da4bcec
Right voltage bounding values plus some improvments
Hadrien-Godard Nov 29, 2021
19b8847
Comment a log
Hadrien-Godard Nov 29, 2021
4ded1c6
Beginning of the pypowsybl model
Hadrien-Godard Dec 9, 2021
fe6babb
Add a TO DO
Hadrien-Godard Dec 10, 2021
97fad42
Active power balance
Hadrien-Godard Mar 4, 2022
00674d9
Improve iteration on df
Hadrien-Godard Mar 4, 2022
f01a657
Improve using iterrows
Hadrien-Godard Mar 4, 2022
e040035
Reactive power balance
Hadrien-Godard Mar 4, 2022
4aaa255
Reorganization
Hadrien-Godard Mar 14, 2022
34eb3b2
Beginning of initial bounds
Hadrien-Godard Mar 14, 2022
e07e078
Initialization of variables plus bounds
Hadrien-Godard Mar 25, 2022
4559e25
Short Circuit Calculation (#236)
JB-H Jul 29, 2022
6b1cc79
Restore sonar comment passing from push on to push pr (#235)
Walid-Sahnoun Jul 30, 2022
9d87f82
Remove ShortCircuitNetwork (#237)
geofjamg Aug 1, 2022
753f9be
Improvement of the code coverage (#238)
JB-H Aug 7, 2022
a023696
Update slack link (#229)
colinepiloquet Aug 7, 2022
4f42120
Merge branch 'main' into poc_optimization
geofjamg Aug 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: CI

on: [push]
on:
push:
branches:
- 'main'
- 'release-v**'
pull_request:

jobs:
build:
Expand Down
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,18 @@ org.eclipse.core.resources.prefs
org.eclipse.jdt.core.prefs
org.eclipse.m2e.core.prefs
org.eclipse.jdt.groovy.core.prefs
/ampl_files/ampl_network_batteries.txt
/ampl_files/ampl_network_branches.txt
/ampl_files/ampl_network_buses.txt
/ampl_files/ampl_network_generators.txt
/ampl_files/ampl_network_hvdc.txt
/ampl_files/ampl_network_lcc_converter_stations.txt
/ampl_files/ampl_network_limits.txt
/ampl_files/ampl_network_loads.txt
/ampl_files/ampl_network_ptc.txt
/ampl_files/ampl_network_rtc.txt
/ampl_files/ampl_network_shunts.txt
/ampl_files/ampl_network_static_var_compensators.txt
/ampl_files/ampl_network_substations.txt
/ampl_files/ampl_network_tct.txt
/ampl_files/ampl_network_vsc_converter_stations.txt
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=com.powsybl%3Apowsybl-incubator&metric=alert_status)](https://sonarcloud.io/dashboard?id=com.powsybl%3Apowsybl-incubator)
[![MPL-2.0 License](https://img.shields.io/badge/license-MPL_2.0-blue.svg)](https://www.mozilla.org/en-US/MPL/2.0/)
[![Join the community on Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://spectrum.chat/powsybl)
[![Slack](https://img.shields.io/badge/slack-powsybl-blueviolet.svg?logo=slack)](https://join.slack.com/t/powsybl/shared_invite/zt-rzvbuzjk-nxi0boim1RKPS5PjieI0rA)
57 changes: 57 additions & 0 deletions ampl_files/ampl_computed_data.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#--- COMPUTED DATA ---
# We are assuming that the "variant" input data always equals 1
# VARIANTS check
set VARIANTS = union{(i,j) in VARIANTS_BUSES} {i};
if card(VARIANTS) > 1 then {
printf "Two different variants in data files !\n";
quit;
} else
printf "Correct using of variant input\n";

# PV/PQ BUSES definitions and checks
param set_target_V default 0;
param generator_controling default 0;
set BUSES = union{(i,j) in VARIANTS_BUSES} {j};
set GENS = union{(i,j) in VARIANTS_GENS} {j};
set PV_BUSES = {i in BUSES: card({j in GENS: gen_bus[1, j] == i and gen_vregul[1, j] == "true"}) >= 1};
set PQ_BUSES = {i in BUSES: card({j in GENS: gen_bus[1, j] == i and gen_vregul[1, j] == "true"}) == 0};
param targetV{PV_BUSES};
for{i in PV_BUSES} {
let set_target_V := 0;
for{j in GENS: gen_bus[1,j]==i} {
if gen_conbus[1,j] != i then {
# FIX ME
printf "Control of generator %d is not local.\nHowever it will be turned to local in this simulation.\n", j;
}
if set_target_V == 1 then {
if targetV[i] != gen_targetv[1,j] then printf"Inconsistent target V between generators %d and %d at bus %d.\nGenerator %d is chosen as reference.\n", j, generator_controling, i, generator_controling;
} else {
let targetV[i] := gen_targetv[1,j];
let set_target_V := 1;
let generator_controling := j;
}
}
}

#BRANCHES and LOADS definitions
set BRANCHES = union{(i,j) in VARIANTS_BRANCHES} {j};
set LOADS = union{(i,j) in VARIANTS_LOADS} {j};


# Compute slack node
param slack_bus default 0;
param voltage_level_slack default 0;
param neighbours_slack default 0;
for{i in PV_BUSES} {
if ss_nomv[1,bus_substations[1,i]] >= voltage_level_slack then {
if card({j in BUSES: exists {k in BRANCHES} ((br_bus1[1,k]==i and br_bus2[1,k]==j) or (br_bus1[1,k]==j and br_bus2[1,k]==i))}) > neighbours_slack then {
let slack_bus := i;
let voltage_level_slack := ss_nomv[1,bus_substations[1,i]];
let neighbours_slack := card({j in BUSES: exists {k in BRANCHES} ((br_bus1[1,k]==i and br_bus2[1,k]==j) or (br_bus1[1,k]==j and br_bus2[1,k]==i))});
}
}
}

# Branches data computations
param br_y{i in BRANCHES} := 1/sqrt(br_r[1,i]*br_r[1,i] + br_x[1,i]*br_x[1,i]);
param br_ksi{i in BRANCHES} := atan2(br_r[1,i], br_x[1,i]);
11 changes: 11 additions & 0 deletions ampl_files/ampl_data.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
data;

param: VARIANTS_BUSES: bus_substations bus_cc bus_v bus_theta bus_p bus_q bus_fault bus_curative bus_id := include ampl_network_buses.txt;

param: VARIANTS_GENS: gen_bus gen_conbus gen_substation gen_minp gen_maxp gen_minqmaxp gen_minq0 gen_minqminp gen_maxqmaxp gen_maxq0 gen_maxqminp gen_vregul gen_targetv gen_targetp gen_targetq gen_fault gen_curative gen_id gen_desc gen_p gen_q := include ampl_network_generators.txt;

param: VARIANTS_BRANCHES: br_bus1 br_bus2 br_3wtnum br_sub1 br_sub2 br_r br_x br_g1 br_g2 br_b1 br_b2 br_cstr br_ratiotc br_phasetc br_p1 br_p2 br_q1 br_q2 br_patl1 br_patl2 br_merged br_fault br_curative br_id br_desc := include ampl_network_branches.txt;

param: VARIANTS_SS: ss_unused1 ss_unused2 ss_nomv ss_minv ss_maxv ss_fault ss_curative ss_country ss_id ss_desc := include ampl_network_substations.txt;

param: VARIANTS_LOADS: ld_bus ld_ss ld_p0 ld_q0 ld_fault ld_curative ld_id ld_desc ld_p ld_q := include ampl_network_loads.txt;
91 changes: 91 additions & 0 deletions ampl_files/ampl_dataread_model.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#--- READ DATA ---
set VARIANTS_BUSES dimen 2;

param bus_substations{VARIANTS_BUSES};
param bus_cc{VARIANTS_BUSES};
param bus_v{VARIANTS_BUSES};
param bus_theta{VARIANTS_BUSES};
param bus_p{VARIANTS_BUSES};
param bus_q{VARIANTS_BUSES};
param bus_fault{VARIANTS_BUSES} binary;
param bus_curative{VARIANTS_BUSES} binary;
param bus_id{VARIANTS_BUSES} symbolic;

set VARIANTS_GENS dimen 2;
param gen_bus{VARIANTS_GENS};
param gen_conbus{VARIANTS_GENS};
param gen_substation{VARIANTS_GENS};
param gen_minp{VARIANTS_GENS};
param gen_maxp{VARIANTS_GENS};
param gen_minqmaxp{VARIANTS_GENS};
param gen_minq0{VARIANTS_GENS};
param gen_minqminp{VARIANTS_GENS};
param gen_maxqmaxp{VARIANTS_GENS};
param gen_maxq0{VARIANTS_GENS};
param gen_maxqminp{VARIANTS_GENS};
param gen_vregul{VARIANTS_GENS} symbolic;
param gen_targetv{VARIANTS_GENS};
param gen_targetp{VARIANTS_GENS};
param gen_targetq{VARIANTS_GENS};
param gen_fault{VARIANTS_GENS} binary;
param gen_curative{VARIANTS_GENS} binary;
param gen_id{VARIANTS_GENS} symbolic;
param gen_desc{VARIANTS_GENS} symbolic;
param gen_p{VARIANTS_GENS};
param gen_q{VARIANTS_GENS};

set VARIANTS_BRANCHES dimen 2;
param br_bus1{VARIANTS_BRANCHES};
param br_bus2{VARIANTS_BRANCHES};
param br_3wtnum{VARIANTS_BRANCHES};
param br_sub1{VARIANTS_BRANCHES};
param br_sub2{VARIANTS_BRANCHES};
param br_r{VARIANTS_BRANCHES};
param br_x{VARIANTS_BRANCHES};
param br_g1{VARIANTS_BRANCHES};
param br_g2{VARIANTS_BRANCHES};
param br_b1{VARIANTS_BRANCHES};
param br_b2{VARIANTS_BRANCHES};
param br_cstr{VARIANTS_BRANCHES};
param br_ratiotc{VARIANTS_BRANCHES};
param br_phasetc{VARIANTS_BRANCHES};
param br_p1{VARIANTS_BRANCHES};
param br_p2{VARIANTS_BRANCHES};
param br_q1{VARIANTS_BRANCHES};
param br_q2{VARIANTS_BRANCHES};
param br_patl1{VARIANTS_BRANCHES};
param br_patl2{VARIANTS_BRANCHES};
param br_merged{VARIANTS_BRANCHES} symbolic;
param br_fault{VARIANTS_BRANCHES} binary;
param br_curative{VARIANTS_BRANCHES} binary;
param br_id{VARIANTS_BRANCHES} symbolic;
param br_desc{VARIANTS_BRANCHES} symbolic;

set VARIANTS_SS dimen 2;
param ss_unused1{VARIANTS_SS} symbolic;
param ss_unused2{VARIANTS_SS};
param ss_nomv{VARIANTS_SS};
param ss_minv{VARIANTS_SS};
param ss_maxv{VARIANTS_SS};
param ss_fault{VARIANTS_SS} binary;
param ss_curative{VARIANTS_SS} binary;
param ss_country{VARIANTS_SS} symbolic;
param ss_id{VARIANTS_SS} symbolic;
param ss_desc{VARIANTS_SS} symbolic;

set VARIANTS_LOADS dimen 2;
param ld_bus{VARIANTS_LOADS};
param ld_ss{VARIANTS_LOADS};
param ld_p0{VARIANTS_LOADS};
param ld_q0{VARIANTS_LOADS};
param ld_fault{VARIANTS_LOADS} binary;
param ld_curative{VARIANTS_LOADS} binary;
param ld_id{VARIANTS_LOADS} symbolic;
param ld_desc{VARIANTS_LOADS} symbolic;
param ld_p{VARIANTS_LOADS};
param ld_q{VARIANTS_LOADS};

param v_min{VARIANTS_BUSES} default 0.8;
param v_max{VARIANTS_BUSES} default 1.2;

param p_pu default 100;
39 changes: 39 additions & 0 deletions ampl_files/ampl_model.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Variables
var V{i in BUSES} default if bus_v[1,i] > 0 then bus_v[1,i] else 1;
var Phi{BUSES} default 0;
var Q{PV_BUSES} default 0;

# Objectif function
minimize Quadratic_Error:
sum {i in PQ_BUSES: bus_v[1,i] > 0} ( (V[i] - bus_v[1,i]) * (V[i] - bus_v[1,i]) );

# Constraints
subject to Active_power_balance{i in BUSES: i != slack_bus}:
sum {j in BRANCHES: br_bus1[1,j] == i and br_bus2[1,j] != -1} ( br_cstr[1,j] * V[i] * ( br_g1[1,j] * br_cstr[1,j] * V[i] + br_y[j] * br_cstr[1,j] * V[i] * sin(br_ksi[j]) - br_y[j] * 1 * V[br_bus2[1,j]] * sin(br_ksi[j] - 0 + 0 - Phi[i] + Phi[br_bus2[1,j]]) ) )
+ sum {j in BRANCHES: br_bus2[1,j] == i and br_bus1[1,j] != -1} ( 1 * V[i] * ( br_g2[1,j] * 1 * V[i] - br_y[j] * br_cstr[1,j] * V[br_bus1[1,j]] * sin(br_ksi[j] + 0 - 0 + Phi[br_bus1[1,j]] - Phi[i]) + br_y[j] * 1 * V[i] * sin(br_ksi[j]) ) )
== (sum {j in GENS: gen_bus[1,j] == i} gen_targetp[1,j] - sum {j in LOADS: ld_bus[1,j] == i} ld_p0[1,j])/p_pu;

subject to Null_phase_slack{i in BUSES: i == slack_bus}:
Phi[i] == 0;

subject to Rective_power_balance_PQ{i in PQ_BUSES}:
sum {j in BRANCHES: br_bus1[1,j] == i and br_bus2[1,j] != -1} ( br_cstr[1,j] * V[i] * (- br_b1[1,j] * br_cstr[1,j] * V[i] + br_y[j] * br_cstr[1,j] * V[i] * cos(br_ksi[j]) - br_y[j] * 1 * V[br_bus2[1,j]] * cos(br_ksi[j] - 0 + 0 - Phi[i] + Phi[br_bus2[1,j]]) ) )
+ sum {j in BRANCHES: br_bus2[1,j] == i and br_bus1[1,j] != -1} ( 1 * V[i] * ( - br_b2[1,j] * 1 * V[i] - br_y[j] * br_cstr[1,j] * V[br_bus1[1,j]] * cos(br_ksi[j] + 0 - 0 + Phi[br_bus1[1,j]] - Phi[i]) + br_y[j] * 1 * V[i] * cos(br_ksi[j]) ) )
== (sum {j in GENS: gen_bus[1,j] == i} gen_targetq[1,j] - sum {j in LOADS: ld_bus[1,j] == i} ld_q0[1,j])/p_pu;

subject to Rective_power_balance_PV{i in PV_BUSES}:
sum {j in BRANCHES: br_bus1[1,j] == i and br_bus2[1,j] != -1} ( br_cstr[1,j] * V[i] * (- br_b1[1,j] * br_cstr[1,j] * V[i] + br_y[j] * br_cstr[1,j] * V[i] * cos(br_ksi[j]) - br_y[j] * 1 * V[br_bus2[1,j]] * cos(br_ksi[j] - 0 + 0 - Phi[i] + Phi[br_bus2[1,j]]) ) )
+ sum {j in BRANCHES: br_bus2[1,j] == i and br_bus1[1,j] != -1} ( 1 * V[i] * ( - br_b2[1,j] * 1 * V[i] - br_y[j] * br_cstr[1,j] * V[br_bus1[1,j]] * cos(br_ksi[j] + 0 - 0 + Phi[br_bus1[1,j]] - Phi[i]) + br_y[j] * 1 * V[i] * cos(br_ksi[j]) ) )
== Q[i]/p_pu;

subject to Reactive_power_inf{i in PV_BUSES}:
sum {j in GENS: gen_bus[1,j] == i} gen_minq0[1,j] - sum {j in LOADS: ld_bus[1,j] == i} ld_q0[1,j] <= Q[i];

subject to Reactive_power_sup{i in PV_BUSES}:
Q[i] <= sum {j in GENS: gen_bus[1,j] == i} gen_maxq0[1,j] - sum {j in LOADS: ld_bus[1,j] == i} ld_q0[1,j];

subject to Voltage_limit_inf{i in BUSES}:
sum{(j,k) in VARIANTS_SS: k == bus_substations[1,i] and j == 1} ss_minv[j,k] <= V[i];

subject to Voltage_limit_sup{i in BUSES}:
V[i] <= sum{(j,k) in VARIANTS_SS: k == bus_substations[1,i] and j == 1} ss_maxv[j,k];
45 changes: 45 additions & 0 deletions ampl_files/ampl_model.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
model ampl_dataread_model.mod;
data ampl_data.dat;
model ampl_computed_data.mod;
model ampl_model.mod;
option solver knitroampl;
option knitro_options "feastol=1e-3";
/*
display BUSES;
display PV_BUSES;
display PQ_BUSES;
display br_x;
display ss_country;
display BRANCHES;
display slack_bus;
display ld_p0;
display br_y;
display br_ksi;
*/
problem Initialize_voltage_plan: V, Phi, Q, Quadratic_Error, Active_power_balance, Null_phase_slack, Rective_power_balance_PQ, Rective_power_balance_PV, Reactive_power_inf, Reactive_power_sup, Voltage_limit_inf, Voltage_limit_sup;

solve Initialize_voltage_plan;
/*
display V;
display Phi;
display Active_power_balance;

for{i in BUSES: i != slack_bus} {
display i;
display sum {j in BRANCHES: br_bus1[1,j] == i} ( br_cstr[1,j] * V[i] * ( br_g1[1,j] * br_cstr[1,j] * V[i] + br_y[j] * br_cstr[1,j] * V[i] * sin(br_ksi[j]) - br_y[j] * 1 * V[br_bus2[1,j]] * sin(br_ksi[j] - 0 + 0 - Phi[i] + Phi[br_bus2[1,j]]) ) )
+ sum {j in BRANCHES: br_bus2[1,j] == i} ( 1 * V[i] * ( br_g2[1,j] * 1 * V[i] - br_y[j] * br_cstr[1,j] * V[br_bus1[1,j]] * sin(br_ksi[j] + 0 - 0 + Phi[br_bus1[1,j]] - Phi[i]) + br_y[j] * 1 * V[i] * sin(br_ksi[j]) ) );
display sum {j in GENS: gen_bus[1,j] == i} gen_targetp[1,j] - sum {j in LOADS: ld_bus[1,j] == i} ld_p0[1,j];
display sum {j in BRANCHES: br_bus1[1,j] == i} ( br_cstr[1,j] * V[i] * (- br_b1[1,j] * br_cstr[1,j] * V[i] + br_y[j] * br_cstr[1,j] * V[i] * cos(br_ksi[j]) - br_y[j] * 1 * V[br_bus2[1,j]] * cos(br_ksi[j] - 0 + 0 - Phi[i] + Phi[br_bus2[1,j]]) ) )
+ sum {j in BRANCHES: br_bus2[1,j] == i} ( 1 * V[i] * ( - br_b2[1,j] * 1 * V[i] - br_y[j] * br_cstr[1,j] * V[br_bus1[1,j]] * cos(br_ksi[j] + 0 - 0 + Phi[br_bus1[1,j]] - Phi[i]) + br_y[j] * 1 * V[i] * cos(br_ksi[j]) ) );
display sum {j in GENS: gen_bus[1,j] == i} gen_targetq[1,j] - sum {j in LOADS: ld_bus[1,j] == i} ld_q0[1,j];
}

for{i in BUSES} {
if sum{(j,k) in VARIANTS_SS: k == bus_substations[1,i] and j == 1} ss_minv[j,k] > V[i] or sum{(j,k) in VARIANTS_SS: k == bus_substations[1,i] and j == 1} ss_maxv[j,k] < V[i] then printf "Bus %d : %f < %f < %f\n", i, sum{(j,k) in VARIANTS_SS: k == bus_substations[1,i] and j == 1} ss_minv[j,k], V[i], sum{(j,k) in VARIANTS_SS: k == bus_substations[1,i] and j == 1} ss_maxv[j,k];
}

printf "slack node (i=1) \n";
display sum {j in BRANCHES: br_bus1[1,j] == 1} ( br_cstr[1,j] * V[1] * ( br_g1[1,j] * br_cstr[1,j] * V[1] + br_y[j] * br_cstr[1,j] * V[1] * sin(br_ksi[j]) - br_y[j] * 1 * V[br_bus2[1,j]] * sin(br_ksi[j] - 0 + 0 - Phi[1] + Phi[br_bus2[1,j]]) ) )
+ sum {j in BRANCHES: br_bus2[1,j] == 1} ( 1 * V[1] * ( br_g2[1,j] * 1 * V[1] - br_y[j] * br_cstr[1,j] * V[br_bus1[1,j]] * sin(br_ksi[j] + 0 - 0 + Phi[br_bus1[1,j]] - Phi[1]) + br_y[j] * 1 * V[1] * sin(br_ksi[j]) ) );
display Q[1];
*/
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@
</developers>

<modules>
<module>simulator</module>
</modules>

<properties>
<java.version>11</java.version>
<powsybl-core.version>4.9.2</powsybl-core.version>
<powsybl-dependencies.version>1.2.2</powsybl-dependencies.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-core</artifactId>
<version>${powsybl-core.version}</version>
<artifactId>powsybl-dependencies</artifactId>
<version>${powsybl-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Loading