Utilities for Dynamic Flowsheets

These are utility functions for working with dynamic IDAES flowsheets.

Methods

This module contains utility functions for dynamic IDAES models.

idaes.core.util.dyn_utils.copy_non_time_indexed_values(fs_tgt, fs_src, copy_fixed=True)[source]

Function to set the values of all variables that are not (implicitly or explicitly) indexed by time to their values in a different flowsheet.

Parameters:
  • fs_tgt – Flowsheet into which values will be copied.
  • fs_src – Flowsheet from which values will be copied.
  • copy_fixed – Bool marking whether or not to copy over fixed variables in the target flowsheet.
Returns:

None

idaes.core.util.dyn_utils.copy_values_at_time(fs_tgt, fs_src, t_target, t_source, copy_fixed=True, outlvl=0)[source]

Function to set the values of all (explicitly or implicitly) time-indexed variables in a flowsheet to similar values (with the same name) but at different points in time and (potentially) in different flowsheets.

Parameters:
  • fs_tgt – Target flowsheet, whose variables’ values will get set
  • fs_src – Source flowsheet, whose variables’ values will be used to set those of the target flowsheet. Could be the target flowsheet
  • t_target – Target time point
  • t_source – Source time point
  • copy_fixed – Bool of whether or not to copy over fixed variables in target model
  • outlvl – IDAES logger output level
Returns:

None

idaes.core.util.dyn_utils.deactivate_constraints_unindexed_by(b, time)[source]

Searches block b for and constraints not indexed by time and deactivates them.

Parameters:
  • b – Block to search
  • time – Set with respect to which to find unindexed constraints
Returns:

List of constraints deactivated

idaes.core.util.dyn_utils.deactivate_model_at(b, cset, pts, outlvl=0)[source]

Finds any block or constraint in block b, indexed explicitly (and not implicitly) by cset, and deactivates it at points specified. Implicitly indexed components are excluded because one of their parent blocks will be deactivated, so deactivating them too would be redundant.

Parameters:
  • b – Block to search
  • cset – ContinuousSet of interest
  • pts – Value or list of values, in ContinuousSet, to deactivate at
Returns:

A dictionary mapping points in pts to lists of component data that have been deactivated there

idaes.core.util.dyn_utils.find_comp_in_block(tgt_block, src_block, src_comp, allow_miss=False)[source]

This function finds a component in a source block, then uses the same local names and indices to try to find a corresponding component in a target block. This is used when we would like to verify that a component of the same name exists in the target block, as in model predictive control where certain variables must be correllated between plant and controller model.

Parameters:
  • tgt_block – Target block that will be searched for component
  • src_block – Source block in which the original component is located
  • src_comp – Component whose name will be searched for in target block
  • allow_miss – If True, will ignore attribute and key errors due to searching for non-existant components in the target model
Returns:

Component with the same name in the target block

idaes.core.util.dyn_utils.find_comp_in_block_at_time(tgt_block, src_block, src_comp, time, t0, allow_miss=False)[source]

This function finds a component in a source block, then uses the same local names and indices to try to find a corresponding component in a target block, with the exception of time index in the target component, which is replaced by a specified time point. This is used for validation of a component by its name in the case where blocks may differ by at most time indices, for example validating a steady-state model or a model with a different time discretization.

Parameters:
  • tgt_block – Target block that will be searched for component
  • src_block – Source block in which the original component is located
  • src_comp – Component whose name will be searched for in target block
  • time – Set whose index will be replaced in the target component
  • t0 – Index of the time set that will be used in the target component
  • allow_miss – If True, will ignore attribute and key errors due to searching for non-existant components in the target model
idaes.core.util.dyn_utils.fix_vars_unindexed_by(b, time)[source]

Searches block b for variables not indexed by time and fixes them.

Parameters:
  • b – Block to search
  • time – Set with respect to which to find unindexed variables
Returns:

List of variables fixed

idaes.core.util.dyn_utils.get_activity_dict(b)[source]

Function that builds a dictionary telling whether or not each ConstraintData and BlockData object in a model is active. Uses the objects’ ids as the hash.

Parameters:b – A Pyomo Block to be searched for active components
Returns:A dictionary mapping id of constraint and block data objects to a bool indicating if they are active
idaes.core.util.dyn_utils.get_derivatives_at(b, time, pts)[source]

Finds derivatives with respect to time at points specified. No distinction made for multiple derivatives or mixed partials.

Parameters:
  • b – Block to search for derivatives
  • time – ContinuousSet to look for derivatives with respect to
  • pts – Value or list of values in time set at which to return derivatives
Returns
Dictionary mapping time points to lists of derivatives at those points
idaes.core.util.dyn_utils.get_fixed_dict(b)[source]

Function that builds a dictionary telling whether or not each VarData object in a model is fixed. Uses the objects’ ids as the hash.

Parameters:b – A Pyomo block to be searched for fixed variables
Returns:A dictionary mapping id of VarData objects to a bool indicating if they are fixed
idaes.core.util.dyn_utils.get_implicit_index_of_set(comp, wrt)[source]

For some data object contained (at some level of the hierarchy) in a block indexed by wrt, returns the index corresponding to wrt in that block.

Parameters:
  • comp – Component data object whose (parent blocks’) indices will be searched
  • wrt – Set whose index will be searched for
Returns:

Value of the specified set

idaes.core.util.dyn_utils.get_index_of_set(comp, wrt)[source]

For some data object of an indexed component, gets the value of the index corresponding to some 1-dimensional pyomo set.

Parameters:
  • comp – Component data object whose index will be searched
  • wrt – Set whose index will be searched for
Returns:

Value of the specified set in the component data object

idaes.core.util.dyn_utils.get_location_of_coordinate_set(setprod, subset)[source]

For a SetProduct and some 1-dimensional coordinate set of that SetProduct, returns the location of an index of the coordinate set within the index of the setproduct.

Parameters:
  • setprod – SetProduct containing the subset of interest
  • subset – 1-dimensional set whose location will be found in the SetProduct
Returns:

Integer location of the subset within the SetProduct

idaes.core.util.dyn_utils.path_from_block(comp, blk, include_comp=False)[source]

Returns a list of tuples with (local_name, index) pairs required to locate comp from blk

Parameters:
  • comp – Component(Data) object to locate
  • blk – Block(Data) to locate comp from
  • include_comp – Bool of whether or not to include the local_name, index of the component itself
Returns:

A list of string, index tuples that can be used to locate comp from blk