monee models

monee base models for model creation

class monee.model.Branch(model, from_node_id, to_node_id, formulation=None, constraints=None, grid=None, name=None, active=True, independent=True)[source]

Bases: Component

No docstring provided.

equations(grid, from_node_model, to_node_model, **kwargs)[source]
minimize(grid, from_node_model, to_node_model, **kwargs)[source]
property tid

No docstring provided.

class monee.model.BranchModel(**kwargs)[source]

Bases: GenericModel

Abstract base class for network branch models, defining the interface for branch-specific equations, loss calculation, and initialization.

BranchModel provides a common foundation for implementing custom branch types (such as power lines or pipes) in network simulations. Subclasses must implement the abstract equations method to define the physical relationships for the branch. Optional methods such as loss_percent, is_cp, and init can be overridden to customize loss calculations, control point designation, and initialization logic. This class inherits from GenericModel and is intended for use within extensible, multi-domain network modeling frameworks.

_ext_data

Stores extra data passed during initialization for use in extended models.

Type:

dict

equations(grid, from_node_model, to_node_model, ``**kwargs``)[source]

Abstract. Must be implemented by subclasses to define branch equations.

loss_percent()[source]

Returns the loss percentage for the branch (default 0; override as needed).

is_cp()[source]

Indicates if the branch is a control point (default False; override as needed).

init(grid)[source]

Optional initialization logic for the branch (default is no-op).

Example:

class MyCustomBranch(BranchModel):
    def equations(self, grid, from_node_model, to_node_model, **kwargs):
        # Implement branch-specific equations
        pass

    def loss_percent(self):
        # Custom loss calculation
        return compute_actual_loss(self)

    def is_cp(self):
        # Mark this branch as a control point
        return True

    def init(self, grid):
        # Custom initialization logic
        pass
abstractmethod equations(grid, from_node_model, to_node_model, **kwargs)[source]

No docstring provided.

init(grid)[source]

No docstring provided.

is_cp()[source]

Indicates whether the branch model represents a control point (CP) in the network.

This method is used to determine if the current branch model instance should be treated as a control point, which may affect optimization or control strategies in network simulations. By default, this implementation always returns False, meaning the branch is not a control point. Override this method in subclasses if specific branch types should be considered as control points.

Returns:

False, indicating the branch model is not a control point by default.

Return type:

bool

Examples

Check if a branch model is a control point:
if branch_model.is_cp():

# Apply control logic …

loss_percent()[source]

Returns the percentage of losses for the branch model, defaulting to zero.

This method provides a placeholder for calculating the loss percentage associated with a branch in the network, such as power or heat losses. By default, it returns 0, indicating no losses are considered. Override this method in subclasses to implement specific loss calculations relevant to the branch type.

Returns:

Always returns 0, representing zero loss percentage by default.

Return type:

int

Examples

# In a custom branch model, override to provide actual loss calculation
class MyBranchModel(BranchModel):
    def loss_percent(self):
        return compute_actual_loss(self)

In base usage:

loss = branch_model.loss_percent()  # Returns 0 unless overridden
minimize(grid, from_node_model, to_node_model, **kwargs)[source]

Minimization of an expression as minimization may necessary due to some formulation (when replacing constraints with slack variables)

Parameters:

self – Description

class monee.model.Bus(base_kv)[source]

Bases: NodeModel

No docstring provided.

calc_signed_power_values(from_branch_models, to_branch_models, connected_node_models)[source]

No docstring provided.

equations(grid, from_branch_models, to_branch_models, connected_node_models, **kwargs)[source]

No docstring provided.

p_mw_equation(child_models)[source]

No docstring provided.

q_mvar_equation(child_models)[source]

No docstring provided.

class monee.model.CHP(diameter_m: float, efficiency_power: float, efficiency_heat: float, mass_flow_setpoint: float, q_mvar_setpoint: float = 0, temperature_ext_k: float = 293, regulation=1)[source]

Bases: MultiGridCompoundModel

No docstring provided.

create(network: monee.model.network.Network, gas_node: monee.model.core.Node, heat_node: monee.model.core.Node, heat_return_node: monee.model.core.Node, power_node: monee.model.core.Node)[source]

No docstring provided.

class monee.model.CHPControlNode(mass_flow_capacity, efficiency_power, efficiency_heat, hhv, q_mvar=0, regulation=1, **kwargs)[source]

Bases: MultiGridNodeModel, Junction, Bus

Represents a control node for combined heat and power (CHP) systems, managing energy and mass balances across power, heat, and gas domains.

CHPControlNode extends MultiGridNodeModel, Junction, and Bus to provide a unified interface for modeling the operational logic and constraints of a CHP unit within a multi-energy network. It tracks key parameters such as fuel mass flow, electrical and thermal efficiencies, and regulation factors, and exposes variables for integration with network branches. Use this class when simulating or optimizing CHP systems that require explicit coupling between gas, heat, and electrical grids.

Example:

chp_node = CHPControlNode(
    mass_flow_capacity=1.2,
    efficiency_power=0.35,
    efficiency_heat=0.5,
    hhv=42.5e6,
    q_mvar=0,
    regulation=1
)
# Integrate chp_node into a network and call chp_node.equations(...) during simulation
Parameters:
  • mass_flow_capacity – Maximum or setpoint mass flow of fuel (e.g., gas) supplied to the CHP unit.

  • efficiency_power – Electrical efficiency (fraction, 0 < value ≤ 1).

  • efficiency_heat – Thermal efficiency (fraction, 0 < value ≤ 1).

  • hhv – Higher heating value of the fuel (J/kg).

  • q_mvar (optional) – Reactive power setpoint for the generator. Defaults to 0.

  • regulation (optional) – Regulation factor for operational flexibility. Defaults to 1.

  • **kwargs – Additional keyword arguments for parent class initialization.

mass_flow_capacity

Fuel mass flow capacity or setpoint.

efficiency_power

Electrical efficiency.

efficiency_heat

Thermal efficiency.

gen_q_mvar

Reactive power setpoint.

_hhv

Higher heating value of the fuel.

regulation

Regulation factor.

_gen_p_mw

Electrical power generation variable.

heat_gen_w

Thermal power generation variable.

el_gen_mw

Electrical power generation variable (duplicate for unified interface).

el_mw

Unified electrical power variable.

gas_kgps

Unified gas mass flow variable.

heat_w

Unified heat power variable.

t_k

Node temperature (K).

t_pu

Node temperature (per unit).

pressure_pa

Node pressure (Pa).

pressure_pu

Node pressure (per unit).

equations(grid, from_branch_models, to_branch_models, childs, **kwargs)[source]

Defines the system of equations for the CHP node, including mass and energy balances, power and heat conversion, and normalization constraints.

equations(grid, from_branch_models, to_branch_models, childs, **kwargs)[source]

Defines the system of equations for a combined heat and power (CHP) control node, capturing energy and mass balances across power, heat, and gas domains.

This method assembles the physical and operational constraints for a CHP node, including mass flow balances for heat and gas, power balance equations, and thermodynamic relationships for energy conversion. It integrates the effects of efficiency, regulation, and fuel properties, and links the node’s internal variables to the connected branches. Use this method during network simulation or optimization to ensure the CHP node’s behavior is accurately represented within the multi-energy system.

Parameters:
  • grid – List or collection of grid objects, where grid[1] is expected to be the heat grid for reference values.

  • from_branch_models (list) – Branch models representing flows entering the node.

  • to_branch_models (list) – Branch models representing flows leaving the node.

  • childs (list) – Child component models attached to the node.

  • **kwargs – Additional keyword arguments for solver options or equation customization.

Returns:

A tuple of equations representing:

  • Heat mass flow balance at the node.

  • Heat energy flow balance at the node.

  • Gas mass flow balance at the node.

  • Power balance equations (active and reactive).

  • Heat exchanger energy conversion constraint.

  • Electrical power generation constraint.

  • Consistency between internal heat and electrical variables and branch flows.

  • Temperature and pressure normalization constraints.

Return type:

tuple

Raises:
  • IndexError – If no SubHE branch is found in the heat_from_branches list.

  • KeyError – If expected variables are missing from branch models.

Examples

# Called automatically during network simulation: eqs = chp_control_node.equations(grid, from_branches, to_branches, childs)

class monee.model.Child(child_id, model, formulation=None, constraints=None, grid=None, name=None, active=True, independent=True)[source]

Bases: Component

No docstring provided.

equations(grid, node_model, **kwargs)[source]
minimize(grid, node_model, **kwargs)[source]
class monee.model.ChildModel(regulation: float = 1.0, **kwargs)[source]

Bases: GenericModel

Base class for leaf components attached to a single node (loads, generators, ext-grids).

Sign convention — the internal representation follows the load convention:

  • Positive values represent consumption (load, sink).

  • Negative values represent generation (injection, source).

Concrete subclasses such as PowerGenerator and Source negate the user-supplied magnitude in __init__ so that the public API always accepts positive numbers for generators:

PowerGenerator(p_mw=5)   → self.p_mw = -5   (injecting 5 MW)
PowerLoad(p_mw=5)        → self.p_mw = +5   (consuming 5 MW)
Parameters:
  • regulation (float) – Scaling factor applied to the component’s setpoint, in the range [0.0, 1.0]. A value of 1.0 (default) means full output/consumption; 0.0 effectively disables the component. The factor is used by multi-energy coupling components (P2H, CHP, …) to model partial dispatch.

  • **kwargs – Forwarded to GenericModel.

abstractmethod equations(grid, node_model, **kwargs)[source]

No docstring provided.

minimize(grid, node_model, **kwargs)[source]

Minimization of an expression as minimization may necessary due to some formulation (when replacing constraints with slack variables)

Parameters:

self – Description

overwrite(node_model, grid)[source]

Pin node variables to fixed setpoints (optional).

Override this method in grid-forming components (e.g. ExtPowerGrid) to replace free node Var instances with Const values before the solver runs. The default implementation is a no-op.

Parameters:
  • node_model – The node model the child is attached to.

  • grid – The grid domain of the node.

class monee.model.Component(id, model, formulation=None, constraints=None, grid=None, name=None, active=True, independent=True)[source]

Bases: ABC

No docstring provided.

property formulation
property nid

No docstring provided.

property tid

No docstring provided.

class monee.model.Compound(compound_id, model: monee.model.core.CompoundModel, connected_to, subcomponents, formulation=None, constraints=None, grid=None, name=None, active=True)[source]

Bases: Component

No docstring provided.

component_of_type(comp_type)[source]

No docstring provided.

equations(network, **kwargs)[source]
minimize(network, **kwargs)[source]
class monee.model.CompoundModel(**kwargs)[source]

Bases: GenericModel

Base class for composite components that span multiple nodes and/or carriers.

A CompoundModel groups several sub-components (internal branches, child attachments, etc.) into a single logical unit — for example a P2H unit that internally creates a water pipe and couples it to an electricity bus.

Subclasses must implement create(), which receives the network and is expected to add the required sub-components. Optionally override equations() to add coupling constraints between the sub-components’ variables, and minimize() to contribute objective terms.

abstractmethod create(network)[source]

Materialise the compound’s sub-components in network.

Called once when the compound is added to the network. Implementations should call network.node(), network.branch(), network.child_to() etc. to create internal topology.

Parameters:

network – The Network the compound belongs to.

equations(network, **kwargs)[source]

Return coupling constraints between sub-component variables.

Override this method to add equations that link variables across the compound’s internal sub-components (e.g. energy-balance between the electrical and hydraulic side of a P2H unit). Returns an empty list by default.

minimize(network, **kwargs)[source]

Minimization of an expression as minimization may necessary due to some formulation (when replacing constraints with slack variables)

Parameters:

self – Description

class monee.model.Const(value)[source]

Bases: object

A fixed (non-optimised) constant that participates in the model attribute protocol.

Use Const when a value must be readable by value() but should never be turned into a solver decision variable. The primary use-case is inside overwrite() implementations, where a child component pins a node variable to a fixed setpoint:

node_model.vm_pu = Const(1.02)   # fixed voltage — not a free variable
Parameters:

value – The fixed scalar value.

class monee.model.ConsumeHydrGrid(mass_flow=0.1, pressure_pu=1, t_k=293, **kwargs)[source]

Bases: NoVarChildModel

Hydraulic demand point (consumption) for gas or water networks.

Represents a fixed-pressure offtake point (e.g. a building substation or a gas consumer). Pins the junction pressure to a setpoint and applies a fixed mass-flow consumption.

Follows the load convention: internally stores a negative mass-flow so that the junction balance treats it as withdrawal. The constructor accepts positive magnitudes and negates them:

ConsumeHydrGrid(mass_flow=0.5)  →  self.mass_flow = -0.5
Parameters:
  • mass_flow (float) – Mass flow rate in kg/s to consume (positive = consumption). Defaults to 0.1.

  • pressure_pu (float) – Junction pressure setpoint in per-unit. Defaults to 1.0.

  • t_k (float) – Return temperature in Kelvin. Defaults to 293 K.

overwrite(node_model, grid)[source]

Pin the junction pressure to the configured setpoint.

class monee.model.ElectricityIslandingMode(angle_bound: float = 3.15, big_m_conn: int = 200)[source]

Bases: IslandingMode

Islanding configuration for the electricity carrier.

Adds: * Single-commodity connectivity-flow constraints (via the base class). * source_reference_angle at every grid-forming bus → θ = 0. * angle_{upper,lower}_bound_energized at every regular bus →

forces θ = 0 when e_i = 0 (de-energised).

Parameters:
  • angle_bound (float) – Maximum absolute angle (radians) for energised buses. Default ≈ π.

  • big_m_conn (int) – Big-M for connectivity-flow arc capacity. Must be ≥ number of carrier nodes.

add_physical_constraints(network, gf_nodes, regular_nodes, e_vars)[source]

Electricity-specific physical constraint equations (returned as a list).

  • Grid-forming nodes: angle reference = 0 (source_reference_angle from dc.py).

  • Regular nodes: angle bounds conditional on energisation.

Return type:

list

carrier_grid_type

alias of PowerGrid

prepare(network: monee.model.network.Network)[source]

Phase 1 — add electricity islanding Var placeholders.

Return type:

None

var_prefix: str = 'el'
class monee.model.ExtHydrGrid(mass_flow=-1, pressure_pu=1, t_k=356, **kwargs)[source]

Bases: NoVarChildModel, GridFormingMixin

External hydraulic grid (slack source) — the pressure/temperature reference for a gas or water island.

ExtHydrGrid pins the junction pressure and temperature to fixed setpoints (via overwrite()) and exposes mass_flow as a free Var decision variable that absorbs the island’s flow imbalance.

Follows the load convention: the default mass_flow=-1 represents injection (negative = generation/source). The solver determines the actual mass flow.

Parameters:
  • mass_flow (float) – Initial mass-flow guess in kg/s. Negative = injection (source), positive = consumption (sink). Defaults to -1.

  • pressure_pu (float) – Junction pressure setpoint in per-unit. Defaults to 1.0.

  • t_k (float) – Supply temperature setpoint in Kelvin. Defaults to 356 K.

overwrite(node_model, grid)[source]

Pin the junction pressure and temperature to the configured setpoints.

class monee.model.ExtPowerGrid(p_mw, q_mvar, vm_pu=1, va_degree=0, **kwargs)[source]

Bases: NoVarChildModel, GridFormingMixin

External (slack) power grid connection — the reference bus for an electrical island.

ExtPowerGrid pins the bus voltage magnitude and angle to fixed setpoints (via overwrite()) and exposes p_mw / q_mvar as free Var decision variables that absorb the island’s power imbalance.

Follows the load convention: positive p_mw / q_mvar at the node represents net import from the external grid (consumption perspective). The p_mw / q_mvar initial values are starting guesses; the solver determines the final values.

Parameters:
  • p_mw (float) – Initial active power exchange in MW.

  • q_mvar (float) – Initial reactive power exchange in Mvar.

  • vm_pu (float) – Voltage magnitude setpoint in per-unit. Defaults to 1.0.

  • va_degree (float) – Voltage angle setpoint in degrees. Defaults to 0.0.

overwrite(node_model, grid)[source]

Pin the bus voltage magnitude and angle to the configured setpoints.

class monee.model.GasGrid(name: str, compressibility: float, molar_mass: float, gas_temperature: float, dynamic_visc: float, higher_heating_value: float, universal_gas_constant: float, t_k: float, t_ref: float, pressure_ref: float, nominal_pressure_pu: float, f_max: float, p_squared_pu_max: float, p_squared_pu_min: float)[source]

Bases: Grid

Represents a gas grid domain within a multi-energy network model, encapsulating physical and thermodynamic properties of the gas system.

GasGrid extends the base Grid class to provide attributes and parameters specific to gas networks, such as compressibility, molar mass, temperature, and reference pressures. Use this class to model gas infrastructure, perform flow calculations, or integrate gas dynamics into multi-domain simulations. It is typically instantiated as part of a larger network model where gas transport, conversion, or coupling with other energy domains is required.

compressibility

Compressibility factor of the gas.

Type:

float

molar_mass

Molar mass of the gas (kg/mol).

Type:

float

gas_temperature

Operating temperature of the gas (K).

Type:

float

dynamic_visc

Dynamic viscosity of the gas (Pa·s).

Type:

float

higher_heating_value

Higher heating value of the gas (J/kg).

Type:

float

universal_gas_constant

Universal gas constant (J/(mol·K)).

Type:

float

t_k

Absolute temperature in Kelvin for calculations.

Type:

float

t_ref

Reference temperature in Kelvin.

Type:

float

pressure_ref

Reference pressure in Pascals.

Type:

float

Example

gas_grid = GasGrid() gas_grid.compressibility = 0.98 gas_grid.molar_mass = 0.016 gas_grid.gas_temperature = 293.15 # … set other properties as needed

compressibility: float
dynamic_visc: float
f_max: float
gas_temperature: float
higher_heating_value: float
molar_mass: float
nominal_pressure_pu: float
p_squared_pu_max: float
p_squared_pu_min: float
pressure_ref: float
t_k: float
t_ref: float
universal_gas_constant: float
class monee.model.GasIslandingMode(big_m_conn: int = 200)[source]

Bases: IslandingMode

Islanding configuration for the gas carrier.

Adds: * Single-commodity connectivity-flow constraints (via the base class). * Pressure bounds conditional on energisation for regular junctions:

pressure_pu p_max · e_i so that de-energised junctions have pressure = 0.

The pressure at grid-forming junctions is already pinned by GridFormingSource.overwrite() (or ExtHydrGrid.overwrite()), so no additional pinning is needed for GF nodes in this method.

Parameters:

big_m_conn (int) – Big-M for connectivity-flow arc capacity. Must be ≥ number of carrier nodes.

add_physical_constraints(network, gf_nodes, regular_nodes, e_vars)[source]

Gas-specific physical constraint equations (returned as a list).

Force pressure_pu = 0 for de-energised junctions via an upper bound that is conditional on e_i.

Return type:

list

carrier_grid_type

alias of GasGrid

prepare(network: monee.model.network.Network)[source]

Phase 1 — add gas islanding Var placeholders.

Return type:

None

var_prefix: str = 'gas'
class monee.model.GasPipe(diameter_m, length_m, temperature_ext_k=296.15, roughness=0.0001, on_off=1, friction=None)[source]

Bases: BranchModel

No docstring provided.

equations(grid: monee.model.grid.GasGrid, from_node_model, to_node_model, **kwargs)[source]

No docstring provided.

class monee.model.GasToHeat(heat_energy_w, diameter_m, temperature_ext_k, efficiency)[source]

Bases: MultiGridCompoundModel

No docstring provided.

create(network: monee.model.network.Network, gas_node: monee.model.core.Node, heat_node: monee.model.core.Node, heat_return_node: monee.model.core.Node)[source]

No docstring provided.

class monee.model.GasToHeatControlNode(heat_gen_w, efficiency_heat, hhv, regulation=1, **kwargs)[source]

Bases: MultiGridNodeModel, Junction

No docstring provided.

equations(grid, from_branch_models, to_branch_models, childs, **kwargs)[source]

No docstring provided.

class monee.model.GasToPower(efficiency, p_mw_setpoint, q_mvar_setpoint=0, regulation=1)[source]

Bases: MultiGridBranchModel

No docstring provided.

equations(grids, from_node_model, to_node_model, **kwargs)[source]

No docstring provided.

loss_percent()[source]

No docstring provided.

class monee.model.GenericModel(**kwargs)[source]

Bases: ABC

Base class for all component models (nodes, branches, children, compounds).

Provides the vars and values introspection properties that the solver backends use to discover and inject decision variables. Any attribute whose name does not start with _ is considered part of the model’s public state and will be included in vars/values and in the result DataFrames.

Subclasses should store parameters and decision variables as plain Python attributes in __init__. Use Var for decision variables, Const for fixed setpoints that must participate in the attribute protocol, and plain scalars for parameters that never enter the solver.

Extra keyword arguments passed to __init__ are stored in _ext_data and ignored by the solver.

is_cp()[source]

Return True if this model acts as a multi-grid control point. Default: False.

property values

All public attributes with Var/Const/Intermediate unwrapped to scalars.

property vars

All public attributes as a {name: value} dict (includes Var, Const, scalars).

class monee.model.GenericPowerBranch(tap, shift, br_r, br_x, g_fr, b_fr, g_to, b_to, max_i_ka=3.19, backup=False, on_off=1, **kwargs)[source]

Bases: BranchModel

No docstring provided.

_summary_

Parameters:
  • tap (_type_) – _description_

  • shift (_type_) – _description_

  • br_r (_type_) – resistence

  • br_x (_type_) – reactance

  • g_fr (_type_) – from conductance

  • b_fr (_type_) – from susceptance

  • g_to (_type_) – to conductance

  • b_to (_type_) – to susceptance

equations(grid: monee.model.grid.PowerGrid, from_node_model, to_node_model, **kwargs)[source]

No docstring provided.

property loading_percent

No docstring provided.

loss_percent()[source]

No docstring provided.

class monee.model.GenericTransferBranch(loss=0, **kwargs)[source]

Bases: MultiGridBranchModel

No docstring provided.

equations(grids, from_node_model, to_node_model, **kwargs)[source]

Defines the system of equations for a multi-grid branch, relating variables across multiple grids and connected nodes.

This abstract method must be implemented by subclasses to specify the physical or operational relationships governing the branch’s behavior in a multi-grid context (e.g., coupling between electrical, gas, and heat networks). Use this method when modeling branches that interact with more than one grid domain. The method is typically called during network simulation or optimization to assemble the overall system equations.

Parameters:
  • grids (dict) – Dictionary of grid objects involved in the branch (e.g., {‘el’: el_grid, ‘gas’: gas_grid}).

  • from_node_model – Model instance representing the source node connected to the branch.

  • to_node_model – Model instance representing the destination node connected to the branch.

  • **kwargs – Additional keyword arguments for solver options or equation customization.

Returns:

The equations or constraints representing the branch’s behavior. The return type and structure depend on the modeling framework and implementation.

Return type:

Any

Raises:

NotImplementedError – If not implemented in a subclass.

Examples

class MyMultiGridBranch(MultiGridBranchModel):
    def equations(self, grids, from_node_model, to_node_model, **kwargs):
        # Define equations coupling electrical and gas flows
        return [eq1, eq2, eq3]
init(grids)[source]

No docstring provided.

is_cp()[source]

No docstring provided.

loss_percent()[source]

No docstring provided.

class monee.model.Grid(name: str)[source]

Bases: object

Represents a resource grid or domain within a multi-energy network model.

The Grid class serves as an abstract base or marker for specific grid types, such as electrical, gas, or heat grids. It provides a common interface for identifying and managing different resource domains in network simulations or optimization frameworks. Use this class as a foundation for implementing grid-specific logic, attributes, or methods.

name

The unique name or identifier for the grid domain (e.g., “el”, “gas”, “heat”).

Type:

str

Example

class ElectricalGrid(Grid):
def __init__(self):

self.name = “el”

grid = ElectricalGrid() print(grid.name) # Output: “el”

name: str
class monee.model.GridFormingGenerator(p_mw_max: float, q_mvar_max: float, vm_pu: float = 1.0, **kwargs)[source]

Bases: NoVarChildModel, GridFormingMixin

Grid-forming generator for islanded electricity networks.

Acts as the slack bus of its island: variable active/reactive power output (absorbs the island’s power imbalance) with a fixed voltage magnitude setpoint.

Unlike PowerGenerator (which has fixed p/q), this component has variable p_mw and q_mvar so that it can balance any generation–load mismatch in its island. The voltage angle is not pinned here; instead, the ElectricityIslandingMode formulation pins the angle to 0 via source_reference_angle from dc.py.

Parameters:
  • p_mw_max (float) – Maximum active power injection (and absorption) in MW.

  • q_mvar_max (float) – Maximum reactive power injection (and absorption) in Mvar.

  • vm_pu (float) – Voltage magnitude setpoint in per-unit. The overwrite() method pins node_model.vm_pu to this constant, making this bus a PV/slack bus.

overwrite(node_model, grid)[source]

Pin the bus voltage magnitude (like ExtPowerGrid.overwrite).

Return type:

None

class monee.model.GridFormingMixin[source]

Bases: object

Marker mixin: this child component can serve as the reference node (slack bus / pressure reference) for an islanded sub-network.

Any child class that carries this mixin must implement overwrite() to pin the carrier-specific reference variable (voltage angle, pressure, …) on the node model it is attached to. When islanding is enabled, find_ignored_nodes treats components that contain a GridFormingMixin child as “leading” and keeps them in the solve.

class monee.model.GridFormingSource(pressure_pu: float = 1.0, t_k: float = 356.0, mass_flow_max: float = 1000000.0)[source]

Bases: ChildModel, GridFormingMixin

Grid-forming source for islanded gas or water networks.

Acts as the pressure reference of its island: the node’s pressure is pinned to pressure_pu via overwrite(), and the source’s mass_flow is a variable so it can absorb any supply–demand imbalance in the island.

Parameters:
  • pressure_pu (float) – Pressure setpoint in per-unit. Pinned on the junction model by overwrite().

  • t_k (float) – Temperature in Kelvin (used to pin t_pu and t_k on the junction).

  • mass_flow_max (float) – Maximum absolute mass flow (kg/s). Set to a large value if unconstrained.

equations(grid, node_model, **kwargs)[source]

No docstring provided.

overwrite(node_model, grid)[source]

Pin the junction pressure (like ExtHydrGrid.overwrite).

Return type:

None

class monee.model.HeatExchanger(q_mw, diameter_m, roughness=0.0001, length_m=2.5, temperature_ext_k=293, regulation=1, friction=None)[source]

Bases: BranchModel

No docstring provided.

equations(grid: monee.model.grid.WaterGrid, from_node_model, to_node_model, **kwargs)[source]

No docstring provided.

class monee.model.HeatExchangerGenerator(q_mw, diameter_m, temperature_ext_k=293)[source]

Bases: HeatExchanger

No docstring provided.

class monee.model.HeatExchangerLoad(q_mw, diameter_m, temperature_ext_k=293)[source]

Bases: HeatExchanger

No docstring provided.

class monee.model.Intermediate(value=0)[source]

Bases: object

A placeholder for a computed (derived) quantity that is not itself a decision variable.

The solver backend evaluates IntermediateEq expressions and writes the result back to the corresponding Intermediate.value after each solve. Use this when you want a model attribute to hold a derived quantity (e.g. a line loading percentage) that can be read from results but is not an independent variable in the optimisation.

Parameters:

value – Initial/default value before the first solve.

class monee.model.IntermediateEq(attr, eq)[source]

Bases: object

Declares how to compute an Intermediate attribute from other variables.

Return an IntermediateEq from a model’s equations() method to register a derived quantity. The solver extracts it from the equation list, evaluates the expression, and stores the result on the model attribute named by attr:

class MyBranch(BranchModel):
    def __init__(self):
        self.loading_percent = Intermediate()

    def equations(self, grid, from_node, to_node, **kwargs):
        return [
            ...,  # regular constraints
            IntermediateEq("loading_percent", self.i_from_ka / self.max_i_ka * 100),
        ]
Parameters:
  • attr – Name of the Intermediate attribute on the model.

  • eq – The expression (solver-native or Python numeric) to evaluate.

class monee.model.IslandingMode[source]

Bases: NetworkConstraint, ABC

Per-carrier islanding configuration.

Subclasses must set the class attributes carrier_grid_type and var_prefix, and may override add_physical_constraints to add carrier-specific constraints (e.g. angle pinning for DC electricity, pressure bounds for gas/water).

Implements NetworkConstraint: - prepare(network) → Phase 1: adds Var placeholders. - equations(network, ignored) → Phase 2: returns constraint list.

add_physical_constraints(*_)[source]

Carrier-specific physical constraints (returned as a plain list).

Override in subclasses to add e.g. angle pinning for electricity or pressure bounds for gas/water. The default returns an empty list.

Return type:

list

carrier_grid_type: type
equations(network: monee.model.network.Network, ignored_nodes: set)[source]

Phase 2 — return all islanding constraint equations as a plain list.

Combines connectivity-flow constraints with carrier-specific physical constraints from add_physical_constraints.

Return type:

list

is_grid_forming(child)[source]

Return True if child anchors an island for this carrier.

Return type:

bool

abstractmethod prepare(network: monee.model.network.Network)[source]

Phase 1 — add Var placeholders to node and branch models before solver variable injection.

The normal inject_gekko_vars / inject_pyomo_vars loops pick up these Var objects automatically. Each subclass sets its attributes directly, e.g. node.model.e_el = Var(...).

Return type:

None

var_prefix: str
class monee.model.Junction[source]

Bases: NodeModel

No docstring provided.

calc_signed_heat_flow(from_branch_models, to_branch_models, connected_node_models, grid)[source]

No docstring provided.

calc_signed_mass_flow(from_branch_models, to_branch_models, connected_node_models)[source]

No docstring provided.

equations(grid, from_branch_models, to_branch_models, connected_node_models, **kwargs)[source]

No docstring provided.

class monee.model.MultiGridBranchModel(**kwargs)[source]

Bases: BranchModel

Abstract base class for branch models that couple multiple grid domains, such as electrical, gas, and heat networks.

This class extends BranchModel to support branches that interact with more than one grid type, enabling the modeling of multi-energy systems and sector coupling. Subclasses must implement the abstract equations method to define the physical or operational relationships across the involved grids. The is_cp method returns True by default, indicating that multi-grid branches are treated as control points in the network. The init method can be overridden to perform any setup or pre-processing required for multi-grid branches.

equations(grids, from_node_model, to_node_model, ``**kwargs``)[source]

Abstract. Must be implemented by subclasses to define the system of equations for the multi-grid branch.

is_cp()[source]

Returns True, indicating this branch is a control point by default.

init(grids)[source]

Optional initialization logic for the branch (default is no-op).

Example:

class MyMultiGridBranch(MultiGridBranchModel):
    def equations(self, grids, from_node_model, to_node_model, **kwargs):
        # Define equations coupling electrical and gas flows
        return [eq1, eq2, eq3]

    def init(self, grids):
        self.el_grid = grids['el']
        self.gas_grid = grids['gas']
abstractmethod equations(grids, from_node_model, to_node_model, **kwargs)[source]

Defines the system of equations for a multi-grid branch, relating variables across multiple grids and connected nodes.

This abstract method must be implemented by subclasses to specify the physical or operational relationships governing the branch’s behavior in a multi-grid context (e.g., coupling between electrical, gas, and heat networks). Use this method when modeling branches that interact with more than one grid domain. The method is typically called during network simulation or optimization to assemble the overall system equations.

Parameters:
  • grids (dict) – Dictionary of grid objects involved in the branch (e.g., {‘el’: el_grid, ‘gas’: gas_grid}).

  • from_node_model – Model instance representing the source node connected to the branch.

  • to_node_model – Model instance representing the destination node connected to the branch.

  • **kwargs – Additional keyword arguments for solver options or equation customization.

Returns:

The equations or constraints representing the branch’s behavior. The return type and structure depend on the modeling framework and implementation.

Return type:

Any

Raises:

NotImplementedError – If not implemented in a subclass.

Examples

class MyMultiGridBranch(MultiGridBranchModel):
    def equations(self, grids, from_node_model, to_node_model, **kwargs):
        # Define equations coupling electrical and gas flows
        return [eq1, eq2, eq3]
init(grids)[source]

Initializes the multi-grid branch model with the provided grid objects.

This method is intended to perform any setup or pre-processing required before the branch is used in simulation or optimization, such as caching grid parameters or establishing references to grid-specific data. Override this method in subclasses to implement custom initialization logic for multi-grid branches. It is typically called once during network assembly or before equation evaluation.

Parameters:

grids (dict) – Dictionary of grid objects relevant to the branch (e.g., {‘el’: el_grid, ‘gas’: gas_grid}).

Returns:

None

Examples

class MyMultiGridBranch(MultiGridBranchModel):
def init(self, grids):

self.el_grid = grids[‘el’] self.gas_grid = grids[‘gas’]

is_cp()[source]

Indicates that the multi-grid branch model is a control point (CP) in the network.

This method returns True to signal that this branch should be treated as a control point, which may affect optimization, control strategies, or system observability in multi-grid network simulations. Override this method in subclasses if a different control point designation is required.

Returns:

Always returns True, indicating the branch is a control point.

Return type:

bool

Examples

if branch_model.is_cp():

# Apply control logic specific to control points …

class monee.model.MultiGridCompoundModel(**kwargs)[source]

Bases: CompoundModel

No docstring provided.

is_cp()[source]

No docstring provided.

class monee.model.Network(active_grid=None, el_model=None, water_model=None, gas_model=None)[source]

Bases: object

No docstring provided.

activate(component)[source]

No docstring provided.

activate_by_id(cls, id)[source]

No docstring provided.

activate_grid(grid)[source]

No docstring provided.

add_extension(ext: monee.model.formulation.core.NetworkConstraint)[source]

Register a NetworkConstraint extension on this network.

Return type:

None

all_components()[source]

No docstring provided.

all_models()[source]

No docstring provided.

all_models_with_grid()[source]

No docstring provided.

apply_formulation(network_formulation: monee.model.formulation.core.NetworkFormulation)[source]
as_dataframe_dict()[source]

No docstring provided.

as_dataframe_dict_str()[source]

No docstring provided.

as_result_dataframe_dict()[source]

No docstring provided.

branch(model, from_node_id, to_node_id, formulation=None, constraints=None, grid=None, name=None, auto_node_creator=None, auto_grid_key=None, **kwargs)[source]

No docstring provided.

branch_by_id(branch_id)[source]

No docstring provided.

property branches: list[Branch]

No docstring provided.

branches_by_ids(branch_ids)[source]

No docstring provided.

Return type:

list[monee.model.core.Branch]

branches_by_type(cls)[source]

No docstring provided.

branches_connected_to(node_id)[source]

No docstring provided.

Return type:

list[monee.model.core.Branch]

child(model, attach_to_node_id=None, formulation=None, constraints=None, overwrite_id=None, name=None, auto_node_creator=None, auto_grid_key=None)[source]

No docstring provided.

child_by_id(child_id)[source]

No docstring provided.

child_to(model, node_id, formulation=None, constraints=None, overwrite_id=None, name=None, auto_node_creator=None, auto_grid_key=None)[source]

No docstring provided.

property childs: list[Child]

No docstring provided.

childs_by_ids(child_ids)[source]

No docstring provided.

Return type:

list[monee.model.core.Child]

childs_by_type(cls)[source]

No docstring provided.

clear_childs()[source]

No docstring provided.

components_connected_to(node_id)[source]

No docstring provided.

Return type:

list[monee.model.core.Component]

compound(model: monee.model.core.CompoundModel, formulation=None, constraints=None, overwrite_id=None, **connected_node_ids)[source]

No docstring provided.

compound_by_id(compound_id)[source]

No docstring provided.

compound_of(subcomponent_component_id)[source]

No docstring provided.

Return type:

list[monee.model.core.Component]

compound_of_node(node_id)[source]

No docstring provided.

property compounds: list[Compound]

No docstring provided.

compounds_by_type(cls)[source]

No docstring provided.

compounds_connected_to(node_id)[source]

No docstring provided.

Return type:

list[monee.model.core.Component]

constraint(constraint_equation)[source]

No docstring provided.

property constraints

No docstring provided.

copy()[source]

No docstring provided.

property cps: list[GenericModel]

No docstring provided.

deactivate(component)[source]

No docstring provided.

deactivate_by_id(cls, id)[source]

No docstring provided.

property extensions: list[NetworkConstraint]

Solver-agnostic network-level constraint extensions.

first_node()[source]

No docstring provided.

get_branch_between(node_id_one, node_id_two)[source]

No docstring provided.

get_childs_by_type(branch, cls)[source]

No docstring provided.

Return type:

list[monee.model.core.Child]

property graph

No docstring provided.

property grids

No docstring provided.

has_any_child_of_type(branch, cls)[source]

No docstring provided.

Return type:

bool

has_branch(branch_id)[source]

No docstring provided.

has_branch_between(node_id_one, node_id_two)[source]

No docstring provided.

has_child(child_id)[source]

No docstring provided.

has_node(node_id)[source]

No docstring provided.

is_blacklisted(obj)[source]

No docstring provided.

move_branch(branch_id, new_from_id, new_to_id)[source]

No docstring provided.

node(model, grid=None, formulation=None, child_ids=None, constraints=None, overwrite_id=None, name=None, position=None)[source]
node_by_id(node_id)[source]

No docstring provided.

Return type:

monee.model.core.Node

node_by_id_or_create(node_id, auto_node_creator, auto_grid_key)[source]

No docstring provided.

property nodes: list[Node]

No docstring provided.

nodes_by_type(cls)[source]

No docstring provided.

objective(objective_function)[source]

No docstring provided.

property objectives

No docstring provided.

remove_branch(branch_id)[source]

No docstring provided.

remove_branch_between(node_one, node_two, key=0)[source]

No docstring provided.

remove_child(child_id)[source]

No docstring provided.

remove_compound(compound_id)[source]

No docstring provided.

remove_node(node_id)[source]

No docstring provided.

set_default_grid(key, grid)[source]

No docstring provided.

statistics()[source]

No docstring provided.

class monee.model.NetworkIslandingConfig(electricity: monee.model.islanding.core.IslandingMode | None = None, gas: monee.model.islanding.core.IslandingMode | None = None, water: monee.model.islanding.core.IslandingMode | None = None)[source]

Bases: NetworkConstraint

Container bundling per-carrier IslandingMode instances.

Register on a network via network.add_extension(config), or use the top-level enable_islanding() helper which also sets network.islanding_config for find_ignored_nodes compatibility.

equations(network: monee.model.network.Network, ignored_nodes: set)[source]

Phase 2: return equations for all active carrier modes.

Return type:

list

modes()[source]

Return the list of active (non-None) carrier modes.

Return type:

list[monee.model.islanding.core.IslandingMode]

prepare(network: monee.model.network.Network)[source]

Phase 1: add Var placeholders for all active carrier modes.

Return type:

None

class monee.model.Node(node_id, model, child_ids=None, formulation=None, constraints=None, grid=None, name=None, position=None, active=True, independent=True)[source]

Bases: Component

Represents a node in the network, managing connectivity, child components, and node-specific attributes.

The Node class extends Component to provide functionality for managing network nodes, including tracking incoming and outgoing branches, associated child components, and node-specific constraints or metadata. Nodes serve as connection points for branches and can represent buses, junctions, or other network entities. Use this class when constructing or modifying network topologies, performing connectivity analysis, or managing nodal attributes in simulation workflows.

Example

node = Node(node_id=1, model=my_node_model, position=(10, 20)) node.add_from_branch_id((2, 1, 0)) node.add_to_branch_id((1, 3, 0)) node.remove_branch((2, 1, 0))

Parameters:
  • node_id – Unique identifier for the node.

  • model – The node’s associated model object.

  • child_ids (list, optional) – List of child component IDs attached to the node.

  • constraints (list, optional) – List of operational constraints for the node.

  • grid (optional) – The grid or domain to which the node belongs.

  • name (str, optional) – Human-readable name for the node.

  • position (optional) – Geographical or logical position of the node.

  • active (bool, optional) – Whether the node is active in the network. Defaults to True.

  • independent (bool, optional) – Whether the node is independent in the network. Defaults to True.

child_ids

IDs of child components attached to the node.

Type:

list

constraints

Operational constraints for the node.

Type:

list

from_branch_ids

Identifiers of incoming branches.

Type:

list

to_branch_ids

Identifiers of outgoing branches.

Type:

list

position

Geographical or logical position of the node.

add_from_branch_id(branch_id)[source]

Registers a branch as incoming to the node.

add_to_branch_id(branch_id)[source]

Registers a branch as outgoing from the node.

_remove_branch(branch_id)[source]

Removes a branch from incoming or outgoing lists.

remove_branch(branch_id)[source]

Removes both a branch and its reversed counterpart from the node’s branch lists.

add_from_branch_id(branch_id)[source]

Adds a branch identifier to the list of incoming branches for the node.

Use this method to register a new incoming branch connection to the node, typically during network construction or when dynamically modifying the network topology. This ensures that the node maintains an accurate record of all branches entering it, which is essential for connectivity management and nodal analysis.

Parameters:

branch_id – The identifier of the branch to add as an incoming connection. Must be a hashable object representing the branch.

Returns:

None

Examples

node.add_from_branch_id((1, 2, 0)) # Registers branch (1, 2, 0) as incoming to the node.

add_to_branch_id(branch_id)[source]

Adds a branch identifier to the list of outgoing branches for the node.

This method is used to register a new outgoing branch connection from the node, typically during network construction or when updating the network topology. Maintaining an accurate list of outgoing branches is essential for connectivity management, nodal analysis, and network traversal algorithms.

Parameters:

branch_id – The identifier of the branch to add as an outgoing connection. Should be a hashable object representing the branch.

Returns:

None

Examples

node.add_to_branch_id((2, 3, 1)) # Registers branch (2, 3, 1) as outgoing from the node.

equations(grid, in_branch_models, out_branch_models, childs, **kwargs)[source]
minimize(grid, in_branch_models, out_branch_models, childs, **kwargs)[source]
remove_branch(branch_id)[source]

Removes a branch identifier and its reversed counterpart from the node’s branch lists.

This method updates the node’s connectivity by removing both the specified branch ID and its reversed form (with the from/to nodes swapped) from the incoming and outgoing branch lists. Use this method when deleting a branch or reconfiguring the network to ensure all references to the branch are cleared, regardless of direction. It is typically called during network modification or cleanup operations.

Parameters:

branch_id – The identifier of the branch to remove, as a tuple (from_node, to_node, branch_index).

Returns:

None

Examples

node.remove_branch((1, 2, 0)) # Removes both (1, 2, 0) and (2, 1, 0) from the node’s branch lists if present.

class monee.model.NodeModel(**kwargs)[source]

Bases: GenericModel

Abstract base class for node models in a network, defining the interface for nodal equations and behavior.

NodeModel provides a foundation for representing nodes within various grid domains (e.g., electrical, gas, heat) in network simulations. Subclasses must implement the abstract equations method to specify the physical or operational relationships at the node, such as flow conservation, voltage balance, or other nodal constraints. This class is intended for use in extensible, multi-domain network modeling frameworks and supports integration with branch and child component models.

Example:

class MyNodeModel(NodeModel):
    def equations(self, grid, in_branch_models, out_branch_models, childs, **kwargs):
        # Implement nodal balance equations
        return [eq1, eq2]
equations(grid, in_branch_models, out_branch_models, childs, ``**kwargs``)[source]

Abstract. Must be implemented by subclasses to define the system of equations for the node.

abstractmethod equations(grid, in_branch_models, out_branch_models, childs, **kwargs)[source]

Defines the system of equations for a node in the network, relating incoming and outgoing branches and attached child components.

This abstract method must be implemented by subclasses to specify the physical or operational relationships governing the node’s behavior within a grid. Use this method to model node constraints such as flow conservation, voltage balance, or other nodal conditions. It is typically called during network simulation or optimization to assemble the overall system equations.

Parameters:
  • grid – The grid object to which the node belongs (e.g., electrical, gas, or heat grid).

  • in_branch_models (list) – List of branch model instances representing incoming branches to the node.

  • out_branch_models (list) – List of branch model instances representing outgoing branches from the node.

  • childs (list) – List of child component models attached to the node (e.g., loads, generators).

  • **kwargs – Additional keyword arguments for solver options or equation customization.

Returns:

The equations or constraints representing the node’s behavior. The return type and structure depend on the modeling framework and implementation.

Return type:

Any

Raises:

NotImplementedError – If not implemented in a subclass.

Examples

class MyNodeModel(NodeModel):
    def equations(self, grid, in_branch_models, out_branch_models, childs, **kwargs):
        # Define nodal balance equations
        return [eq1, eq2]
minimize(grid, in_branch_models, out_branch_models, childs, **kwargs)[source]

Minimization of an expression as minimization may necessary due to some formulation (when replacing constraints with slack variables)

Parameters:

self – Description

class monee.model.PowerBranch(tap, shift, backup=False, on_off=1, **kwargs)[source]

Bases: GenericPowerBranch, ABC

No docstring provided.

_summary_

Parameters:
  • tap (_type_) – _description_

  • shift (_type_) – _description_

  • br_r (_type_) – resistence

  • br_x (_type_) – reactance

  • g_fr (_type_) – from conductance

  • b_fr (_type_) – from susceptance

  • g_to (_type_) – to conductance

  • b_to (_type_) – to susceptance

abstractmethod calc_r_x(grid, from_node_model, to_node_model)[source]

No docstring provided.

equations(grid: monee.model.grid.PowerGrid, from_node_model, to_node_model, **kwargs)[source]

No docstring provided.

class monee.model.PowerGenerator(p_mw, q_mvar, **kwargs)[source]

Bases: NoVarChildModel

Fixed-setpoint active/reactive power generator.

Follows the load convention: internally stores negative values so that the node balance sees this component as an injection. The constructor accepts positive magnitudes and negates them:

PowerGenerator(p_mw=5, q_mvar=0)  →  p_mw=-5, q_mvar=0
Parameters:
  • p_mw (float) – Active power output in MW (positive = generation).

  • q_mvar (float) – Reactive power output in Mvar (positive = generation).

class monee.model.PowerGrid(name: str, sn_mva: float = 1)[source]

Bases: Grid

Represents an electrical power grid domain within a multi-energy network model.

PowerGrid extends the base Grid class to encapsulate properties specific to electrical networks, such as the system base power (sn_mva). Use this class to model electrical infrastructure, perform power flow calculations, or integrate electrical dynamics into multi-domain simulations. It is typically instantiated as part of a larger network model where electrical transmission, distribution, or sector coupling is required.

sn_mva

System base power in megavolt-amperes (MVA). Used for per-unit normalization and power system calculations. Defaults to 1.

Type:

float

Example

power_grid = PowerGrid(name=”el”, sn_mva=100) print(power_grid.name) # Output: “el” print(power_grid.sn_mva) # Output: 100

sn_mva: float = 1
class monee.model.PowerLine(length_m, r_ohm_per_m, x_ohm_per_m, parallel, backup=False, on_off=1, **kwargs)[source]

Bases: PowerBranch

No docstring provided.

_summary_

Parameters:
  • tap (_type_) – _description_

  • shift (_type_) – _description_

  • br_r (_type_) – resistence

  • br_x (_type_) – reactance

  • g_fr (_type_) – from conductance

  • b_fr (_type_) – from susceptance

  • g_to (_type_) – to conductance

  • b_to (_type_) – to susceptance

calc_r_x(grid: monee.model.grid.PowerGrid, from_node_model, to_node_model)[source]

No docstring provided.

class monee.model.PowerLoad(p_mw, q_mvar, **kwargs)[source]

Bases: NoVarChildModel

Fixed-setpoint active/reactive power load.

Follows the load convention: positive values represent consumption. Unlike PowerGenerator, the constructor does not negate the supplied values:

PowerLoad(p_mw=5, q_mvar=1)  →  p_mw=+5, q_mvar=+1
Parameters:
  • p_mw (float) – Active power demand in MW (positive = consumption).

  • q_mvar (float) – Reactive power demand in Mvar (positive = consumption).

class monee.model.PowerToGas(efficiency, mass_flow_setpoint, consume_q_mvar_setpoint=0, regulation=1)[source]

Bases: MultiGridBranchModel

No docstring provided.

equations(grids, from_node_model, to_node_model, **kwargs)[source]

No docstring provided.

loss_percent()[source]

No docstring provided.

class monee.model.PowerToHeat(heat_energy_w, diameter_m, temperature_ext_k, efficiency, q_mvar_setpoint=0)[source]

Bases: MultiGridCompoundModel

No docstring provided.

create(network: monee.model.network.Network, power_node: monee.model.core.Node, heat_node: monee.model.core.Node, heat_return_node: monee.model.core.Node)[source]

No docstring provided.

set_active(activation_flag)[source]

No docstring provided.

class monee.model.PowerToHeatControlNode(load_p_mw, load_q_mvar, heat_energy_w, efficiency, **kwargs)[source]

Bases: MultiGridNodeModel, Junction, Bus

No docstring provided.

equations(grid, from_branch_models, to_branch_models, childs, **kwargs)[source]

No docstring provided.

class monee.model.Sink(mass_flow, **kwargs)[source]

Bases: NoVarChildModel

Fixed-setpoint mass-flow sink (withdrawal) for gas or water networks.

Follows the load convention: positive values represent consumption. Unlike Source, the constructor does not negate the supplied value:

Sink(mass_flow=2.0)  →  self.mass_flow = +2.0
Parameters:

mass_flow (float) – Mass flow rate in kg/s to withdraw (positive = consumption).

class monee.model.Source(mass_flow, **kwargs)[source]

Bases: NoVarChildModel

Fixed-setpoint mass-flow source (injection) for gas or water networks.

Follows the load convention: internally stores a negative mass-flow so that the junction balance treats this component as an injection. The constructor accepts positive magnitudes and negates them:

Source(mass_flow=2.0)  →  self.mass_flow = -2.0
Parameters:

mass_flow (float) – Mass flow rate in kg/s to inject (positive = injection).

class monee.model.Trafo(vk_percent=12.2, vkr_percent=0.25, sn_trafo_mva=160, shift=0)[source]

Bases: PowerBranch

No docstring provided.

_summary_

Parameters:
  • tap (_type_) – _description_

  • shift (_type_) – _description_

  • br_r (_type_) – resistence

  • br_x (_type_) – reactance

  • g_fr (_type_) – from conductance

  • b_fr (_type_) – from susceptance

  • g_to (_type_) – to conductance

  • b_to (_type_) – to susceptance

calc_r_x(grid: monee.model.grid.PowerGrid, lv_model, hv_model)[source]

No docstring provided.

equations(grid: monee.model.grid.PowerGrid, from_node_model, to_node_model, **kwargs)[source]

No docstring provided.

class monee.model.Var(value, max=None, min=None, integer=False, name=None)[source]

Bases: object

A decision variable (or mutable parameter) in the energy-flow / optimisation model.

During a solve the solver backend replaces Var instances with its own internal variable objects via the injection/withdrawal protocol. After the solve, the result is written back to Var.value so callers can read it with value().

Sign convention for child components — positive values represent consumption (load), negative values represent generation (injection). Child model constructors such as PowerGenerator and Source negate their constructor argument so that user-facing API always receives positive magnitudes:

PowerGenerator(p_mw=5)   →  internally stores p_mw = -5  (generation)
PowerLoad(p_mw=5)        →  internally stores p_mw = +5  (consumption)

Comparison operators (<, <=, >, >=) compare against the bound of the variable, not the current value. They return False when the relevant bound is None (i.e. the variable is unbounded in that direction). This is useful for bound-checking in formulation code:

v = Var(10, max=100)
v < 200   # True  — upper bound 100 < 200
v > 0     # False — lower bound is None (not 10)
Parameters:
  • value – Initial/default value. Serves as the solver’s starting point.

  • max – Upper bound. None means unbounded above.

  • min – Lower bound. None means unbounded below.

  • integer – If True, the variable is constrained to integer values (requires a MINLP-capable solver backend).

  • name – Optional symbolic name forwarded to the solver for diagnostics.

class monee.model.WaterGrid(name: str, fluid_density: float = 998, dynamic_visc: float = 0.000596, t_ref: float = 356, pressure_ref: float = 1000000, f_max: float = 200)[source]

Bases: Grid

Represents a water grid domain within a multi-energy network model, encapsulating key physical properties for hydraulic simulations.

WaterGrid extends the base Grid class to provide attributes specific to water networks, such as fluid density, dynamic viscosity, reference temperature, and reference pressure. Use this class to model water infrastructure, perform hydraulic calculations, or integrate water system dynamics into multi-domain simulations. It is typically instantiated as part of a larger network model where water transport, distribution, or sector coupling is required.

fluid_density

Density of water in kg/m³. Defaults to 998.

Type:

float

dynamic_visc

Dynamic viscosity of water in Pa·s. Defaults to 0.000596.

Type:

float

t_ref

Reference temperature in Kelvin. Defaults to 356.

Type:

float

pressure_ref

Reference pressure in Pascals. Defaults to 1,000,000.

Type:

float

Example

water_grid = WaterGrid() print(water_grid.fluid_density) # Output: 998 print(water_grid.dynamic_visc) # Output: 0.000596

dynamic_visc: float = 0.000596
f_max: float = 200
fluid_density: float = 998
pressure_ref: float = 1000000
t_ref: float = 356
class monee.model.WaterIslandingMode(big_m_conn: int = 200)[source]

Bases: IslandingMode

Islanding configuration for the water/heat carrier.

Structurally identical to GasIslandingMode; pressure bounds are applied to de-energised junctions so that pressure_pu = 0 when e_i = 0.

Use GridFormingSource (from monee.model.islanding.gas) as the grid-forming child for water junctions.

Parameters:

big_m_conn (int) – Big-M for connectivity-flow arc capacity. Must be ≥ number of carrier nodes.

add_physical_constraints(network, gf_nodes, regular_nodes, e_vars)[source]

Force pressure_pu = 0 for de-energised water junctions (returned as list).

Return type:

list

carrier_grid_type

alias of WaterGrid

prepare(network: monee.model.network.Network)[source]

Phase 1 — add water islanding Var placeholders.

Return type:

None

var_prefix: str = 'water'
class monee.model.WaterPipe(diameter_m, length_m, temperature_ext_k=283.15, roughness=4.5e-05, lambda_insulation_w_per_k=0.025, insulation_thickness_m=0.12, on_off=1, friction=None)[source]

Bases: BranchModel

No docstring provided.

equations(grid: monee.model.grid.WaterGrid, from_node_model, to_node_model, **kwargs)[source]

No docstring provided.

loss_percent()[source]

No docstring provided.

monee.model.calc_coordinates(network: monee.model.network.Network, component: monee.model.core.Component)[source]

No docstring provided.

monee.model.create_gas_grid(name, type='lgas')[source]

Creates and returns a GasGrid instance with predefined attributes for a specified gas grid type.

This function streamlines the instantiation of a GasGrid by automatically applying a set of standard physical and thermodynamic properties based on the selected grid type (e.g., ‘lgas’). Use this function when you need to quickly set up a gas grid domain for simulation, analysis, or integration into a multi-energy network model. The function retrieves the appropriate attribute set from GAS_GRID_ATTRS and passes them to the GasGrid constructor.

Parameters:
  • name (str) – The unique name or identifier for the gas grid.

  • type (str, optional) – The type of gas grid to create (e.g., ‘lgas’). Must be a key in GAS_GRID_ATTRS. Defaults to ‘lgas’.

Returns:

An instance of GasGrid initialized with the specified name and standard attributes for the chosen type.

Return type:

GasGrid

Raises:

KeyError – If the specified type is not found in GAS_GRID_ATTRS.

Examples

# Create a default low-pressure gas grid gas_grid = create_gas_grid(‘city_gas’)

# Create a high-pressure gas grid if defined in GAS_GRID_ATTRS gas_grid = create_gas_grid(‘transmission_gas’, type=’hgas’)

monee.model.create_power_grid(name, sn_mva=1)[source]

Creates and returns a PowerGrid instance with the specified name and system base power.

Use this function to instantiate an electrical power grid domain for use in network modeling, simulation, or optimization. The function allows you to specify the grid’s unique name and the system base power (sn_mva), which is essential for per-unit calculations and power system analysis.

Parameters:
  • name (str) – The unique name or identifier for the power grid.

  • sn_mva (float, optional) – System base power in megavolt-amperes (MVA). Defaults to 1.

Returns:

An instance of PowerGrid initialized with the given name and base power.

Return type:

PowerGrid

Examples

# Create a default power grid with 1 MVA base grid = create_power_grid(‘el’)

# Create a power grid with a custom base power grid = create_power_grid(‘transmission’, sn_mva=100)

monee.model.create_water_grid(name)[source]

Creates and returns a WaterGrid instance with the specified name.

Use this function to instantiate a water grid domain for use in network modeling, hydraulic simulation, or multi-domain energy system analysis. The function initializes a WaterGrid object with default physical properties and assigns the provided name for identification within the network.

Parameters:

name (str) – The unique name or identifier for the water grid.

Returns:

An instance of WaterGrid initialized with the given name and default attributes.

Return type:

WaterGrid

Examples

# Create a water grid named “district_water” grid = create_water_grid(‘district_water’)

monee.model.lower(var_or_const)[source]

Returns the lower bound (minimum value) of a variable or constant.

This function is used to extract the minimum allowed value from a Var instance, which may represent a decision variable or parameter in an optimization or simulation context. If the input is a Var and its min attribute is set, that value is returned; otherwise, the current value is returned. For non-Var inputs, the input is returned unchanged. Use this function when you need to retrieve the lower bound for constraints, reporting, or validation.

Parameters:

var_or_const – A Var instance or a constant value. If a Var, must have a min attribute.

Returns:

The minimum value for a Var, or the input value for constants.

Return type:

float or Any

Examples

v = Var(5, min=2) lower(v) # Returns 2 lower(10) # Returns 10 v2 = Var(7) lower(v2) # Returns 7 (since min is None)

monee.model.model(cls)[source]

Class decorator that registers a model class in the global component registry.

Applying @model to a NodeModel, BranchModel, ChildModel, or CompoundModel subclass adds the class to component_list, which is used by introspection utilities (e.g. serialisation helpers) to enumerate all known component types at runtime.

Usage:

@model
class MyLoad(ChildModel):
    def equations(self, grid, node_model, **kwargs):
        return [self.p_mw == node_model.p_mw]
monee.model.to_spanning_tree(network: monee.model.network.Network)[source]

No docstring provided.

class monee.model.tracked(value, max=None, min=None, integer=False, name=None)[source]

Bases: Var

A Var whose solved value is automatically carried to the next timestep in a timeseries simulation.

Use this as a drop-in replacement for Var on any attribute that should participate in inter-step state tracking. The framework detects tracked instances during variable injection, records the attribute name on the model, and extracts the solved float value after each step — no inter_step_vars() method required.

Example:

class RampGenerator(PowerGenerator):
    def __init__(self, p_mw, ramp_up, ramp_down, **kwargs):
        super().__init__(p_mw, **kwargs)
        self.p_mw = tracked(p_mw, min=0, max=500)
        self.ramp_up = ramp_up
        self.ramp_down = ramp_down

    def inter_step_equations(self, prev_state, component_id, **kwargs):
        prev_p = prev_state.get(component_id, 'p_mw')
        if prev_p is None:
            return []
        return [
            self.p_mw - prev_p <= self.ramp_up,
            prev_p - self.p_mw <= self.ramp_down,
        ]
monee.model.transform_network(network: monee.model.network.Network, graph_transform)[source]

No docstring provided.

monee.model.upper(var_or_const)[source]

Returns the upper bound (maximum value) of a variable or constant.

This function extracts the maximum allowed value from a Var instance, which may represent a decision variable or parameter in an optimization or simulation context. If the input is a Var and its max attribute is set, that value is returned; otherwise, the current value is returned. For non-Var inputs, the input is returned unchanged. Use this function to retrieve the upper bound for constraints, reporting, or validation.

Parameters:

var_or_const – A Var instance or a constant value. If a Var, must have a max attribute.

Returns:

The maximum value for a Var, or the input value for constants.

Return type:

float or Any

Examples

v = Var(5, max=10) upper(v) # Returns 10 upper(7) # Returns 7 v2 = Var(3) upper(v2) # Returns 3 (since max is None)

monee.model.value(var_or_const)[source]

Extract the scalar value from a Var, Const, or Intermediate.

Plain Python numbers and other non-model types are returned unchanged. This is the canonical way to read back a result after a solve, because the solver replaces Var instances with its own objects during injection and restores them (with updated .value) during withdrawal.

Parameters:

var_or_const – A Var, Const, Intermediate, or plain scalar.

Returns:

The .value attribute for model types, or var_or_const unchanged.

Examples:

v = Var(42.0)
value(v)       # 42.0
value(3.14)    # 3.14