monee.model.extension¶
All public names are re-exported at top level (monee.*) and from
monee.model; the sections below document each submodule under its
canonical path.
Base¶
- class monee.model.extension.core.NetworkAspect[source]¶
Bases:
objectSolver-agnostic network-level extension.
Analogous to
BranchFormulation/NodeFormulationbut spanning the entire network. Register withnetwork.add_extension(aspect).Phase 1 -
prepare(network): called before variable injection; addVarplaceholders to model objects so the injection loop picks them up.Phase 2 -
equations(network, ignored_nodes) → list: called after variable injection; return relational expressions (==,<=,>=) built from injected model attributes. The solver registers them withm.Equations(eqs)/pm.cons.addwithout inspecting their content - exactly like branch/node equations.- activate_timeseries(network, ignored_nodes: set, step_state=None)[source]¶
Called after
prepare()and variable injection, before node equations are assembled, when a timeseries or multi-period solve begins.Override to set flags on model objects that modify equation assembly for coupled solves - for example, suppressing a degenerate algebraic equation whose role is taken over by an inter-step constraint.
step_state is provided so extensions can warm-start solver variable initializations from the previous step’s solved values. No-op by default.
- Return type:
- equations(network, ignored_nodes: set)[source]¶
Return solver-agnostic relational expressions (empty by default).
- Return type:
- inter_period_equations(network, ignored_nodes: set, period_state)[source]¶
Return expressions coupling current variables to other period values (multi-period only). Empty by default.
- Return type:
- inter_step_equations(network, ignored_nodes: set, step_state)[source]¶
Return expressions coupling current variables to previous-step values (timeseries only). Empty by default.
- Return type:
Gas linepack¶
Gas linepack extension.
Pipelines act as distributed storage: \(\text{linepack\_kg} = V_{pipe} \cdot \rho_{avg}\) with \(\rho = p \cdot M / (R \cdot T)\). Between timesteps, \(\text{net\_pack\_kgs}(t) \cdot \Delta t = \text{linepack\_kg}(t) - \text{linepack\_kg}(t-1)\) - positive = charging. Each endpoint junction sees \(+0.5 \cdot \text{net\_pack\_kgs}\) (outflow-positive convention).
Single-step solves pin net_pack_kgs = 0; timeseries activates the temporal coupling.
- class monee.model.extension.linepack.GasLinepack(overrides: dict[int, dict] | None = None)[source]¶
Bases:
NetworkAspectLinepack extension. Injects
linepack_kgandnet_pack_kgson every GasPipe; auto-sizes initial/max from grid params. Per-pipe overrides via theoverrides{branch_id: {"linepack_kg_initial": ..., "linepack_kg_max": ...}}.- activate_timeseries(network, ignored_nodes: set, step_state=None)[source]¶
Mark timeseries so equations() stops pinning net_pack_kgs=0; warm-start linepack_kg from step_state when available.
- Return type:
- equations(network, ignored_nodes: set)[source]¶
\(\text{linepack\_kg} = V_{pipe} \cdot \text{gas\_density\_kg\_per\_m3}\); pin
net_pack_kgs = 0in steady-state mode.- Return type:
Lumped thermal capacitance¶
Lumped Thermal Capacitance (LTC) extension for water junctions.
Each junction gets thermal mass \(\rho \cdot \sum V_{pipe}/2\) from connected pipes. The inertia equation:
replaces the degenerate \(T_n \cdot \text{mass\_balance} = 0\) heat balance at LTC nodes. No-op in single-step solves.
- class monee.model.extension.ltc.LumpedThermalCapacitance(default_t_init: float | None = None, t_init_overrides: dict | None = None, first_step_steady_state: bool = False)[source]¶
Bases:
NetworkAspectLTC extension. Nodes with a GridFormingMixin child are excluded.
First-step anchor precedence (anchored mode, the default - required for NLP solvers like GEKKO/IPOPT):
t_init_overrides[node_id]→default_t_init→ the junction’s ownt_puVar initialiser. Passdefault_t_initnear the operating mean to skip the warm-up transient.first_step_steady_state=Truedrops the first-step inertia term (emitsnet_heat == 0); MIP backends only.- activate_timeseries(network, ignored_nodes: set, step_state=None)[source]¶
Mark LTC junctions
_ltc_activeso the default degenerate heat balance is skipped (avoids a near-singular Jacobian); warm-start t_pu.- Return type:
- equations(network, ignored_nodes: set)[source]¶
Return solver-agnostic relational expressions (empty by default).
- Return type:
- inter_temporal_equations(network, ignored_nodes: set, temporal_state)[source]¶
\(\rho \cdot V \cdot (T_{pu}(t) - T_{pu}(t-1))/\Delta t = \text{net\_convective\_heat\_in}\) per LTC junction.
T_prevfalls back to the first-step anchor (see class docstring) whentemporal_state.getreturns None.- Return type:
Islanding¶
Islanding system for multi-carrier grid restoration.
IslandingMode is the per-carrier base (implements NetworkAspect);
NetworkIslandingConfig bundles modes for registration via
network.add_extension().
- class monee.model.extension.islanding.core.IslandingMode[source]¶
Bases:
NetworkAspect,ABCPer-carrier islanding base. Subclasses set
carrier_grid_typeandvar_prefix, and may overrideadd_physical_constraints()to add e.g. angle pinning / pressure bounds.- add_physical_constraints(*_)[source]¶
Carrier-specific physics (override in subclasses). Empty by default.
- Return type:
- equations(network: monee.model.network.Network, ignored_nodes: set)[source]¶
Return solver-agnostic relational expressions (empty by default).
- Return type:
- abstractmethod prepare(network: monee.model.network.Network)[source]¶
Add Var placeholders before solver variable injection.
- Return type:
- class monee.model.extension.islanding.core.NetworkIslandingConfig(electricity: monee.model.extension.islanding.core.IslandingMode | None = None, gas: monee.model.extension.islanding.core.IslandingMode | None = None, water: monee.model.extension.islanding.core.IslandingMode | None = None)[source]¶
Bases:
NetworkAspectBundle per-carrier
IslandingModeinstances; register vianetwork.add_extensionorenable_islanding().- equations(network: monee.model.network.Network, ignored_nodes: set)[source]¶
Return solver-agnostic relational expressions (empty by default).
- Return type:
- prepare(network: monee.model.network.Network)[source]¶
Add Var placeholders before variable injection (no-op by default).
- Return type:
Electricity¶
Electricity-carrier islanding mode and grid-forming generator model.
- class monee.model.extension.islanding.el.ElectricityIslandingMode(angle_bound: float = 3.15, big_m_conn: int = 200)[source]¶
Bases:
IslandingModeElectricity islanding: connectivity flow plus \(\theta=0\) at GF buses and energisation-gated angle bounds elsewhere.
- add_physical_constraints(network, gf_nodes, regular_nodes, e_vars)[source]¶
Carrier-specific physics (override in subclasses). Empty by default.
- Return type:
- prepare(network: monee.model.network.Network)[source]¶
Add Var placeholders before solver variable injection.
- Return type:
- class monee.model.extension.islanding.el.GridFormingGenerator(p_mw_max: float, q_mvar_max: float, vm_pu: float = 1.0, **kwargs)[source]¶
Bases:
NoVarChildModel,GridFormingMixinGrid-forming generator: variable p_mw/q_mvar (absorbs island imbalance) with a pinned vm_pu. Angle is pinned by
ElectricityIslandingMode.
Gas¶
Gas-carrier islanding mode and grid-forming source model.
- class monee.model.extension.islanding.gas.GasIslandingMode(big_m_conn: int = 200)[source]¶
Bases:
IslandingModeGas islanding: connectivity flow plus \(pressure_{pu} \le 2 \cdot e\) on regular junctions (GF junctions already pin pressure via overwrite()).
- add_physical_constraints(network, gf_nodes, regular_nodes, e_vars)[source]¶
Carrier-specific physics (override in subclasses). Empty by default.
- Return type:
- prepare(network: monee.model.network.Network)[source]¶
Add Var placeholders before solver variable injection.
- Return type:
- class monee.model.extension.islanding.gas.GridFormingSource(pressure_pu: float = 1.0, t_k: float = 356.0, mass_flow_max_kgs: float = 1000000.0)[source]¶
Bases:
ChildModel,GridFormingMixinGrid-forming source: pins pressure (and t_pu/t_k) on the junction, leaves mass_flow_kgs as a Var to absorb island imbalance.
Water¶
Water-carrier islanding mode (structurally identical to GasIslandingMode).
- class monee.model.extension.islanding.water.WaterIslandingMode(big_m_conn: int = 200)[source]¶
Bases:
IslandingModeWater/heat islanding. Use
GridFormingSourcefrom the gas module.- add_physical_constraints(network, gf_nodes, regular_nodes, e_vars)[source]¶
Carrier-specific physics (override in subclasses). Empty by default.
- Return type:
- prepare(network: monee.model.network.Network)[source]¶
Add Var placeholders before solver variable injection.
- Return type: