Model and block structure¶
This page explains how a flex-pse model gets assembled from Pyomo/IDAES blocks, and how variables on those blocks get indexed. Two questions come up again and again when you read or write a unit model, and they have different answers.
Time indexing. Which variables vary over the horizon, and against what set?
Property (state) indexing. Where does a stream’s
flow_vol_phase,pressure, andtemperaturelive, and how do they carry a time dimension?
The block hierarchy¶
A flex-pse model is a plain Pyomo ConcreteModel (or a dynamic=False IDAES
flowsheet, never a dynamic=True/Pyomo.DAE flowsheet, see
Time and dynamics for why). On it sit a small, fixed set of block
kinds.
ConcreteModel
├── TimeBlock the discrete-time substrate (exactly one)
├── <PropertyPackage> a parameter block (SimpleAqueousFlow, SimpleGasFlow, …)
└── <unit> : OpsBlock one per process unit
├── power_electrical[t] base power Var(s), kW, indexed by time
├── power_thermal[t]
├── <state blocks> built from the property package, one scalar block per stream
├── <balance constraints> 1 to 3, hand-written (no ControlVolumes)
└── _io_registry what this unit exposes (IORegistry)
TimeBlock, the one ordered set everything indexes against¶
TimeBlock builds the ordered integer set
time_index equal to 0..N-1, the elapsed time Param time (i*dt), and
the step dt, which carries units. It’s the only set flex-pse variables
index over for the time dimension. Time is discrete on purpose, for unit
commitment index arithmetic like dwell times, startup delays, and rolling
horizon windows. See Time and dynamics for the full rationale. There
is exactly one TimeBlock per model. A unit finds it by searching the model
(the interim _find_time_block helper), a stopgap until the flowsheet()
chain arrives.
OpsBlock, the base of every unit model¶
OpsBlockData inherits IDAES
UnitModelBlockData for its ConfigBlock, Port, and costing registration
machinery, but it uses no ControlVolumes. Each subclass hand writes its
one to three balance constraints as difference equations against
time_block.dt. The base provides the following.
The power Vars, via
declare_power().The registration API (
register_io_variable(),register_process_parameter(),register_power()).The in place update hook
update_parameters(). flex-pse never deletes a built component. Anything else holding a reference to it (an aggregated power constraint, an expanded arc) would otherwise keep the stale one silently. Mutate Params in place, ordeactivate()constraints instead.The stream port helper
add_stream_ports(). It builds one{port}_stateblock per requested port from the configuredproperty_package(default oneinletand oneoutlet), registers the caller chosenio_varson each (the actual state blockVar, not aReference) as input or output IO variables (the default isflow_vol_phase, since which variables count as meaningful IO depends on the property package), and exposes the ports through the inherited IDAESadd_inlet_port/add_outlet_porthelpers.
Property packages, a parameter block plus state blocks¶
A property package is an IDAES PhysicalParameterBlock (the parameter
block: phases, components, supported property metadata, default units)
paired with a StateBlockData subclass (the state block: the actual state
Vars). flex-pse ships two, both modeled structurally on WaterTAP’s zero
order package.
SimpleAqueousFlowis flow only by default. It carriesflow_vol_phase(indexed by the singleLiqphase and time), with opt-inpressure/temperature.SimpleGasFlowis the gas counterpart. It always carries all three state variables (flow_vol_phaseover the singleVapphase and time, pluspressure/temperature). A gas stream’s conditions always matter. It imposes no equation of state. A unit adds any relation it needs as its own constraint. Its first consumer isCombustor, N fuel sources (inlet ports and/or utility fuel names) burned into one flue gas outlet, exporting power. So the extensive/intensive table below describes something real, not a hypothetical.
Ports built from state blocks carry a stream between units over standard
IDAES/Pyomo Arcs, honoring the extensive/intensive split described below.
How variable indexing works¶
Variables fall into two families, indexed two different ways. Getting the family right is the single most important structural decision when you write a unit.
Operational variables get indexed over the time set¶
Everything that represents an operating decision or quantity over the
horizon is a Var indexed directly over time_block.time_index. This
includes both base provided and unit declared variables.
Power draw.
declare_power()createspower_electrical[t](orpower_thermal[t]) asVar(time_block.time_index, units=kW). Both are powers in kW. See Energy nomenclature.Process IO variables. These are a unit’s controllable inputs and reported outputs (flows, setpoints, on/off status). Most are indexed by time, but that’s not required. A fixed geometry or a design decision that doesn’t vary over the horizon is a scalar Var instead. The
IOVariableRecordrecords this in itstime_indexedflag, so FlexParameterize and the docs generator know which axis a registered variable spans.
time_index is a plain integer Set, so difference equations get written
with ordinary index arithmetic, V[t+1] == V[t] + dt*(inflow[t] - outflow[t]).
That’s exactly why the time set is discrete.
Property state variables carry the time index themselves¶
The state variables flow_vol_phase, pressure, and temperature get
declared inside StateBlockData.build, indexed over the time set
directly. The extensive, per phase flow_vol_phase is
Var(time, phase_list) (time first, phase second), while the intensive
stream properties pressure and temperature drop the phase index and
become Var(time) (assumed equal across phases in a stream). So a single
state block describes a stream over the whole horizon.
The time set reaches the state block through its time_index config
option. A property package’s build_state_block(time_index=<time Set>)
returns a single scalar block whose variables span that set. A unit’s
add_stream_ports() does exactly
this for its inlet and outlet streams, then wires the flows and ports.
# inside a unit's build():
self.add_stream_ports() # builds scalar inlet_state, outlet_state + ports
# then, per time point t:
self.inlet_state.flow_vol_phase[t, "Liq"] # volumetric flow at time t
self.inlet_state.pressure[t] # pressure at time t (when enabled)
So indexing stays single layer. There’s one state block per stream, and
time is the leading index on the state variables inside it (flow_vol_phase
also carries a trailing phase index). That’s why the tests build a three
point stream with build_state_block(time_index=m.time) and then read
state.flow_vol_phase[0, "Liq"], state.flow_vol_phase[1, "Liq"], and so
on.
Extensive vs. intensive, how state variables cross an arc¶
Within a state block, the state variables split by how they combine at a connection.
State variable |
Kind |
Across an arc |
Port rule |
|---|---|---|---|
|
extensive |
conserved (sum of flows balances at a node) |
|
|
intensive |
equal on both sides |
|
This is why volumetric flow is the quantity a mixer sums and a splitter
divides, while pressure and temperature simply get equated across a
connection. That’s exactly the split
Mixer and
Splitter build around. Note that
the Port rule column describes the modeling intent. The state blocks
build every port member as Port.Equality, so one port carries one arc. A
junction gives each stream its own port instead of splitting one port
across several arcs.
Where each thing is declared, a summary¶
Quantity |
Block it lives on |
Indexed over |
Declared by |
|---|---|---|---|
|
|
none / |
|
|
the unit ( |
|
|
process IO variables |
the unit ( |
|
the unit’s |
design/regression parameters |
the unit ( |
usually scalar |
the unit’s |
|
a scalar state block (one per stream) |
time on the variable, and |
the property package’s |
Discovery ties it together. Every unit exposes what it declared through its
IORegistry, and
iter_io_registry() walks the whole model to
find every block that registered something. That gives FlexParameterize and
the docs generator a model wide view.