Skip to content

Commit 0908ed4

Browse files
committed
Use nomopyomo instead of PyPSA default pyomo
1 parent 899f81d commit 0908ed4

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ venv/
4747

4848
move_weather.py
4949

50-
*.zip
50+
*.zip
51+
52+
nomopyomo.py

solve.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
from shapely.geometry import box, Point, Polygon, MultiPolygon
3838

39+
import nomopyomo
40+
3941
octant_folder = "../cutouts/"
4042

4143
colors = {"wind":"#3B6182",
@@ -440,10 +442,17 @@ def run_optimisation(assumptions, pu):
440442
efficiency = assumptions_df.at['battery_power','efficiency'])
441443

442444
def extra_functionality(network,snapshots):
443-
def battery(model):
444-
return model.link_p_nom["battery_power"] == model.link_p_nom["battery_discharge"]*network.links.at["battery_power","efficiency"]
445-
446-
network.model.battery = Constraint(rule=battery)
445+
group = "battery"
446+
nomopyomo.add_group(network,"constraint",group,1)
447+
start = network.constraint_positions.at[group,"start"]
448+
449+
# charge-power = efficiency * discharge-power
450+
constraint_matrix = {}
451+
i_battery_power = network.variable_positions.at["Link-p_nom","start"] + network.links.index.get_loc("battery_power")
452+
i_battery_discharge = network.variable_positions.at["Link-p_nom","start"] + network.links.index.get_loc("battery_discharge")
453+
constraint_matrix[i_battery_power] = 1.
454+
constraint_matrix[i_battery_discharge] = -network.links.at["battery_power","efficiency"]
455+
nomopyomo.write_constraint(network,constraint_matrix,"==",0.,start)
447456
else:
448457
def extra_functionality(network,snapshots):
449458
pass
@@ -481,9 +490,10 @@ def extra_functionality(network,snapshots):
481490

482491
solver_name = "cbc"
483492
formulation = "kirchhoff"
484-
status, termination_condition = network.lopf(solver_name=solver_name,
485-
formulation=formulation,
486-
extra_functionality=extra_functionality)
493+
status, termination_condition = nomopyomo.network_lopf(network,
494+
solver_name=solver_name,
495+
formulation=formulation,
496+
extra_functionality=extra_functionality)
487497

488498
print(status,termination_condition)
489499

templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,6 @@ <h3>Privacy statement</h3>
483483
});
484484
}
485485
</script>
486-
<script src="{{ url_for('static', filename='solver-190727.js') }}"></script>
486+
<script src="{{ url_for('static', filename='solver-190829.js') }}"></script>
487487
</body>
488488
</html>

0 commit comments

Comments
 (0)