/[ascend]/trunk/doc/syntax.lyx
ViewVC logotype

Annotation of /trunk/doc/syntax.lyx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1384 - (hide annotations) (download) (as text)
Fri Apr 6 16:15:11 2007 UTC (17 years, 7 months ago) by jpye
File MIME type: application/x-lyx
File size: 177739 byte(s)
Some work on the formatting. Some editing out of old comments about 'new ascend 4'
1 jpye 1384 #LyX 1.4.3 created this file. For more info see http://www.lyx.org/
2 johnpye 828 \lyxformat 245
3     \begin_document
4     \begin_header
5     \textclass book
6     \begin_preamble
7     \usepackage[bookmarks]{hyperref}
8     \usepackage{lmodern}
9     \end_preamble
10     \language english
11     \inputencoding auto
12     \fontscheme default
13     \graphics default
14     \paperfontsize default
15     \spacing single
16     \papersize default
17     \use_geometry false
18     \use_amsmath 1
19     \cite_engine basic
20     \use_bibtopic false
21     \paperorientation portrait
22     \secnumdepth 3
23     \tocdepth 3
24     \paragraph_separation indent
25     \defskip medskip
26     \quotes_language english
27     \papercolumns 1
28     \papersides 1
29     \paperpagestyle default
30     \tracking_changes false
31     \output_changes false
32     \end_header
33    
34     \begin_body
35    
36     \begin_layout Chapter
37 jpye 1384 Syntax reference
38 johnpye 828 \begin_inset LatexCommand \label{cha:ASCENDSyntax}
39    
40     \end_inset
41    
42    
43     \end_layout
44    
45     \begin_layout Standard
46     We shall present an informal description of the ASCEND IV language.
47     Being informal, we shall usually include examples and descriptions of the
48     intended semantics along with the syntax of the items.
49     At times the inclusion of semantics will seem to anticipate later definitions.
50     We do this because we would also like this chapter to be used as a reference
51     for the ASCEND language even after one generally understands it.
52     Often one will need to clarify a point about a particular item and will
53     not wish to have to search in several places to do so.
54     \end_layout
55    
56     \begin_layout Standard
57     Syntax
58     \begin_inset LatexCommand \index{syntax}
59    
60     \end_inset
61    
62     is the form or structure for the statements in ASCEND, where one worries
63     about the exact words one uses, their ordering, the punctuation, etc.
64     Semantics
65     \begin_inset LatexCommand \index{semantics}
66    
67     \end_inset
68    
69     describe the meaning of a statement.
70     \end_layout
71    
72     \begin_layout Standard
73     To distinguish between syntax and semantics, consider the statement
74     \end_layout
75    
76     \begin_layout LyX-Code
77     y IS_A fraction;
78     \end_layout
79    
80     \begin_layout Standard
81     Rules on the syntax for this statement tell us we need a user supplied instance
82     name, y, followed by the ASCEND operator IS_A, followed by a type name
83     (fraction).
84     The statement terminates with a semicolon.
85     The statement semantics says we are declaring the existence of an instance,
86     locally named y, of the type fraction as a part within the current model
87     definition and it is to be constructed when an instance of the current
88     model definition is constructed.
89     \end_layout
90    
91     \begin_layout Standard
92     The syntax for a computer language is often defined by using a Bachus-Naur
93     \begin_inset LatexCommand \index{Bachus-Naur}
94    
95     \end_inset
96    
97     formal (BNF
98     \begin_inset LatexCommand \index{BNF}
99    
100     \end_inset
101    
102     ) description.
103     The complete YACC
104     \begin_inset LatexCommand \index{YACC}
105    
106     \end_inset
107    
108     and FLEX
109     \begin_inset LatexCommand \index{FLEX}
110    
111     \end_inset
112    
113     description of the language described (as presently implemented) is available
114     by FTP and via the World Wide Web.
115     The semantics of a very high level modeling language such as ASCEND IV
116     are generally much more restrictive than the syntax.
117     For this reason we do not include a BNF description in this paper.
118     ASCEND IV is an experiment.
119     The language is under constant scrutiny and improvement, so this document
120     is under constant revision.
121    
122     \end_layout
123    
124     \begin_layout List
125     \labelwidthstring 00000.00000.00000.000
126     \InsetSpace ~
127    
128     \end_layout
129    
130     \begin_deeper
131 jpye 1384 \begin_layout Chapter
132 johnpye 828 Preliminaries
133     \end_layout
134    
135     \begin_layout Standard
136     We will start off with some background information and some tips that make
137     the rest of the chapter easier to read.
138     ASCEND is an object-oriented (OO) language for hierarchical modeling that
139     has been somewhat specialized for mathematical models.
140     Most of the specialization is in the implementation and the user interface
141     rather than the language definition.
142    
143     \end_layout
144    
145     \begin_layout Standard
146     We feel the single most distinguishing feature of mathematical models is
147     that solving them efficiently requires that the solving algorithms be able
148     to address the entire problem either simultaneously or in a decomposition
149     of the natural problem structure that the algorithm determines is best
150     for the machine(s) in use.
151     In the ASCEND language object-orientation is used to organize natural structure
152     s and make them easier to understand.
153     It is not used to hide the details of the objects.
154     The user (or machine) is free to ignore uninteresting details, and the
155     ASCEND environment provides tools for the runtime suppression of these.
156     \end_layout
157    
158     \begin_layout Standard
159     ASCEND is well into its 4th generation.
160     Some features we will describe are not yet implemented (some merely speculative
161     ) and these are clearly marked (* 4+ *).
162     Any feature not marked (* 4+ *)has been completely implemented, and thus
163     any mismatch between the description given here and the software we distribute
164     is a bug we want you to tell us about.
165    
166     \end_layout
167    
168     \begin_layout Standard
169     The syntax and semantics of ASCEND may seem at first a bit unusual.
170     However, do not be afraid to just try what comes naturally if what we write
171     here is unclear.
172     The parser and compiler of ASCEND IV really will help you get things right.
173     Of course if what we write here is unclear, please ask us about it because
174     we aim to continuously improve both this document and the language system
175     it describes.
176     \end_layout
177    
178     \begin_layout Standard
179     We will describe, starting in Section
180     \begin_inset LatexCommand \vref{sub:x.1.2Basic-Elements}
181    
182     \end_inset
183    
184     , the higher level concepts of ASCEND, but first some important punctuation
185     rules.
186     \end_layout
187    
188     \end_deeper
189     \begin_layout List
190     \labelwidthstring 00000.00000.00000.000
191     ASCEND\InsetSpace ~
192     is\InsetSpace ~
193     cAsE\InsetSpace ~
194     sensitive
195     \begin_inset LatexCommand \index{case sensitive}
196    
197     \end_inset
198    
199     !
200     \end_layout
201    
202     \begin_deeper
203     \begin_layout Standard
204     The keywords that are shown capitalized (or in lower case) in this chapter
205     are that way because ASCEND is case sensitive.
206     IS_A is an ASCEND keyword; isa, Is_a, and all the other permutations you
207     can think of are NOT equivalent to IS_A.
208     In declaring new types of models and variables the user is free to use
209     any style of capitalization he or she may prefer; however, they must remain
210     consistent or undefined types and instances will result.
211     \end_layout
212    
213     \begin_layout Standard
214     This case restriction makes our code very readable, but hard to type without
215     a smart editor.
216     We have kept the case-sensitivity because, like all mathematicians, we
217     find ourselves running out of good variable names if we are restricted
218     to a 26 letter alphabet.
219     We have developed smart add-ins for two UNIX editors, EMACS
220     \begin_inset LatexCommand \index{EMACS}
221    
222     \end_inset
223    
224     and vi
225     \begin_inset LatexCommand \index{vi}
226    
227     \end_inset
228    
229     , for handling the upper case keywords and some other syntax elements.
230     The use of these editors is described in another chapter.
231    
232     \end_layout
233    
234     \begin_layout Standard
235     The ASCEND IV parser is very picky and pedantic.
236     It also tries to give helpful messages and occasionally even suggestions.
237     New users should just dive in and make errors, letting the system help
238     them learn how to avoid errors.
239     \end_layout
240    
241 jpye 1384 \begin_layout Section
242 johnpye 828 Punctuation
243     \begin_inset LatexCommand \index{punctuation}
244    
245     \end_inset
246    
247    
248     \end_layout
249    
250 jpye 1384 \end_deeper
251 johnpye 828 \begin_layout Standard
252     This section covers both the punctuation that must be understood to read
253     this document and the punctuation of ASCEND code.
254     \end_layout
255    
256     \begin_layout List
257     \labelwidthstring 00000.00000.00000.000
258     keywords
259     \begin_inset LatexCommand \index{keywords}
260    
261     \end_inset
262    
263     : ASCEND keywords and type names are given in the left column in bold format.
264     It is generally clear from the main text which are keywords and which are
265     type names.
266     \end_layout
267    
268     \begin_layout List
269     \labelwidthstring 00000.00000.00000.000
270    
271     \bar under
272     Minor\InsetSpace ~
273     items:
274     \bar default
275     Minor headings that are helpful in finding details are given in the left
276     column in underline format.
277     \end_layout
278    
279     \begin_layout List
280     \labelwidthstring 00000.00000.00000.000
281     Tips: Special notes and hints are sometimes placed on the left.
282     \end_layout
283    
284     \begin_layout List
285     \labelwidthstring 00000.00000.00000.000
286    
287     \bar under
288     LHS
289     \begin_inset LatexCommand \index{LHS}
290    
291     \end_inset
292    
293     :
294     \bar default
295     Left Hand Side.
296     Abbreviation used frequently.
297     \end_layout
298    
299     \begin_layout List
300     \labelwidthstring 00000.00000.00000.000
301    
302     \bar under
303     RHS
304     \begin_inset LatexCommand \index{RHS}
305    
306     \end_inset
307    
308     :
309     \bar default
310     Right Hand Side.
311     Abbreviation used frequently.
312     \end_layout
313    
314     \begin_layout List
315     \labelwidthstring 00000.00000.00000.000
316    
317     \bar under
318     Simple\InsetSpace ~
319     names
320     \begin_inset LatexCommand \index{simple names}
321    
322     \end_inset
323    
324     :
325     \bar default
326     In ASCEND simple names are made of the characters a through z, A through
327     Z, _, (*4+*: $).
328     The underscore is used as a letter, but it cannot be the first letter in
329     a name.
330     The $
331     \begin_inset LatexCommand \index{\$}
332    
333     \end_inset
334    
335     character is used exclusively as the first character in the name of system
336     defined built-in parts.
337     "$" is explained in more detail in Section
338     \begin_inset LatexCommand \vref{sub:x.6.2Supported-attributes}
339    
340     \end_inset
341    
342     .
343     Simple names should be no more than 80 characters long.
344    
345     \end_layout
346    
347     \begin_layout List
348     \labelwidthstring 00000.00000.00000.000
349    
350     \bar under
351     Compound\InsetSpace ~
352     names
353     \begin_inset LatexCommand \index{compound names}
354    
355     \end_inset
356    
357     :
358     \bar default
359     Compound names are simple names strung together with dots (.).
360     See the description of "." below.
361     \end_layout
362    
363     \begin_layout List
364     \labelwidthstring 00000.00000.00000.000
365    
366     \bar under
367     Groupings:
368     \end_layout
369    
370     \begin_layout List
371     \labelwidthstring 00000.00000.00000.000
372    
373     \bar under
374     «\InsetSpace ~
375     »
376     \bar default
377 jpye 1384 In documentation
378     \series bold
379     optional fields
380     \series default
381    
382 johnpye 828 \begin_inset LatexCommand \index{optional fields}
383    
384     \end_inset
385    
386     are surrounded by these markers.
387     \end_layout
388    
389     \begin_layout List
390     \labelwidthstring 00000.00000.00000.000
391 jpye 1384
392     \family typewriter
393 johnpye 828 (*\InsetSpace ~
394     *)
395 jpye 1384 \family default
396    
397 johnpye 828 \begin_inset LatexCommand \index{(* *)}
398    
399     \end_inset
400    
401     Comment.
402 jpye 1384 Anything inside these is a comment.
403     Comments can nest
404 johnpye 828 \begin_inset LatexCommand \index{nest}
405    
406     \end_inset
407    
408 jpye 1384 in ASCEND and span several lines.
409 johnpye 828 \end_layout
410    
411     \begin_layout List
412     \labelwidthstring 00000.00000.00000.000
413 jpye 1384
414     \family typewriter
415 johnpye 828 (\InsetSpace ~
416     )
417 jpye 1384 \family default
418    
419 johnpye 828 \begin_inset LatexCommand \index{( )}
420    
421     \end_inset
422    
423     Rounded parentheses
424     \begin_inset LatexCommand \index{parentheses}
425    
426     \end_inset
427    
428    
429     \begin_inset LatexCommand \index{rounded parentheses}
430    
431     \end_inset
432    
433     .
434     Used to enclose arguments for functions or models where the order of the
435     arguments matters.
436     Also used to group terms in complex arithmetic, logical, or set expressions
437     where the order of operations needs to be specified.
438    
439     \end_layout
440    
441     \begin_layout List
442     \labelwidthstring 00000.00000.00000.000
443     Efficiency\InsetSpace ~
444     tip: The compiler can simplify relation definitions in a particularly
445     efficient manner if constants are grouped together.
446     \end_layout
447    
448     \begin_layout List
449     \labelwidthstring 00000.00000.00000.000
450 jpye 1384
451     \family typewriter
452 johnpye 828 {\InsetSpace ~
453     }
454 jpye 1384 \family default
455    
456 johnpye 828 \begin_inset LatexCommand \index{{ }}
457    
458     \end_inset
459    
460     Curly braces
461     \begin_inset LatexCommand \index{Curly braces}
462    
463     \end_inset
464    
465     .
466     Used to enclose units.
467     For example, 1 {kg_mole/s}.
468     Also used to enclose the body of annotations.
469     Note: Curly braces are also used in TCL, the language of the ASCEND user
470     interface, about which we will say more in another chapter.
471     \end_layout
472    
473     \begin_layout List
474     \labelwidthstring 00000.00000.00000.000
475 jpye 1384
476     \family typewriter
477 johnpye 828 [\InsetSpace ~
478     ]
479 jpye 1384 \family default
480    
481 johnpye 828 \begin_inset LatexCommand \index{[ ]}
482    
483     \end_inset
484    
485     Square brackets
486     \begin_inset LatexCommand \index{square brackets}
487    
488     \end_inset
489    
490     .
491     Used to enclose sets or elements of sets.
492     Examples: my_integer_set :== [1,2,3], demonstrates the use of square brackets
493     in the assignment of a set.
494     My_array[1] demonstrates the use of square brackets in naming an array
495     object indexed over an integer set which includes the element 1.
496     \end_layout
497    
498     \begin_layout List
499     \labelwidthstring 00000.00000.00000.000
500 jpye 1384
501     \family typewriter
502 johnpye 828 .
503 jpye 1384 \family default
504    
505 johnpye 828 \begin_inset LatexCommand \index{.}
506    
507     \end_inset
508    
509     Dot
510     \begin_inset LatexCommand \index{dot}
511    
512     \end_inset
513    
514     .
515     The dot is used, as in PASCAL and C, to construct the names of nested objects.
516     Examples: if object a has a part b, then the way to refer to b is as a.b.
517     Tray[1].vle shows a dot following a square bracket; here Tray[1] has a part
518     named vle.
519     \end_layout
520    
521     \begin_layout List
522     \labelwidthstring 00000.00000.00000.000
523 jpye 1384
524     \family typewriter
525 johnpye 828 ..
526 jpye 1384 \family default
527    
528 johnpye 828 \begin_inset LatexCommand \index{..}
529    
530     \end_inset
531    
532     Dot-dot or double dot
533     \begin_inset LatexCommand \index{double dot}
534    
535     \end_inset
536    
537     .
538     Integer range shorthand.
539     For example, my_integer_set :== [1,2,3] and my_integer_set :== [1..3] are
540     equivalent.
541     If ..
542     appears in a context requiring (), such as the ALIASES/IS_A statement,
543     then the range is expanded and ordered as we would naturally expect.
544     \end_layout
545    
546     \begin_layout List
547     \labelwidthstring 00000.00000.00000.000
548 jpye 1384
549     \family typewriter
550 johnpye 828 :
551 jpye 1384 \family default
552    
553 johnpye 828 \begin_inset LatexCommand \index{:}
554    
555     \end_inset
556    
557     Colon
558     \begin_inset LatexCommand \index{colon}
559    
560     \end_inset
561    
562     .
563     A separator used in various ways, principally to set the name of an arithmetic
564     relation apart from the definition.
565     \end_layout
566    
567     \begin_layout List
568     \labelwidthstring 00000.00000.00000.000
569 jpye 1384
570     \family typewriter
571 johnpye 828 ::
572 jpye 1384 \family default
573    
574 johnpye 828 \begin_inset LatexCommand \index{::}
575    
576     \end_inset
577    
578     Double colon
579     \begin_inset LatexCommand \index{double colon}
580    
581     \end_inset
582    
583     .
584     A separator used in the methods section for accessing methods defined on
585     types other than the type the method is part of.
586     Explained in Section
587     \begin_inset LatexCommand \vref{sec:x.4Procedural-statements}
588    
589     \end_inset
590    
591     .[
592     \end_layout
593    
594     \begin_layout List
595     \labelwidthstring 00000.00000.00000.000
596 jpye 1384
597     \family typewriter
598 johnpye 828 ;
599 jpye 1384 \family default
600    
601 johnpye 828 \begin_inset LatexCommand \index{;}
602    
603     \end_inset
604    
605     Semicolon
606     \begin_inset LatexCommand \index{semicolon}
607    
608     \end_inset
609    
610     .
611     The separator of statements.
612     \end_layout
613    
614     \begin_deeper
615 jpye 1384 \begin_layout Section
616 johnpye 828 Basic Elements
617     \begin_inset LatexCommand \index{basic elements}
618    
619     \end_inset
620    
621    
622     \begin_inset LatexCommand \label{sub:x.1.2Basic-Elements}
623    
624     \end_inset
625    
626    
627     \end_layout
628    
629     \end_deeper
630     \begin_layout List
631     \labelwidthstring 00000.00000.00000.000
632    
633     \bar under
634     Boolean\InsetSpace ~
635     value
636     \bar default
637    
638     \begin_inset LatexCommand \index{value, Boolean}
639    
640     \end_inset
641    
642    
643     \begin_inset LatexCommand \index{Boolean value}
644    
645     \end_inset
646    
647 jpye 1384
648     \family sans
649     TRUE
650     \family default
651    
652 johnpye 828 \begin_inset LatexCommand \index{TRUE}
653    
654     \end_inset
655    
656 jpye 1384 or
657     \family sans
658     FALSE
659     \family default
660    
661 johnpye 828 \begin_inset LatexCommand \index{FALSE}
662    
663     \end_inset
664    
665     .
666 jpye 1384 Can't get much simpler, eh? In the language definition
667     \family sans
668     TRUE
669     \family default
670     and
671     \family sans
672     FALSE
673     \family default
674     do not map to 1 and 0 or any other type of numeric value.
675 johnpye 828 (In the implementation, of course, they do.)
676     \end_layout
677    
678     \begin_layout List
679     \labelwidthstring 00000.00000.00000.000
680     User\InsetSpace ~
681     interface\InsetSpace ~
682     tip: The ASCEND user interface programmers have found it very
683     convenient, however, to allow T/F, 1/0, Y/N, and other obvious boolean
684     conventions as interactive input when assigning boolean values.
685     We are lazy users.
686     \end_layout
687    
688     \begin_layout List
689     \labelwidthstring 00000.00000.00000.000
690    
691     \bar under
692     Integer\InsetSpace ~
693     value
694     \bar default
695    
696     \begin_inset LatexCommand \index{value, integer}
697    
698     \end_inset
699    
700    
701     \begin_inset LatexCommand \index{integer value}
702    
703     \end_inset
704    
705     A signed whole number up to the maximum that can be represented by the
706     computer on which one is running ASCEND.
707 jpye 1384
708     \family sans
709     MAX_INTEGER
710     \family default
711    
712 johnpye 828 \begin_inset LatexCommand \index{MAX\_INTEGER}
713    
714     \end_inset
715    
716     is machine dependent.
717     Examples are:
718     \end_layout
719    
720     \begin_deeper
721     \begin_layout LyX-Code
722     \align block
723     123
724     \end_layout
725    
726     \begin_layout LyX-Code
727     \align block
728     -5
729     \end_layout
730    
731     \begin_layout LyX-Code
732     \align block
733     MAX_INTEGER, typically 2147483647.
734     \end_layout
735    
736     \end_deeper
737     \begin_layout List
738     \labelwidthstring 00000.00000.00000.000
739    
740     \bar under
741     Real\InsetSpace ~
742     value
743     \bar default
744    
745     \begin_inset LatexCommand \index{value. real}
746    
747     \end_inset
748    
749    
750     \begin_inset LatexCommand \index{real value}
751    
752     \end_inset
753    
754     ASCEND represents reals almost exactly as any other mathematically oriented
755     programming language does.
756     The mantissa
757     \begin_inset LatexCommand \index{mantissa}
758    
759     \end_inset
760    
761     has an optional negative sign followed by a string of digits and at most
762     one decimal point.
763 jpye 1384 The exponent is the letter
764     \family typewriter
765     e
766     \family default
767     or
768     \family typewriter
769     E
770     \family default
771     followed by an integer.
772 johnpye 828 The number must not exceed the largest the computer is able to handle.
773     There can be no blank characters in a real.
774 jpye 1384
775     \family sans
776     MAX_REAL
777     \family default
778    
779 johnpye 828 \begin_inset LatexCommand \index{MAX\_REAL}
780    
781     \end_inset
782    
783     is machine dependent.
784     The following are legitimate reals in ASCEND:
785     \end_layout
786    
787     \begin_deeper
788     \begin_layout LyX-Code
789     \align block
790     -1
791     \end_layout
792    
793     \begin_layout LyX-Code
794     \align block
795     1.2
796     \end_layout
797    
798     \begin_layout LyX-Code
799     \align block
800     1.3e-2
801     \end_layout
802    
803     \begin_layout LyX-Code
804     \align block
805     7.888888e+34
806     \end_layout
807    
808     \begin_layout LyX-Code
809     \align block
810     .6E21
811     \end_layout
812    
813     \begin_layout LyX-Code
814     \align block
815     MAX_REAL, typically about 1.79E+308.
816     \end_layout
817    
818     \begin_layout Standard
819     while the following are not:
820     \end_layout
821    
822     \begin_layout LyX-Code
823     \align block
824     1.
825 jpye 1384 2 (*contains a blank within it*)
826 johnpye 828 \end_layout
827    
828     \begin_layout LyX-Code
829     \align block
830     1.3e2.0 (*exponent has a decimal in it*)
831     \end_layout
832    
833 jpye 1384 \begin_layout LyX-Code
834    
835     \family typewriter
836     +1.3 (* illegal unary + sign.
837 johnpye 828 x = +1.3 not allowed*)
838     \end_layout
839    
840     \end_deeper
841     \begin_layout List
842     \labelwidthstring 00000.00000.00000.000
843    
844     \bar under
845     Reals\InsetSpace ~
846     stored\InsetSpace ~
847     in\InsetSpace ~
848     SI
849     \begin_inset LatexCommand \index{SI}
850    
851     \end_inset
852    
853     \InsetSpace ~
854     units
855     \bar default
856    
857     \end_layout
858    
859     \begin_deeper
860     \begin_layout Standard
861     We store all real values as double precision
862     \begin_inset LatexCommand \index{double precision}
863    
864     \end_inset
865    
866 jpye 1384 numbers in the metre-kilogram-second (MKS)
867 johnpye 828 \begin_inset LatexCommand \index{MKS}
868    
869     \end_inset
870    
871     system of units.
872     This eliminates many common errors in the modeling of physical systems.
873     Since we also place the burden of scaling equations on system routines
874     and a simple modeling methodology, the internal units are not of concern
875     to most users.
876     \end_layout
877    
878     \end_deeper
879     \begin_layout List
880     \labelwidthstring 00000.00000.00000.000
881    
882     \bar under
883     Dimensionality
884     \begin_inset LatexCommand \index{dimensionality}
885    
886     \end_inset
887    
888     :
889     \bar default
890     Real values have dimensionality such as length/time for velocity.
891 jpye 1384
892     \series bold
893     Dimensionality
894     \series default
895     is to be distinguished from the
896     \series bold
897     units
898     \series default
899     such as ft/s.
900 johnpye 828 ASCEND takes care of mapping between units
901     \begin_inset LatexCommand \index{units}
902    
903     \end_inset
904    
905     and dimensions.
906     A value without units (this includes integer values) is taken to be dimensionle
907     ss
908     \begin_inset LatexCommand \index{dimensionless}
909    
910     \end_inset
911    
912     .
913     Dimensionality is built up from the following base dimensions:
914     \end_layout
915    
916     \begin_layout List
917     \labelwidthstring 00000.00000.00000.000
918     Name
919     \bar under
920     definition; typical units
921     \end_layout
922    
923     \begin_layout List
924     \labelwidthstring 00000.00000.00000.000
925     L
926     \begin_inset LatexCommand \index{L, length dimension}
927    
928     \end_inset
929    
930     length
931     \begin_inset LatexCommand \index{length}
932    
933     \end_inset
934    
935 jpye 1384 ; metre, m
936 johnpye 828 \end_layout
937    
938     \begin_layout List
939     \labelwidthstring 00000.00000.00000.000
940     M
941     \begin_inset LatexCommand \index{M, mass dimension}
942    
943     \end_inset
944    
945     mass
946     \begin_inset LatexCommand \index{mass}
947    
948     \end_inset
949    
950     ; kilogram, kg
951     \end_layout
952    
953     \begin_layout List
954     \labelwidthstring 00000.00000.00000.000
955     T
956     \begin_inset LatexCommand \index{T, time dimension}
957    
958     \end_inset
959    
960     time
961     \begin_inset LatexCommand \index{time}
962    
963     \end_inset
964    
965     ; second, s
966     \end_layout
967    
968     \begin_layout List
969     \labelwidthstring 00000.00000.00000.000
970     E
971     \begin_inset LatexCommand \index{E, electric current dimension}
972    
973     \end_inset
974    
975     electric current
976     \begin_inset LatexCommand \index{electric current}
977    
978     \end_inset
979    
980     ; ampere, A
981     \end_layout
982    
983     \begin_layout List
984     \labelwidthstring 00000.00000.00000.000
985     Q
986     \begin_inset LatexCommand \index{Q, quantity dimension}
987    
988     \end_inset
989    
990     quantity
991     \begin_inset LatexCommand \index{quantity}
992    
993     \end_inset
994    
995     ; mole, mole
996     \end_layout
997    
998     \begin_layout List
999     \labelwidthstring 00000.00000.00000.000
1000     TMP
1001     \begin_inset LatexCommand \index{TMP, temperature dimension}
1002    
1003     \end_inset
1004    
1005     temperature
1006     \begin_inset LatexCommand \index{temperature}
1007    
1008     \end_inset
1009    
1010     ; Kelvin, K
1011     \end_layout
1012    
1013     \begin_layout List
1014     \labelwidthstring 00000.00000.00000.000
1015     LUM
1016     \begin_inset LatexCommand \index{LUM, luminous intensity dimension}
1017    
1018     \end_inset
1019    
1020     luminous intensity
1021     \begin_inset LatexCommand \index{luminous intensity}
1022    
1023     \end_inset
1024    
1025     ; candela, cd
1026     \end_layout
1027    
1028     \begin_layout List
1029     \labelwidthstring 00000.00000.00000.000
1030     P
1031     \begin_inset LatexCommand \index{P, phase angle dimension}
1032    
1033     \end_inset
1034    
1035     plane angle
1036     \begin_inset LatexCommand \index{plane angle}
1037    
1038     \end_inset
1039    
1040     ; radian, rad
1041     \end_layout
1042    
1043     \begin_layout List
1044     \labelwidthstring 00000.00000.00000.000
1045     S
1046     \begin_inset LatexCommand \index{S, solid angle dimension}
1047    
1048     \end_inset
1049    
1050     solid angle
1051     \begin_inset LatexCommand \index{solid angle}
1052    
1053     \end_inset
1054    
1055     ; steradian, srad
1056     \end_layout
1057    
1058     \begin_layout List
1059     \labelwidthstring 00000.00000.00000.000
1060     C
1061     \begin_inset LatexCommand \index{C, currency dimension}
1062    
1063     \end_inset
1064    
1065     currency
1066     \begin_inset LatexCommand \index{currency}
1067    
1068     \end_inset
1069    
1070     ; currency, CR
1071     \end_layout
1072    
1073     \begin_deeper
1074     \begin_layout Standard
1075     The atom and constant definitions in the library illustrate the use of dimension
1076     ality.
1077     \end_layout
1078    
1079     \begin_layout Standard
1080     Dimensions may be any combination of these symbols along with rounded parenthese
1081 jpye 1384 s, (), and the operators *,
1082     \family typewriter
1083     ^
1084     \family default
1085     and
1086     \family typewriter
1087     /
1088     \family default
1089     .
1090     Examples include
1091     \family typewriter
1092     M/T
1093     \family default
1094     or
1095     \family typewriter
1096     M*L^2/T^2/TMP
1097     \family default
1098     {this latter means
1099     \family typewriter
1100     (M*(L^2)/(T^2))/TMP
1101     \family default
1102     }.
1103     The second operand for the to-the-power-of operator,
1104     \family typewriter
1105     ^
1106     \family default
1107     , must be an integer value (e.g., -2 or 3) because fractional powers of dimensiona
1108     l numbers are physically undefined
1109     \begin_inset Note Note
1110     status open
1111    
1112     \begin_layout Standard
1113     although we do seem them occasionally...
1114 johnpye 828 \end_layout
1115    
1116 jpye 1384 \end_inset
1117    
1118     .
1119     \end_layout
1120    
1121 johnpye 828 \begin_layout Standard
1122     If the dimensionality for a real value is undefined, then ASCEND gives it
1123 jpye 1384 a wildcard dimensionality
1124 johnpye 828 \begin_inset LatexCommand \index{wild card dimensionality}
1125    
1126     \end_inset
1127    
1128     .
1129     If ASCEND can later deduce its dimensionality from its use in a model definitio
1130     n it will do so.
1131 jpye 1384 For example consider the real variable
1132     \family typewriter
1133     a
1134     \family default
1135     , suppose
1136     \family typewriter
1137     a
1138     \family default
1139     has wildcard dimensionality,
1140     \family typewriter
1141     b
1142     \family default
1143     has dimensionality of
1144     \family typewriter
1145     L/T
1146     \family default
1147     .
1148 johnpye 828 Then the statement:
1149     \end_layout
1150    
1151     \end_deeper
1152     \begin_layout List
1153     \labelwidthstring 00000.00000.00000.000
1154     Example\InsetSpace ~
1155     of\InsetSpace ~
1156     a\InsetSpace ~
1157     dimensionally\InsetSpace ~
1158     consistent
1159     \begin_inset LatexCommand \index{dimensionally consistent}
1160    
1161     \end_inset
1162    
1163     \InsetSpace ~
1164     equation.
1165    
1166     \end_layout
1167    
1168     \begin_layout List
1169     \labelwidthstring 00000.00000.00000.000
1170     \InsetSpace ~
1171 jpye 1384
1172     \family typewriter
1173     a + b = 3 {ft/s};
1174 johnpye 828 \end_layout
1175    
1176     \begin_deeper
1177     \begin_layout Standard
1178 jpye 1384 requires that
1179     \family typewriter
1180     a
1181     \family default
1182     have the same dimensionality as the other two terms, namely,
1183     \family typewriter
1184     L/T
1185     \family default
1186     .
1187     ASCEND will assign this dimensionality to
1188     \family typewriter
1189     a
1190     \family default
1191     .
1192 johnpye 828 The user will be warned of dimensionally inconsistent equations.
1193     \end_layout
1194    
1195     \end_deeper
1196     \begin_layout List
1197     \labelwidthstring 00000.00000.00000.000
1198    
1199     \bar under
1200     Unit\InsetSpace ~
1201     expression
1202     \bar default
1203     A unit expression
1204     \begin_inset LatexCommand \index{unit expression}
1205    
1206     \end_inset
1207    
1208     may be composed of any combination of unit names defined by the system
1209 jpye 1384 and any numerical constants combined with times (
1210     \family typewriter
1211     *
1212     \family default
1213     ), divide(
1214     \family typewriter
1215     /
1216     \family default
1217     ) and to the power (
1218     \family typewriter
1219     ^
1220     \family default
1221     ) operators.
1222     The RHS of
1223     \family typewriter
1224     ^
1225     \family default
1226     must be an integer.
1227     Parentheses can be used to group subexpressions with the exception that
1228     a divide operator may
1229     \emph on
1230     not
1231     \emph default
1232     be followed by a grouped subexpression.
1233 johnpye 828
1234     \end_layout
1235    
1236     \begin_deeper
1237     \begin_layout Standard
1238 jpye 1384 So,
1239     \family typewriter
1240     {kg/m/s}
1241     \family default
1242     is fine, but
1243     \family typewriter
1244     {kg/(m*s)}
1245     \family default
1246     is not.
1247 johnpye 828 Although the two expressions are mathematically equivalent, it makes the
1248     system programming and output formatting easier to code and faster to execute
1249     if we disallow expressions of the latter sort.
1250     \end_layout
1251    
1252     \begin_layout Standard
1253 jpye 1384 The units understood by the system are defined in the first part of this
1254     manual.
1255 johnpye 828 Note that several units defined are really values of interesting constants
1256     in SI, e.g.
1257 jpye 1384
1258     \family typewriter
1259     R :== 1{GAS_C}
1260     \family default
1261     yields the correct value of the thermodynamic gas constant.
1262 johnpye 828 Users can define additional units.
1263     \end_layout
1264    
1265     \end_deeper
1266     \begin_layout List
1267     \labelwidthstring 00000.00000.00000.000
1268    
1269     \bar under
1270     Units
1271     \bar default
1272    
1273     \begin_inset LatexCommand \index{units}
1274    
1275     \end_inset
1276    
1277 jpye 1384 A Unit expression unit expression must be enclosed in curly braces
1278     \family typewriter
1279     {}
1280     \family default
1281     .
1282 johnpye 828 When a real number is used in a mathematical expression in ASCEND, it must
1283     have a set of units expressed with it.
1284     If it does not, ASCEND assumes the number is dimensionless, which may not
1285     be the intent of the modeler.
1286     An example is shown in the dimensionally consistent equation above where
1287 jpye 1384 the number 3 has the units
1288     \family typewriter
1289     {ft/s}
1290     \family default
1291     associated with it.
1292 johnpye 828
1293     \end_layout
1294    
1295     \begin_deeper
1296     \begin_layout Standard
1297     Examples:
1298     \end_layout
1299    
1300     \begin_layout LyX-Code
1301     \align block
1302     {kg_mole/s/m} same as {(kg_mole/s)/m}
1303     \end_layout
1304    
1305     \begin_layout LyX-Code
1306     \align block
1307     {m^3/yr}
1308     \end_layout
1309    
1310     \begin_layout LyX-Code
1311     \align block
1312     {3/100*ft} same as {0.03*ft}
1313     \end_layout
1314    
1315     \begin_layout LyX-Code
1316     \align block
1317     {s^-1} same as {1/s}
1318     \end_layout
1319    
1320     \begin_layout Standard
1321     Illegal unit examples are
1322     \end_layout
1323    
1324     \begin_layout LyX-Code
1325     \align block
1326     {m/(K*kg_mole)}
1327     \end_layout
1328    
1329     \begin_deeper
1330     \begin_layout Standard
1331     grouped subexpression used in the denominator; should be written {m/K/kg_mole}.
1332     \end_layout
1333    
1334     \end_deeper
1335     \begin_layout LyX-Code
1336     \align block
1337     {m^3.5}
1338     \end_layout
1339    
1340     \begin_deeper
1341     \begin_layout Standard
1342     power of units or dimensions must be integer.
1343     \end_layout
1344    
1345     \end_deeper
1346     \end_deeper
1347     \begin_layout List
1348     \labelwidthstring 00000.00000.00000.000
1349    
1350     \bar under
1351     Symbol\InsetSpace ~
1352     Value
1353     \bar default
1354    
1355     \begin_inset LatexCommand \index{value, symbol}
1356    
1357     \end_inset
1358    
1359    
1360     \begin_inset LatexCommand \index{symbol value}
1361    
1362     \end_inset
1363    
1364     The format for a symbol is that of an arbitrary character string enclosed
1365     between two single quotes.
1366     There is no way to embed a single quote
1367     \begin_inset LatexCommand \index{'}
1368    
1369     \end_inset
1370    
1371    
1372     \begin_inset LatexCommand \index{single quote}
1373    
1374     \end_inset
1375    
1376     in a symbol: we are not in the escape sequence business at this time.
1377     The following are legal symbols in ASCEND:
1378     \end_layout
1379    
1380     \begin_deeper
1381     \begin_layout LyX-Code
1382     'H2O'
1383     \end_layout
1384    
1385     \begin_layout LyX-Code
1386     'r1'
1387     \end_layout
1388    
1389     \begin_layout LyX-Code
1390     'Bill said,foo to whom?'
1391     \end_layout
1392    
1393     \begin_layout Standard
1394     while the following are not legal symbol values:
1395     \end_layout
1396    
1397     \begin_layout LyX-Code
1398     "ethanol" (double quotes not allowed)
1399     \end_layout
1400    
1401     \begin_layout LyX-Code
1402     water (no single quotes given)
1403     \end_layout
1404    
1405     \begin_layout LyX-Code
1406     i cant do this (no embedded quotes)
1407     \end_layout
1408    
1409     \begin_layout Standard
1410     There is an arbitrary upper limit to the number of characters in a symbol
1411     (something like 10,000) so that we may detect a missing close quote in
1412     a bad input file without crashing.
1413     \end_layout
1414    
1415     \end_deeper
1416     \begin_layout List
1417     \labelwidthstring 00000.00000.00000.000
1418     Sets\InsetSpace ~
1419     values
1420     \begin_inset LatexCommand \index{values, set}
1421    
1422     \end_inset
1423    
1424    
1425     \begin_inset LatexCommand \index{set values}
1426    
1427     \end_inset
1428    
1429 jpye 1384 Set values are lists of elements, all of type
1430     \family sans
1431     integer_constant
1432     \family default
1433     or all of type
1434     \family sans
1435     symbol_constant
1436     \family default
1437     , enclosed between square brackets
1438     \family typewriter
1439     []
1440     \family default
1441     .
1442 johnpye 828 The following are examples of sets:
1443     \end_layout
1444    
1445     \begin_deeper
1446     \begin_layout LyX-Code
1447     \align block
1448     ['methane', 'ethane', 'propane']
1449     \end_layout
1450    
1451     \begin_layout LyX-Code
1452     \align block
1453     [1..5, 7, 15]
1454     \end_layout
1455    
1456     \begin_layout LyX-Code
1457     \align block
1458     [2..n_stages]
1459     \end_layout
1460    
1461     \begin_layout LyX-Code
1462     \align block
1463     [1, 4, 2, 1, 16]
1464     \end_layout
1465    
1466     \begin_layout LyX-Code
1467     \align block
1468     []
1469     \end_layout
1470    
1471     \end_deeper
1472     \begin_layout List
1473     \labelwidthstring 00000.00000.00000.000
1474     More\InsetSpace ~
1475     about\InsetSpace ~
1476     sets
1477     \begin_inset LatexCommand \index{sets}
1478    
1479     \end_inset
1480    
1481     \InsetSpace ~
1482     in\InsetSpace ~
1483     Section\InsetSpace ~
1484    
1485     \begin_inset LatexCommand \vref{sub:x.2.2Sets}
1486    
1487     \end_inset
1488    
1489     .
1490     \end_layout
1491    
1492     \begin_deeper
1493     \begin_layout Standard
1494 jpye 1384 The value range
1495     \family typewriter
1496     1..5
1497     \family default
1498     is an allowable shorthand for the integers 1, 2, 3, 4 and 5 while the value
1499     range
1500     \family typewriter
1501     2..n_stages
1502     \family default
1503     (where
1504     \family typewriter
1505     n_stages
1506     \family default
1507     must be of type
1508     \family sans
1509     integer_constant
1510     \family default
1511     ) means all integers from 2 to
1512     \family typewriter
1513     n_stages
1514     \family default
1515     .
1516     If
1517     \family typewriter
1518     n_stages
1519     \family default
1520     is less than 2, then the third set is empty.
1521     The repeated occurrence of
1522     \family typewriter
1523     1
1524     \family default
1525     in the fourth set is ignored.
1526 johnpye 828 The fifth set is the empty set
1527     \begin_inset LatexCommand \index{empty set}
1528    
1529     \end_inset
1530    
1531    
1532     \begin_inset LatexCommand \index{set, empty}
1533    
1534     \end_inset
1535    
1536     .
1537     \end_layout
1538    
1539     \begin_layout Standard
1540     We use the term set in an almost pure mathematical sense.
1541     The elements have no order.
1542     One can only ask two things of a set: (1) if an element is a member of
1543     it and (2) its cardinality
1544     \begin_inset LatexCommand \index{cardinality}
1545    
1546     \end_inset
1547    
1548 jpye 1384 (
1549     \family sans
1550     CARD
1551     \family default
1552    
1553 johnpye 828 \begin_inset LatexCommand \index{CARD}
1554    
1555     \end_inset
1556    
1557 jpye 1384
1558     \family typewriter
1559     (set)
1560     \family default
1561     ).
1562 johnpye 828 Repeated elements used in defining a set are ignored.
1563     The elements of sets cannot themselves be sets in ASCEND; i.e., there can
1564     be no sets of set.
1565     \end_layout
1566    
1567     \end_deeper
1568     \begin_layout List
1569     \labelwidthstring 00000.00000.00000.000
1570     Sets\InsetSpace ~
1571     are\InsetSpace ~
1572     unordered.
1573     A set of integers may appear to be ordered to the modeler as the natural
1574     numbers have an order.
1575     However, it is the user imposing and using the ordering, not ASCEND.
1576     ASCEND sees these integers as elements in the set with NO ordering.
1577     Therefore, there are no operators in ASCEND such as successor or precursor
1578     member of a set.
1579     \end_layout
1580    
1581     \begin_layout List
1582     \labelwidthstring 00000.00000.00000.000
1583    
1584     \bar under
1585     Arrays
1586     \bar default
1587    
1588     \begin_inset LatexCommand \index{arrays}
1589    
1590     \end_inset
1591    
1592     An array is a list of instances indexed over a set, in computer-speak,
1593     an associative array of objects.
1594     The instances are all of the same base type (as that is the only way they
1595     can be defined).
1596     An individual member of a list may later be more refined than the other
1597     members (we shall illustrate that possibility).
1598     The following are arrays in ASCEND.
1599     \end_layout
1600    
1601     \begin_deeper
1602     \begin_layout LyX-Code
1603     \align block
1604     stage[1..n_stages]
1605     \end_layout
1606    
1607     \begin_layout LyX-Code
1608     \align block
1609     y[components]
1610     \end_layout
1611    
1612     \begin_layout LyX-Code
1613     \align block
1614     column[areas][processes]
1615     \end_layout
1616    
1617     \begin_layout Standard
1618     where components, areas and processes are sets.
1619 jpye 1384 For example components could be the set of symbols
1620     \family typewriter
1621     ['ethylene', 'propylene']
1622     \family default
1623     , areas the set of symbols
1624     \family typewriter
1625     ['feed_prep', 'prod_purification']
1626     \family default
1627     while processes could be the set
1628     \family typewriter
1629     ['alcohol_manuf', 'poly_propropylene_manuf']
1630     \family default
1631     .
1632     Note that the third example (
1633     \family typewriter
1634     column
1635     \family default
1636     ) is a list of lists (the way that ASCEND permits a multiply subscripted
1637     array).
1638 johnpye 828
1639     \end_layout
1640    
1641     \begin_layout Standard
1642     The following are elements in the above arrays:
1643     \end_layout
1644    
1645     \begin_layout LyX-Code
1646     stage[1]
1647     \end_layout
1648    
1649     \begin_layout LyX-Code
1650     y['ethylene']
1651     \end_layout
1652    
1653     \begin_layout LyX-Code
1654     column['feed_prep'][alcohol_manuf']
1655     \end_layout
1656    
1657     \begin_layout Standard
1658 jpye 1384 provided that
1659     \family typewriter
1660     n_stages
1661     \family default
1662     is 1 or larger.
1663 johnpye 828
1664     \end_layout
1665    
1666     \begin_layout Standard
1667     There can be any number of subscripts
1668     \begin_inset LatexCommand \index{subscripts}
1669    
1670     \end_inset
1671    
1672     for an array.
1673     We point out, however, that in virtually every application of arrays requiring
1674     more than two subscripts, there is usually a some underlying concept that
1675     is much better modeled as an object than as part of a deeply subscripted
1676     \begin_inset LatexCommand \index{subscripted, deeply}
1677    
1678     \end_inset
1679    
1680    
1681     \begin_inset LatexCommand \index{deeply subscripted}
1682    
1683     \end_inset
1684    
1685     array.
1686     In the following jagged array example, there are really the concepts of
1687     unit operation and stream that would be better understood if made explicit.
1688     \end_layout
1689    
1690     \end_deeper
1691     \begin_layout List
1692     \labelwidthstring 00000.00000.00000.000
1693    
1694     \bar under
1695     Arrays\InsetSpace ~
1696     can\InsetSpace ~
1697     be\InsetSpace ~
1698     jagged
1699     \bar default
1700    
1701     \begin_inset LatexCommand \label{lyx:Arrays-can-be}
1702    
1703     \end_inset
1704    
1705 jpye 1384 Arrays can be sparse
1706 johnpye 828 \begin_inset LatexCommand \index{sparse}
1707    
1708     \end_inset
1709    
1710     or jagged
1711     \begin_inset LatexCommand \index{jagged}
1712    
1713     \end_inset
1714    
1715     .
1716     For example:
1717     \end_layout
1718    
1719     \begin_deeper
1720     \begin_layout LyX-Code
1721     process[1..3] IS_A set OF integer;
1722     \end_layout
1723    
1724     \begin_layout LyX-Code
1725     process[1] :== [2];
1726     \end_layout
1727    
1728     \begin_layout LyX-Code
1729     process[2] :== [7,5,3];
1730     \end_layout
1731    
1732     \begin_layout LyX-Code
1733     process[3] :== [4,6];
1734     \end_layout
1735    
1736     \begin_layout LyX-Code
1737     FOR i in [1..3] CREATE
1738     \end_layout
1739    
1740     \begin_layout LyX-Code
1741     FOR j IN process[i] CREATE
1742     \end_layout
1743    
1744     \begin_layout LyX-Code
1745     flow[i][j] IS_A mass;
1746     \end_layout
1747    
1748     \begin_layout LyX-Code
1749     END FOR;
1750     \end_layout
1751    
1752     \begin_layout LyX-Code
1753     END FOR;
1754     \end_layout
1755    
1756     \begin_layout Standard
1757     process is an array of sets (not to be confused with a set of sets which
1758     ASCEND does not have) and flow is an array with six elements spread over
1759     three rows:
1760     \end_layout
1761    
1762     \begin_layout LyX-Code
1763     flow[1][2]
1764     \end_layout
1765    
1766     \begin_layout LyX-Code
1767     flow[2][7], flow[2][3], flow[2][5]
1768     \end_layout
1769    
1770     \begin_layout LyX-Code
1771     flow[3][4], flow[3][6]
1772     \end_layout
1773    
1774     \end_deeper
1775     \begin_layout List
1776     \labelwidthstring 00000.00000.00000.000
1777     Arrays\InsetSpace ~
1778     are\InsetSpace ~
1779     also\InsetSpace ~
1780     instances
1781     \end_layout
1782    
1783     \begin_deeper
1784     \begin_layout Standard
1785     Each array is itself an object.
1786 jpye 1384 That is, when you write
1787     \family typewriter
1788     a[1..2] IS_A real
1789     \family default
1790     , three objects get created:
1791     \family typewriter
1792     a[1]
1793     \family default
1794     ,
1795     \family typewriter
1796     a[2]
1797     \family default
1798     , and
1799     \family typewriter
1800     a
1801     \family default
1802     .
1803     The object
1804     \family typewriter
1805     a
1806     \family default
1807     is an array instance which has parts named
1808     \family typewriter
1809     [1]
1810     \family default
1811     and
1812     \family typewriter
1813     [2]
1814     \family default
1815     that are real instances.
1816 johnpye 828 When a parameterized model requires an array, you pass it the single item
1817 jpye 1384
1818     \family typewriter
1819     a
1820     \family default
1821     , not the elements
1822     \family typewriter
1823     a[1..2]
1824     \family default
1825     .
1826 johnpye 828 \end_layout
1827    
1828     \end_deeper
1829     \begin_layout List
1830     \labelwidthstring 00000.00000.00000.000
1831     No\InsetSpace ~
1832     contiguous\InsetSpace ~
1833     storage
1834     \begin_inset LatexCommand \index{contiguous storage, no}
1835    
1836     \end_inset
1837    
1838    
1839     \end_layout
1840    
1841     \begin_deeper
1842     \begin_layout Standard
1843     Just in case you still have not caught on, ASCEND arrays are not blocks
1844     of memory such as are seen in low-level languages like C
1845     \begin_inset LatexCommand \index{C, computer language}
1846    
1847     \end_inset
1848    
1849     , FORTRAN
1850     \begin_inset LatexCommand \index{FORTRAN}
1851    
1852     \end_inset
1853    
1854     , and Matlab
1855     \begin_inset LatexCommand \index{Matlab}
1856    
1857     \end_inset
1858    
1859     .
1860     The modeling language does not provide things like MatMult
1861     \begin_inset LatexCommand \index{MatMult}
1862    
1863     \end_inset
1864    
1865     , Transpose
1866     \begin_inset LatexCommand \index{Transpose}
1867    
1868     \end_inset
1869    
1870     , and Inverse
1871     \begin_inset LatexCommand \index{Inverse}
1872    
1873     \end_inset
1874    
1875     because these are procedural solving tools.
1876     If you are dedicated, you could write METHODs that implement matrix algebra,
1877     but this is a really dumb idea.
1878     We aim to structure our software so that it can interact openly with separate,
1879     dedicated tools (such as Matlab) when those tools are needed.
1880     \end_layout
1881    
1882     \end_deeper
1883     \begin_layout List
1884     \labelwidthstring 00000.00000.00000.000
1885     Index\InsetSpace ~
1886     variable
1887     \begin_inset LatexCommand \index{index variable}
1888    
1889     \end_inset
1890    
1891     One can introduce a variable as an index ranging over a set.
1892     Index variables are local to the statements in which they occur.
1893     An example of using an index variable is the following FOR statement:
1894     \end_layout
1895    
1896     \begin_deeper
1897     \begin_layout LyX-Code
1898     FOR i IN components CREATE
1899     \end_layout
1900    
1901     \begin_layout LyX-Code
1902     VLE_equil[i]: y[i] = K[i]*x[i];
1903     \end_layout
1904    
1905     \begin_layout LyX-Code
1906     END FOR;
1907     \end_layout
1908    
1909     \begin_layout Standard
1910     In this example i implicitly is of the same type as the values in the set
1911     components.
1912     If another object i exists in the model containing the FOR loop, it is
1913     ignored while executing the statements in that loop.
1914     This may cause unexpected results and the compiler will generate warnings
1915     about loop index shadowed variables.
1916     \end_layout
1917    
1918     \end_deeper
1919     \begin_layout List
1920     \labelwidthstring 00000.00000.00000.000
1921     Label
1922     \begin_inset LatexCommand \index{label}
1923    
1924     \end_inset
1925    
1926     : One can label statements which define arithmetic relationships (objective
1927     functions, equalities, and inequalities) in ASCEND.
1928     Labeling is highly recommended because it makes models much more readable
1929     and more easily debugged.
1930     Labels are also necessary for relations which are going to be used in condition
1931     al modeling or differentiation functions.
1932     A label is a sequence of alphanumeric characters ending in a colon.
1933     An example of a labeled equation is:
1934     \end_layout
1935    
1936     \begin_deeper
1937     \begin_layout LyX-Code
1938     mass_balance: m_in = m_out;
1939     \end_layout
1940    
1941     \begin_layout Standard
1942     An example of a labeled objective function is:
1943     \end_layout
1944    
1945     \begin_layout LyX-Code
1946     obj1: MAXIMIZE revenue - cost;
1947     \end_layout
1948    
1949     \begin_layout Standard
1950     If a relation is defined within a FOR statement, it must have an array indexed
1951     label so that each instance created using the statement is distinguishable
1952     from the others.
1953     An example is:
1954     \end_layout
1955    
1956     \begin_layout LyX-Code
1957     FOR i IN components CREATE
1958     \end_layout
1959    
1960     \begin_layout LyX-Code
1961     equil[i]: y[i] = K[i]*x[i];
1962     \end_layout
1963    
1964     \begin_layout LyX-Code
1965     END FOR;
1966     \end_layout
1967    
1968     \begin_layout Standard
1969     The ASCEND interactive user interface identifies relationships by their
1970     labels.
1971     If one has not provided such a label, the system generates the label:
1972     \end_layout
1973    
1974     \begin_layout LyX-Code
1975    
1976     \emph on
1977     modelname_equationnumber
1978     \end_layout
1979    
1980     \begin_layout Standard
1981     where modelname and equationnumber are the name of the model and the equation
1982     number in the model.
1983     An example is
1984     \end_layout
1985    
1986     \begin_layout LyX-Code
1987     mixture_14
1988     \end_layout
1989    
1990     \begin_layout Standard
1991     for the unlabeled 14th relation in the mixture definition.
1992     If there is a conflict caused with an existing name, the generated name
1993     has enough letters added after equationnumber to make it a unique name.
1994     Remember that each model in a refinement hierarchy inherits the equations
1995     of its less refined ancestors, so the first equation appearing in the source
1996     code of a refining model may actually be the nth relation in that model.
1997     \end_layout
1998    
1999     \end_deeper
2000     \begin_layout List
2001     \labelwidthstring 00000.00000.00000.000
2002    
2003     \bar under
2004     Lists
2005     \bar default
2006    
2007     \begin_inset LatexCommand \index{lists}
2008    
2009     \end_inset
2010    
2011     Often in a statement one can include a list of names or expression.
2012     A name list is one or more names where multiple list entries are separated
2013     from each other by commas.
2014     Examples of a list of names are:
2015     \end_layout
2016    
2017     \begin_deeper
2018     \begin_layout LyX-Code
2019     \align block
2020     T1, inlet_T, outlet_T
2021     \end_layout
2022    
2023     \begin_layout LyX-Code
2024     \align block
2025     y[components], y_in
2026     \end_layout
2027    
2028     \begin_layout LyX-Code
2029     \align block
2030     stage[1..n_stages]
2031     \end_layout
2032    
2033     \end_deeper
2034     \begin_layout List
2035     \labelwidthstring 00000.00000.00000.000
2036    
2037     \bar under
2038     Ordered\InsetSpace ~
2039     lists
2040     \begin_inset LatexCommand \index{lists, ordered}
2041    
2042     \end_inset
2043    
2044    
2045     \begin_inset LatexCommand \index{ordered lists}
2046    
2047     \end_inset
2048    
2049     :
2050     \bar default
2051     If the ordering of names in a list matters, that list is enclosed in ().
2052     Order matters in: calling externally defined methods or models, calling
2053     most real-valued functions, passing parameters to ASCEND models or methods,
2054     and declaring the controlling parameters that SELECT, SWITCH, and WHEN
2055     statements make decisions on.
2056     \end_layout
2057    
2058     \begin_deeper
2059 jpye 1384 \begin_layout Section
2060 johnpye 828 Basic Concepts
2061     \end_layout
2062    
2063     \end_deeper
2064     \begin_layout List
2065     \labelwidthstring 00000.00000.00000.000
2066    
2067     \bar under
2068     Instances
2069     \begin_inset LatexCommand \index{instances}
2070    
2071     \end_inset
2072    
2073     \InsetSpace ~
2074     and\InsetSpace ~
2075     types
2076     \bar default
2077    
2078     \begin_inset LatexCommand \index{types}
2079    
2080     \end_inset
2081    
2082     This is an opportune time to emphasize the distinction between the terms
2083     instance and type.
2084     A type in ASCEND is what we define when we declare an ASCEND model or atom.
2085     It is the formal definition of the attributes (parts) and attribute default
2086     values that an object will have if it is created using the type definition.
2087     Methods are associated with types.
2088     \end_layout
2089    
2090     \begin_deeper
2091     \begin_layout Standard
2092     In ASCEND there are two meanings (closely related) of an instance.
2093    
2094     \end_layout
2095    
2096     \begin_layout Itemize
2097     An instance is a named part that exists within a type definition.
2098    
2099     \end_layout
2100    
2101     \begin_layout Itemize
2102     An instance is a compiled object.
2103    
2104     \end_layout
2105    
2106     \begin_layout Standard
2107     If one is in the context of the ASCEND interface, the system compiles an
2108     instance of a model type to create an object with which one carries out
2109     computations.
2110     The system requires the user to give a simple name for this simulation
2111     instance.
2112     This name given is then the first part of the qualified name for all the
2113     parts of the compiled object.
2114     \end_layout
2115    
2116     \end_deeper
2117     \begin_layout List
2118     \labelwidthstring 00000.00000.00000.000
2119    
2120     \bar under
2121     Implicit\InsetSpace ~
2122     types
2123     \bar default
2124    
2125     \begin_inset LatexCommand \index{types, implicit}
2126    
2127     \end_inset
2128    
2129    
2130     \begin_inset LatexCommand \index{types, implicit}
2131    
2132     \end_inset
2133    
2134     It is possible to create an instance that does not have a corresponding
2135     type definition in the library.
2136 jpye 1384 The type of such an instance is said to be
2137     \series bold
2138     implicit
2139     \series default
2140    
2141     \begin_inset Foot
2142     status collapsed
2143    
2144     \begin_layout Standard
2145     (Some people use the word
2146     \emph on
2147     anonymous
2148     \emph default
2149    
2150 johnpye 828 \begin_inset LatexCommand \index{type, anonymous}
2151    
2152     \end_inset
2153    
2154    
2155     \begin_inset LatexCommand \index{anonymous type}
2156    
2157     \end_inset
2158    
2159     .
2160     However, no computable type is anonymous and the implicit type of an instance
2161 jpye 1384 is theoretically computable)
2162     \end_layout
2163    
2164     \end_inset
2165    
2166     .
2167 johnpye 828 The simplest example of an implicit type is the type of an instance compiled
2168 jpye 1384 from the built-in definition
2169     \family sans
2170     integer_constant
2171     \family default
2172     .
2173 johnpye 828 For example:
2174     \end_layout
2175    
2176     \begin_deeper
2177     \begin_layout LyX-Code
2178     i, j IS_A integer_constant;
2179     \end_layout
2180    
2181     \begin_layout LyX-Code
2182     i:== 2;
2183     \end_layout
2184    
2185     \begin_layout LyX-Code
2186     j:== 3;
2187     \end_layout
2188    
2189     \begin_layout Standard
2190 jpye 1384 Instances
2191     \family typewriter
2192     i
2193     \family default
2194     and
2195     \family typewriter
2196     j
2197     \family default
2198     , though of the same formal type, are implicit type incompatible because
2199     they have been assigned distinct values.
2200 johnpye 828 \end_layout
2201    
2202     \begin_layout Standard
2203     Instances which are either formally or implicitly type incompatible cannot
2204     be merged.
2205     This will be discussed further in Section
2206     \begin_inset LatexCommand \vref{sec:x.3Declarative-statements}
2207    
2208     \end_inset
2209    
2210     .
2211     \end_layout
2212    
2213     \end_deeper
2214     \begin_layout List
2215     \labelwidthstring 00000.00000.00000.000
2216     Parsing
2217     \begin_inset LatexCommand \index{parsing}
2218    
2219     \end_inset
2220    
2221     Most errors in the declaration of an ASCEND model can be caught at parse
2222     time because the object type of any well-formed name in an ASCEND definition
2223     can be resolved or proved ambiguous.
2224     We cannot prove at parse time whether a specific array element will exist,
2225     but we can know that should such an element exist, it must be of the type
2226     with which the array is defined.
2227    
2228     \end_layout
2229    
2230     \begin_deeper
2231     \begin_layout Standard
2232     Ambiguity is warned about loudly because it is caused by either misspelling
2233     or poor modeling style.
2234     The simplest example of ambiguity follows.
2235     \end_layout
2236    
2237     \begin_layout Standard
2238     Assume a type, stream, and a refinement of stream, heat_stream, which adds
2239 jpye 1384 the new variable
2240     \family typewriter
2241     H
2242     \family default
2243     .
2244 johnpye 828 Now, if we write:
2245     \end_layout
2246    
2247     \begin_layout LyX-Code
2248     MODEL mixer;
2249     \end_layout
2250    
2251     \begin_layout LyX-Code
2252     input[1..2] IS_A stream;
2253     \end_layout
2254    
2255     \begin_layout LyX-Code
2256     output IS_A heat_stream;
2257     \end_layout
2258    
2259     \begin_layout LyX-Code
2260     input[1].H + input[2].H = output.H;
2261     \end_layout
2262    
2263     \begin_layout LyX-Code
2264     END mixer;
2265     \end_layout
2266    
2267     \begin_layout Standard
2268     We see the parser can find the definition of H in the type heat_stream,
2269 jpye 1384 so
2270     \family typewriter
2271     output.H
2272     \family default
2273     is well defined.
2274     The author of the mixer model may intend to refine
2275     \family typewriter
2276     input[1]
2277     \family default
2278     and
2279     \family typewriter
2280     input[2]
2281     \family default
2282 johnpye 828 to be objects of different types, say steam_stream and electric_stream,
2283 jpye 1384 where each defines an
2284     \family typewriter
2285     H
2286     \family default
2287     suitable for use in the equation.
2288     The parser cannot read the authors mind, so it warns that
2289     \family typewriter
2290     input[1].H
2291     \family default
2292     and
2293     \family typewriter
2294     input[2].H
2295     \family default
2296     are ambiguous in the mixer definition.
2297 johnpye 828 The mixer model is not highly reusable except by the author, but sometimes
2298     reusability is not a high priority objective.
2299     The mixer definition is allowed, but it may cause problems in instantiation
2300     if the author has forgotten the assumption that is not explicitly stated
2301     in the model and neglects to refine the input streams appropriately.
2302     \end_layout
2303    
2304     \end_deeper
2305     \begin_layout List
2306     \labelwidthstring 00000.00000.00000.000
2307    
2308     \bar under
2309     Instantiation
2310     \bar default
2311    
2312     \begin_inset LatexCommand \index{instantiation}
2313    
2314     \end_inset
2315    
2316     Creating an simulation based on a type definition is a multi-phase
2317     \begin_inset LatexCommand \index{multi-phase}
2318    
2319     \end_inset
2320    
2321     process called compiling
2322     \begin_inset LatexCommand \index{compiling}
2323    
2324     \end_inset
2325    
2326     (or instantiation).
2327     When an instantiation cannot be completed because some structural parameter
2328     (a symbol_constant, real_constant, boolean_constant, integer_constant,
2329     or set) does not have a value there will be PENDING
2330     \begin_inset LatexCommand \index{PENDING}
2331    
2332     \end_inset
2333    
2334     statements.
2335     The user interface will warn that something is incomplete.
2336     \end_layout
2337    
2338     \begin_deeper
2339     \begin_layout Standard
2340     In phase
2341     \begin_inset LatexCommand \index{phases, compiler}
2342    
2343     \end_inset
2344    
2345     1 all statements that create instance structures or assign constant values
2346     are executed.
2347     This phase theoretically requires an infinite number of passes through
2348     the structural statements of a definition.
2349     We allow a maximum of 5 and have never needed more than 3.
2350     There may be pending statements at the end of phase 1.
2351     The compiler or interface will issue warnings about pending statements,
2352     starting with warnings about unassigned constants.
2353     \end_layout
2354    
2355     \begin_layout Standard
2356     Phase 2 compiles as many real arithmetic relation definitions as possible.
2357     Some relations may be impossible to compile because the constants or sets
2358     they depend on do not have values assigned.
2359     Other relations may be impossible because they reference variables that
2360     do not exist.
2361     This is determined in a single pass.
2362     \end_layout
2363    
2364     \begin_layout Standard
2365     Phase 3 compiles as many logical arithmetic relation definitions as possible.
2366     Some relations may be impossible to compile because the constants or sets
2367     they depend on do not have values assigned.
2368     Other relations may be impossible because they reference real arithmetic
2369     relations that do not exist.
2370     This is determined in a single pass.
2371     \end_layout
2372    
2373     \begin_layout Standard
2374 jpye 1384 Phase 4 compiles as many conditional programming statements (
2375     \family sans
2376     WHEN
2377     \family default
2378     s) as possible.
2379     Some
2380     \family sans
2381     WHEN
2382     \family default
2383     relations may be impossible to compile because the discrete variables,
2384     models, or relations they depend on do not exist.
2385 johnpye 828 This is determined in a single pass.
2386     \end_layout
2387    
2388     \begin_layout Standard
2389     Phase 5 executes the variable defaulting statements made in the declarative
2390 jpye 1384 section of each model
2391     \emph on
2392     if and only if
2393     \emph default
2394     there are no pending statements from phases 1-4 anywhere in the simulation.
2395 johnpye 828 \end_layout
2396    
2397     \end_deeper
2398     \begin_layout List
2399     \labelwidthstring 00000.00000.00000.000
2400     default_self
2401     \begin_inset LatexCommand \index{default\_self}
2402    
2403     \end_inset
2404    
2405     After all phases are done, the method default_self is called in the top-most
2406     model of the simulation, if this method exists.
2407     \end_layout
2408    
2409     \begin_deeper
2410     \begin_layout Standard
2411     The first occurrence of each impossible statement will be explained during
2412     a failed compilation.
2413     Impossible statements include:
2414     \end_layout
2415    
2416     \begin_layout Itemize
2417     Relations containing undefinable variables (often misspellings).
2418     \end_layout
2419    
2420     \begin_layout Itemize
2421     Assignments that are dimensionally inconsistent or containing mismatched
2422     types.
2423     \end_layout
2424    
2425     \begin_layout Itemize
2426     Structure building or modifying statements that refer to model parts which
2427     cannot exist or that require a type-incompatible argument, refinement,
2428     or merge.
2429     \end_layout
2430    
2431 jpye 1384 \begin_layout Chapter
2432 johnpye 828 Data Type Declarations
2433     \begin_inset LatexCommand \index{data type declarations}
2434    
2435     \end_inset
2436    
2437    
2438     \end_layout
2439    
2440     \begin_layout Standard
2441     In the spectrum of OO languages, ASCEND is best considered as being class-based
2442     \begin_inset LatexCommand \index{class-based}
2443    
2444     \end_inset
2445    
2446     , though it is rather more a hybrid.
2447 jpye 1384 We have atom and model definitions, called
2448     \series bold
2449     types
2450     \series default
2451     , and the compiled objects themselves, called
2452     \series bold
2453     instances
2454     \series default
2455     .
2456 johnpye 828 ASCEND instances have a record of what type they were constructed from.
2457     \end_layout
2458    
2459     \end_deeper
2460     \begin_layout List
2461     \labelwidthstring 00000.00000.00000.000
2462    
2463     \bar under
2464     Type\InsetSpace ~
2465     qualifiers
2466     \begin_inset LatexCommand \index{type qualifiers}
2467    
2468     \end_inset
2469    
2470     :
2471     \end_layout
2472    
2473     \begin_layout List
2474     \labelwidthstring 00000.00000.00000.000
2475 jpye 1384
2476     \family sans
2477 johnpye 828 UNIVERSAL
2478 jpye 1384 \family default
2479    
2480 johnpye 828 \begin_inset LatexCommand \index{UNIVERSAL}
2481    
2482     \end_inset
2483    
2484 jpye 1384 Universal is an optional modifier of all
2485     \family sans
2486     ATOM
2487     \family default
2488     ,
2489     \family sans
2490     CONSTANT
2491     \family default
2492     and
2493     \family sans
2494     MODEL
2495     \family default
2496     definitions.
2497     If
2498     \family sans
2499     UNIVERSAL
2500     \family default
2501     precedes the definition, then
2502     \emph on
2503     all
2504     \emph default
2505     instances of that type will actually refer to the first instance of the
2506     type that is created.
2507 johnpye 828 This saves memory and ensures global consistency of data.
2508    
2509     \end_layout
2510    
2511     \begin_deeper
2512     \begin_layout Standard
2513     Examples of universal type definitions are
2514     \end_layout
2515    
2516     \begin_layout LyX-Code
2517     UNIVERSAL MODEL methane
2518     \end_layout
2519    
2520     \begin_layout LyX-Code
2521     REFINES generic_component_model;
2522     \end_layout
2523    
2524     \begin_layout LyX-Code
2525     UNIVERSAL CONSTANT circle_constant
2526     \end_layout
2527    
2528     \begin_layout LyX-Code
2529     REFINES real_constant :== 1{PI};
2530     \end_layout
2531    
2532     \begin_layout LyX-Code
2533     UNIVERSAL ATOM counter_1
2534     \end_layout
2535    
2536     \begin_layout LyX-Code
2537     REFINES integer;
2538     \end_layout
2539    
2540     \end_deeper
2541     \begin_layout List
2542     \labelwidthstring 00000.00000.00000.000
2543     Tip:\InsetSpace ~
2544     Do\InsetSpace ~
2545     not\InsetSpace ~
2546     use\InsetSpace ~
2547 jpye 1384
2548     \family sans
2549     UNIVERSAL
2550     \family default
2551     \InsetSpace ~
2552 johnpye 828 variables\InsetSpace ~
2553     in\InsetSpace ~
2554     relations.
2555     \end_layout
2556    
2557     \begin_deeper
2558     \begin_layout Standard
2559 jpye 1384 It is important to note that, because
2560     \emph on
2561     variables
2562     \emph default
2563     must store information about which relations they occur in, it is a very
2564     bad idea to use
2565     \family sans
2566     UNIVERSAL
2567     \family default
2568     typed variables in relations.
2569 johnpye 828 The construction and maintenance of the relation list becomes very expensive
2570     for universal variables.
2571 jpye 1384
2572     \family sans
2573     UNIVERSAL
2574     \family default
2575    
2576     \emph on
2577     constants
2578     \emph default
2579     are fine to use, though, because there are no relation links for constants.
2580 johnpye 828 \end_layout
2581    
2582 jpye 1384 \begin_layout Section
2583 johnpye 828 Models
2584     \end_layout
2585    
2586     \end_deeper
2587     \begin_layout List
2588     \labelwidthstring 00000.00000.00000.000
2589 jpye 1384
2590     \family sans
2591 johnpye 828 MODEL
2592 jpye 1384 \family default
2593    
2594 johnpye 828 \begin_inset LatexCommand \index{MODEL}
2595    
2596     \end_inset
2597    
2598     An ASCEND model has a declarative part and an optional procedural part
2599     headed by the METHODS word.
2600     Models are essentially containers for variables and relations.
2601     We will explain the various statements that can be made within models in
2602     Section
2603     \begin_inset LatexCommand \vref{sec:x.3Declarative-statements}
2604    
2605     \end_inset
2606    
2607     and Section
2608     \begin_inset LatexCommand \vref{sec:x.4Procedural-statements}
2609    
2610     \end_inset
2611    
2612     .
2613     \end_layout
2614    
2615     \begin_layout Standard
2616     Simple\InsetSpace ~
2617     models
2618     \begin_inset LatexCommand \index{models, simple}
2619    
2620     \end_inset
2621    
2622     :
2623     \end_layout
2624    
2625     \begin_layout List
2626     \labelwidthstring 00000.00000.00000.000
2627     foo
2628     \family typewriter
2629     \InsetSpace ~
2630     \InsetSpace ~
2631     \InsetSpace ~
2632     \InsetSpace ~
2633     MODEL foo;
2634     \end_layout
2635    
2636     \begin_deeper
2637     \begin_layout LyX-Code
2638     (* statements about foo go here*)
2639     \end_layout
2640    
2641     \begin_layout LyX-Code
2642     METHODS
2643     \end_layout
2644    
2645     \begin_layout LyX-Code
2646     (* METHODs for foo go here*)
2647     \end_layout
2648    
2649     \begin_layout LyX-Code
2650     END foo;
2651     \end_layout
2652    
2653     \end_deeper
2654     \begin_layout List
2655     \labelwidthstring 00000.00000.00000.000
2656     bar
2657     \family typewriter
2658     \InsetSpace ~
2659     \InsetSpace ~
2660     \InsetSpace ~
2661     \InsetSpace ~
2662     MODEL bar REFINES foo;
2663     \end_layout
2664    
2665     \begin_deeper
2666     \begin_layout LyX-Code
2667     (*additional statements about foo *)
2668     \end_layout
2669    
2670     \begin_layout LyX-Code
2671     METHODS
2672     \end_layout
2673    
2674     \begin_layout LyX-Code
2675     (* additional METHODs for bar *)
2676     \end_layout
2677    
2678     \begin_layout LyX-Code
2679     END bar;
2680     \end_layout
2681    
2682     \end_deeper
2683     \begin_layout List
2684     \labelwidthstring 00000.00000.00000.000
2685    
2686     \bar under
2687     Parameterized\InsetSpace ~
2688     Models
2689     \bar default
2690    
2691     \begin_inset LatexCommand \index{models, parameterized}
2692    
2693     \end_inset
2694    
2695 jpye 1384 Parameterizing models makes them easier to understand and faster for the
2696     system to compile.
2697 johnpye 828 The syntax for a parameterized model vaguely resembles a function call
2698     in imperative languages, but it is NOT.
2699     When constructing a reusable model, all the constants that determine the
2700     sizes of arrays and other structures should be declared in the parameter
2701     list so that
2702     \end_layout
2703    
2704     \begin_deeper
2705     \begin_layout Itemize
2706     the user knows what is required to reuse the model.
2707     \end_layout
2708    
2709     \begin_layout Itemize
2710     the compiler knows what values must be set before it should bother attempting
2711     to compile the model.
2712     \end_layout
2713    
2714     \begin_layout Standard
2715     There is no reason that other items could not also go in the parameter list,
2716     such as key variables which might be considered inputs or outputs or control
2717     parameters in the mathematical application of the model.
2718     A simple example of parameterization would be:
2719     \end_layout
2720    
2721     \end_deeper
2722     \begin_layout List
2723     \labelwidthstring 00000.00000.00000.000
2724     column(n,s)
2725     \end_layout
2726    
2727     \begin_deeper
2728     \begin_layout LyX-Code
2729     MODEL column(
2730     \end_layout
2731    
2732     \begin_layout LyX-Code
2733     ntrays WILL_BE integer_constant;
2734     \end_layout
2735    
2736     \begin_layout LyX-Code
2737     components IS_A set of symbol_constant;
2738     \end_layout
2739    
2740     \begin_layout LyX-Code
2741     );
2742     \end_layout
2743    
2744     \begin_layout LyX-Code
2745     stage[1..ntrays] IS_A simple_tray;
2746     \end_layout
2747    
2748     \begin_layout LyX-Code
2749     END column;
2750     \end_layout
2751    
2752     \end_deeper
2753     \begin_layout List
2754     \labelwidthstring 00000.00000.00000.000
2755     flowsheet
2756     \end_layout
2757    
2758     \begin_deeper
2759     \begin_layout LyX-Code
2760     MODEL flowsheet;
2761     \end_layout
2762    
2763     \begin_layout LyX-Code
2764     tower4size IS_A integer_constant;
2765     \end_layout
2766    
2767     \begin_layout LyX-Code
2768     tower4size :== 22;
2769     \end_layout
2770    
2771     \begin_layout LyX-Code
2772     ct IS_A column(tower4size,[c5,c6]);
2773     \end_layout
2774    
2775     \begin_layout LyX-Code
2776     (* additional flowsheet statements *)
2777     \end_layout
2778    
2779     \begin_layout LyX-Code
2780     END flowsheet;
2781     \end_layout
2782    
2783     \begin_layout Standard
2784     In this example, the column model takes the first argument, ntrays, by reference.
2785 jpye 1384 That is,
2786     \family typewriter
2787     ct.ntrays
2788     \family default
2789     is an alias for the flowsheet instance
2790     \family typewriter
2791     tower4size
2792     \family default
2793     .
2794 johnpye 828
2795 jpye 1384 \family typewriter
2796     tower4size
2797     \family default
2798     must be compiled and assigned a value before we will attempt to compile
2799     the column model instance
2800     \family typewriter
2801     ct
2802     \family default
2803     .
2804     The second argument is taken by value,
2805     \family typewriter
2806     [c5,c6]
2807     \family default
2808     , and assigned to components, a column part that was declared with
2809     \family sans
2810     IS_A
2811     \family default
2812     in the parameter list.
2813     There is only one name for this set,
2814     \family typewriter
2815     ct.components
2816     \family default
2817     .
2818     Note that in the
2819     \family typewriter
2820     flowsheet
2821     \family default
2822     model there is no part that is a set of
2823     \family sans
2824     symbol_constant
2825     \family default
2826     .
2827    
2828 johnpye 828 \end_layout
2829    
2830     \begin_layout Standard
2831     The use of parameters in ASCEND modeling requires some thought, and we will
2832     present that set of thoughts in Section
2833     \begin_inset LatexCommand \vref{sec:x.5Parameterized-models}
2834    
2835     \end_inset
2836    
2837     .
2838     Beginners may wish to create new models without parameters until they are
2839     comfortable using the existing parameterized library definitions.
2840     Parameters are intended to support model reuse and efficient compilation
2841     which are not issues in the very earliest phase of developing novel models.
2842     \end_layout
2843    
2844 jpye 1384 \begin_layout Section
2845 johnpye 828 Sets
2846     \begin_inset LatexCommand \index{sets}
2847    
2848     \end_inset
2849    
2850    
2851     \begin_inset LatexCommand \label{sub:x.2.2Sets}
2852    
2853     \end_inset
2854    
2855    
2856     \end_layout
2857    
2858     \begin_layout Standard
2859     Arrays in ASCEND, as already discussed in Section
2860     \begin_inset LatexCommand \vref{sub:x.1.2Basic-Elements}
2861    
2862     \end_inset
2863    
2864     , are defined over sets.
2865     A set is simply an instance with a set value.
2866 jpye 1384 The elements of sets are
2867     \emph on
2868     not
2869     \emph default
2870     instances or sets.
2871 johnpye 828 \end_layout
2872    
2873     \end_deeper
2874     \begin_layout List
2875     \labelwidthstring 00000.00000.00000.000
2876    
2877     \bar under
2878     Set\InsetSpace ~
2879     Declaration:
2880     \bar default
2881     A set is made of either symbol_constants or integer_constants, so a set
2882     object is declared in one of two ways:
2883     \end_layout
2884    
2885     \begin_deeper
2886     \begin_layout LyX-Code
2887     my_integer_set IS_A set OF integer_constant;
2888     \end_layout
2889    
2890     \begin_layout Standard
2891     or
2892     \end_layout
2893    
2894     \begin_layout LyX-Code
2895     my_symbol_set IS_A set OF symbol_constant;
2896     \end_layout
2897    
2898     \end_deeper
2899     \begin_layout List
2900     \labelwidthstring 00000.00000.00000.000
2901 jpye 1384
2902     \family typewriter
2903 johnpye 828 :==
2904 jpye 1384 \family default
2905    
2906 johnpye 828 \begin_inset LatexCommand \index{:==}
2907    
2908     \end_inset
2909    
2910     A set is assigned a value like so:
2911     \end_layout
2912    
2913     \begin_deeper
2914     \begin_layout LyX-Code
2915     my_integer_set :== [1,4];
2916     \end_layout
2917    
2918     \begin_layout Standard
2919     The RHS of such an assignment must be either the name of another set instance
2920     or an expression enclosed in square brackets and made up of only set operators,
2921     other sets, and the names of integer_constants or symbol_constants.
2922     Sets can only be assigned once.
2923     \end_layout
2924    
2925     \end_deeper
2926     \begin_layout List
2927     \labelwidthstring 00000.00000.00000.000
2928    
2929     \bar under
2930     Set\InsetSpace ~
2931     Operations
2932     \bar default
2933 jpye 1384
2934     \family sans
2935     UNION
2936     \family default
2937    
2938 johnpye 828 \begin_inset LatexCommand \index{UNION}
2939    
2940     \end_inset
2941    
2942 jpye 1384
2943     \family typewriter
2944 johnpye 828 [setlist]
2945     \end_layout
2946    
2947     \begin_deeper
2948     \begin_layout Standard
2949     A function taken over a list of sets.
2950     The result is the set that includes all the members of all the sets in
2951     the list.
2952 jpye 1384 Note that the result of the
2953     \family sans
2954     UNION
2955     \family default
2956     operation is an unordered set and the argument order to the union function
2957     does not matter.
2958 johnpye 828 The syntax is:
2959     \end_layout
2960    
2961     \end_deeper
2962     \begin_layout List
2963     \labelwidthstring 00000.00000.00000.000
2964     +
2965     \begin_inset LatexCommand \index{+, sets}
2966    
2967     \end_inset
2968    
2969 jpye 1384
2970     \family typewriter
2971     UNION[list_of_sets]
2972 johnpye 828 \end_layout
2973    
2974     \begin_layout List
2975     \labelwidthstring 00000.00000.00000.000
2976 jpye 1384
2977     \family typewriter
2978     A+B
2979     \family default
2980     \InsetSpace ~
2981 johnpye 828 is\InsetSpace ~
2982     shorthand\InsetSpace ~
2983 jpye 1384 for
2984     \family typewriter
2985     UNION[A,B]
2986 johnpye 828 \end_layout
2987    
2988     \begin_deeper
2989     \begin_layout Standard
2990     Consider the following sets for the examples to follow.
2991     \end_layout
2992    
2993     \begin_layout LyX-Code
2994     A := [1, 2, 3, 5, 9];
2995     \end_layout
2996    
2997     \begin_layout LyX-Code
2998     B := [2, 4, 6, 8];
2999     \end_layout
3000    
3001     \begin_layout Standard
3002 jpye 1384 Then
3003     \family typewriter
3004     UNION[A, B]
3005     \family default
3006     is equal to the set
3007     \family typewriter
3008     [1, 2, 3, 4, 5, 6, 8, 9]
3009     \family default
3010     which equals
3011     \family typewriter
3012     [1..6, 8, 9]
3013     \family default
3014     which equals
3015     \family typewriter
3016     [[1..9] - [7]]
3017     \family default
3018     .
3019 johnpye 828 \end_layout
3020    
3021     \end_deeper
3022     \begin_layout List
3023     \labelwidthstring 00000.00000.00000.000
3024 jpye 1384
3025     \family sans
3026 johnpye 828 INTERSECTION
3027 jpye 1384 \family default
3028    
3029 johnpye 828 \begin_inset LatexCommand \index{INTERSECTION}
3030    
3031     \end_inset
3032    
3033     [] INTERSECTION[list of set expressions].
3034     Finds the intersection (and) of the sets listed.
3035    
3036     \end_layout
3037    
3038     \begin_layout List
3039     \labelwidthstring 00000.00000.00000.000
3040     *
3041     \begin_inset LatexCommand \index{*, sets}
3042    
3043     \end_inset
3044    
3045 jpye 1384 Equivalent to
3046     \family sans
3047     INTERSECTION
3048     \family typewriter
3049     [list_of_sets]
3050     \family default
3051     .
3052 johnpye 828 \end_layout
3053    
3054     \begin_layout List
3055     \labelwidthstring 00000.00000.00000.000
3056 jpye 1384
3057     \family typewriter
3058     A*B
3059     \family default
3060     \InsetSpace ~
3061 johnpye 828 is\InsetSpace ~
3062     shorthand\InsetSpace ~
3063     for\InsetSpace ~
3064 jpye 1384 I
3065     \family typewriter
3066     NTERSECTION[A,B]
3067 johnpye 828 \end_layout
3068    
3069     \begin_deeper
3070     \begin_layout Standard
3071 jpye 1384 For the sets A and B defined just above,
3072     \family typewriter
3073     INTERSECTION[A, B]
3074     \family default
3075     is the set
3076     \family typewriter
3077     [2]
3078     \family default
3079     .
3080     The
3081     \family typewriter
3082     *
3083     \family default
3084     shorthand for intersection is
3085     \emph on
3086     not
3087     \emph default
3088     recommended for use except in libraries no one will look at.
3089 johnpye 828 \end_layout
3090    
3091     \end_deeper
3092     \begin_layout List
3093     \labelwidthstring 00000.00000.00000.000
3094     Set\InsetSpace ~
3095     difference
3096     \begin_inset LatexCommand \index{set difference}
3097    
3098     \end_inset
3099    
3100     : One can subtract one set from another.
3101     The result is the first set less any members in the set union of the first
3102     and second set.
3103     The syntax is
3104     \end_layout
3105    
3106 jpye 1384 \begin_deeper
3107     \begin_layout LyX-Code
3108    
3109     \family typewriter
3110     first_set
3111     \family default
3112 johnpye 828 -
3113     \begin_inset LatexCommand \index{-, sets}
3114    
3115     \end_inset
3116    
3117 jpye 1384
3118 johnpye 828 \family typewriter
3119 jpye 1384 second_set
3120 johnpye 828 \end_layout
3121    
3122     \begin_layout Standard
3123 jpye 1384 For the sets
3124     \family typewriter
3125     A
3126     \family default
3127     and
3128     \family typewriter
3129     B
3130     \family default
3131     defined above, the set difference
3132     \family typewriter
3133     A - B
3134     \family default
3135     is the set
3136     \family typewriter
3137     [1, 3, 5, 9]
3138     \family default
3139     while the set difference
3140     \family typewriter
3141     B - A
3142     \family default
3143     is the set
3144     \family typewriter
3145     [4, 6, 8]
3146     \family default
3147     .
3148 johnpye 828 \end_layout
3149    
3150     \end_deeper
3151     \begin_layout List
3152     \labelwidthstring 00000.00000.00000.000
3153 jpye 1384
3154     \family sans
3155 johnpye 828 CARD
3156 jpye 1384 \family default
3157    
3158 johnpye 828 \begin_inset LatexCommand \index{CARD}
3159    
3160     \end_inset
3161    
3162     [set] Cardinality
3163     \begin_inset LatexCommand \index{cardinality}
3164    
3165     \end_inset
3166    
3167     .
3168     Returns an integer constant value that is the number of items in the set.
3169     \end_layout
3170    
3171     \begin_layout List
3172     \labelwidthstring 00000.00000.00000.000
3173 jpye 1384
3174     \family sans
3175 johnpye 828 CHOICE
3176 jpye 1384 \family default
3177    
3178 johnpye 828 \begin_inset LatexCommand \index{CHOICE}
3179    
3180     \end_inset
3181    
3182     [set] Choose one.
3183 jpye 1384 The result of running the
3184     \family sans
3185     CHOICE
3186     \family default
3187     function over a set is an arbitrary (but consistent: for any set instance
3188     you always get the same result) single element of that set.
3189 johnpye 828
3190     \end_layout
3191    
3192     \begin_deeper
3193     \begin_layout Standard
3194 jpye 1384 Running
3195     \family typewriter
3196     CHOICE[A]
3197     \family default
3198     gives any member from the set A.
3199 johnpye 828 The result is a member, not a set.
3200     To make the result into a set, it must be enclosed in square brackets.
3201 jpye 1384 Thus
3202     \family typewriter
3203     [CHOICE[A]]
3204     \family default
3205     is a set with a single element arbitrarily chosen from the set A.
3206 johnpye 828 Good modelers do not leave modeling decisions to the compiler; they do
3207 jpye 1384 not use
3208     \family sans
3209     CHOICE
3210     \family default
3211     .
3212 johnpye 828 We are stuck with it for historical reasons.
3213     \end_layout
3214    
3215     \begin_layout Standard
3216     To reduce a set by one element, one can use the following
3217     \end_layout
3218    
3219     \begin_layout LyX-Code
3220     A_less_one IS_A set OF integer;
3221     \end_layout
3222    
3223     \begin_layout LyX-Code
3224     A_less_one :== A - [CHOICE[A]];
3225     \end_layout
3226    
3227     \end_deeper
3228     \begin_layout List
3229     \labelwidthstring 00000.00000.00000.000
3230 jpye 1384
3231     \family sans
3232 johnpye 828 IN
3233 jpye 1384 \family default
3234    
3235 johnpye 828 \begin_inset LatexCommand \index{IN}
3236    
3237     \end_inset
3238    
3239 jpye 1384
3240     \family typewriter
3241     lhs IN rhs
3242     \family default
3243     can only be well explained by examples.
3244    
3245     \family sans
3246     IN
3247     \family default
3248     is used in index expressions.
3249     If
3250     \family typewriter
3251     lhs
3252     \family default
3253     is a simple and not previously defined name, it is created as a temporary
3254     loop index which will take on the values of the rhs set definition.
3255     If lhs is something that already exists, the result of
3256     \family typewriter
3257     lhs IN rhs
3258     \family default
3259     is a boolean value; stare at the model
3260     \family typewriter
3261     set_example
3262     \family default
3263     below which demonstrates both
3264     \family sans
3265     IN
3266     \family default
3267     and
3268     \family sans
3269     SUCH_THAT
3270     \family default
3271     .
3272     If you still are not satisfied, you might examine [[westerbergksets]]
3273     \begin_inset Note Note
3274     status open
3275    
3276     \begin_layout Standard
3277     fix this reference
3278 johnpye 828 \end_layout
3279    
3280 jpye 1384 \end_inset
3281    
3282     .
3283     \end_layout
3284    
3285 johnpye 828 \begin_layout List
3286     \labelwidthstring 00000.00000.00000.000
3287 jpye 1384
3288     \family sans
3289 johnpye 828 SUCH_THAT
3290 jpye 1384 \family default
3291    
3292 johnpye 828 \begin_inset LatexCommand \index{SUCH\_THAT}
3293    
3294     \end_inset
3295    
3296 jpye 1384 Set expressions can be rather clever.
3297 johnpye 828 We will give a detailed example from chemistry because unordered sets are
3298     unfamiliar to most people and set arithmetic is quite powerful.
3299     In this example we see arrays of sets and sparse arrays.
3300    
3301     \end_layout
3302    
3303     \begin_layout LyX-Code
3304     MODEL set_example;
3305     \end_layout
3306    
3307     \begin_layout LyX-Code
3308 jpye 1384 (* we define a sparse matrix of reaction
3309 johnpye 828 \end_layout
3310    
3311     \begin_layout LyX-Code
3312 jpye 1384 coefficient information and the species
3313 johnpye 828 \end_layout
3314    
3315     \begin_layout LyX-Code
3316 jpye 1384 balance equations.
3317 johnpye 828 *)
3318     \end_layout
3319    
3320     \begin_layout LyX-Code
3321 jpye 1384 rxns IS_A set OF integer_constant;
3322 johnpye 828 \end_layout
3323    
3324     \begin_layout LyX-Code
3325 jpye 1384 rxns :== [1..3];
3326 johnpye 828 \end_layout
3327    
3328     \begin_layout LyX-Code
3329 jpye 1384 species IS_A set OF symbol_constant;
3330 johnpye 828 \end_layout
3331    
3332     \begin_layout LyX-Code
3333 jpye 1384 species :== ['A','B','C','D'];
3334 johnpye 828 \end_layout
3335    
3336     \begin_layout LyX-Code
3337 jpye 1384 reactants[rxns] IS_A set OF symbol_constant; (* species
3338 johnpye 828 \end_layout
3339    
3340     \begin_layout LyX-Code
3341 jpye 1384 in each rxn_j *)
3342 johnpye 828 \end_layout
3343    
3344     \begin_layout LyX-Code
3345 jpye 1384 reactants[1] :== ['A','B','C'];
3346 johnpye 828 \end_layout
3347    
3348     \begin_layout LyX-Code
3349 jpye 1384 reactants[2] :== ['A','C'];
3350 johnpye 828 \end_layout
3351    
3352     \begin_layout LyX-Code
3353 jpye 1384 reactants[3] :== ['A','B','D'];
3354 johnpye 828 \end_layout
3355    
3356     \begin_layout LyX-Code
3357 jpye 1384 reactions[species] IS_A set OF integer_constant;
3358 johnpye 828 \end_layout
3359    
3360     \begin_layout LyX-Code
3361 jpye 1384 FOR i IN species CREATE (* rxns for each species i *)
3362 johnpye 828 \end_layout
3363    
3364     \begin_layout LyX-Code
3365 jpye 1384 reactions[i] :== [j IN rxns SUCH_THAT i IN reactants[j]];
3366 johnpye 828 \end_layout
3367    
3368     \begin_layout LyX-Code
3369 jpye 1384 END FOR;
3370 johnpye 828 \end_layout
3371    
3372     \begin_layout LyX-Code
3373 jpye 1384 (* Define sparse stoichiometric matrix.
3374 johnpye 828 Values of eta_ij
3375     \end_layout
3376    
3377     \begin_layout LyX-Code
3378 jpye 1384 set later.*)
3379 johnpye 828 \end_layout
3380    
3381     \begin_layout LyX-Code
3382 jpye 1384 FOR j IN rxns CREATE
3383 johnpye 828 \end_layout
3384    
3385     \begin_layout LyX-Code
3386 jpye 1384 FOR i IN reactants[j] CREATE
3387 johnpye 828 \end_layout
3388    
3389     \begin_layout LyX-Code
3390 jpye 1384 (* eta_ij --> mole i/mole rxn j*)
3391 johnpye 828 \end_layout
3392    
3393     \begin_layout LyX-Code
3394 jpye 1384 eta[i][j] IS_A real_constant;
3395 johnpye 828 \end_layout
3396    
3397     \begin_layout LyX-Code
3398 jpye 1384 END FOR;
3399 johnpye 828 \end_layout
3400    
3401     \begin_layout LyX-Code
3402 jpye 1384 END FOR;
3403 johnpye 828 \end_layout
3404    
3405     \begin_layout LyX-Code
3406 jpye 1384 production[species] IS_A molar_rate;
3407 johnpye 828 \end_layout
3408    
3409     \begin_layout LyX-Code
3410 jpye 1384 rate[rxns] IS_A molar_rate; (* mole rxn j/time *)
3411 johnpye 828 \end_layout
3412    
3413     \begin_layout LyX-Code
3414 jpye 1384 FOR i IN species CREATE
3415 johnpye 828 \end_layout
3416    
3417     \begin_layout LyX-Code
3418 jpye 1384 gen_eqn[i]: production[i] =
3419 johnpye 828 \end_layout
3420    
3421     \begin_layout LyX-Code
3422 jpye 1384 SUM[eta[i][j]*rate[j] | j IN reactions[i]];
3423 johnpye 828 \end_layout
3424    
3425     \begin_layout LyX-Code
3426 jpye 1384 END FOR;
3427 johnpye 828 \end_layout
3428    
3429     \begin_layout LyX-Code
3430     END set_example;
3431     \end_layout
3432    
3433     \begin_layout List
3434     \labelwidthstring 00000.00000.00000.000
3435 jpye 1384 "
3436     \family typewriter
3437     |
3438     \family default
3439    
3440 johnpye 828 \begin_inset LatexCommand \index{|}
3441    
3442     \end_inset
3443    
3444 jpye 1384 " is shorthand for
3445     \family sans
3446     SUCH_THAT
3447     \family default
3448     .
3449 johnpye 828 \end_layout
3450    
3451     \begin_deeper
3452     \begin_layout Standard
3453 jpye 1384 The array
3454     \family typewriter
3455     eta
3456     \family default
3457     has only 8 elements, and we defined those elements in a set for each reaction.
3458     The equation needs to know about the set of reactions for a species
3459     \family typewriter
3460     i
3461     \family default
3462     , and that set is calculated automatically in the models first
3463     \family sans
3464     FOR/CREATE
3465     \family default
3466 johnpye 828 statement.
3467    
3468     \end_layout
3469    
3470 jpye 1384 \begin_layout Standard
3471     The
3472     \family typewriter
3473 johnpye 828 |
3474 jpye 1384 \family default
3475     symbol is the ASCEND III notation for
3476     \family sans
3477     SUCH_THAT
3478     \family default
3479     .
3480     We noted that "
3481     \family typewriter
3482     |
3483     \family default
3484     " is often read as "for all", which is different in that "for all" makes
3485     one think of a
3486     \family sans
3487     FOR
3488     \family default
3489     loop where the loop index is on the left of an
3490     \family sans
3491     IN
3492     \family default
3493     operator.
3494     For example, the
3495     \family typewriter
3496     j
3497     \family default
3498     loop in the
3499     \family sans
3500     SUM
3501     \family default
3502     of
3503     \family typewriter
3504     gen_eqn[i]
3505     \family default
3506     above.
3507 johnpye 828
3508     \end_layout
3509    
3510 jpye 1384 \begin_layout Section
3511 johnpye 828 Constants
3512     \begin_inset LatexCommand \index{constants}
3513    
3514     \end_inset
3515    
3516    
3517     \end_layout
3518    
3519     \begin_layout Standard
3520     ASCEND supports real, integer, boolean and character string constants.
3521     Constants in ASCEND do not have any attributes other than their value.
3522     Constants are scalar quantities that can be assigned exactly once.
3523 jpye 1384 Constants may only be assigned using the
3524     \family typewriter
3525     :==
3526     \family default
3527     operator and the RHS expression they are assigned from must itself be constant.
3528 johnpye 828 Constants do not have subparts.
3529     Integer and symbol constants may be used in determining the definitions
3530     of sets.
3531    
3532     \end_layout
3533    
3534     \begin_layout Standard
3535     Explicit refinements of the built-in constant types may be defined as exemplifie
3536     d in the description of real_constant.
3537     Implicit type refinements may be done by instantiating an incompletely
3538     defined constant and assigning its final value.
3539    
3540     \end_layout
3541    
3542     \begin_layout Standard
3543     Sets could be considered constant because they are assigned only once, however
3544     sets are described separately because they are not quite scalar quantities.
3545     \end_layout
3546    
3547     \end_deeper
3548     \begin_layout List
3549     \labelwidthstring 00000.00000.00000.000
3550 jpye 1384
3551     \family sans
3552 johnpye 828 real_constant
3553 jpye 1384 \family default
3554    
3555 johnpye 828 \begin_inset LatexCommand \index{real\_constant}
3556    
3557     \end_inset
3558    
3559     Real number with dimensionality.
3560     Note that the dimensionality of a real constant can be specified via the
3561     type definition without immediately defining the value, as in the following
3562     pair of definitions.
3563     \end_layout
3564    
3565     \begin_layout List
3566     \labelwidthstring 00000.00000.00000.000
3567    
3568     \bar under
3569     CONSTANT\InsetSpace ~
3570     declaration\InsetSpace ~
3571     example:
3572     \end_layout
3573    
3574     \begin_deeper
3575     \begin_layout LyX-Code
3576     CONSTANT molar_weight
3577     \end_layout
3578    
3579     \begin_layout LyX-Code
3580     REFINES real_constant DIMENSION M/Q;
3581     \end_layout
3582    
3583     \begin_layout LyX-Code
3584     CONSTANT hydrogen_weight
3585     \end_layout
3586    
3587     \begin_layout LyX-Code
3588     REFINES molar_weight :== 1.004{g/mole};
3589     \end_layout
3590    
3591     \end_deeper
3592     \begin_layout List
3593     \labelwidthstring 00000.00000.00000.000
3594 jpye 1384
3595     \family sans
3596 johnpye 828 integer_constant
3597 jpye 1384 \family default
3598    
3599 johnpye 828 \begin_inset LatexCommand \index{integer\_constant}
3600    
3601     \end_inset
3602    
3603     Integer number.
3604     Principally used in determining model structure.
3605     If appearing in equations, integers are evaluated as dimensionless reals.
3606 jpye 1384 Typical use is inside a
3607     \family sans
3608     MODEL
3609     \family default
3610     definition and looks like:
3611 johnpye 828 \end_layout
3612    
3613     \begin_deeper
3614     \begin_layout LyX-Code
3615     n_trays IS_A integer_constant;
3616     \end_layout
3617    
3618     \begin_layout LyX-Code
3619     n_trays :== 50;
3620     \end_layout
3621    
3622     \begin_layout LyX-Code
3623     tray[1..n_trays] IS_A vl_equilibrium_tray;
3624     \end_layout
3625    
3626     \end_deeper
3627     \begin_layout List
3628     \labelwidthstring 00000.00000.00000.000
3629 jpye 1384
3630     \family sans
3631 johnpye 828 symbol_constant
3632 jpye 1384 \family default
3633    
3634 johnpye 828 \begin_inset LatexCommand \index{symbol\_constant}
3635    
3636     \end_inset
3637    
3638     Object with a symbol value.
3639     May be used in determining model structure.
3640     \end_layout
3641    
3642     \begin_layout List
3643     \labelwidthstring 00000.00000.00000.000
3644 jpye 1384
3645     \family sans
3646 johnpye 828 boolean_constant
3647 jpye 1384 \family default
3648    
3649 johnpye 828 \begin_inset LatexCommand \index{boolean\_constant}
3650    
3651     \end_inset
3652    
3653     Logical value.
3654     May be used in determining model structure.
3655     \end_layout
3656    
3657     \begin_layout List
3658     \labelwidthstring 00000.00000.00000.000
3659    
3660     \bar under
3661     Setting\InsetSpace ~
3662     constants
3663     \bar default
3664    
3665     \begin_inset LatexCommand \index{constants, setting}
3666    
3667     \end_inset
3668    
3669    
3670     \end_layout
3671    
3672     \begin_layout List
3673     \labelwidthstring 00000.00000.00000.000
3674     :==
3675     \begin_inset LatexCommand \index{:==}
3676    
3677     \end_inset
3678    
3679     Constant and set assignment operator.
3680    
3681     \end_layout
3682    
3683     \begin_deeper
3684     \begin_layout Standard
3685     It is suggested, but not required, that names of all types that refine the
3686     built-in constant types have names that end in _constant.
3687     \end_layout
3688    
3689     \begin_layout LyX-Code
3690     LHS_list :== RHS;
3691     \end_layout
3692    
3693     \begin_layout Standard
3694     Here it is required that the one or more items in the LHS be of the same
3695     constant type and that RHS is a single-valued expression made up of values,
3696     operators, and other constants.
3697 jpye 1384 The
3698     \family typewriter
3699     :==
3700     \family default
3701     is used to make clear to both the user and the system what scalar objects
3702     are constants.
3703 johnpye 828
3704     \end_layout
3705    
3706 jpye 1384 \begin_layout Section
3707 johnpye 828 Variables
3708     \begin_inset LatexCommand \index{variables}
3709    
3710     \end_inset
3711    
3712    
3713     \end_layout
3714    
3715     \begin_layout Standard
3716     There are four built-in types which may be used to construct variables:
3717     symbol, boolean, integer, and real.
3718     At this time symbol types have special restrictions.
3719 jpye 1384 Refinements of these variable base types are defined with the
3720     \family sans
3721     ATOM
3722     \family default
3723     statement.
3724 johnpye 828 Atom types may declare attribute fields with types real, integer, boolean,
3725     symbol, and set.
3726 jpye 1384 These attributes are
3727     \emph on
3728     not
3729     \emph default
3730     independent objects and therefore cannot be refined, merged, or put in
3731     a refinement clique (
3732     \family sans
3733     ARE_ALIKE
3734     \family default
3735     d).
3736 johnpye 828 \end_layout
3737    
3738     \end_deeper
3739     \begin_layout List
3740     \labelwidthstring 00000.00000.00000.000
3741 jpye 1384
3742     \family sans
3743 johnpye 828 ATOM
3744 jpye 1384 \family default
3745    
3746 johnpye 828 \begin_inset LatexCommand \index{ATOM}
3747    
3748     \end_inset
3749    
3750     The syntax for declaring a new atom type is
3751     \end_layout
3752    
3753     \begin_deeper
3754     \begin_layout LyX-Code
3755     ATOM
3756     \emph on
3757     atom_type_name
3758     \emph default
3759     REFINES
3760     \emph on
3761     variable_type
3762     \end_layout
3763    
3764     \begin_layout LyX-Code
3765     «DIMENSION
3766     \emph on
3767     dimension_expression
3768     \emph default
3769     »
3770     \end_layout
3771    
3772     \begin_layout LyX-Code
3773     «DEFAULT
3774     \emph on
3775     value
3776     \emph default
3777     »; (* note the ; *)
3778     \end_layout
3779    
3780     \begin_layout LyX-Code
3781     «
3782     \emph on
3783     initial attribute assignment
3784     \emph default
3785    
3786     \end_layout
3787    
3788     \begin_layout LyX-Code
3789     END
3790     \emph on
3791     atom_type_name
3792     \emph default
3793     ;
3794     \end_layout
3795    
3796     \end_deeper
3797     \begin_layout List
3798     \labelwidthstring 00000.00000.00000.000
3799 jpye 1384
3800     \family sans
3801 johnpye 828 DEFAULT
3802 jpye 1384 \family default
3803    
3804 johnpye 828 \begin_inset LatexCommand \index{DEFAULT}
3805    
3806     \end_inset
3807    
3808 jpye 1384 ,
3809     \family sans
3810     \InsetSpace ~
3811 johnpye 828 DIMENSION
3812 jpye 1384 \family default
3813    
3814 johnpye 828 \begin_inset LatexCommand \index{DIMENSION}
3815    
3816     \end_inset
3817    
3818     ,\InsetSpace ~
3819     and\InsetSpace ~
3820 jpye 1384
3821     \family sans
3822 johnpye 828 DIMENSIONLESS
3823 jpye 1384 \family default
3824    
3825 johnpye 828 \begin_inset LatexCommand \index{DIMENSIONLESS}
3826    
3827     \end_inset
3828    
3829    
3830     \end_layout
3831    
3832     \begin_deeper
3833     \begin_layout Standard
3834 jpye 1384 The
3835     \family sans
3836     DIMENSION
3837     \family default
3838     attribute is for variables whose base type is real.
3839 johnpye 828 It is an optional field.
3840     If not defined for any atom with base type real, the dimensions will be
3841     left as undefined.
3842     Any variable which is later declared to be one of these types will be given
3843     wild card dimensionality (represented in the interactive display by an
3844     asterisk (*)).
3845     The system will deduce the dimensionality from its use in the relationships
3846     in which it appears or in the declaring of default values for it, if possible.
3847     \end_layout
3848    
3849     \end_deeper
3850     \begin_layout List
3851     \labelwidthstring 00000.00000.00000.000
3852 jpye 1384
3853     \family sans
3854 johnpye 828 solver_var
3855 jpye 1384 \family default
3856    
3857 johnpye 828 \begin_inset LatexCommand \index{solver\_var}
3858    
3859     \end_inset
3860    
3861 jpye 1384 is a special case of
3862     \family sans
3863     ATOM
3864     \family default
3865     and we will say much more about it in Section
3866 johnpye 828 \begin_inset LatexCommand \vref{sub:x.6.1Variables-for-solvers}
3867    
3868     \end_inset
3869    
3870     .
3871     \end_layout
3872    
3873     \begin_deeper
3874     \begin_layout LyX-Code
3875     ATOM solver_var REFINES real DEFAULT 0.5 {?
3876     \begin_inset LatexCommand \index{?}
3877    
3878     \end_inset
3879    
3880     };
3881     \end_layout
3882    
3883     \begin_layout LyX-Code
3884     lower_bound IS_A real;
3885     \end_layout
3886    
3887     \begin_layout LyX-Code
3888     upper_bound IS_A real;
3889     \end_layout
3890    
3891     \begin_layout LyX-Code
3892     nominal IS_A real;
3893     \end_layout
3894    
3895     \begin_layout LyX-Code
3896     fixed IS_A boolean;
3897     \end_layout
3898    
3899     \begin_layout LyX-Code
3900     fixed := FALSE;
3901     \end_layout
3902    
3903     \begin_layout LyX-Code
3904     lower_bound := -1e20 {?};
3905     \end_layout
3906    
3907     \begin_layout LyX-Code
3908     upper_bound := 1e20 {?};
3909     \end_layout
3910    
3911     \begin_layout LyX-Code
3912     nominal := 0.5 {?};
3913     \end_layout
3914    
3915     \begin_layout LyX-Code
3916     END solver_var;
3917     \end_layout
3918    
3919     \begin_layout Standard
3920     The default field is also optional.
3921     If the atom has a declared dimensionality, then this value must be expressed
3922     with units which are compatible with this dimensionality.
3923     In the solver_var example, we see a DEFAULT value of 0.5 with the unspecified
3924     unit
3925     \begin_inset LatexCommand \index{unit, unspecified}
3926    
3927     \end_inset
3928    
3929    
3930     \begin_inset LatexCommand \index{unspecified unit}
3931    
3932     \end_inset
3933    
3934     {?
3935     \begin_inset LatexCommand \index{}
3936    
3937     \end_inset
3938    
3939     } which leaves the dimensionality wild
3940     \begin_inset LatexCommand \index{wild dimensionality}
3941    
3942     \end_inset
3943    
3944     .
3945     \end_layout
3946    
3947     \end_deeper
3948     \begin_layout List
3949     \labelwidthstring 00000.00000.00000.000
3950     real
3951     \begin_inset LatexCommand \index{real}
3952    
3953     \end_inset
3954    
3955     Real valued variable quantity.
3956     At present, all variables that you want to be attended to by solver tools
3957     must be refinements of the type solver_var.
3958     This is so that modifiable parametric values can be included in equations
3959     without treating them as variables.
3960     Strictly speaking, this is a characteristic of the solver interface and
3961     not the ASCEND language.
3962     Each tool in the total ASCEND system may have its own semantics that go
3963     beyond the ASCEND object definition language.
3964     \end_layout
3965    
3966     \begin_layout List
3967     \labelwidthstring 00000.00000.00000.000
3968     integer
3969     \begin_inset LatexCommand \index{integer}
3970    
3971     \end_inset
3972    
3973     Integer valued variable quantity.
3974     We find these mighty convenient for use in certain procedural computations
3975     and as attributes of solver_var atoms.
3976     \end_layout
3977    
3978     \begin_layout List
3979     \labelwidthstring 00000.00000.00000.000
3980     boolean
3981     \begin_inset LatexCommand \index{boolean}
3982    
3983     \end_inset
3984    
3985     Truth valued variable quantity.
3986     These are principally used as flags on solver_vars and relations.
3987     They can also be used procedurally and as variables in logical programming
3988     models, subject to the logical solver tools semantics.
3989     (Compare solver_boolean and boolean_var in Section
3990     \begin_inset LatexCommand \vref{sec:x.6Miscellany}
3991    
3992     \end_inset
3993    
3994     .)
3995     \end_layout
3996    
3997     \begin_layout List
3998     \labelwidthstring 00000.00000.00000.000
3999     symbol
4000     \begin_inset LatexCommand \index{symbol}
4001    
4002     \end_inset
4003    
4004 jpye 1384 Symbol valued variable quantity.
4005 johnpye 828 We do not yet have operators for building symbols out of other symbols.
4006     \end_layout
4007    
4008     \begin_layout List
4009     \labelwidthstring 00000.00000.00000.000
4010    
4011     \bar under
4012     Setting\InsetSpace ~
4013     variables
4014     \bar default
4015    
4016     \begin_inset LatexCommand \index{variables, setting}
4017    
4018     \end_inset
4019    
4020    
4021     \end_layout
4022    
4023     \begin_layout List
4024     \labelwidthstring 00000.00000.00000.000
4025     :=
4026     \begin_inset LatexCommand \index{:=}
4027    
4028     \end_inset
4029    
4030     Procedural equals
4031     \begin_inset LatexCommand \index{equals, procedural}
4032    
4033     \end_inset
4034    
4035     differs from the ordinary equals (=) in that it means the left-hand-side
4036     (LHS) variables are to be assigned the value of the right-hand-side (RHS)
4037     expression when this statement is processed.
4038     Processing happens in the last phase of compiling (instantiation) or when
4039     executing a method interactively through the ASCEND user interface.
4040     The order the system encounters these statements matters, therefore, with
4041     a later result overwriting an earlier one if both statements have the same
4042     the same LHS variable.
4043    
4044     \end_layout
4045    
4046     \begin_deeper
4047     \begin_layout Standard
4048     Note that variable assignments (also known as defaulting statements) written
4049     in the declarative section are executed only after an instance has been
4050     fully created.
4051     This is a frequent source of confusion and errors, therefore we recommend
4052     that you DO NOT ASSIGN VARIABLES IN THE DECLARATIVE SECTION.
4053    
4054     \end_layout
4055    
4056     \end_deeper
4057     \begin_layout List
4058     \labelwidthstring 00000.00000.00000.000
4059     Note\InsetSpace ~
4060     that\InsetSpace ~
4061     :=\InsetSpace ~
4062     IS\InsetSpace ~
4063     NOT\InsetSpace ~
4064     =.
4065     \end_layout
4066    
4067     \begin_deeper
4068     \begin_layout Standard
4069     We use an ordinary equals (=) when defining a real valued equation to state
4070     that the LHS expression is to equal the RHS expression at the solution
4071     for the model.
4072     We use == for logical equations.
4073     \end_layout
4074    
4075     \end_deeper
4076     \begin_layout List
4077     \labelwidthstring 00000.00000.00000.000
4078 jpye 1384 \begin_inset Note Note
4079     status open
4080 johnpye 828
4081 jpye 1384 \begin_layout List
4082     \labelwidthstring 00000.00000.00000.000
4083    
4084 johnpye 828 \bar under
4085     Tabular\InsetSpace ~
4086     assignments
4087