Variable-Like Expressions

Variable-Like Expressions#

There are a number of cases within IDAES where a modeler may wish to use an Expression in place of a Var to reduce the complexity of their model. A common example of this is in the ideal Separator unit where the outlet Ports use Expressions for the state variable in order to reduce the number of variables (and thus constraints) in the model.

In these cases, it is possible that a user might mistake the Expression for a Var and attempt to use methods such as fix() on it. In order to provide the user with a useful error message informing them that this will not work, IDAES has created a derived VarLikeExpression component for these situations. This component derives directly from Pyomo’s Expression component and implements common methods associated with Vars which will return an error message informing the user that the component is an Expression, and a suggestion on how to proceed.

class idaes.core.base.var_like_expression.VarLikeExpression(*args, **kwds)[source]#

A shared var-like expression container, which may be defined over a index.

Constructor Arguments:

initialize: A Pyomo expression or dictionary of expressions used to initialize this object.

expr: A synonym for initialize.

rule: A rule function used to initialize this object.

class idaes.core.base.var_like_expression.SimpleVarLikeExpression(*args, **kwds)[source]#
add(index, expr)[source]#

Add an expression with a given index.

class idaes.core.base.var_like_expression.IndexedVarLikeExpression(*args, **kwds)[source]#
add(index, expr)[source]#

Add an expression with a given index.

class idaes.core.base.var_like_expression.VarLikeExpressionData(expr=None, component=None)[source]#

An object derived from ExpressionData which implements methods for common APIs on Vars.

Constructor Arguments:

expr: The Pyomo expression stored in this expression.

component: The Expression object that owns this data.

Public Class Attributes:

expr: The expression owned by this data.

Private class attributes:

_component: The expression component.

set_value(value, force=False)[source]#

Overload set_value method to provide meaningful error if user attempts to set the value of the Expression. In order to support changing the expression (and setting it originally), if self.expr is None or force=True, the value of the expression will be updated, otherwise a TypeError will be raised.

  • value – value to set for expr

  • force – force updating of expr if True (default = False)




TypeError if expr is not None and force=False