/[ascend]/trunk/doc/howto-atoms.lyx
ViewVC logotype

Contents of /trunk/doc/howto-atoms.lyx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1766 - (show annotations) (download) (as text)
Mon Apr 7 09:06:56 2008 UTC (10 years, 5 months ago) by jpye
File MIME type: application/x-lyx
File size: 28881 byte(s)
Fixed heading numbers in book.pdf, some tinkering to expose bug in IDA when there are derivs with out undiff vars.
1 #LyX 1.5.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 276
3 \begin_document
4 \begin_header
5 \textclass book
6 \language english
7 \inputencoding auto
8 \font_roman default
9 \font_sans default
10 \font_typewriter default
11 \font_default_family default
12 \font_sc false
13 \font_osf false
14 \font_sf_scale 100
15 \font_tt_scale 100
16 \graphics default
17 \paperfontsize default
18 \spacing single
19 \papersize a4paper
20 \use_geometry false
21 \use_amsmath 2
22 \use_esint 0
23 \cite_engine basic
24 \use_bibtopic false
25 \paperorientation portrait
26 \secnumdepth 3
27 \tocdepth 3
28 \paragraph_separation indent
29 \defskip medskip
30 \quotes_language english
31 \papercolumns 1
32 \papersides 2
33 \paperpagestyle default
34 \tracking_changes false
35 \output_changes false
36 \author ""
37 \end_header
38
39 \begin_body
40
41 \begin_layout Chapter
42 Defining Variables and Scaling Values
43 \begin_inset LatexCommand label
44 name "cha:atoms"
45
46 \end_inset
47
48
49 \end_layout
50
51 \begin_layout Standard
52 \begin_inset Marginal
53 status collapsed
54
55 \begin_layout Standard
56 the purpose of this chapter
57 \end_layout
58
59 \end_inset
60
61 By now you have probably read Chapter\InsetSpace ~
62
63 \begin_inset LatexCommand vref
64 reference "cha:model1"
65
66 \end_inset
67
68 and seen an example of how to create a model using existing variable types
69 in ASCEND.
70 You found that variables of types area, length, mass, mass_density, and
71 volume were needed and that they could be found in the library
72 \family typewriter
73 atoms.a4l
74 \family default
75 .
76 You want to know how to generalize on that; how to use variables, constants,
77 and scaling values in your own models so that the models will be easier
78 to solve.
79 \end_layout
80
81 \begin_layout Standard
82 This chapter is meant to explain the following things:
83 \end_layout
84
85 \begin_layout Itemize
86 The "Big Picture" of how variables, constants, and scaling values relate
87 to the rest of the ASCEND IV language and to equations in particular.
88 We'll keep it simple here.
89 More precise explanations for the language purist can be found in our syntax
90 document **syntax.fm5**.
91 You do not need to read about the "Big Picture" in order to read and use
92 the other parts of this chapter, but you may find it helpful if you are
93 having trouble writing an equation
94 \begin_inset LatexCommand index
95 name "equation, writing"
96
97 \end_inset
98
99 so that ASCEND will accept it.
100 \end_layout
101
102 \begin_layout Itemize
103 How to find the type of variable (or constant) you want.
104 We keep a mess of interesting
105 \family typewriter
106 ATOM
107 \family default
108 and
109 \family typewriter
110 CONSTANT
111 \family default
112 definitions in
113 \family typewriter
114 atoms.a4l
115 \family default
116 .
117 We provide tools to search in already loaded libraries to locate the type
118 you need.
119 \end_layout
120
121 \begin_layout Itemize
122 How to define a new type of variable when we do not have a predefined
123 \family typewriter
124 ATOM
125 \family default
126 or
127 \family typewriter
128 CONSTANT
129 \family default
130 that suits your needs.
131 It is very easy to define your own variable types by copying code into
132 an atoms library of your own from
133 \family typewriter
134 atoms.a4l
135 \family default
136 and then editing the copied definition.
137 \end_layout
138
139 \begin_layout Itemize
140 How to define a scaling variable to make your equations much easier to solve.
141 \end_layout
142
143 \begin_layout Section
144 The Big Picture: a taxonomy
145 \begin_inset LatexCommand index
146 name "taxonomy"
147
148 \end_inset
149
150
151 \end_layout
152
153 \begin_layout Standard
154 As you read in Chapter\InsetSpace ~
155
156 \begin_inset LatexCommand ref
157 reference "cha:model1"
158
159 \end_inset
160
161 , simulations are built from MODEL and ATOM definitions, and MODEL and ATOM
162 definitions are defined by creating types in an ASCEND language text file
163 that you load into the ASCEND system.
164 Figure
165 \begin_inset LatexCommand ref
166 reference "fig:atoms.taxonomy"
167
168 \end_inset
169
170
171 \noun off
172 shows the types of objects that can be defined.
173 You can see there are many more types than simply real variables used for
174 writing equations.
175 Some of these types can also be used in equations.
176 You also see that there are three kinds of equations, not simply real relations.
177 Throughout our documentation we call real relations simply "relations"
178 because that is the kind of equation most people are interested in most
179 of the time.
180 Notice that "scaling values" do not appear in this diagram.
181 We will cover scaling values at the end of this The major features of this
182 diagram are:
183 \end_layout
184
185 \begin_layout Standard
186 \begin_inset Float figure
187 wide false
188 sideways false
189 status open
190
191 \begin_layout Standard
192 \align center
193
194 \noun off
195 \begin_inset Graphics
196 filename howto-atomsFig1.eps
197 scale 90
198
199 \end_inset
200
201
202 \end_layout
203
204 \begin_layout Standard
205 \begin_inset Caption
206
207 \begin_layout Standard
208 \begin_inset LatexCommand label
209 name "fig:atoms.taxonomy"
210
211 \end_inset
212
213 The big picture: how to think about variables
214 \end_layout
215
216 \end_inset
217
218
219 \end_layout
220
221 \end_inset
222
223
224 \end_layout
225
226 \begin_layout Paragraph
227
228 \noun off
229 \begin_inset LatexCommand index
230 name "atom"
231
232 \end_inset
233
234
235 \noun default
236 ATOM
237 \end_layout
238
239 \begin_layout Itemize
240 Any variable quantity for use in relations, logical relations, or when statement
241 s or other computations.
242 These come in the usual programming language flavors real, boolean, symbol,
243 integer.
244 Not all kinds of atoms can be used in all kinds of equations, as we shall
245 explain when describing relations in a little bit.
246 Atoms may be assigned values many times interactively, with the Script
247 ASSIGN statement, with the METHOD := assignment operator, or by an ASCEND
248 client such as a solver.
249 \end_layout
250
251 \begin_layout Standard
252 An ATOM may have attributes other than its value, such as .fixed in solver_var,
253 but these attributes are not atoms.
254 They are subatomic particles and cannot be used in equations.
255 These attributes are interpretable by ASCEND clients, and assignable by
256 the user in the same ways that the user assigns atom values.
257 \end_layout
258
259 \begin_layout Standard
260 Each subatomic particle instance belongs to exactly one atom instance (one
261 variable in your compiled simulation).
262 This contrasts with an atom instance which can be shared among several
263 models by passing the atom instance from one model into another or by creating
264 aliases for it.
265 \end_layout
266
267 \begin_layout Paragraph
268 \begin_inset LatexCommand index
269 name "constant"
270
271 \end_inset
272
273 CONSTANT
274 \end_layout
275
276 \begin_layout Itemize
277 Constants are "variables" that can be assigned no more than once.
278 By convention, all constant types in atoms.a4l have names that end in _constant
279 so that they are not easily confused with atoms.
280 A constant gets a values from the DEFAULT portion of its type definition,
281 by an interactive assignment, or by an assignment in the a model which
282 uses the :== assignment operator.
283 Constants cannot be assigned in a METHOD, nor can they be assigned with
284 the := operator.
285 \end_layout
286
287 \begin_layout Standard
288 Integer and symbol constants can appear as members of sets or as subscripts
289 of arrays.
290 Integer, boolean, and symbol constants can be used to control SELECT statements
291 which determine your simulation's structure at compile-time or to control
292 SWITCH and WHEN behavior during problem solving .
293 \end_layout
294
295 \begin_layout Paragraph
296 \begin_inset LatexCommand index
297 name "set"
298
299 \end_inset
300
301 set
302 \end_layout
303
304 \begin_layout Itemize
305 Sets are unordered lists of either integer or symbol constants.
306 A set is assigned its value exactly once.
307 The user interface always presents a set in sorted order, but this is for
308 convenience only.
309 Sets are useful for defining an array range or for writing indexed relations.
310 More about sets and their use can be found in **syntax.fm5**.
311 \end_layout
312
313 \begin_layout Paragraph
314 \begin_inset LatexCommand index
315 name "relationship"
316
317 \end_inset
318
319 relationships
320 \end_layout
321
322 \begin_layout Itemize
323 Relations and logical relations allow you to state
324 \begin_inset LatexCommand index
325 name "equalities"
326
327 \end_inset
328
329 equalities and
330 \begin_inset LatexCommand index
331 name "inequalitites"
332
333 \end_inset
334
335 inequalities among the variables and constants in you models.
336 WHEN statements allow you to state relationships among the models and equations
337 which depend on the values of variables in those models.
338 Sets and symbols are not allowed in real or logical relations except when
339 used as array subscripts.
340 \end_layout
341
342 \begin_layout Standard
343 Real
344 \begin_inset LatexCommand index
345 name "real"
346
347 \end_inset
348
349
350 \begin_inset LatexCommand index
351 name "relation, real"
352
353 \end_inset
354
355 relations relate the values of real atoms, real constants, and integer constants.
356 Real relations cannot contain boolean constants and atoms, nor can they
357 contain integer atoms.
358
359 \end_layout
360
361 \begin_layout Standard
362 Logical
363 \begin_inset LatexCommand index
364 name "logical"
365
366 \end_inset
367
368 relations
369 \begin_inset LatexCommand index
370 name "logical relation"
371
372 \end_inset
373
374 relate the values of boolean atoms and boolean constants.
375 The
376 \family typewriter
377 SATISFIED
378 \family default
379
380 \begin_inset LatexCommand index
381 name "SATISFIED"
382
383 \end_inset
384
385 operator makes it possible to include real relations in a logical relation.
386 Neither integer atoms and constants nor real atoms and constants are allowed
387 in logical relations.
388 If you find yourself trying to write an equation with integer atoms, you
389 are really creating a conditional model for which you should use the WHEN
390 statement instead.
391 See **conditional modeling** to learn about how ASCEND represents this
392 kind of mathematical model.
393 There are also a real variable types, solver_integer and solver_binary,
394 which are used to formulate equations when the solver is expected to initially
395 treat the variable as a real value but drive it to an integer or 0-1 value
396 at the solution.
397 The integer programming features of ASCEND are described **elsewhere**.
398 \end_layout
399
400 \begin_layout Standard
401 Like atoms, real and logical relations may have attributes, subatomic particles
402 for use by ASCEND clients and users.
403 The name of a relation can be used in writing logical relations and WHEN
404 statements.
405
406 \end_layout
407
408 \begin_layout Standard
409 WHEN statements are outside the scope of this chapter; please see **conditional
410 modeling** or **syntax.fm5** for the details.
411 \end_layout
412
413 \begin_layout Paragraph
414 \begin_inset LatexCommand index
415 name "model"
416
417 \end_inset
418
419
420 \family typewriter
421 MODEL
422 \end_layout
423
424 \begin_layout Itemize
425 A model is simply a container for a collection of atoms, constants, sets,
426 relations, logical relations, when statements, and arrays of any of these.
427 The container also specifies some of the methods that can be used to manipulate
428 its contents.
429 Compiling a model creates an instance of it-- a simulation
430 \begin_inset LatexCommand index
431 name "simulation"
432
433 \end_inset
434
435 .
436 \end_layout
437
438 \begin_layout Paragraph
439
440 \family typewriter
441 SOLVER_VAR
442 \end_layout
443
444 \begin_layout Itemize
445 The real atom type
446 \family typewriter
447 solver_var
448 \family default
449 is the type from which all real variables that you want the system to solve
450 for must spring.
451 If you define a real variable using a type which is not a refinement of
452
453 \family typewriter
454 solver_var
455 \family default
456 , all solvers will treat that variable as an a scaling value or other given
457 constant rather than as a variable.
458
459 \end_layout
460
461 \begin_layout Standard
462 Solver_vars have a number of subatomic attributes (
463 \family typewriter
464 upper_bound
465 \family default
466 ,
467 \family typewriter
468 lower_bound
469 \family default
470 , and so forth) that help solvers find the solution of your model.
471 ATOM definitions specify appropriate default values for these attributes
472 that depend on the expected applications of the atom.
473 These attribute values can (and should) be modified by methods in the final
474 application model where the most accurate problem information is available.
475 \end_layout
476
477 \begin_layout Paragraph
478 Scaling
479 \begin_inset LatexCommand index
480 name "scaling"
481
482 \end_inset
483
484 value
485 \end_layout
486
487 \begin_layout Itemize
488 A real that is not a member of the
489 \family typewriter
490 solver_var
491 \family default
492 family is ignored by the solver.
493 Numerical solvers for problems with many equations in many variables work
494 better if the error computed for each equation (before the system is solved)
495 is of approximately size 1.0.
496 This is most critical when you are starting to solve a new problem at values
497 far, far away from the solution.
498 When the error of one equation is much larger than the errors in the others,
499 that error will skew the behavior of most numerical solvers and will cause
500 poor performance.
501
502 \end_layout
503
504 \begin_layout Standard
505 This is one of the many reasons that scientists and engineers work with
506 dimensionless models
507 \begin_inset LatexCommand index
508 name "dimensionless models"
509
510 \end_inset
511
512 : the process of scaling the equations into dimensionless form has the effect
513 of making the error of each equation roughly the same size even far away
514 from the solution.
515 It is sometimes easiest to obtain a dimensionless equation by writing the
516 equation in its dimensional form using natural variables and then dividing
517 both sides by an appropriate scaling value.
518 We will see how to define an atom for scaling purposes in the last part
519 of this chapter.
520 \end_layout
521
522 \begin_layout Section
523 How to find the right variable type
524 \begin_inset LatexCommand index
525 name "type, variable"
526
527 \end_inset
528
529
530 \end_layout
531
532 \begin_layout Standard
533 The type of real atom you want to use depends first on the dimensionality
534 (length, mass/time, etc.) needed and then on the application in which the
535 atom is going to be used.
536 For example, if you are modeling a moving car and you want an atom type
537 to describe the car's speed, then you need to find an atom with dimensionality
538 length/time or in ASCEND terms L/T.
539 There may be two or three types with this dimensionality, possibly including
540 real_constants, a real scaling value, and an atom derived from solver_var.
541 \end_layout
542
543 \begin_layout Standard
544 \begin_inset Marginal
545 status collapsed
546
547 \begin_layout Standard
548 Load atoms.a4l
549 \end_layout
550
551 \end_inset
552
553 The first step to finding the variable type needed is to make sure that
554 atoms.a4l is loaded in your Library window from
555 \family typewriter
556 ascend4/models/atoms.a4l
557 \family default
558 .
559 \end_layout
560
561 \begin_layout Standard
562 \begin_inset Marginal
563 status collapsed
564
565 \begin_layout Standard
566 Find an ATOM or CONSTANT by units
567 \end_layout
568
569 \end_inset
570
571 The next step is to open the "ATOM by units" dialog found in the Library
572 window's Find menu.
573 This dialog asks for the units of the real variable type you want.
574 For our example, speed, you would enter "feet/second," "furlongs/fortnight,"
575 "meter^3/second/ft^2" or any other combination of units that corresponds
576 to the dimensionality L/T.
577
578 \end_layout
579
580 \begin_layout Standard
581 If the system is able to deduce the dimensionality of the units you have
582 entered, it will return a list of all the currently loaded ATOM and CONSTANT
583 definitions with matching dimensions.
584 It may fail to understand the units, in which case you should try the correspon
585 ding SI units.
586 If it understands the units but there are no matching atoms or constants,
587 you will be duly informed.
588 If there is no atom that meets your needs, you should create one as outlined
589 in **the next section**.
590 \end_layout
591
592 \begin_layout Standard
593 \begin_inset Marginal
594 status collapsed
595
596 \begin_layout Standard
597 Selecting the right type
598 \end_layout
599
600 \end_inset
601
602 The resulting list of types includes a Code button which will display the
603 definition of any of the types listed once you select (highlight) that
604 type with the mouse.
605 Usually you will need to examine several of the alternatives to see which
606 one is most appropriate to the physics and mathematics of your problem.
607 Compare the default, bounds, and nominal values defined to those you need.
608 Check whether the type you are looking at is a
609 \family typewriter
610 CONSTANT
611 \family default
612 or an
613 \family typewriter
614 ATOM
615 \family default
616 .
617
618 \end_layout
619
620 \begin_layout Standard
621 You now know the name of the variable type you need, or you know that you
622 must create a new one to suit your needs.
623 \end_layout
624
625 \begin_layout Section
626 How to define a new type of variable
627 \begin_inset LatexCommand index
628 name "type, variable"
629
630 \end_inset
631
632
633 \begin_inset LatexCommand label
634 name "ssec:atoms.newVarType"
635
636 \end_inset
637
638
639 \end_layout
640
641 \begin_layout Standard
642 In this section we will give examples of defining the atom and constant
643 types as well as outline a few exceptional situations when you should NOT
644 define a new type.
645 More examples can be found and copied from
646 \family typewriter
647 atoms.a4l
648 \family default
649 .
650 You should define your new atoms in your personal atoms library.
651
652 \end_layout
653
654 \begin_layout Standard
655 \begin_inset Marginal
656 status collapsed
657
658 \begin_layout Standard
659 Saving customized variable types
660 \end_layout
661
662 \end_inset
663
664 The user data file
665 \family typewriter
666 ~
667 \backslash
668 ascdata
669 \backslash
670 myatoms.a4l
671 \family default
672 is the normal location for a personal
673 \begin_inset LatexCommand index
674 name "library, personal"
675
676 \end_inset
677
678 library.
679 This file contains the following three lines and then the
680 \family typewriter
681 ATOM
682 \family default
683 and
684 \family typewriter
685 CONSTANT
686 \family default
687 definitions you create.
688 \end_layout
689
690 \begin_layout LyX-Code
691 REQUIRE "atoms.a4l"; (* loads our atoms first *)
692 \end_layout
693
694 \begin_layout LyX-Code
695 PROVIDE "myatoms.a4l"; (* registers your library *)
696 \end_layout
697
698 \begin_layout LyX-Code
699 (* Custom atoms created by <insert your name here> *)
700 \end_layout
701
702 \begin_layout Standard
703 If you develop an interesting set of atoms for some problem domain outside
704 chemical engineering thermodynamics, please consider mailing it to us through
705 our web page.
706
707 \end_layout
708
709 \begin_layout Standard
710 The user data directory
711 \family typewriter
712 ~/
713 \begin_inset LatexCommand index
714 name "ascdata"
715
716 \end_inset
717
718 ascdata
719 \family default
720 may have a different name if you are running under Windows and do not have
721 the environment variable HOME
722 \begin_inset LatexCommand index
723 name "HOME"
724
725 \end_inset
726
727 defined.
728 It may be something like C:
729 \backslash
730 ascdata or
731 \backslash
732 WINNT
733 \backslash
734 Profiles
735 \backslash
736 Your Name
737 \backslash
738 ascdata.
739 When ASCEND is started, it prints out the name of this directory.
740 \end_layout
741
742 \begin_layout Standard
743 When you write a
744 \family typewriter
745 MODEL
746 \family default
747 which depends on the definition of your new atoms, do not forget to add
748 the statement
749 \end_layout
750
751 \begin_layout LyX-Code
752 REQUIRE "myatoms.a4l";
753 \end_layout
754
755 \begin_layout Standard
756 at the very top of your model file so that your atoms will be loaded before
757 your model definitions try to use them.
758 \end_layout
759
760 \begin_layout Subsection
761 A new real variable for solver use
762 \end_layout
763
764 \begin_layout Standard
765 Suppose you need an atom with units {dollar/ft^2/year} for some equation
766 relating amortized construction costs to building size.
767 Maybe this example is a bit far fetched, but it is a safe bet that our
768 library is not going to have an atom or a constant for these units.
769 Here is the standard incantation for defining a new variable type based
770 on
771 \family typewriter
772 solver_var
773 \family default
774 .
775 ASCEND allows a few permutations on this incantation, but they are of no
776 practical value.
777 The parts of this incantation that are in italics should be changed to
778 match your needs.
779 You can skip the comments, but you
780 \emph on
781 must
782 \emph default
783 include the units of the default on the bounds and nominal.
784 \end_layout
785
786 \begin_layout LyX-Code
787 ATOM amortized_area_cost
788 \end_layout
789
790 \begin_layout LyX-Code
791 REFINES solver_var DEFAULT 3.0 {dollar/ft^2/year};
792 \end_layout
793
794 \begin_layout LyX-Code
795 lower_bound := 0 {dollar/ft^2/year};
796 \end_layout
797
798 \begin_layout LyX-Code
799 (* minimum value *)
800 \end_layout
801
802 \begin_layout LyX-Code
803 upper_bound := 10000 {dollar/ft^2/year};
804 \end_layout
805
806 \begin_layout LyX-Code
807 (* maximum value for any sane application *)
808 \end_layout
809
810 \begin_layout LyX-Code
811 nominal := 10 {dollar/ft^2/year};
812 \end_layout
813
814 \begin_layout LyX-Code
815 (* expected size for all reasonable applications*)
816 \end_layout
817
818 \begin_layout LyX-Code
819 END amortized_area_cost;
820 \end_layout
821
822 \begin_layout Standard
823 In picking the name of your atom, remember that names should be as self-explanat
824 ory as possible.
825 Also avoid choosing a name that ends in _constant (as this is conventionally
826 applied only to CONSTANT
827 \begin_inset LatexCommand index
828 name "CONSTANT"
829
830 \end_inset
831
832 definitions) or _parameter.
833 Parameter is an extremely ambiguous and therefore useless word.
834 Also remember that the role a variable plays in solving a set of equations
835 depends on how the solver being applied interprets .fixed and other attributes
836 of the variable.
837 \end_layout
838
839 \begin_layout Standard
840 \begin_inset Marginal
841 status collapsed
842
843 \begin_layout Standard
844 Exceptions
845 \end_layout
846
847 \end_inset
848
849 If an atom type matches all but one of the attributes you need for your
850 problem, say for example the
851 \family typewriter
852 upper_bound
853 \family default
854 is way too high, use the existing variable type and reassign the bound
855 to a more sensible value in the
856 \family typewriter
857 default_self
858 \family default
859 method of the model where the variable is created.
860 Having a dozen atoms defined for the same units gets confusing in short
861 order to anyone you might share your models with.
862 \end_layout
863
864 \begin_layout Standard
865 The exception to the exception (yes, there always seems to be one of those)
866 is the case of a
867 \family typewriter
868 lower_bound
869 \family default
870 set at zero.
871 Usually a
872 \family typewriter
873 lower_bound
874 \family default
875 of zero indicates that there is something inherently positive about variables
876 of that type.
877 Variables with a bound of this type should not have these physical bounds
878 expanded in an application.
879 Another example of this type of bound is the
880 \family typewriter
881 upper_bound
882 \family default
883 1.0 on the type fraction.
884 \end_layout
885
886 \begin_layout Standard
887 For example, negative temperature just is not sensible for most physical
888 systems.
889 ASCEND defines a temperature atom for use in equations involving the absolute
890 temperature.
891 On the other hand, a temperature difference, delta T, is frequently negative
892 so a separate atom is defined.
893 Anyone receiving a model written using the two types of atoms, which both
894 have units of {Kelvin}, can easily tell which variables might legitimately
895 take on negative values by noting whether the variable is defined as a
896 temperature or a delta_temperature.
897 \end_layout
898
899 \begin_layout Subsection
900 A new real constant
901 \begin_inset LatexCommand index
902 name "real constant"
903
904 \end_inset
905
906
907 \begin_inset LatexCommand index
908 name "constant, real"
909
910 \end_inset
911
912 type
913 \end_layout
914
915 \begin_layout Standard
916 Real constants which do not have a default value are usually needed only
917 in libraries of reusable models, such as
918 \family typewriter
919 components.a4l
920 \family default
921 , where the values depend on the end-user's selection from alternatives
922 in a database.
923 The standard incantation to define a new real constant type is:
924 \end_layout
925
926 \begin_layout LyX-Code
927 CONSTANT
928 \shape italic
929 critical_pressure_constant
930 \end_layout
931
932 \begin_layout LyX-Code
933 REFINES real_constant DIMENSION
934 \shape italic
935 M/L/T^2
936 \shape default
937 ;
938 \end_layout
939
940 \begin_layout Standard
941 Here again, the italic parts of this incantation should be redefined for
942 your purpose.
943 \end_layout
944
945 \begin_layout Standard
946 \begin_inset Marginal
947 status collapsed
948
949 \begin_layout Standard
950 Universal exceptions and unit conversions
951 \end_layout
952
953 \end_inset
954
955 It is wasteful to define a
956 \family typewriter
957 CONSTANT
958 \family default
959 type and a compiled object to represent a universal
960 \begin_inset LatexCommand index
961 name "universal constant"
962
963 \end_inset
964
965
966 \begin_inset LatexCommand index
967 name "constant, universal"
968
969 \end_inset
970
971 constant.
972 For example, the thermodynamic gas constant, R = 8.314...
973 {J/mole/K}, is frequently needed in modeling chemical systems.
974 The SI value of R does not vary with its application.
975 Neither does the value of
976 \begin_inset LatexCommand index
977 name "pi"
978
979 \end_inset
980
981
982 \begin_inset Formula $\pi$
983 \end_inset
984
985 .
986 Numeric constants of this sort are better represented as a numeric coefficient
987 and an appropriately defined unit conversion.
988 Consider the
989 \begin_inset LatexCommand index
990 name "ideal gas law"
991
992 \end_inset
993
994 ideal gas law, PV = NRT and the ASCEND unit conversion {GAS_C} which appears
995 in the library ascend4/models/measures.a4l.
996 This equation should be written:
997 \end_layout
998
999 \begin_layout LyX-Code
1000 P * V = n * 1.0{GAS_C} * T;
1001 \end_layout
1002
1003 \begin_layout Standard
1004 Similarly, area = pi*r^2 should be written
1005 \end_layout
1006
1007 \begin_layout LyX-Code
1008 area = 1{PI} * r^2;
1009 \end_layout
1010
1011 \begin_layout Standard
1012 The coefficient 1 of
1013 \family typewriter
1014 {GAS_C}
1015 \family default
1016 and {PI} in these equations takes of the dimensionality of and is multiplied
1017 by the conversion factor implied by the
1018 \family typewriter
1019 UNITS
1020 \family default
1021 definition for the units.
1022 If we check
1023 \family typewriter
1024 measures.a4l
1025 \family default
1026 , we find the definition of PI is simply {3.14159...} and the definition of
1027
1028 \family typewriter
1029 GAS_C
1030 \family default
1031 is {8.314...
1032 J/mole/K} as we ought to expect.
1033 \end_layout
1034
1035 \begin_layout Standard
1036 For historical reasons there are a few universal constant definitions in
1037
1038 \family typewriter
1039 atoms.a4l
1040 \family default
1041 .
1042 New modelers should not use them; they are only provided to support outdated
1043 models that no one has yet taken the time to update.
1044 \end_layout
1045
1046 \begin_layout Subsection
1047 New types for integers, symbols, and booleans
1048 \end_layout
1049
1050 \begin_layout Standard
1051 The syntax for
1052 \family typewriter
1053 ATOM
1054 \family default
1055 and
1056 \family typewriter
1057 CONSTANT
1058 \family default
1059 definitions of the non-real types is the same as for real number types,
1060 except that units are not involved.
1061 Take your best guess based on the examples above, and you will get it right.
1062 If even that is too hard, more details are given in **syntax.fm5**.
1063 \end_layout
1064
1065 \begin_layout Section
1066 How to define a
1067 \begin_inset LatexCommand index
1068 name "scaling"
1069
1070 \end_inset
1071
1072 scaling variable
1073 \end_layout
1074
1075 \begin_layout Standard
1076 A scaling variable
1077 \family typewriter
1078 ATOM
1079 \family default
1080 is defined with a name that ends in _scale as follows.
1081 Note that this
1082 \family typewriter
1083 ATOM
1084 \family default
1085 does not refine
1086 \family typewriter
1087 solver_var
1088 \family default
1089 , so solvers will not try to change variables of this type during the solution
1090 process.
1091 \end_layout
1092
1093 \begin_layout LyX-Code
1094 ATOM distance_scale REFINES real DEFAULT 1.0{meter};
1095 \end_layout
1096
1097 \begin_layout LyX-Code
1098 END distance_scale;
1099 \end_layout
1100
1101 \begin_layout Standard
1102 \begin_inset Marginal
1103 status collapsed
1104
1105 \begin_layout Standard
1106 ASCEND cannot do it all for you
1107 \end_layout
1108
1109 \end_inset
1110
1111 ASCEND uses a combination of symbolic and numerical techniques to create
1112 and solve mathematical problems.
1113 Once you get the problem close to the solution, ASCEND can internally compute
1114 its own scaling values for relations, known elsewhere as "relation nominals
1115 \begin_inset LatexCommand index
1116 name "nominals"
1117
1118 \end_inset
1119
1120 ,
1121 \begin_inset Quotes erd
1122 \end_inset
1123
1124 assuming you have set good values for the .nominal attribute of all the
1125 variables.
1126 It does this by computing the largest additive term in each equation.
1127 The absolute value of this term is a very good scaling value.
1128 \end_layout
1129
1130 \begin_layout Standard
1131 This internal scaling works quite well, but not when the problem is very
1132 far away from the solution so that the largest additive terms computed
1133 are not at all representative of the physical situation being modeled.
1134 The
1135 \family typewriter
1136 scale_self
1137 \family default
1138
1139 \begin_inset LatexCommand index
1140 name "scale\\_self"
1141
1142 \end_inset
1143
1144 method, which should be written for every model as described in Section\InsetSpace ~
1145
1146 \begin_inset LatexCommand ref
1147 reference "sssec:methods.scaleself"
1148
1149 \end_inset
1150
1151 of Chapter
1152 \noun off
1153 \InsetSpace ~
1154
1155 \begin_inset LatexCommand vref
1156 reference "cha:methods"
1157
1158 \end_inset
1159
1160 should set the equation scaling values you have defined in a
1161 \family typewriter
1162 \noun default
1163 MODEL
1164 \family default
1165 \noun off
1166 based on the best available information.
1167 In a chemical engineering flowsheeting problem, for example, information
1168 about a key process material flow should be propagated throughout the process
1169 flowsheet to scale all the other flows, material balance equations, and
1170 energy balance equations.
1171 \end_layout
1172
1173 \begin_layout Standard
1174 \begin_inset Marginal
1175 status collapsed
1176
1177 \begin_layout Standard
1178 Scaling atom default value
1179 \end_layout
1180
1181 \end_inset
1182
1183 The
1184 \begin_inset LatexCommand index
1185 name "default value"
1186
1187 \end_inset
1188
1189 default value for any scaling atom should always be 1.0 in appropriate SI
1190 units, so that the scaling will have no effect until you assign a problem
1191 specific value.
1192 Multiplying or dividing both sides of an equation by 1.0 obviously will
1193 not change the mathematical behavior, but you do not want to change the
1194 behavior arbitrarily either-- you want to change it based on problem informatio
1195 n that is not contained in your
1196 \family typewriter
1197 myatoms.a4l
1198 \family default
1199 file.
1200 \end_layout
1201
1202 \end_body
1203 \end_document

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22