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: MultGridCompoundModel

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: int = 1, **kwargs)[source]

Bases: GenericModel

No docstring provided.

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)[source]

No docstring provided.

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 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

No docstring provided.

abstractmethod create(network)[source]

No docstring provided.

equations(network, **kwargs)[source]

No docstring provided.

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

No docstring provided.

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

Bases: NoVarChildModel

No docstring provided.

overwrite(node_model)[source]

No docstring provided.

class monee.model.ExtHydrGrid(mass_flow=1, pressure_pa=1000000, t_k=359, **kwargs)[source]

Bases: NoVarChildModel

No docstring provided.

overwrite(node_model)[source]

No docstring provided.

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

Bases: NoVarChildModel

No docstring provided.

overwrite(node_model)[source]

No docstring provided.

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)[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
gas_temperature: float
higher_heating_value: float
molar_mass: float
pressure_ref: float
t_k: float
t_ref: float
universal_gas_constant: float
class monee.model.GasPipe(diameter_m, length_m, temperature_ext_k=296.15, roughness=0.0001, on_off=1)[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: MultGridCompoundModel

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

No docstring provided.

is_cp()[source]

No docstring provided.

property values

No docstring provided.

property vars

No docstring provided.

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 generic transfer branch, enforcing variable consistency across connected nodes and grids.

This method generates the physical and operational constraints for a transfer branch that may span multiple grid domains, such as water or gas networks. For water grids, it enforces temperature and pressure continuity between the branch and its connected nodes. The method is typically called during network simulation or optimization to ensure correct variable propagation and coupling between nodes.

Parameters:
  • grids – The grid object or a dictionary of grid objects relevant to the branch (e.g., WaterGrid, GasGrid).

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

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

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

Returns:

A list of equations enforcing variable consistency (e.g., temperature and pressure) across the branch and its nodes. The list may be empty if no relevant grid is present.

Return type:

list

Examples

# Called automatically during network simulation: eqs = transfer_branch.equations(grids, from_node, to_node) # eqs will contain temperature and pressure continuity constraints for water grids.

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.HeatExchanger(q_mw, diameter_m, roughness=0.0001, length_m=2.5, temperature_ext_k=293, regulation=1)[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

No docstring provided.

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

Bases: object

No docstring provided.

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.Network(active_grid=None, el_model=PowerGrid(name='power', sn_mva=1), water_model=WaterGrid(name='water', fluid_density=998, dynamic_visc=0.000596, t_ref=356, pressure_ref=1000000), gas_model=GasGrid(name='gas', compressibility=1, molar_mass=0.0165, gas_temperature=300, dynamic_visc=1.2190162697374919e-05, higher_heating_value=15.3, universal_gas_constant=8.314, t_k=300, t_ref=356, pressure_ref=1000000))[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.

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.

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]

No docstring provided.

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.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

No docstring provided.

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

No docstring provided.

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_mw, diameter_m, temperature_ext_k, efficiency, q_mvar_setpoint=0)[source]

Bases: MultGridCompoundModel

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_mw, 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

No docstring provided.

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

Bases: NoVarChildModel

No docstring provided.

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

No docstring provided.

class monee.model.WaterGrid(name: str, fluid_density: float = 998, dynamic_visc: float = 0.000596, t_ref: float = 356, pressure_ref: float = 1000000)[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
fluid_density: float = 998
pressure_ref: float = 1000000
t_ref: float = 356
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)[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]

No docstring provided.

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

No docstring provided.

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]

No docstring provided.