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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1352 - (show annotations) (download) (as text)
Sat Mar 17 23:48:07 2007 UTC (16 years, 2 months ago) by jpye
File MIME type: application/x-lyx
File size: 45256 byte(s)
Added some references to items in the ASCEND bibliography
1 #LyX 1.4.3 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 default
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 1
25 \paperpagestyle default
26 \tracking_changes false
27 \output_changes true
28 \end_header
29
30 \begin_body
31
32 \begin_layout Chapter
33 The modeling of a simple dynamic tank
34 \begin_inset LatexCommand \index{dynamic tank}
35
36 \end_inset
37
38
39 \begin_inset LatexCommand \label{cha:ivp}
40
41 \end_inset
42
43
44 \end_layout
45
46 \begin_layout Standard
47 This chapter assumes you have read Chapter
48 \color black
49 \InsetSpace ~
50
51 \begin_inset LatexCommand \vref{cha:model1}
52
53 \end_inset
54
55 and Chapter\InsetSpace ~
56
57 \begin_inset LatexCommand \vref{cha:model2}
58
59 \end_inset
60
61 , which introduce you to ASCEND modeling concepts.
62 \end_layout
63
64 \begin_layout Standard
65 The purpose of this chapter is to be a good first step along the path to
66 learning how to use ASCEND for dynamic simulations
67 \begin_inset LatexCommand \index{dynamic simulation}
68
69 \end_inset
70
71
72 \begin_inset Foot
73 status open
74
75 \begin_layout Standard
76 Some further information on this topic is available in the report by Perry
77 and Allan
78 \begin_inset LatexCommand \cite{Perry1996}
79
80 \end_inset
81
82
83 \end_layout
84
85 \end_inset
86
87 .
88 We shall lead you through the steps for creating a simple model.
89 You will also learn the standard methods that we employ for our dynamic
90 libraries
91 \begin_inset LatexCommand \index{dynamic libraries}
92
93 \end_inset
94
95 .
96 We will present our reasons for the steps we take.
97
98 \end_layout
99
100 \begin_layout Subsubsection*
101 The problem
102 \end_layout
103
104 \begin_layout List
105 \labelwidthstring 00.00.0000
106 Step\InsetSpace ~
107 1: We would like to create a dynamic model of a simple tank.
108 \end_layout
109
110 \begin_layout Subsubsection*
111 Topics covered in this chapter are:
112 \end_layout
113
114 \begin_layout Itemize
115 Converting the word description to an ASCEND model.
116 \end_layout
117
118 \begin_layout Itemize
119 Solving the model.
120 \end_layout
121
122 \begin_layout Itemize
123 Creating a script to load and execute an instance of the model.
124 \end_layout
125
126 \begin_layout Itemize
127 Integrating
128 \begin_inset LatexCommand \index{integrating}
129
130 \end_inset
131
132 the model.
133 \end_layout
134
135 \begin_layout Itemize
136 View Integration Results.
137 \end_layout
138
139 \begin_layout Section
140 Converting the word description
141 \newline
142 into an ASCEND model
143 \end_layout
144
145 \begin_layout Standard
146 As stated in Section\InsetSpace ~
147
148 \begin_inset LatexCommand \vref{sec:model1.converting-the-word}
149
150 \end_inset
151
152
153 \color none
154 , we need to make an instance of a type and solve the instance.
155 So we shall start by creating a tank type definition.
156 We will have to create our type definition as a text file using a text
157 editor.
158 (Possible text editors
159 \begin_inset LatexCommand \index{text editor}
160
161 \end_inset
162
163 are Word
164 \begin_inset LatexCommand \index{Word}
165
166 \end_inset
167
168 , Emacs
169 \begin_inset LatexCommand \index{Emacs}
170
171 \end_inset
172
173 , Notepad
174 \begin_inset LatexCommand \index{Notepad}
175
176 \end_inset
177
178 , pico
179 \begin_inset LatexCommand \index{pico}
180
181 \end_inset
182
183 , vi
184 \begin_inset LatexCommand \index{vi}
185
186 \end_inset
187
188 , etc.
189 We shall discuss editors shortly.)
190 \end_layout
191
192 \begin_layout Standard
193 We need first to decide the parts to our model.
194 In this case we know that we need the variables listed in Table\InsetSpace ~
195
196 \begin_inset LatexCommand \eqref{cap:Variables-required-for}
197
198 \end_inset
199
200 We readily fill in the first three columns in this table, and we can also
201 fill out the fourth column if we know the units that are associated with
202 each of the parts.
203 To find the ASCEND variable type needed for the fourth column use the find
204 menu on the library window and select ATOM by units
205 \begin_inset LatexCommand \index{atom, select by units}
206
207 \end_inset
208
209 .
210 The result of this search will be all the ASCEND variable type that have
211 the units you entered.
212 \end_layout
213
214 \begin_layout Standard
215 \begin_inset Float table
216 wide false
217 sideways false
218 status open
219
220 \begin_layout Caption
221 \begin_inset LatexCommand \label{cap:Variables-required-for}
222
223 \end_inset
224
225 Variables required for model
226 \end_layout
227
228 \begin_layout Standard
229 \begin_inset Tabular
230 <lyxtabular version="3" rows="8" columns="4">
231 <features>
232 <column alignment="center" valignment="top" leftline="true" width="0">
233 <column alignment="center" valignment="top" leftline="true" width="1.5in">
234 <column alignment="center" valignment="top" leftline="true" width="1.5in">
235 <column alignment="center" valignment="top" leftline="true" rightline="true" width="1in">
236 <row topline="true" bottomline="true">
237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
238 \begin_inset Text
239
240 \begin_layout Standard
241 Symbol
242 \end_layout
243
244 \end_inset
245 </cell>
246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
247 \begin_inset Text
248
249 \begin_layout Standard
250 Meaning
251 \end_layout
252
253 \end_inset
254 </cell>
255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
256 \begin_inset Text
257
258 \begin_layout Standard
259 Typical Units
260 \begin_inset Foot
261 status collapsed
262
263 \begin_layout Standard
264 as entered into ASCEND
265 \end_layout
266
267 \end_inset
268
269
270 \end_layout
271
272 \end_inset
273 </cell>
274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
275 \begin_inset Text
276
277 \begin_layout Standard
278 ASCEND variable type
279 \end_layout
280
281 \end_inset
282 </cell>
283 </row>
284 <row topline="true">
285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
286 \begin_inset Text
287
288 \begin_layout Standard
289
290 \family typewriter
291 M
292 \end_layout
293
294 \end_inset
295 </cell>
296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
297 \begin_inset Text
298
299 \begin_layout Standard
300 Moles in Tank
301 \end_layout
302
303 \end_inset
304 </cell>
305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
306 \begin_inset Text
307
308 \begin_layout Standard
309 mol, kmol
310 \end_layout
311
312 \end_inset
313 </cell>
314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
315 \begin_inset Text
316
317 \begin_layout Standard
318 mole
319 \end_layout
320
321 \end_inset
322 </cell>
323 </row>
324 <row topline="true">
325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
326 \begin_inset Text
327
328 \begin_layout Standard
329
330 \family typewriter
331 dM_dt
332 \end_layout
333
334 \end_inset
335 </cell>
336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
337 \begin_inset Text
338
339 \begin_layout Standard
340 Rate of change of Moles in tank (derivative)
341 \end_layout
342
343 \end_inset
344 </cell>
345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
346 \begin_inset Text
347
348 \begin_layout Standard
349 mol/sec, kmol/sec
350 \end_layout
351
352 \end_inset
353 </cell>
354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
355 \begin_inset Text
356
357 \begin_layout Standard
358 molar_rate
359 \end_layout
360
361 \end_inset
362 </cell>
363 </row>
364 <row topline="true">
365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
366 \begin_inset Text
367
368 \begin_layout Standard
369
370 \family typewriter
371 input
372 \end_layout
373
374 \end_inset
375 </cell>
376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
377 \begin_inset Text
378
379 \begin_layout Standard
380 Feed flow rate
381 \end_layout
382
383 \end_inset
384 </cell>
385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
386 \begin_inset Text
387
388 \begin_layout Standard
389 mol/sec, kmol/sec
390 \end_layout
391
392 \end_inset
393 </cell>
394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
395 \begin_inset Text
396
397 \begin_layout Standard
398 molar_rate
399 \end_layout
400
401 \end_inset
402 </cell>
403 </row>
404 <row topline="true">
405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
406 \begin_inset Text
407
408 \begin_layout Standard
409
410 \family typewriter
411 output
412 \end_layout
413
414 \end_inset
415 </cell>
416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
417 \begin_inset Text
418
419 \begin_layout Standard
420 Output flow rate
421 \end_layout
422
423 \end_inset
424 </cell>
425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
426 \begin_inset Text
427
428 \begin_layout Standard
429 mol/sec, kmol/sec
430 \end_layout
431
432 \end_inset
433 </cell>
434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
435 \begin_inset Text
436
437 \begin_layout Standard
438 molar_rate
439 \end_layout
440
441 \end_inset
442 </cell>
443 </row>
444 <row topline="true">
445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
446 \begin_inset Text
447
448 \begin_layout Standard
449
450 \family typewriter
451 Volume
452 \end_layout
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \begin_layout Standard
460 Volume of liquid in the tank
461 \end_layout
462
463 \end_inset
464 </cell>
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
466 \begin_inset Text
467
468 \begin_layout Standard
469 m^3,ft^3
470 \end_layout
471
472 \end_inset
473 </cell>
474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
475 \begin_inset Text
476
477 \begin_layout Standard
478 volume
479 \end_layout
480
481 \end_inset
482 </cell>
483 </row>
484 <row topline="true">
485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
486 \begin_inset Text
487
488 \begin_layout Standard
489
490 \family typewriter
491 density
492 \end_layout
493
494 \end_inset
495 </cell>
496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
497 \begin_inset Text
498
499 \begin_layout Standard
500 Molar density of tank fluid
501 \end_layout
502
503 \end_inset
504 </cell>
505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
506 \begin_inset Text
507
508 \begin_layout Standard
509 mol/m^3,mol/ft^3
510 \end_layout
511
512 \end_inset
513 </cell>
514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
515 \begin_inset Text
516
517 \begin_layout Standard
518 molar_density
519 \end_layout
520
521 \end_inset
522 </cell>
523 </row>
524 <row topline="true" bottomline="true">
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
526 \begin_inset Text
527
528 \begin_layout Standard
529
530 \family typewriter
531 dynamic
532 \end_layout
533
534 \end_inset
535 </cell>
536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
537 \begin_inset Text
538
539 \begin_layout Standard
540 Boolean for switching between dynamic and steady state simulations
541 \end_layout
542
543 \end_inset
544 </cell>
545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
546 \begin_inset Text
547
548 \begin_layout Standard
549 N/A
550 \end_layout
551
552 \end_inset
553 </cell>
554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
555 \begin_inset Text
556
557 \begin_layout Standard
558 boolean
559 \end_layout
560
561 \end_inset
562 </cell>
563 </row>
564 </lyxtabular>
565
566 \end_inset
567
568
569 \end_layout
570
571 \end_inset
572
573
574 \end_layout
575
576 \begin_layout Standard
577 We would like to be able to compute the number of moles in the tank for
578 a given volume assuming steady state
579 \begin_inset LatexCommand \index{steady state}
580
581 \end_inset
582
583 (dM_dt = 0).
584 We would also like to be able to calculate how the volume changes if we
585 are not at steady state.
586 The following equations describe the simple tank system.
587 \end_layout
588
589 \begin_layout Standard
590 The first equation is the differential equation that relates the input and
591 output flows to the accumulation in the tank.
592 The second equation is the relation of the moles in the tank to the volume
593 of liquid and should be rearranged to avoid division
594 \begin_inset LatexCommand \index{division, avoid}
595
596 \end_inset
597
598 .
599 These equations are all that is need for a simple tank.
600 \end_layout
601
602 \begin_layout Standard
603 \begin_inset Formula \begin{equation}
604 dM\_dt=input-output\label{eq:ivp.dMdt}\end{equation}
605
606 \end_inset
607
608
609 \end_layout
610
611 \begin_layout Standard
612 \begin_inset Formula \begin{equation}
613 Volume=\frac{M}{density}\label{eq:ivp.Volume}\end{equation}
614
615 \end_inset
616
617
618 \end_layout
619
620 \begin_layout Subsubsection*
621 The first version of the code for tank
622 \end_layout
623
624 \begin_layout LyX-Code
625 REQUIRE "ivpsystem.a4l";
626 \end_layout
627
628 \begin_layout LyX-Code
629 REQUIRE "atoms.a4l";
630 \end_layout
631
632 \begin_layout LyX-Code
633 MODEL tank
634 \begin_inset LatexCommand \index{tank, dynamic MODEL}
635
636 \end_inset
637
638 ;
639 \end_layout
640
641 \begin_layout LyX-Code
642 (* List of Variables *)
643 \end_layout
644
645 \begin_layout LyX-Code
646 dM_dt IS_A molar_rate;
647 \end_layout
648
649 \begin_layout LyX-Code
650 M IS_A mole;
651 \end_layout
652
653 \begin_layout LyX-Code
654 input IS_A molar_rate;
655 \end_layout
656
657 \begin_layout LyX-Code
658 output IS_A molar_rate;
659 \end_layout
660
661 \begin_layout LyX-Code
662 Volume IS_A volume;
663 \end_layout
664
665 \begin_layout LyX-Code
666 density IS_A real_constant;
667 \end_layout
668
669 \begin_layout LyX-Code
670 dynamic IS_A boolean;
671 \end_layout
672
673 \begin_layout LyX-Code
674 t IS_A time;
675 \end_layout
676
677 \begin_layout LyX-Code
678 (* Equations *)
679 \end_layout
680
681 \begin_layout LyX-Code
682 dM_dt = input - output;
683 \end_layout
684
685 \begin_layout LyX-Code
686 M = Volume * density;
687 \end_layout
688
689 \begin_layout LyX-Code
690 (* Assignment of values to Constants *)
691 \end_layout
692
693 \begin_layout LyX-Code
694 density :==10 {mol/m^3};
695 \end_layout
696
697 \begin_layout LyX-Code
698
699 \end_layout
700
701 \begin_layout LyX-Code
702 METHODS
703 \end_layout
704
705 \begin_layout LyX-Code
706
707 \end_layout
708
709 \begin_layout LyX-Code
710 METHOD check_self;
711 \end_layout
712
713 \begin_layout LyX-Code
714 IF (input < 1e-4 {mole/s}) THEN
715 \end_layout
716
717 \begin_layout LyX-Code
718 STOP {Input dried up in tank};
719 \end_layout
720
721 \begin_layout LyX-Code
722 END IF;
723 \end_layout
724
725 \begin_layout LyX-Code
726 IF (output < 1e-4 {mole/s}) THEN
727 \end_layout
728
729 \begin_layout LyX-Code
730 STOP {Output dried up in tank};
731 \end_layout
732
733 \begin_layout LyX-Code
734 END IF;
735 \end_layout
736
737 \begin_layout LyX-Code
738 END check_self;
739 \end_layout
740
741 \begin_layout LyX-Code
742 METHOD check_all;
743 \end_layout
744
745 \begin_layout LyX-Code
746 RUN check_self;
747 \end_layout
748
749 \begin_layout LyX-Code
750 END check_all;
751 \end_layout
752
753 \begin_layout LyX-Code
754
755 \end_layout
756
757 \begin_layout LyX-Code
758 METHOD default_self;
759 \end_layout
760
761 \begin_layout LyX-Code
762 dynamic := FALSE;
763 \end_layout
764
765 \begin_layout LyX-Code
766 t :=0 {sec};
767 \end_layout
768
769 \begin_layout LyX-Code
770 dM_dt :=0 {mol/sec};
771 \end_layout
772
773 \begin_layout LyX-Code
774 dM_dt.lower_bound := -1e49 {mol/sec};
775 \end_layout
776
777 \begin_layout LyX-Code
778 END default_self;
779 \end_layout
780
781 \begin_layout LyX-Code
782
783 \end_layout
784
785 \begin_layout LyX-Code
786 METHOD default_all;
787 \end_layout
788
789 \begin_layout LyX-Code
790 RUN default_self;
791 \end_layout
792
793 \begin_layout LyX-Code
794 END default_all;
795 \end_layout
796
797 \begin_layout LyX-Code
798
799 \end_layout
800
801 \begin_layout LyX-Code
802 METHOD bound_self;
803 \end_layout
804
805 \begin_layout LyX-Code
806 END bound_self;
807 \end_layout
808
809 \begin_layout LyX-Code
810
811 \end_layout
812
813 \begin_layout LyX-Code
814 METHOD bound_all;
815 \end_layout
816
817 \begin_layout LyX-Code
818 RUN bound_self;
819 \end_layout
820
821 \begin_layout LyX-Code
822 END bound_all;
823 \end_layout
824
825 \begin_layout LyX-Code
826
827 \end_layout
828
829 \begin_layout LyX-Code
830 METHOD scale_self;
831 \end_layout
832
833 \begin_layout LyX-Code
834 END scale_self;
835 \end_layout
836
837 \begin_layout LyX-Code
838
839 \end_layout
840
841 \begin_layout LyX-Code
842 METHOD scale_all;
843 \end_layout
844
845 \begin_layout LyX-Code
846 RUN scale_self;
847 \end_layout
848
849 \begin_layout LyX-Code
850 END scale_all;
851 \end_layout
852
853 \begin_layout LyX-Code
854
855 \end_layout
856
857 \begin_layout LyX-Code
858 METHOD seqmod;
859 \end_layout
860
861 \begin_layout LyX-Code
862 dM_dt.fixed :=TRUE;
863 \end_layout
864
865 \begin_layout LyX-Code
866 M.fixed :=FALSE;
867 \end_layout
868
869 \begin_layout LyX-Code
870 Volume.fixed :=TRUE;
871 \end_layout
872
873 \begin_layout LyX-Code
874 input.fixed :=TRUE;
875 \end_layout
876
877 \begin_layout LyX-Code
878 output.fixed :=FALSE;
879 \end_layout
880
881 \begin_layout LyX-Code
882 IF dynamic THEN
883 \end_layout
884
885 \begin_layout LyX-Code
886 dM_dt.fixed :=FALSE;
887 \end_layout
888
889 \begin_layout LyX-Code
890 M.fixed :=TRUE;
891 \end_layout
892
893 \begin_layout LyX-Code
894 Volume.fixed :=FALSE;
895 \end_layout
896
897 \begin_layout LyX-Code
898 output.fixed :=TRUE;
899 \end_layout
900
901 \begin_layout LyX-Code
902 END IF;
903 \end_layout
904
905 \begin_layout LyX-Code
906 END seqmod;
907 \end_layout
908
909 \begin_layout LyX-Code
910
911 \end_layout
912
913 \begin_layout LyX-Code
914 METHOD specify;
915 \end_layout
916
917 \begin_layout LyX-Code
918 input.fixed :=TRUE;
919 \end_layout
920
921 \begin_layout LyX-Code
922 RUN seqmod;
923 \end_layout
924
925 \begin_layout LyX-Code
926 END specify;
927 \end_layout
928
929 \begin_layout LyX-Code
930
931 \end_layout
932
933 \begin_layout LyX-Code
934 METHOD set_ode;
935 \end_layout
936
937 \begin_layout LyX-Code
938 (* set ODE_TYPE -1=independent variable,
939 \end_layout
940
941 \begin_layout LyX-Code
942 0=algebraic variable, 1=state variable,
943 \end_layout
944
945 \begin_layout LyX-Code
946 2=derivative *)
947 \end_layout
948
949 \begin_layout LyX-Code
950 t.ode_type :=-1;
951 \end_layout
952
953 \begin_layout LyX-Code
954 dM_dt.ode_type :=2;
955 \end_layout
956
957 \begin_layout LyX-Code
958 M.ode_type :=1;
959 \end_layout
960
961 \begin_layout LyX-Code
962 (* Set ODE_ID *)
963 \end_layout
964
965 \begin_layout LyX-Code
966 dM_dt.ode_id :=1;
967 \end_layout
968
969 \begin_layout LyX-Code
970 M.ode_id :=1;
971 \end_layout
972
973 \begin_layout LyX-Code
974 END set_ode;
975 \end_layout
976
977 \begin_layout LyX-Code
978
979 \end_layout
980
981 \begin_layout LyX-Code
982 METHOD set_obs;
983 \end_layout
984
985 \begin_layout LyX-Code
986 (* Set OBS_ID to any integer value greater
987 \end_layout
988
989 \begin_layout LyX-Code
990 than 0, the variable will be recorded
991 \end_layout
992
993 \begin_layout LyX-Code
994 (i.e., observed) *)
995 \end_layout
996
997 \begin_layout LyX-Code
998 M.obs_id :=1;
999 \end_layout
1000
1001 \begin_layout LyX-Code
1002 Volume.obs_id :=2;
1003 \end_layout
1004
1005 \begin_layout LyX-Code
1006 input.obs_id :=3;
1007 \end_layout
1008
1009 \begin_layout LyX-Code
1010 output.obs_id :=4;
1011 \end_layout
1012
1013 \begin_layout LyX-Code
1014 END set_obs;
1015 \end_layout
1016
1017 \begin_layout LyX-Code
1018
1019 \end_layout
1020
1021 \begin_layout LyX-Code
1022 METHOD values;
1023 \end_layout
1024
1025 \begin_layout LyX-Code
1026 Volume :=5 {m^3};
1027 \end_layout
1028
1029 \begin_layout LyX-Code
1030 input :=100 {mole/s};
1031 \end_layout
1032
1033 \begin_layout LyX-Code
1034 END values;
1035 \end_layout
1036
1037 \begin_layout LyX-Code
1038 END tank;
1039 \end_layout
1040
1041 \begin_layout Standard
1042 Our model definition has the following structure for it so far:
1043 \end_layout
1044
1045 \begin_layout Itemize
1046 MODEL statement
1047 \end_layout
1048
1049 \begin_layout Itemize
1050 list of variables we intend to use in the type definition
1051 \end_layout
1052
1053 \begin_layout Itemize
1054 equations
1055 \end_layout
1056
1057 \begin_layout Itemize
1058 METHODS
1059 \end_layout
1060
1061 \begin_layout Itemize
1062 END statement
1063 \end_layout
1064
1065 \begin_layout Standard
1066 While we have put the statements in this order, we could mix them up and
1067 intermix the middle two types of statements, even going to the extreme
1068 of defining the variables after we first use them.
1069 Once the
1070 \family typewriter
1071 METHODS
1072 \family default
1073 section is started no new equations or variables can be declared.
1074 The
1075 \family typewriter
1076 MODEL
1077 \family default
1078 and
1079 \family typewriter
1080 END
1081 \family default
1082 statements begin and end the type definition.
1083 \end_layout
1084
1085 \begin_layout Standard
1086 There are two new methods added to a dynamic model that you would not see
1087 in a steady state model, and they are the
1088 \family typewriter
1089 set_ode
1090 \family default
1091 and
1092 \family typewriter
1093 set_obs
1094 \family default
1095 methods.
1096 The
1097 \family typewriter
1098 set_ode
1099 \family default
1100 method is used to setup the model for integration.
1101 The
1102 \family typewriter
1103 set_obs
1104 \family default
1105 method is used to tell ASCEND which variables you would like to observe
1106 in the output of the integration.
1107 \end_layout
1108
1109 \begin_layout Standard
1110 Now we need to discuss the how and why of the two new methods.
1111 The
1112 \family typewriter
1113 set_ode
1114 \family default
1115 method is used to set up the equations and variables described in the model
1116 for integration by LSODE
1117 \begin_inset LatexCommand \index{LSODE}
1118
1119 \end_inset
1120
1121 .
1122 In order for LSODE to be able to integrate the model, it needs to know
1123 which variable is the independent variable - in this case
1124 \family typewriter
1125 t
1126 \family default
1127 (time), which variables are the derivatives, and which are the states.
1128 The way we do this is we have to add a few extra attributes to each variable.
1129 In Section\InsetSpace ~
1130
1131 \begin_inset LatexCommand \ref{sec:model1.converting-the-word}
1132
1133 \end_inset
1134
1135
1136 \color none
1137 , the idea of an atom was discussed with its units, default value, bounds
1138 etc.
1139 We need to add 5 more of this type of parameter.
1140 These attributes
1141 \begin_inset LatexCommand \index{attributes, ODE variables}
1142
1143 \end_inset
1144
1145 are
1146 \family typewriter
1147 \color black
1148 ode_type
1149 \family default
1150 \color none
1151 ,
1152 \family typewriter
1153 ode_id
1154 \family default
1155 ,
1156 \family typewriter
1157 obs_id
1158 \family default
1159 ,
1160 \family typewriter
1161 ode_rtol
1162 \family default
1163 and
1164 \family typewriter
1165 ode_atol
1166 \family default
1167 .
1168
1169 \end_layout
1170
1171 \begin_layout Standard
1172 This now brings us to the reason there is a
1173 \family typewriter
1174 system.a4l
1175 \family default
1176 and an
1177 \family typewriter
1178 ivpsystem.a4l
1179 \family default
1180
1181 \begin_inset LatexCommand \index{ivpsystem.a4l}
1182
1183 \end_inset
1184
1185 .
1186 For a steady state model the new attributes discussed above are not needed,
1187 and would take up memory and introduce confusion; therefore, they are excluded
1188 for the system library.
1189 If a dynamic simulations is to be loaded and solved, the ivpsystem library
1190 needs to be loaded instead of the system library so the extra attributes
1191 will be present with each part.
1192 \end_layout
1193
1194 \begin_layout Standard
1195 We will now go through the purpose of each of these attributes.
1196 First
1197 \family typewriter
1198 ode_type
1199 \family default
1200 is to tell the system what type of variable it is.
1201 A value of -1 for
1202 \family typewriter
1203 ode_type
1204 \family default
1205 means the variable is the independent variable, 0 means it is an algebraic
1206 variable (default), 1 means it is a state variable, and finally 2 means
1207 it is a derivative.
1208
1209 \end_layout
1210
1211 \begin_layout Standard
1212 The attribute
1213 \family typewriter
1214 ode_id
1215 \family default
1216 is used to match the state variables with their derivatives and only needs
1217 to be used if the variable is a state or derivative.
1218 In the example
1219 \family typewriter
1220 M
1221 \family default
1222 is a state and
1223 \family typewriter
1224 dM_dt
1225 \family default
1226 is the derivative.
1227 Therefore they both need to have the same
1228 \family typewriter
1229 ode_id
1230 \family default
1231 so ASCEND will know that they belong together.
1232 Each state and derivative pair needs to have a different
1233 \family typewriter
1234 ode_id
1235 \family default
1236 ; however, it does not matter what the number is as long as it is a positive
1237 integer and no other state and derivative pair has the same number.
1238
1239 \end_layout
1240
1241 \begin_layout Standard
1242 Next
1243 \family typewriter
1244 obs_id
1245 \family default
1246 is used by the user to flag a variable for observation while integrating.
1247 For any integer value of
1248 \family typewriter
1249 obs_id
1250 \family default
1251 greater then 0 the variable will be observed.
1252 The result of flagging a variable for observation is that its values will
1253 be in a data column in one of two output files.
1254 One of the files of data produced with each integration contains the values
1255 of the states and the second the values of the variables flagged for observatio
1256 n.
1257 The default file names are
1258 \family typewriter
1259 y.dat
1260 \family default
1261 and
1262 \family typewriter
1263 obs.dat
1264 \family default
1265 respectfully; however, they can be changed in the solver options
1266 \begin_inset LatexCommand \index{options, solver}
1267
1268 \end_inset
1269
1270 general menu.
1271
1272 \end_layout
1273
1274 \begin_layout Standard
1275 Last, but not least, are the error control attributes for LSODE:
1276 \family typewriter
1277 ode_rtol
1278 \family default
1279 and
1280 \family typewriter
1281 ode_atol
1282 \family default
1283 .
1284 Both of these come directly from the LSODE attributes rtol and atol which
1285 are the local relative and absolute error tolerances for the variable respectiv
1286 ely.
1287 \end_layout
1288
1289 \begin_layout Standard
1290 There is one other thing about methods that we need to discuss before moving
1291 on and that is the
1292 \family typewriter
1293 seqmod
1294 \family default
1295 method.
1296 If you have not already noticed, it is a little different from the other
1297 examples as it has an IF statement in it.
1298 This is an important part of the dynamic simulation.
1299 It switches the degrees of freedom depending on if we are computing an
1300 initial condition or performing an integration step.
1301 We use the boolean
1302 \family typewriter
1303 dynamic
1304 \family default
1305
1306 \begin_inset LatexCommand \index{dynamic, boolean variable}
1307
1308 \end_inset
1309
1310 to control whether we are going to solve the model as a steady state model
1311 (
1312 \family typewriter
1313 dynamic := FALSE;
1314 \family default
1315 ) or as a dynamic model (
1316 \family typewriter
1317 dynamic := TRUE;
1318 \family default
1319 ).
1320 For the current example, we have a simple tank and, for steady state, we
1321 would like to calculate the number of moles and output flow rate for a
1322 fixed tank volume and input flow rate.
1323 Also, for the model to be at steady state, we have to fix the derivative
1324 and set it equal to zero,
1325 \family typewriter
1326 (dM_dt.fixed :=TRUE; dM_dt :=0 {mole/s};.
1327
1328 \family default
1329 The derivative is normally set to zero in the
1330 \family typewriter
1331 default_self
1332 \family default
1333 method to prepare the model to solve for initial steady-state conditions.)
1334 If we then want to integrate this model for a fixed output flow (as when
1335 pumping the liquid out under flow control), we would free up the volume
1336 and fix the output flow rate.
1337 The model will then compute how the liquid volume will change with time.
1338
1339 \end_layout
1340
1341 \begin_layout Standard
1342 In dynamic simulation, an initial value integration package, such as LSODE,
1343 repeatedly asks the model to compute the time derivatives for the state
1344 variables, given fixed values for the states.
1345 Using values for
1346 \family typewriter
1347 dM_dt
1348 \family default
1349 computed by the model, the integration package will then update the state
1350 variable,
1351 \family typewriter
1352 M
1353 \family default
1354 , to its new value.
1355 To accommodate this calculation, we therefore fix the state variable,
1356 \family typewriter
1357 M
1358 \family default
1359 , and free up the derivative,
1360 \family typewriter
1361 dM_dt
1362 \family default
1363 .
1364 \end_layout
1365
1366 \begin_layout Section
1367 Solving an ASCEND instance
1368 \end_layout
1369
1370 \begin_layout Standard
1371 We are now ready to read in and compile an instance of our tank model.
1372 We are assuming that you understand how to use the scripting window, and
1373 we will show how to go about reading, compiling, solving and integrating
1374 a dynamic model using the following script.
1375 \end_layout
1376
1377 \begin_layout Subsubsection*
1378 Script code
1379 \begin_inset LatexCommand \index{script, solve dynamic model}
1380
1381 \end_inset
1382
1383
1384 \end_layout
1385
1386 \begin_layout LyX-Code
1387 DELETE TYPES;
1388 \end_layout
1389
1390 \begin_layout LyX-Code
1391 READ FILE "example.a4c";
1392 \end_layout
1393
1394 \begin_layout LyX-Code
1395 COMPILE ex OF tank;
1396 \end_layout
1397
1398 \begin_layout LyX-Code
1399 BROWSE ex;
1400 \end_layout
1401
1402 \begin_layout LyX-Code
1403 RUN {ex.default_self};
1404 \end_layout
1405
1406 \begin_layout LyX-Code
1407 RUN {ex.reset};
1408 \end_layout
1409
1410 \begin_layout LyX-Code
1411 RUN {ex.values};
1412 \end_layout
1413
1414 \begin_layout LyX-Code
1415 SOLVE ex WITH QRSlv;
1416 \end_layout
1417
1418 \begin_layout LyX-Code
1419 RUN {ex.check_all};
1420 \end_layout
1421
1422 \begin_layout LyX-Code
1423 ASSIGN {ex.dynamic} TRUE;
1424 \end_layout
1425
1426 \begin_layout LyX-Code
1427 RUN {ex.reset};
1428 \end_layout
1429
1430 \begin_layout LyX-Code
1431 RUN {ex.set_ode};
1432 \end_layout
1433
1434 \begin_layout LyX-Code
1435 RUN {ex.set_obs};
1436 \end_layout
1437
1438 \begin_layout LyX-Code
1439 # User will need to edit the next line to correct path
1440 \end_layout
1441
1442 \begin_layout LyX-Code
1443 # to the models directory
1444 \end_layout
1445
1446 \begin_layout LyX-Code
1447 source "$env(ASCENDDIST)/models/set_intervals.tcl";
1448 \end_layout
1449
1450 \begin_layout LyX-Code
1451 set_int 500 10 {s};
1452 \end_layout
1453
1454 \begin_layout LyX-Code
1455 INTEGRATE ex FROM 0 TO 50 WITH BLSODE;
1456 \end_layout
1457
1458 \begin_layout LyX-Code
1459 ASSIGN {ex.input} 120 {mole/s};
1460 \end_layout
1461
1462 \begin_layout LyX-Code
1463 INTEGRATE ex FROM 50 TO 499 WITH BLSODE;
1464 \end_layout
1465
1466 \begin_layout LyX-Code
1467 # In order to view integration results for both the
1468 \end_layout
1469
1470 \begin_layout LyX-Code
1471 # integrations the user will have to go to the solver
1472 \end_layout
1473
1474 \begin_layout LyX-Code
1475 # window, select options, general and turn off the
1476 \end_layout
1477
1478 \begin_layout LyX-Code
1479 # overwrite integrator logs toggle.
1480 \end_layout
1481
1482 \begin_layout LyX-Code
1483 # (NOTE: If you were then to run a different model or this
1484 \end_layout
1485
1486 \begin_layout LyX-Code
1487 # same simulation again it would still write to the same
1488 \end_layout
1489
1490 \begin_layout LyX-Code
1491 # files)
1492 \end_layout
1493
1494 \begin_layout LyX-Code
1495 # In order to see both sets of data at the same time on
1496 \end_layout
1497
1498 \begin_layout LyX-Code
1499 # one plot you will have to merge the two sets of data in
1500 \end_layout
1501
1502 \begin_layout LyX-Code
1503 # the file.
1504 This is done with following command.
1505 \end_layout
1506
1507 \begin_layout LyX-Code
1508 asc_merge_data_file ascend new_obs.dat obs.dat;
1509 \end_layout
1510
1511 \begin_layout LyX-Code
1512 # This command can also be used to convert data into a
1513 \end_layout
1514
1515 \begin_layout LyX-Code
1516 # format that can be loaded into matlab for further work.
1517 \end_layout
1518
1519 \begin_layout LyX-Code
1520 asc_merge_data_file matlab matlab_obs.m obs.dat;
1521 \end_layout
1522
1523 \begin_layout LyX-Code
1524 # This command can also be used to convert data into a
1525 \end_layout
1526
1527 \begin_layout LyX-Code
1528 # format that can be loaded into excel as a tab delimited
1529 \end_layout
1530
1531 \begin_layout LyX-Code
1532 # text file.
1533 \end_layout
1534
1535 \begin_layout LyX-Code
1536 asc_merge_data_file excel excel_obs.txt obs.dat;
1537 \end_layout
1538
1539 \begin_layout Standard
1540 First of all reading and compiling an instance of a dynamic model is the
1541 same as a steady state model except, as stated earlier, we must load
1542 \family typewriter
1543 ivpsystem.a4l
1544 \family default
1545 instead of
1546 \family typewriter
1547 system.a4l
1548 \family default
1549 .
1550 The file containing
1551 \family typewriter
1552 example.a4c
1553 \family default
1554 in the first version of the code has
1555 \family typewriter
1556 REQUIRE
1557 \family default
1558 statements to load the right system file and the file
1559 \family typewriter
1560 atoms.a4l
1561 \family default
1562 .
1563
1564 \end_layout
1565
1566 \begin_layout Standard
1567 Now it is time to solve the model, and this is where things start to change.
1568 We must first solve the model for its initial conditions.
1569 We set the boolean variable
1570 \family typewriter
1571 dynamic
1572 \family default
1573 to
1574 \family typewriter
1575 FALSE
1576 \family default
1577 (in the
1578 \family typewriter
1579 default_self
1580 \family default
1581 method) and run the
1582 \family typewriter
1583 reset
1584 \family default
1585 method to get a well-posed steady-state model.
1586 We also need to run the
1587 \family typewriter
1588 values
1589 \family default
1590 method to set the fixed values of the initial conditions.
1591 Finally we are solve, getting as the solution the initial conditions for
1592 our model.
1593 \end_layout
1594
1595 \begin_layout Standard
1596 After solving for the initial conditions
1597 \begin_inset LatexCommand \index{initial conditions}
1598
1599 \end_inset
1600
1601 , we set things up for the dynamic simulation.
1602 We set the boolean variable
1603 \family typewriter
1604 dynamic
1605 \family default
1606 to
1607 \family typewriter
1608 TRUE
1609 \family default
1610 and then run the
1611 \family typewriter
1612 seqmod
1613 \family default
1614 method to give a well-posed dynamic model.
1615 We now have to establish which variables are the independent variables,
1616 the state variables and their corresponding derivatives, and tell which
1617 variables we would like to observe; we run
1618 \family typewriter
1619 set_ode
1620 \family default
1621 and
1622 \family typewriter
1623 set_obs
1624 \family default
1625 methods described above.
1626 \end_layout
1627
1628 \begin_layout Standard
1629 In order for ASCEND and LSODE to know what step size and how many steps
1630 we want to observe, we must load a Tcl file that defines a new script command.
1631 The file we need to load is called
1632 \family typewriter
1633 set_intervals.tcl
1634 \family default
1635 , and it is found in the models subdirectory of the ASCEND distribution.
1636 The command source comes from Tcl and is used to read and execute the a
1637 set of commands in a file.
1638 The file in this case is
1639 \family typewriter
1640 set_intervals.tcl
1641 \family default
1642 and the commands within it setup a new script command
1643 \family typewriter
1644 set_int
1645 \family default
1646 .
1647 Once we have loaded this file, we can use the new command
1648 \family typewriter
1649 set_int
1650 \family default
1651 to set up the number of possible steps and their maximum size.
1652 Now we are ready to integrate.
1653 The way we do this is to use the
1654 \family typewriter
1655 INTEGRATE
1656 \family default
1657 command in the script.
1658 The syntax for these command is as follows.
1659 \end_layout
1660
1661 \begin_layout Subsubsection*
1662 Syntax for
1663 \family typewriter
1664 set_int
1665 \end_layout
1666
1667 \begin_layout LyX-Code
1668 set_int number_of_steps step_size
1669 \end_layout
1670
1671 \begin_layout LyX-Code
1672 {units of step size(time)};
1673 \end_layout
1674
1675 \begin_layout Subsubsection*
1676 Syntax for
1677 \family typewriter
1678 INTEGRATE
1679 \family default
1680
1681 \end_layout
1682
1683 \begin_layout LyX-Code
1684 INTGRATE compiled_model_name
1685 \end_layout
1686
1687 \begin_layout LyX-Code
1688 FROM initial_step
1689 \end_layout
1690
1691 \begin_layout LyX-Code
1692 TO final_step
1693 \end_layout
1694
1695 \begin_layout LyX-Code
1696 WITH BLSODE;
1697 \end_layout
1698
1699 \begin_layout Standard
1700 The command is set up with the initial and final step so that you can integrate
1701 for a number of steps, then make step changes, and then continue to integrate
1702 another number of steps.
1703 \end_layout
1704
1705 \begin_layout Section
1706 Viewing Simulation Results
1707 \end_layout
1708
1709 \begin_layout Standard
1710 To view the simulation results, open the ASCPLOT
1711 \begin_inset LatexCommand \index{ASCPLOT}
1712
1713 \end_inset
1714
1715 window using the Tools menu on the Script window.
1716 To view a plot, first use the File menu to load the data using Load data
1717 set.
1718 Depending on what you want to look at, you can load the file containing
1719 the states or the file containing the variables you flagged for observation.
1720 Once the data file is loaded, you can double click on the file name in
1721 the top window to get a list of the variables in the file.
1722 This list will appear in the left window named Unused variables
1723 \begin_inset LatexCommand \index{variables, unused}
1724
1725 \end_inset
1726
1727 below where you just double clicked.
1728 As you will notice on the line below, the independent variable has already
1729 been set to time.
1730 The way we select the variables we want to plot vs.
1731 time is to highlight them from the list in the left window and, using the
1732 top arrow button, move them over to the plotted variables window on the
1733 right.
1734 We then use the View plot file command from the Execute menu to view the
1735 plot.
1736
1737 \end_layout
1738
1739 \begin_layout Standard
1740 If we now want to plot something else, we simply highlight those variables
1741 that we do not want to plot in the plotted variables window, use the other
1742 arrow to move them back to the unused variable window and then move new
1743 variables to the plotted variables window.
1744
1745 \end_layout
1746
1747 \begin_layout Standard
1748 If we want to change the independent variable, we select the variable we
1749 want to be the new independent variable from the list in either the unused
1750 variable window or the plotted variable window and then use the appropriate
1751 down arrow to move that variable down to become the independent variable.
1752 \end_layout
1753
1754 \begin_layout Subsection
1755 Graphing options
1756 \end_layout
1757
1758 \begin_layout Standard
1759 Now that you are able to view a plot, you might want to add titles or change
1760 the axis scale, line colors, and so forth.
1761 Adding titles can be done by selecting set
1762 \shape italic
1763 titles
1764 \shape default
1765 under the
1766 \shape italic
1767 Display
1768 \shape default
1769 menu, a new window will open in which you will have the option to add a
1770 plot title and axis labels.
1771 To change the axis scale, line color and many other features select see
1772 options from the
1773 \shape italic
1774 Options
1775 \shape default
1776 menu.
1777 \end_layout
1778
1779 \begin_layout Subsubsection*
1780 Graphing in Windows
1781 \end_layout
1782
1783 \begin_layout Standard
1784 Under MS Windows
1785 \begin_inset LatexCommand \index{MS Windows}
1786
1787 \end_inset
1788
1789 the default graph program Tkxgraph
1790 \begin_inset LatexCommand \index{Tkxgraph}
1791
1792 \end_inset
1793
1794 gives you full control of the options without having to go through the
1795 ASCPLOT Options menu.
1796 Tkxgraph is also available for UNIX, but xgraph
1797 \begin_inset LatexCommand \index{xgraph}
1798
1799 \end_inset
1800
1801 does a much better job drawing dashed lines with X11 than Tkxgraph does.
1802 \end_layout
1803
1804 \begin_layout Standard
1805 If you decide you do not like the plotting tools described above, you have
1806 two more options, and they are to convert the ASCEND output data files
1807 so that they can be loaded by Matlab or a spreadsheet.
1808 To convert the data files a new script command needs to be introduced and
1809 the command is
1810 \family typewriter
1811 asc_merge_data_file
1812 \family default
1813
1814 \begin_inset LatexCommand \index{asc\_merge\_data\_file}
1815
1816 \end_inset
1817
1818 .
1819
1820 \end_layout
1821
1822 \begin_layout Subsubsection*
1823 Syntax for
1824 \family typewriter
1825 asc_merge_data_file
1826 \family default
1827 command
1828 \end_layout
1829
1830 \begin_layout LyX-Code
1831 asc_merge_data_file convert_to
1832 \backslash
1833
1834 \end_layout
1835
1836 \begin_layout LyX-Code
1837 output_file_name input_file_names
1838 \end_layout
1839
1840 \begin_layout Standard
1841 The syntax for the
1842 \family typewriter
1843 asc_merge_data_file
1844 \family default
1845 command is as follows.
1846 First of all the
1847 \family typewriter
1848 convert_to
1849 \family default
1850 is the format you want the data converted to.
1851 There are three options matlab, excel or ascend.
1852 The
1853 \family typewriter
1854 output_file_name
1855 \family default
1856 is exactly that, the name of the file in which you want the converted data
1857 to be put.
1858 The
1859 \family typewriter
1860 input_file_names
1861 \family default
1862 is also exactly that, the file name or names that you want converted.
1863 If more than one input file is given the data is combined into one output
1864 file.
1865 \end_layout
1866
1867 \begin_layout Standard
1868 If the matlab
1869 \begin_inset LatexCommand \index{matlab}
1870
1871 \end_inset
1872
1873 option is used the output file extension should be
1874 \family typewriter
1875 m
1876 \family default
1877 , if excel is used the extension should be
1878 \family typewriter
1879 txt
1880 \family default
1881 as it is a tab delimited text file and for ascend the extension should
1882 be
1883 \family typewriter
1884 dat
1885 \family default
1886 for use with ASCPLOT.
1887 \end_layout
1888
1889 \begin_layout Standard
1890 You maybe wondering what exactly is this
1891 \family typewriter
1892 asc_merge_data_file
1893 \family default
1894 command doing.
1895 In the next three paragraphs we will give a brief explanation of each of
1896 the options.
1897 \end_layout
1898
1899 \begin_layout Subsubsection*
1900 Matlab conversion
1901 \end_layout
1902
1903 \begin_layout Standard
1904 When the data is converted to be used in matlab the first thing that is
1905 done is the header of the ascend data file is placed in the output file
1906 but is commented out.
1907 This is so the user can still tell when the data was created.
1908 The next thing is does is put all the data into a matrix that has the same
1909 name as the output file with var added to the end.
1910 All variable names from the ascend data file are then converted to matlab
1911 legal names by replacing the all dots and brackets with underscores(_).
1912 The new variable names are then set equal to there corresponding column
1913 of data in the matrix.
1914 Each variable then becomes a vector.
1915 When the file is run all the data is loaded and set equal to the new variable
1916 names and can easily be plotted using matlab commands.
1917 \end_layout
1918
1919 \begin_layout Subsubsection*
1920 Excel
1921 \begin_inset LatexCommand \index{Excel}
1922
1923 \end_inset
1924
1925 conversion
1926 \end_layout
1927
1928 \begin_layout Standard
1929 When the data is converted to be used in Excel the only thing that happens
1930 is instead of the list of variables and units being a column it is turn
1931 into rows.
1932 When the data is loaded into Excel as a tab delimited text file all the
1933 data will be in columns with the first row being the units of the data
1934 and the second being the ascend variable name.
1935 The data is then easily plotted using the Excel graphing package.
1936 \end_layout
1937
1938 \begin_layout Subsubsection*
1939 Ascend conversion
1940 \end_layout
1941
1942 \begin_layout Standard
1943 This is not so much a conversion as a merge and is the origin of the command.
1944 It is only useful if there are multiple headers in a file or more than
1945 one input file is given.
1946 Multiple headers in the file occur when stopping and starting integrations
1947 with the overwrite option turned off.
1948 This conversion removes all subsequent headers that are the same as the
1949 first, whether in one file or multiple, to leave one output file with what
1950 looks like one data set for plotting.
1951 If the headers are different the data will just be combined into one file
1952 and when loaded in ASCPLOT will still look like different data sets.
1953 \end_layout
1954
1955 \begin_layout Section
1956 Preparing a model for reuse
1957 \begin_inset LatexCommand \index{reuse, model}
1958
1959 \end_inset
1960
1961
1962 \end_layout
1963
1964 \begin_layout Standard
1965 There are four major ways to prepare a model for reuse as described in Chapter\InsetSpace ~
1966
1967 \begin_inset LatexCommand \ref{cha:model2}
1968
1969 \end_inset
1970
1971 .
1972 All of what is said there about reusable models applies to dynamic models.
1973 However, there is one thing that we think should be repeated to make clear
1974 for dynamic models, and that is parameterizing a model.
1975 \end_layout
1976
1977 \begin_layout Subsection
1978 Parameterizing
1979 \begin_inset LatexCommand \index{parameterizing}
1980
1981 \end_inset
1982
1983 the tank model
1984 \end_layout
1985
1986 \begin_layout Standard
1987 As stated in Section\InsetSpace ~
1988
1989 \begin_inset LatexCommand \vref{sec:model2.parameterizingVessel}
1990
1991 \end_inset
1992
1993
1994 \color none
1995 , parameterizing a model type definition alerts a future user as to which
1996 parts of this model you deem to be the most likely to be shared.
1997 An instance of a parameterized model is then created from previously defined
1998 types.
1999 \end_layout
2000
2001 \begin_layout Standard
2002 The new thing that needs to be repeated is that the
2003 \family typewriter
2004 ode_id
2005 \family default
2006 's of derivative and state pairs must be different even if they are in different
2007 part of a larger model.
2008 If for instance we wanted to have two tanks in series we could parameterize
2009 the tank model and connect the two tanks together with the outlet of the
2010 first tank being the feed to the second tank.
2011 However, with the
2012 \family typewriter
2013 set_ode
2014 \family default
2015
2016 \begin_inset LatexCommand \index{set\_ode}
2017
2018 \end_inset
2019
2020 method, as we have currently written it, the derivative and state pairs
2021 for both tanks would have the same
2022 \family typewriter
2023 ode_id
2024 \family default
2025 's.
2026 Our way around this is to introduce an
2027 \family typewriter
2028 ode_counter
2029 \family default
2030 that is used to set the
2031 \family typewriter
2032 ode_id
2033 \family default
2034 's and is incremented after each derivative and state pair is set.
2035 The
2036 \family typewriter
2037 ode_counter
2038 \family default
2039 becomes one of the model parameters and is, therefore, the same in all
2040 models.
2041 We will now give an example of this to help explain.
2042 \end_layout
2043
2044 \begin_layout Subsubsection*
2045
2046 \family typewriter
2047 set_ode
2048 \family default
2049 method for parameterized tank model
2050 \end_layout
2051
2052 \begin_layout LyX-Code
2053 METHOD set_ode;
2054 \end_layout
2055
2056 \begin_layout LyX-Code
2057 (* set ODE_TYPE -1=independent variable,
2058 \end_layout
2059
2060 \begin_layout LyX-Code
2061 0=algebraic variable, 1=state variable,
2062 \end_layout
2063
2064 \begin_layout LyX-Code
2065 2=derivative *)
2066 \end_layout
2067
2068 \begin_layout LyX-Code
2069 t.ode_type :=-1;
2070 \end_layout
2071
2072 \begin_layout LyX-Code
2073 dM_dt.ode_type :=2;
2074 \end_layout
2075
2076 \begin_layout LyX-Code
2077 M.ode_type :=1;
2078 \end_layout
2079
2080 \begin_layout LyX-Code
2081 (* Set ODE_ID *)
2082 \end_layout
2083
2084 \begin_layout LyX-Code
2085 dM_dt.ode_id := ode_offset;
2086 \end_layout
2087
2088 \begin_layout LyX-Code
2089 M.ode_id := ode_offset;
2090 \end_layout
2091
2092 \begin_layout LyX-Code
2093 ode_offset := ode_offset+1;
2094 \end_layout
2095
2096 \begin_layout LyX-Code
2097 END set_ode;
2098 \end_layout
2099
2100 \begin_layout LyX-Code
2101
2102 \end_layout
2103
2104 \begin_layout Subsubsection*
2105
2106 \family typewriter
2107 set_ode
2108 \family default
2109 method for larger model with two tank models being used as parts
2110 \end_layout
2111
2112 \begin_layout LyX-Code
2113
2114 \end_layout
2115
2116 \begin_layout LyX-Code
2117 METHOD set_ode;
2118 \end_layout
2119
2120 \begin_layout LyX-Code
2121 RUN tank_1.set_ode;
2122 \end_layout
2123
2124 \begin_layout LyX-Code
2125 RUN tank_2.set_ode;
2126 \end_layout
2127
2128 \begin_layout LyX-Code
2129 END set_ode;
2130 \end_layout
2131
2132 \begin_layout Standard
2133 The parameterized tank
2134 \family typewriter
2135 set_ode
2136 \family default
2137 method is almost the same as the original one we wrote except it now uses
2138
2139 \family typewriter
2140 ode_offset
2141 \family default
2142 , an
2143 \family typewriter
2144 ode_counter
2145 \family default
2146 , to set the
2147 \family typewriter
2148 ode_id
2149 \family default
2150 s.
2151 It may be obvious, but this is how it works.
2152 When the larger model
2153 \family typewriter
2154 set_ode
2155 \family default
2156 is run, the
2157 \family typewriter
2158 set_ode
2159 \family default
2160 for
2161 \family typewriter
2162 tank_1
2163 \family default
2164 is run, the
2165 \family typewriter
2166 ode_id
2167 \family default
2168 s are set to the current value of
2169 \family typewriter
2170 ode_offset
2171 \family default
2172 , the counter is then incremented and
2173 \family typewriter
2174 set_ode
2175 \family default
2176 is run for
2177 \family typewriter
2178 tank_2
2179 \family default
2180 which then gets the incremented
2181 \family typewriter
2182 ode_offset
2183 \family default
2184 so the values are now different.
2185 You can now hopefully see that we can string as may tanks together as we
2186 like, and all the derivative and state pairs
2187 \family typewriter
2188 ode_id
2189 \family default
2190 will be different.
2191 \end_layout
2192
2193 \begin_layout Standard
2194 This same idea can be applies to setting the observed variables.
2195 The reason this is a good idea is that the variables are placed in the
2196 output files in order of there
2197 \family typewriter
2198 obs_id
2199 \family default
2200 value.
2201 This way we can keep all variables flagged for observation from one part
2202 of a model together.
2203 \end_layout
2204
2205 \begin_layout Standard
2206 The important thing that needs to be stressed for a dynamic system is that
2207 the time variable, dynamic boolean, and ode and obs counters must be in
2208 the parameter list.
2209 All these variable need to be the same in each model to be consistent and
2210 to make sure the model gets setup correctly when the
2211 \family typewriter
2212 set_ode
2213 \family default
2214 method is executed.
2215 \end_layout
2216
2217 \begin_layout Section
2218 In conclusion
2219 \end_layout
2220
2221 \begin_layout Standard
2222 We have just led you step by step through the process of creating a small
2223 dynamic ASCEND model and the basics on how to view the results.
2224 \end_layout
2225
2226 \end_body
2227 \end_document

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