IDAES Utility Functions¶
The IDAES library also includes a number of modules which contain utility functions of potential use to modellers.
Contents
util.config¶
This module contains utility functions useful for validating arguments to IDAES modeling classes. These functions are primarily designed to be used as the domain argument in ConfigBlocks.
-
idaes.core.util.config.
is_parameter_block
(val)[source]¶ Domain validator for property package attributes
Parameters: val – value to be checked Returns: TypeError if val is not an instance of PropertyParameterBase, ‘use_parameter_block’ or None
-
idaes.core.util.config.
is_port
(arg)[source]¶ Domain validator for ports
Parameters: arg – argument to be checked as a Port Returns: Port object or Exception
util.misc¶
This module contains miscellaneous utility functions that of general use in IDAES models.
-
idaes.core.util.misc.
add_object_ref
(local_block, local_name, external_component)[source]¶ Add a reference in a model to non-local Pyomo component. This is used when one Block needs to make use of a component in another Block as if it were part of the local block.
Parameters: - local_block – Block in which to add reference
- local_name – str name for referenced object to use in local_block
- external_component – external component being referenced
Returns: None
-
idaes.core.util.misc.
category
(*args)[source]¶ Decorate tests to enable tiered testing.
- Suggested categories:
- frequent
- nightly
- expensive
- research
Parameters: *args (tuple of strings) – categories to which the test belongs Returns: Either the original test function or skip Return type: function
-
idaes.core.util.misc.
dict_set
(v, d, pre_idx=None, post_idx=None, fix=False)[source]¶ Set the values of array variables based on the values stored in a dictionary. There may already be a better way to do this. Should look into it.
The value of Pyomo variable element with index key is set to d[key]
Arguments: v: Indexed Pyomo variable d: dictonary to set the variable values from, keys should match a subset
of Pyomo variable indexes.pre_idx: fixed indexes before elements to be set or None post_idx: fixed indexes after elements to be set or None fix: bool, fix the variables (otional)
-
idaes.core.util.misc.
doNothing
(*args, **kwargs)[source]¶ Do nothing.
This function is useful for instances when you want to call a function, if it exists. For example: getattr(unit, ‘possibly_defined_function’, getNothing)()
Parameters: - *args (anything) – accepts any argument
- **kwargs (anything) – accepts any keyword arguments
Returns: None
-
idaes.core.util.misc.
fix_port
(port, var, comp=None, value=None, port_idx=None)[source]¶ Method for fixing Vars in Ports.
Parameters: - port – Port object in which to fix Vars
- var – variable name to be fixed (as str)
- comp – index of var to be fixed (if applicable, default = None)
- value – value to use when fixing var (default = None)
- port_idx – list of Port elements at which to fix var. Must be list of valid indices,
Returns: None
-
idaes.core.util.misc.
get_pyomo_tmp_files
()[source]¶ Make Pyomo write it’s temporary files to the current working directory, useful for checking nl, sol, and log files for ASL solvers without needing to track down the temporary file location.
-
idaes.core.util.misc.
get_time
(results)[source]¶ Retrieve the solver-reported elapsed time, if available.
-
idaes.core.util.misc.
hhmmss
(sec_in)[source]¶ Convert elapsed time in seconds to “d days hh:mm:ss.ss” format. This is nice for things that take a long time.
-
idaes.core.util.misc.
requires_solver
(solver)[source]¶ Decorate test to skip if a solver isn’t available.
-
idaes.core.util.misc.
round_
(n, *args, **kwargs)[source]¶ Round the number.
This function duplicates the functionality of round, but when passed positive or negative infinity, simply returns the argument.
-
idaes.core.util.misc.
smooth_abs
(a, eps=0.0001)[source]¶ General function for creating an expression for a smooth minimum or maximum.
Parameters: - a – term to get absolute value from (Pyomo component, float or int)
- eps – smoothing parameter (Param, float or int) (default=1e-4)
Returns: An expression for the smoothed absolute value operation.
-
idaes.core.util.misc.
smooth_max
(a, b, eps=0.0001)[source]¶ Smooth maximum operator.
Parameters: - a – first term in max function
- b – second term in max function
- eps – smoothing parameter (Param or float, default = 1e-4)
Returns: An expression for the smoothed maximum operation.
-
idaes.core.util.misc.
smooth_min
(a, b, eps=0.0001)[source]¶ Smooth minimum operator.
Parameters: - a – first term in min function
- b – second term in min function
- eps – smoothing parameter (Param or float, default = 1e-4)
Returns: An expression for the smoothed minimum operation.
-
idaes.core.util.misc.
smooth_minmax
(a, b, eps=0.0001, sense='max')[source]¶ General function for creating an expression for a smooth minimum or maximum.
Parameters: - a – first term in mix or max function (Pyomo component, float or int)
- b – second term in min or max function (Pyomo component, float or int)
- eps – smoothing parameter (Param, float or int) (default=1e-4)
- sense – ‘mim’ or ‘max’ (default = ‘max’)
Returns: An expression for the smoothed minimum or maximum operation.
-
idaes.core.util.misc.
solve_indexed_blocks
(solver, blocks, **kwds)[source]¶ This method allows for solving of Indexed Block components as if they were a single Block. A temporary Block object is created which is populated with the contents of the objects in the blocks argument and then solved.
Parameters: - solve – a Pyomo solver object to use when solving the Indexed Block
- blocks – an object which inherits from Block, or a list of Blocks
- kwds – a dict of argumnets to be passed to the solver
Returns: A Pyomo solver results object
-
idaes.core.util.misc.
unfix_port
(port, var, comp=None, port_idx=None)[source]¶ Method for unfixing Vars in Ports.
Parameters: - port – Port object in which to unfix Vars
- var – variable name to be unfixed (as str)
- comp – index of var to be unfixed (if applicable, default = None)
- port_idx – list of Port elements at which to unfix var. Must be list of valid indices,
Returns: None