16 A C

of http://ascend.cheme.cmu.edu/ftp/pdfMisc/when_model.pdf. It's a snapshot of the page taken as our search engine crawled the Web.
The web site itself may have changed. You can check the current page or check for previous versions at the Internet Archive. Yahoo! is not affiliated with the authors of this page or responsible for its content.
16 A C
T
HE
WHEN S
TATEMENT
122
/afs/cs.cmu.edu/project/edrc-ascend7/DOCS/Help/when_model.fm5
C
HAPTER
16 A C
ONDITIONAL
M
ODELING
E
XAMPLE
: R
EPRESENTING A
S
UPERSTRUCTURE
To give an example of the application of the conditional modeling tool
in ASCEND -the
WHEN
statement-, we developed a simplied model
for the superstructure given in Figure 16-1. The code listed below
exists in a le in the ASCEND models subdirectory entitled
when_demo.a4c. You could run this example by loading this le and
using it and its corresponding script when_demo.a4s.
16.1 T
HE
WHEN S
TATEMENT
Before showing the example, we want to start by giving a brief
explanation about the semantics of the WHEN statement, a tool which
allows
ASCEND
to represent conditional models efciently.
In the
WHEN
statement, we take advantage of the fact that
ASCEND
is
based on object oriented concepts where model denitions can contain
parts that contain parts to any level. Furthermore, in
ASCEND,
a simple
Figure 16-1
Superstructure used in the example of the application of the when statement
f1
f2
c1
co1
h1
r2
r1
co2
1
h2
h3
c2
Feed 1 (cheap)
Feed 2(exp.)
Pby
<1000
ton/day
>90 %
pure C
high conv, high cost
low conv, low cost
A + B
C
s1
sp1
s2
m1 123
A C
ONDITIONAL
M
ODELING
E
XAMPLE
: R
EPRESENTING A
Last modified: June 20, 1998 10:59 pm
relation is treated as an object by itself and can have a name. Based on
these ideas, the syntax for the
WHEN
statement is:
WHEN (list_of_variables)
CASE list_of_values_1:
USE name_of_equation_1;
USE name_of_model_1;
CASE list_of_values_2:
USE name_of_equation_2;
USE name_of_model_2;
CASE list_of_values_nminus1:
USE name_of_equation_nminu1;
USE name_of_model_nminus1;
OTHERWISE:
USE name_of_equation_n;
USE name_of_model_n;
END;
The following are important observations about the implementation:
1
The
WHEN
statement does not mean conditional compilation. We
create and have available the data structures for all of the variables
and equations in each of the models. This is actually a requirement
for the solution algorithms of conditional models. All the models
and equations whose name is given in each of the cases should be
declared inside the model which contains the
WHEN
statement.
2
The variables in the list of variables can be of any type among
boolean, integer or symbol or any combination of them. That is, we
are not limited to the use of boolean variables. Obviously, The list
of values in each case must be in agreement with the list of
variables in the number of elements and type of each element. In
other words, order matters in the list of variables of the
WHEN
statement, and parentheses are enclosing this list to make clear such
a feature.
3
Names of arrays of models or equations are also allowed inside the
scope of each
CASE
.
The
WHEN
statement represents an important contribution to modeling:
it allows the user to dene the domain of validity of both models and
equations inside the cases of a
WHEN
statement. This feature
enormously increases the scope of modeling in an equation based
modeling environment.
Mainly, there are two different ways in which the
WHEN
statement can
be used.: T
HE
P
ROBLEM
D
ESCRIPTION
124
/afs/cs.cmu.edu/project/edrc-ascend7/DOCS/Help/when_model.fm5
First, the WHEN statement can be used to select a conguration
of a problem among several alternative congurations.
Second, in combination with logical relations, the
WHEN
statement can be used for conditional programming. That is, a
problem in which the system of equations to be solved depends
on the solution of the problem. A typical example of this
situation is the laminar-turbulent ow transition. The selection of
the equation to calculate the friction factor depends on the value
of the Reynolds number, which is an unknown in the problem.
16.2 T
HE
P
ROBLEM
D
ESCRIPTION
In the example, there are two alternative feedstocks, two possible
choices of the reactor and two choices for each of the compression
systems. The user has to make 4 decisions (for example, using either
the cheap feed or the expensive feed), therefore, there are 2
4
= 16
feasible congurations of the problem. All these 16 congurations are
encapsulated in one
ASCEND
model containing 4
WHEN
statements
which depend on the value of 4 boolean variables.
The value of the four boolean variables will determine the structure of
the problem to be solved. In this example, those values are dened by
the modeler, but they also could be dened by some logic inference
algorithm which would allow the automatic change of the structure of
the problem.
The following section gives the code for this model. The rst models
correspond to the different types of unit operations existing in the
superstructure. Those model are very simplied. You may want to skip
them and analyze only the model owsheet, in which the use and
syntax of the WHEN statement as well as the conguration of the
superstructure become evident.
16.3 T
HE
C
ODE
As the code is in our ASCEND examples subdirectory, it has header
information that we required of all such les included as one large
comment extending over several lines. Comments are in the form (*
comment *). The last item in this header information is a list of the
les one must load before loading this one, i.e., system.a4l and
atoms.a4l.
34 125
A C
ONDITIONAL
M
ODELING
E
XAMPLE
: R
EPRESENTING A
Last modified: June 20, 1998 10:59 pm
REQUIRE "atoms.a4l";
35
(* --> measures,system *)
36
PROVIDE "when_demo.a4c";
37
(*********************************************************************\
38
when_demo.a4c
39
by Vicente Rico-Ramirez
40
Part of the Ascend Library
41
42
This file is part of the Ascend modeling library.
43
44
The Ascend modeling library is free software; you can redistribute
45
it and/or modify it under the terms of the GNU General Public License as
46
published by the Free Software Foundation; either version 2 of the
47
License, or (at your option) any later version.
48
49
The Ascend Language Interpreter is distributed in hope that it will be
50
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
51
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
52
General Public License for more details.
53
54
You should have received a copy of the GNU General Public License along with55
the program; if not, write to the Free Software Foundation, Inc., 675
56
Mass Ave, Cambridge, MA 02139 USA. Check the file named COPYING.
57
58
Use
of this module is demonstrated by the associated script file
59
when_demo.a4s.
60
\*********************************************************************)
61
62
(*********************************************************************\
63
$Date: 1998/05/14 21:39:44 $
64
$Revision: 1.5 $
65
$Author: rv2a $
66
$Source: /afs/cs.cmu.edu/project/ascend/Repository/models/when_demo.a4c,v $67
\*********************************************************************)
68
69
(*
70
This model is intended to demonstrate the degree of flexibility
71
that the use of conditional statements -when statement- provides
72
to the representation of superstructures. We hope that this
73
application
will become clear by looking at the MODEL flowsheet,
74
in which the existence/nonexistence of some of the unit operations
75
is represented by when statements. A particular combination of
76
user defined boolean variables -see method values, configuration2,
77
configuration3- will a define a particular configuration of the
78
problem.
79
80 T
HE
C
ODE
126
/afs/cs.cmu.edu/project/edrc-ascend7/DOCS/Help/when_model.fm5
This model requires:
81
"system.a4l"
82
"atoms.a4l"
83
*)
84
85
(* ************************************************* *)
86
87
MODEL mixture;
88
89
components
IS_A set OF symbol_constant;
90
Cpi[components]
IS_A heat_capacity;
91
y[components]
IS_A fraction;
92
P
IS_A pressure;
93
T
IS_A temperature;
94
Cp
IS_A heat_capacity;
95
96
97
SUM[y[i] | i IN components] = 1.0;
98
Cp = SUM[Cpi[i] * y[i] | i IN components];
99
100
METHODS
101
102
METHOD default_self;
103
END default_self;
104
105
METHOD specify;
106
Cpi[components].fixed := TRUE;
107
P.fixed := TRUE;
108
T.fixed := TRUE;
109
y[components].fixed := TRUE;
110
y[CHOICE[components]].fixed := FALSE;
111
END specify;
112
113
END mixture;
114
115
116
(* ************************************************* *)
117
118
MODEL molar_stream;
119
state
IS_A mixture;
120
Ftot,f[components]
IS_A molar_rate;
121
components
IS_A set OF symbol_constant;
122
P
IS_A pressure;
123
T
IS_A temperature;
124
Cp
IS_A heat_capacity;
125
126 127
A C
ONDITIONAL
M
ODELING
E
XAMPLE
: R
EPRESENTING A
Last modified: June 20, 1998 10:59 pm
components, state.components
ARE_THE_SAME;
127
P, state.P
ARE_THE_SAME;
128
T, state.T
ARE_THE_SAME;
129
Cp, state.Cp
ARE_THE_SAME;
130
131
FOR i IN components CREATE
132