Conditional modelling
From ASCEND
Conditional modelling, in the context of ASCEND, refers to the use of a solver which can change the equations for which it is seeking a solution, depending on the current values of the guessed variables in the model, as the solution progresses. An example of a use for conditional modelling is that pipe flow can change from laminar to turbulent depending on the speed of the flow; in the laminar region the friction equations are very different to those in the turbulent region.
ASCEND currently provides just one solver that can solve this type of model, called CMSlv, but the architecture is such that other conditional solvers (aka MINLP solvers?) can also be connected if desired.
The CMSlv solver in ASCEND uses the 'boundary crossing' algorithm, and is currently fully functional, but requires the closed-source CONOPT solver. ASCEND users can get a free trial copy of CONOPT, see What if I do not have CONOPT for more details.
Contents |
[edit] Syntax
The documentation on ASCEND syntax is a little dated, so the current syntax will be summarised here.
[edit] Logical relations
You write logical relations in the declarative part of your MODEL using the following syntax:
mybool1, mybool2 IS_A boolean_var; mybool1 == mybool2;
[edit] Boundary conditions
To declare a boolean variable that becomes TRUE when a certain real-valued boundary is crossed, use the CONDITIONAL statement along with a logical relation:
myvar1, myvar2 IS_A solver_var; CONDITIONAL myboundary1: myvar1 < myvar2; END CONDITIONAL; mybool1 IS_A boolean_var; mybool1 == SATISFIED(myboundary1);
Note that normally the relations inside a CONDITIONAL section would be inequalities. In fact the relations can be equalities as well, or even logical relations. In the case of real-valued equality conditions, the following syntax is advisable, to specify a tolerance limit:
mybool1 == SATISFIED(myequality1, 1e-8 {kJ/kg});
[edit] Conditional relations
To use the value of a boolean var to control what equations are active in your model, use a WHEN statement (continuing from the previous model:
myvar3 IS_A solver_var; mycondexpr1: myvar3 = 2 * (myvar1 - myvar2); mycondexpr2: myvar3 = sin(myvar1 - myvar2); WHEN(mybool1) CASE TRUE: USE mycondexpr1; CASE FALSE: USE mycondexpr2; END WHEN;
You can use multiple variables in your WHEN list, which occasionally saves some typing. Also there is the OTHERWISE clause.
WHEN(mybool1,mybool2) CASE TRUE,FALSE: ... CASE FALSE,FALSE: ... OTHERWISE: ... END WHEN;
[edit] Other conditional syntax
There is also syntax for providing conditional functionality in the METHODS section of a model. See Vicente Rico-Ramirez' thesis.
[edit] Examples
Some complete worked examples exist, for the following cases:
- condensing heat exchanger heatex.a4c
- shocks in adiabatic compressible flow sonic.a4c
- pipe flow network with one-way valves pipeline.a4c
- Rachford-Rice flash model rachford.a4c
- Mass balance for a linear process with multiple 'modes' linmassbal.a4c
[edit] Further documentation
The primary reference for ASCEND's conditional modelling is:
- Vicente Rico-Ramirez' thesis, Representation, Analysis and Solution of Conditional Models in an Equation-Based Environment
Further source of documentation (some of which is a proposed implementation) include:
- The ASCEND HOWTO: Conditional Modelling
- Zaher's Thesis, Conditional Modeling
- There are further documents in the Ascend Bibliograpy
[edit] Slack variables
Note that in some cases, it is possible to model conditional expressions without the need for specialised conditional syntax. This approach has been used in the current thermodynamics library in ASCEND.
For an example, see the model iapws95_2phase in the iapws95.a4c file in the ModelLibrary.
There are some very worthwhile comments on how to go about using slack variables in the following document (page 17):
http://www.gams.com/solvers/conopt.pdf
[edit] Future
It is proposed that we implement an open-source alternative optimiser for ACEND so that CONOPT is not a requirement for conditional modelling. A good candidate appears to be IPOPT.
See also Integration of Conditional Models.

