Domain Classes
The class layer is the in-memory model behind the OpenPinch workflow. Most of
these objects are created for you by
prepare_problem(), but they are also
useful directly when building tests, custom workflows, or post-processing
studies.
How These Objects Fit Together
StreamandStreamCollectionrepresent the thermal streams and ordered stream sets used to build problem tables.Zonegroups streams, utilities, targets, and subzones into a hierarchical model of the process, site, or wider system.ProblemTablestores the numerical temperature-interval cascade that drives pinch and utility calculations.BaseTargetModelstores one solved set of metrics for a zone and is later serialised into the public output schema.Valuewraps scalar and discrete-state quantities with units for report-friendly serialisation.
Core domain classes used throughout OpenPinch.
Streams and Collections
These are the most commonly manipulated domain objects outside the top-level service layer.
Data model representing process and utility streams.
- class OpenPinch.classes.stream.Stream(name='Stream', t_supply=None, t_target=None, p_supply=None, p_target=None, h_supply=None, h_target=None, dt_cont=0.0, dt_cont_multiplier=1.0, heat_flow=0.0, htc=1.0, price=0.0, is_process_stream=True)[source]
Bases:
objectGeneric thermal stream used for both process and utility duties.
A
Streamstores supply/target states together with derived values such as hot/cold classification, shifted temperature bounds, heat-capacity flow rate, and simple economic attributes. The same class is reused for process streams, utilities, and derived net streams created during site- level aggregation.Initialise a stream and infer hot/cold classification.
- Parameters:
name (str)
t_supply (Optional[MaybeVU])
t_target (Optional[MaybeVU])
p_supply (Optional[MaybeVU])
p_target (Optional[MaybeVU])
h_supply (Optional[MaybeVU])
h_target (Optional[MaybeVU])
dt_cont (MaybeVU)
dt_cont_multiplier (float)
heat_flow (MaybeVU)
htc (MaybeVU)
price (MaybeVU)
is_process_stream (bool)
- property dt_cont_act: Value
Effective delta-T contribution used in shifted-temperature calculations.
- property dt_cont_multiplier: float
Effective delta-T contribution used in shifted-temperature calculations.
- property dt_cont_multiplier_locked: bool
Whether the delta-T contribution multiplier is locked against changes.
- property shifted_minimum_temperature: Value | None
Alias for the shifted minimum stream temperature.
- property shifted_maximum_temperature: Value | None
Alias for the shifted maximum stream temperature.
- property delta_t_contribution_multiplier: float
Alias for the shifted-temperature contribution multiplier.
- property effective_delta_t_contribution: Value
Alias for the effective shifted-temperature contribution.
- property heat_capacity_flow_rate: Value | None
Alias for the derived stream heat-capacity flow rate.
Utility container for managing ordered sets of stream objects.
- class OpenPinch.classes.stream_collection.StreamCollection(streams=None)[source]
Bases:
objectA dynamic, ordered collection of streams.
Key features include:
Add and remove streams by name.
Prevent overwriting existing streams by auto-renaming.
Configure sort keys as attributes or callables.
Iterate efficiently with lazy sorting.
Support ascending or descending ordering.
Initialise an empty collection sorted by descending supply temperature.
- property state_ids: dict[str, int] | None
Return the canonical state identifiers for this collection.
- add(stream, key=None, prevent_overwrite=True)[source]
Insert a stream, optionally renaming the key to avoid collisions.
- add_many(streams, keys=None, prevent_overwrite=True)[source]
Insert several streams, optionally using explicit keys for each stream.
- sum_stream_attribute(attr_name, idx=None)[source]
Return the total of a specified attribute for streams in the collection.
- set_common_stream_attribute(attr_name, value, *, idx=None)[source]
Set a common attribute across all streams in the collection.
- set_sort_key(key, reverse=False)[source]
Set the sorting key. Supports attribute names or custom lambdas.
- copy(*, deep=False)[source]
Return a copy of the collection, optionally deep-copying streams.
- Parameters:
deep (bool)
- Return type:
- set_state_context(state_ids, weights, num_states=None)[source]
Persist the canonical shared state model for this collection.
- get_index(stream)[source]
Return the position (index) of a stream object in the sorted stream list.
- Return type:
- export_to_csv(filename='heat pump streams')[source]
Export stream data to
results/<filename>and return the path written.
- get_hot_streams(include_process_streams=True, include_utility_streams=True, invert_utility=False, sort_attr=None)[source]
Return a new collection containing only hot streams.
- get_cold_streams(include_process_streams=True, include_utility_streams=True, invert_utility=False, sort_attr=None)[source]
Return a new collection containing only cold streams.
- get_process_streams(sort_attr=None)[source]
Return a new collection containing only process streams.
- Parameters:
sort_attr (str | None)
- get_hot_process_streams(sort_attr=None)[source]
Return a new collection containing only hot process streams.
- Parameters:
sort_attr (str | None)
- get_cold_process_streams(sort_attr=None)[source]
Return a new collection containing only cold process streams.
- Parameters:
sort_attr (str | None)
- get_utility_streams(sort_attr=None)[source]
Return a new collection containing only utility streams.
- Parameters:
sort_attr (str | None)
- get_hot_utility_streams(sort_attr=None)[source]
Return a new collection containing only hot utility streams.
- Parameters:
sort_attr (str | None)
- get_cold_utility_streams(sort_attr=None)[source]
Return a new collection containing only cold utility streams.
- Parameters:
sort_attr (str | None)
Zones, Targets, and Tables
These classes represent the solved hierarchy and its numerical results.
Zone data structure capturing nested scopes and their thermal targets.
- class OpenPinch.classes.zone.Zone(name='Zone', type='Process Zone', zone_config=None, parent_zone=None)[source]
Bases:
objectHierarchical analysis boundary containing streams, utilities, and targets.
Zones form the backbone of the in-memory OpenPinch model. Each zone can own process streams, utility streams, solved targets, generated graphs, and nested child zones. Direct and indirect integration routines progressively populate this structure as the analysis moves from local process scopes up to site-style aggregation.
Initialise an empty zone with stream, target, and graph containers.
- Parameters:
name (str)
type (str)
zone_config (Configuration | None)
parent_zone (Zone)
- property name
Display name used when addressing the zone in the hierarchy.
- property type
Zone type type from
ZoneType.
- property config
Configuration object controlling analysis behaviour for this zone.
- property parent_zone
Direct parent zone in the site hierarchy, if any.
- property weights
Canonical state weights for this zone.
- property num_states
Number of distinct states for this zone.
- property dt_cont_multiplier: float
Effective multiplier applied to stream and utility
dt_contvalues.
- property hot_streams
Process streams that release heat within this zone.
- property cold_streams
Process streams that require heat within this zone.
- property net_hot_streams
Net hot streams derived from zonal aggregation.
- property net_cold_streams
Net cold streams derived from zonal aggregation.
- property hot_utilities
Hot utility streams assigned to the zone.
- property cold_utilities
Cold utility streams assigned to the zone.
- property graphs
Graphs generated for this zone.
- property subzones
Immediate child zones keyed by name.
- property targets
Energy targets keyed by target name.
- property process_streams
Combined hot and cold process streams for the zone.
- property net_process_streams
Combined net hot and net cold process streams for the zone.
- property utility_streams
Combined hot and cold utility streams for the zone.
- property all_streams
All process and utility streams defined on the zone.
- set_state_context(state_ids, weights, num_states)[source]
Set the canonical state lookup owned by this zone and propagate refs.
- add_graph(name, result)[source]
Store a graph result under
namefor later export or display.- Parameters:
name (str)
- add_zone(zone_to_add, sub=True)[source]
Add a single zone object keyed by its name.
If the zone name already exists: - If the zone is identical (e.g. same stream and utility objects), skip. - If it’s different, add it with a suffix like ‘_1’, ‘_2’, etc.
- Parameters:
sub (bool)
- add_target(target_to_add)[source]
Add one target to a specific zone.
- Parameters:
target_to_add (BaseTargetModel)
- add_targets(targets=[])[source]
Add multiple targets to a specific zone.
- Parameters:
targets (list)
- import_hot_and_cold_streams_from_sub_zones(get_net_streams=False, is_n_zone_depth=True, is_new_stream_collection=True)[source]
Get referenced hot and cold streams across multiple subzones.
Lightweight table structure used by the pinch analysis pipeline.
- class OpenPinch.classes.problem_table.ProblemTable(data_input=None, add_default_labels=True)[source]
Bases:
objectNumPy-backed pinch problem table with enum-friendly accessors.
Initialise the table from a dictionary or list-of-columns structure.
- Parameters:
- class ColumnViewByIndex(parent)[source]
Bases:
objectExpose read/write access to columns addressed by integer index.
- Parameters:
parent (ProblemTable)
- property icol
Return a view for column access by integer position.
- class ColumnViewByName(parent)[source]
Bases:
objectExpose read/write access to columns addressed by label or enum.
- Parameters:
parent (ProblemTable)
- property col
Return a view for column access by string label or ProblemTableLabel.
- class ColumnsViewByName(parent)[source]
Bases:
objectVectorised view over multiple labelled columns or enums.
- Parameters:
parent (ProblemTable)
- property cols
Return a vectorised view over multiple labelled columns or enums.
- class LocationByRowByColName(parent)[source]
Bases:
objectRow/column accessor mirroring
DataFrame.locsemantics.- Parameters:
parent (ProblemTable)
- property loc
Expose row/column access using label semantics (
loc).
- class LocationByRowByCol(parent)[source]
Bases:
objectRow/column accessor mirroring
DataFrame.ilocsemantics.- Parameters:
parent (ProblemTable)
- property iloc
Expose row/column access using positional semantics (
iloc).
- slice(keys)[source]
Return a new ProblemTable containing only the requested columns.
- Parameters:
keys (str | ProblemTableLabel | Sequence[str | ProblemTableLabel])
- Return type:
- property shape
Tuple describing
(rows, columns)for the buffer.
- property copy
Return a deep copy of the table.
- to_list(col=None)[source]
Return table data as Python lists; optionally restrict to a single column.
- Parameters:
col (str | ProblemTableLabel | None)
- pinch_idx(col=ProblemTableLabel.H_NET)[source]
Return the row indices of the hot and cold pinch temperatures.
- pinch_temperatures(col_T=ProblemTableLabel.T, col_H=ProblemTableLabel.H_NET)[source]
Determine the hottest hot and coldest cold pinch temperatures.
- Parameters:
col_T (str | ProblemTableLabel)
col_H (int | str | ProblemTableLabel)
- Return type:
- shift_heat_cascade(dh, col)[source]
Shift a heat-cascade column by
dhand return a table copy.- Parameters:
dh (float)
col (int | str | ProblemTableLabel)
- Return type:
Mutate both tables so they use the union of their temperature intervals.
Returns a tuple containing
(rows_inserted_into_self, rows_inserted_into_other).- Parameters:
other (ProblemTable)
- Return type:
- insert_temperature_interval(T_ls)[source]
Insert any missing temperature intervals and return count inserted.
- insert(row_dict, index)[source]
Insert a single row (dict of column: value) at the specified index.
- update_row(index, row_dict)[source]
Update selected columns for one row using values from
row_dict.
- update(updates=None, T_col=None)[source]
Assign aligned column values in-place using an explicit source T column.
- Parameters:
updates (dict[str | ProblemTableLabel, ndarray] | None)
T_col (ndarray | None)
- Return type:
- sort_by_column(column, ascending=True)[source]
Sort rows in-place by the given column.
- Parameters:
column (str | ProblemTableLabel)
ascending (bool)
Units and Scalar Helpers
Value supports both ordinary scalar
quantities and discrete-state values with state_ids and normalised
weights. This makes it suitable for both deterministic reports and
state-weighted scenario data.
Unit-aware scalar and discrete-state value wrapper powered by Pint quantities.
- class OpenPinch.classes.value.Value(data=None, unit=None)[source]
Bases:
objectThin wrapper around a Pint
Quantitywith serialization helpers.Create a scalar or stateful value from
dataand an optionalunit.- Parameters:
unit (str)
- property value
Return the scalar magnitude or per-state magnitudes for stateful values.
- property unit
Return the unit in a human-friendly compact representation.
Thermal Cycle Classes
These classes support the advanced Heat Pump, refrigeration, and utility system
workflows documented in
OpenPinch.services.heat_pump_integration.heat_pump_and_refrigeration_entry. They are
primarily useful for advanced users who want to inspect or construct detailed
cycle configurations directly.