Skip to content

Commit

Permalink
Use nomopyomo instead of PyPSA default pyomo
Browse files Browse the repository at this point in the history
  • Loading branch information
nworbmot committed Aug 31, 2019
1 parent 899f81d commit 0908ed4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ venv/

move_weather.py

*.zip
*.zip

nomopyomo.py
24 changes: 17 additions & 7 deletions solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

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

import nomopyomo

octant_folder = "../cutouts/"

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

def extra_functionality(network,snapshots):
def battery(model):
return model.link_p_nom["battery_power"] == model.link_p_nom["battery_discharge"]*network.links.at["battery_power","efficiency"]

network.model.battery = Constraint(rule=battery)
group = "battery"
nomopyomo.add_group(network,"constraint",group,1)
start = network.constraint_positions.at[group,"start"]

# charge-power = efficiency * discharge-power
constraint_matrix = {}
i_battery_power = network.variable_positions.at["Link-p_nom","start"] + network.links.index.get_loc("battery_power")
i_battery_discharge = network.variable_positions.at["Link-p_nom","start"] + network.links.index.get_loc("battery_discharge")
constraint_matrix[i_battery_power] = 1.
constraint_matrix[i_battery_discharge] = -network.links.at["battery_power","efficiency"]
nomopyomo.write_constraint(network,constraint_matrix,"==",0.,start)
else:
def extra_functionality(network,snapshots):
pass
Expand Down Expand Up @@ -481,9 +490,10 @@ def extra_functionality(network,snapshots):

solver_name = "cbc"
formulation = "kirchhoff"
status, termination_condition = network.lopf(solver_name=solver_name,
formulation=formulation,
extra_functionality=extra_functionality)
status, termination_condition = nomopyomo.network_lopf(network,
solver_name=solver_name,
formulation=formulation,
extra_functionality=extra_functionality)

print(status,termination_condition)

Expand Down
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,6 @@ <h3>Privacy statement</h3>
});
}
</script>
<script src="{{ url_for('static', filename='solver-190727.js') }}"></script>
<script src="{{ url_for('static', filename='solver-190829.js') }}"></script>
</body>
</html>

0 comments on commit 0908ed4

Please sign in to comment.