flexops.unit_models¶
Unit models are organized by inlet and outlet topology first (the base
sub-package), then specialized physically. The topology
base owns port construction and the per-stream mass balance, and a physical subclass
adds the relationship between flow and energy plus any bounds. Pump and Tank
subclass SISOBlock, which has a single inlet and a single outlet. A Tank also
disables the on/off logic layer, since a tank has no unit commitment status.
Every unit defaults to a constant energy intensity and builds it as the
Constraint power_electrical_relation (power_thermal_relation for a heat
duty). That name is the swap contract. FlexParameterize upgrades a unit’s
relationship by deactivating exactly that Constraint and attaching a fitted
replacement, and it reuses the same registered IO variables, so there is no separate
regression unit class.
Picking a base when adding a new unit model. Ask whether every port
shares one property_package.
If so, subclass the topology base that matches the port count (
SISOBlock/SIDOBlock/DIDOBlock). It already owns port construction and the per-stream mass balance, and the new class only renames the topology’s generic roles into its own nomenclature and adds the relationship between flow and energy inbuild(). To rename, pass a completenaming_dictup to the basebuild(). Spread the base’s_component_namesand override the subset you’re renaming, asReverseOsmosisdoes, and the base registers it before building anything named. Ports are never renamed.If the unit needs more than one property package (e.g. a fuel stream and an air stream on different flow bases), subclass
OpsBlockDatadirectly instead. Declare one named property package config slot per stream family and hand-write the ports and balance across them, rather than forcing a topology base built around a single shared package to fit halfway.If the unit’s port count is itself a config option (e.g. an arbitrary number of gas inlets), no topology base with fixed arity fits either. Subclass
OpsBlockDatadirectly and hand-write the ports and balance, asCombustor,Mixer, andSplitterdo. Give each stream its own port. Port members are equalities, so one port carries one arc. N streams mean N ports, never one port fed by N arcs.
Topology bases¶
Physical units¶
An arbitrary number of fuel sources mix into one flue gas outlet, exporting
electrical power (power_electrical upper-bounded at 0, the same sign convention
used for battery discharge) under either a heating value relation or a
constant intensity relation. The choice resolves automatically based on
whether every fuel source was given a heating value. You can connect fuel sources via inlet
ports (inlet_names), pull them from utilities (utility_fuel_source),
or both. The relation determines power_generated, the
nonnegative magnitude of generation and the unit’s registered IO output. The separate, deliberately unregistered power_electrical_sign constraint
then negates it into the draw, so the export convention holds under any surrogate
swap.
A linear steam boiler with a first-order thermal lag, fired (BoilerType.FIRED)
or heat recovery (BoilerType.HEAT_RECOVERY, with optional duct firing). Fuel
enters through inlet ports (fuel_inlet_names), from utilities
(utility_fuel_source), or both. Feedwater enters at inlet_feedwater and
steam leaves at outlet_steam. Steam heat is a thermal export
(power_thermal upper-bounded at 0). See Steam boilers for the
equations and for how to set its parameters from a detailed boiler model.
Where a |
|
Inlet names a |
|
|
|
|
Like Combustor and BatteryModel, this unit has no fluid ports (no
property_package). It turns an exogenous production profile, whether that’s solar
irradiance, an output curve derived from wind speed, or any other precomputed
capacity factor series, into an electrical export, scaled by a fixable
nameplate capacity. Like a discharging BatteryModel or an exporting
Combustor, the draw is negative (export), and the sign is split from the
relation for the magnitude of generation the same way Combustor splits them.
With curtailable=True the optimizer may spill output: power_curtailed
is subtracted from the available power_generated to give
power_delivered, which is what gets exported. By default power_curtailed
is fixed at 0, and every available kWh is exported.
An arbitrary number of named inlet streams join into one outlet at constant
density, so volume is conserved directly and no energy is involved. Pressure
stays equal across the inlets and passes through to the outlet. The outlet
temperature is either equal to the inlets’ (the linear default) or a blend
weighted by volume, depending on temperature_mixing.
One inlet stream divides among an arbitrary number of named outlets at
constant density. Conservation is its only flow constraint, so the routing
stays a decision variable, with \((N-1)\) degrees of freedom per time point
that the enclosing model’s objective resolves. Use SIDOBlock instead when
you want the split prescribed rather than optimized.
An anaerobic digester that accepts an arbitrary number of feed streams, each carrying its own property package, and converts them into one biogas outlet and an optional treated sludge outlet. A fixed fraction correlation of the total inlet volume drives biogas volume, and you can replace it with a linear surrogate.
An electrolyzer system whose boundary takes in the stack, the gas-liquid
separators on both electrode sides, and the electrolyte recirculation loop, so
every port carries a single phase. Current density drives it: Faraday’s law
sets each product’s molar rate, cell voltage sets the electrical draw (with an
optional quadratic ohmic loss, ohmic_loss), and both
gas outlets leave at the fixed operating temperature and pressure. The
separators hold a liquid inventory, so make-up water can be fed at a
different time from when the stack consumes it. The per-product Faradaic relations and
power_electrical_relation are registered, so you can replace them in place with a
fitted Faradaic-efficiency or polarization curve. The anode reaction is a
second product table, anode_products, which defaults to oxygen evolution.
WaterElectrolyzer fixes the products to hydrogen and oxygen and takes its defaults from technology (PEM or AEM).
CO2Electrolyzer takes a product table and adds the CO2 feed, set by
single-pass conversion, along with carbonate crossover to the anode and a
dissolved fraction of the unreacted CO2. Hydrogen evolution is its
balance_product by default, closing the charge balance, and
mass_transfer_coefficient adds an optional CO2 transport limit. Every gas
port builds from gas_property_package unless it is given its own package
(cathode_gas_property_package, anode_gas_property_package, or
co2_property_package), so each stream can carry a different gas.
Boundary blocks¶
A source with zero inlets and an arbitrary number of named outlets. It owns a boundary
stream (the reference outlet’s states other than flow are the boundary conditions,
and every other outlet is held at them), meters the total withdrawal[t]
crossing the boundary, optionally bounds it with mutable limit Params, and
optionally prices it into opex. Its resource_name is the key the enclosing
plant aggregates it under in total_feed[resource, t], independent of the
block’s own Pyomo name.
withdrawal_basis (and demand_basis on a Product) chooses what the
configured limits mean. A rate ceiling and a horizon allowance are different
constraints, not two spellings of one. On the default
"period" basis the limit is a rate holding in every period
(m**3/hr), built as a Param over the time index. On the "horizon" basis
it is a quantity over the whole horizon (m**3), such as a monthly abstraction
permit or a take-or-pay contract, bounding a scalar withdrawal_total defined
by eq_withdrawal_total as \(\sum_t withdrawal[t] \cdot dt\). This
leaves the optimizer free to shape the profile that reaches it. The metered
withdrawal[t] itself stays indexed by time either way, so costing, plant
aggregation and set_external_dispatch are unaffected. A limit whose units
contradict the declared basis raises FlexConfigError naming the config key.
On the period basis a limit may also be a length-T series (or a time-indexed
Pyomo component), which sets each period’s Param value directly.
The mirror sink, with an arbitrary number of named inlets and zero outlets, aggregates
what arrives into delivery[t] and aggregates into
total_product[resource, t]. It deliberately does not blend. Each
inlet’s intensive states arrive from its own arc and stay independent, so
put a Mixer upstream when you want a single blended stream. Its price
follows the register_scalar_cost sign convention, where positive is a cost (brine
disposal) and negative is revenue (potable water sold).
The plant’s point of interconnection with the electric grid. Built directly on a
PlantBlock (anywhere else raises FlexConfigError), it splits the plant’s
net electrical draw into two non-negative flows,
where \(P_{plant}[t]\) is the plant’s total_electrical_power[t], the
sum of its units’ power_electrical. Generation is negative, so a surplus
appears as export. The unit registers no power draw of its own, because it would
then count itself in the total it balances. A unit added after the
GridConnection is still included: the constraint references the plant total
by name, and cost_process() refreshes that total in place.
min_import/max_import/min_export/max_export are optional
per-period limits, built with the same <name>_min/<name>_max mutable
Params and _limit Constraints as Feed and Product. None means
unlimited. Each limit is a power scalar, a length-T series, or a time-indexed Pyomo
component, so an interconnection limit that varies by hour is given directly.
Billing is unchanged: costing still prices the plant’s net draw. Nothing
prevents importing and exporting in the same period. That is harmless while the
two flows share a price, and an exclusivity binary belongs here once export is
priced separately.
Generic surrogate¶
The default building block for anything without a bespoke physical topology, such as a whole plant modeled as one surrogate, as in the frozen API script.