Source code for monee.model.formulation.misoc.el
from monee.model.core import Intermediate, IntermediateEq, Var
from monee.model.formulation.core import BranchFormulation, NodeFormulation
from monee.model.phys.misoc.pf import (
active_power_loss,
reactive_power_loss,
soc_rel,
voltage_drop,
)
[docs]
class MISOCPElectricityNodeFormulation(NodeFormulation):
[docs]
def ensure_var(self, node):
node.vm_pu_squared = Var(1, min=0, max=3)
node.vm_pu = Intermediate(1)
[docs]
def equations(
self,
node,
grid,
from_branch_models,
to_branch_models,
connected_node_models,
**kwargs,
):
return [
IntermediateEq("vm_pu", kwargs["sqrt_impl"](node.vm_pu_squared)),
]
[docs]
class MISOCPElectricityBranchFormulation(BranchFormulation):
[docs]
def minimize(self, branch, grid, from_node_model, to_node_model, **kwargs):
return [branch.current_pu * branch.br_r]
[docs]
def equations(self, branch, grid, from_node_model, to_node_model, **kwargs):
return [
voltage_drop(
from_node_model.vars["vm_pu_squared"],
to_node_model.vars["vm_pu_squared"],
branch.vars["p_from_mw"] / grid.sn_mva,
branch.vars["q_from_mvar"] / grid.sn_mva,
branch.current_pu,
branch.br_r,
branch.br_x,
)
<= branch.big_M * (1 - branch.on_off),
voltage_drop(
from_node_model.vars["vm_pu_squared"],
to_node_model.vars["vm_pu_squared"],
branch.vars["p_from_mw"] / grid.sn_mva,
branch.vars["q_from_mvar"] / grid.sn_mva,
branch.current_pu,
branch.br_r,
branch.br_x,
)
>= -branch.big_M * (1 - branch.on_off),
soc_rel(
from_node_model.vars["vm_pu_squared"],
branch.vars["p_from_mw"] / grid.sn_mva,
branch.vars["q_from_mvar"] / grid.sn_mva,
branch.current_pu,
),
active_power_loss(
branch.vars["p_from_mw"] / grid.sn_mva,
branch.vars["p_to_mw"] / grid.sn_mva,
branch.current_pu,
branch.br_r,
),
reactive_power_loss(
branch.vars["q_from_mvar"] / grid.sn_mva,
branch.vars["q_to_mvar"] / grid.sn_mva,
branch.current_pu,
branch.br_x,
),
# Calculate the voltage/current error, However using this make the Problem non-convex
# branch.gap == gap_expr(from_node_model.vars["vm_pu_squared"],
# branch.vars["p_from_mw"],
# branch.vars["q_from_mvar"],
# branch.current_pu),
]