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

Annotation of /trunk/doc/syntax.lyx

Parent Directory Parent Directory | Revision Log Revision Log


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