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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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