~jdpipe/ascend/trunk-old

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
#LyX 2.1 created this file. For more info see http://www.lyx.org/
\lyxformat 474
\begin_document
\begin_header
\textclass book
\use_default_options false
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\font_math auto
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 2
\use_package amssymb 2
\use_package cancel 1
\use_package esint 0
\use_package mathdots 0
\use_package mathtools 1
\use_package mhchem 0
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Chapter
The modeling of a simple dynamic tank
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
dynamic tank
\end_layout

\end_inset


\begin_inset CommandInset label
LatexCommand label
name "cha:ivp"

\end_inset


\end_layout

\begin_layout Standard
This chapter assumes you have read Chapter
\color black

\begin_inset space ~
\end_inset


\begin_inset CommandInset ref
LatexCommand vref
reference "cha:model1"

\end_inset

 and Chapter
\begin_inset space ~
\end_inset


\begin_inset CommandInset ref
LatexCommand vref
reference "cha:model2"

\end_inset

, which introduce you to ASCEND modeling concepts.
\end_layout

\begin_layout Standard
The purpose of this chapter is to be a good first step along the path to
 learning how to use ASCEND for dynamic simulations
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
dynamic simulation
\end_layout

\end_inset


\begin_inset Foot
status open

\begin_layout Plain Layout
Some further information on this topic is available in the report by Perry
 and Allan 
\begin_inset CommandInset citation
LatexCommand cite
key "Perry1996"

\end_inset


\end_layout

\end_inset

.
 We shall lead you through the steps for creating a simple model.
 You will also learn the standard methods that we employ for our dynamic
 libraries
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
dynamic libraries
\end_layout

\end_inset

.
 We will present our reasons for the steps we take.
 
\end_layout

\begin_layout Subsubsection*
The problem
\end_layout

\begin_layout Labeling
\labelwidthstring 00.00.0000
Step
\begin_inset space ~
\end_inset

1: We would like to create a dynamic model of a simple tank.
\end_layout

\begin_layout Subsubsection*
Topics covered in this chapter are:
\end_layout

\begin_layout Itemize
Converting the word description to an ASCEND model.
\end_layout

\begin_layout Itemize
Solving the model.
\end_layout

\begin_layout Itemize
Creating a script to load and execute an instance of the model.
\end_layout

\begin_layout Itemize
Integrating
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
integrating
\end_layout

\end_inset

 the model.
\end_layout

\begin_layout Itemize
View Integration Results.
\end_layout

\begin_layout Section
Converting the word description
\begin_inset Newline newline
\end_inset

into an ASCEND model
\end_layout

\begin_layout Standard
As stated in Section
\begin_inset space ~
\end_inset


\begin_inset CommandInset ref
LatexCommand vref
reference "sec:model1.converting-the-word"

\end_inset


\color none
, we need to make an instance of a type and solve the instance.
 So we shall start by creating a tank type definition.
 We will have to create our type definition as a text file using a text
 editor.
 (Possible text editors
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
text editor
\end_layout

\end_inset

 are Word
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
Word
\end_layout

\end_inset

, Emacs
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
Emacs
\end_layout

\end_inset

, Notepad
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
Notepad
\end_layout

\end_inset

, pico
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
pico
\end_layout

\end_inset

, vi
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
vi
\end_layout

\end_inset

, etc.
 We shall discuss editors shortly.)
\end_layout

\begin_layout Standard
We need first to decide the parts to our model.
 In this case we know that we need the variables listed in Table
\begin_inset space ~
\end_inset


\begin_inset CommandInset ref
LatexCommand eqref
reference "cap:Variables-required-for"

\end_inset

We readily fill in the first three columns in this table, and we can also
 fill out the fourth column if we know the units that are associated with
 each of the parts.
 To find the ASCEND variable type needed for the fourth column use the find
 menu on the library window and select ATOM by units
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
atom, select by units
\end_layout

\end_inset

.
 The result of this search will be all the ASCEND variable type that have
 the units you entered.
\end_layout

\begin_layout Standard
\begin_inset Float table
wide false
sideways false
status open

\begin_layout Plain Layout
\begin_inset Caption Standard

\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "cap:Variables-required-for"

\end_inset

Variables required for model
\end_layout

\end_inset


\end_layout

\begin_layout Plain Layout
\begin_inset Tabular
<lyxtabular version="3" rows="8" columns="4">
<features rotate="0" tabularvalignment="middle">
<column alignment="center" valignment="top">
<column alignment="center" valignment="top" width="1.5in">
<column alignment="center" valignment="top" width="1.5in">
<column alignment="center" valignment="top" width="1in">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Symbol
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Meaning
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Typical Units
\begin_inset Foot
status collapsed

\begin_layout Plain Layout
as entered into ASCEND
\end_layout

\end_inset


\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
ASCEND variable type
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\family typewriter
M
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Moles in Tank
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
mol, kmol
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
mole
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\family typewriter
dM_dt
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Rate of change of Moles in tank (derivative)
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
mol/sec, kmol/sec
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
molar_rate
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\family typewriter
input
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Feed flow rate
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
mol/sec, kmol/sec
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
molar_rate
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\family typewriter
output
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Output flow rate
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
mol/sec, kmol/sec
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
molar_rate
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\family typewriter
Volume
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Volume of liquid in the tank
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
m^3,ft^3
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
volume
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\family typewriter
density
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Molar density of tank fluid
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
mol/m^3,mol/ft^3
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
molar_density
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\family typewriter
dynamic
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Boolean for switching between dynamic and steady state simulations
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
N/A
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
boolean
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\end_inset


\end_layout

\begin_layout Standard
We would like to be able to compute the number of moles in the tank for
 a given volume assuming steady state
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
steady state
\end_layout

\end_inset

 (dM_dt = 0).
 We would also like to be able to calculate how the volume changes if we
 are not at steady state.
 The following equations describe the simple tank system.
\end_layout

\begin_layout Standard
The first equation is the differential equation that relates the input and
 output flows to the accumulation in the tank.
 The second equation is the relation of the moles in the tank to the volume
 of liquid and should be rearranged to avoid division
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
division, avoid
\end_layout

\end_inset

.
 These equations are all that is need for a simple tank.
\end_layout

\begin_layout Standard
\begin_inset Formula 
\begin{equation}
dM\_dt=input-output\label{eq:ivp.dMdt}
\end{equation}

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Formula 
\begin{equation}
Volume=\frac{M}{density}\label{eq:ivp.Volume}
\end{equation}

\end_inset


\end_layout

\begin_layout Subsubsection*
The first version of the code for tank
\end_layout

\begin_layout LyX-Code
REQUIRE "ivpsystem.a4l";
\end_layout

\begin_layout LyX-Code
REQUIRE "atoms.a4l";
\end_layout

\begin_layout LyX-Code
MODEL tank
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
tank, dynamic MODEL
\end_layout

\end_inset

;
\end_layout

\begin_layout LyX-Code
(* List of Variables *)
\end_layout

\begin_layout LyX-Code
dM_dt IS_A molar_rate;
\end_layout

\begin_layout LyX-Code
M IS_A mole;
\end_layout

\begin_layout LyX-Code
input IS_A molar_rate;
\end_layout

\begin_layout LyX-Code
output IS_A molar_rate;
\end_layout

\begin_layout LyX-Code
Volume IS_A volume;
\end_layout

\begin_layout LyX-Code
density IS_A real_constant;
\end_layout

\begin_layout LyX-Code
dynamic IS_A boolean;
\end_layout

\begin_layout LyX-Code
t IS_A time;
\end_layout

\begin_layout LyX-Code
(* Equations *)
\end_layout

\begin_layout LyX-Code
dM_dt = input - output;
\end_layout

\begin_layout LyX-Code
M = Volume * density;
\end_layout

\begin_layout LyX-Code
(* Assignment of values to Constants *)
\end_layout

\begin_layout LyX-Code
density :==10 {mol/m^3};
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHODS
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD check_self;
\end_layout

\begin_layout LyX-Code
IF (input < 1e-4 {mole/s}) THEN
\end_layout

\begin_layout LyX-Code
STOP {Input dried up in tank};
\end_layout

\begin_layout LyX-Code
END IF;
\end_layout

\begin_layout LyX-Code
IF (output < 1e-4 {mole/s}) THEN
\end_layout

\begin_layout LyX-Code
STOP {Output dried up in tank}; 
\end_layout

\begin_layout LyX-Code
END IF; 
\end_layout

\begin_layout LyX-Code
END check_self;
\end_layout

\begin_layout LyX-Code
METHOD check_all;
\end_layout

\begin_layout LyX-Code
RUN check_self;
\end_layout

\begin_layout LyX-Code
END check_all;
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD default_self;
\end_layout

\begin_layout LyX-Code
dynamic := FALSE;
\end_layout

\begin_layout LyX-Code
t :=0 {sec};
\end_layout

\begin_layout LyX-Code
dM_dt :=0 {mol/sec};
\end_layout

\begin_layout LyX-Code
dM_dt.lower_bound := -1e49 {mol/sec};
\end_layout

\begin_layout LyX-Code
END default_self;
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD default_all;
\end_layout

\begin_layout LyX-Code
RUN default_self;
\end_layout

\begin_layout LyX-Code
END default_all;
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD bound_self;
\end_layout

\begin_layout LyX-Code
END bound_self;
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD bound_all;
\end_layout

\begin_layout LyX-Code
RUN bound_self;
\end_layout

\begin_layout LyX-Code
END bound_all;
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD scale_self; 
\end_layout

\begin_layout LyX-Code
END scale_self;
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD scale_all;
\end_layout

\begin_layout LyX-Code
RUN scale_self;
\end_layout

\begin_layout LyX-Code
END scale_all;
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD seqmod;
\end_layout

\begin_layout LyX-Code
dM_dt.fixed :=TRUE;
\end_layout

\begin_layout LyX-Code
M.fixed :=FALSE;
\end_layout

\begin_layout LyX-Code
Volume.fixed :=TRUE;
\end_layout

\begin_layout LyX-Code
input.fixed :=TRUE;
\end_layout

\begin_layout LyX-Code
output.fixed :=FALSE;
\end_layout

\begin_layout LyX-Code
IF dynamic THEN
\end_layout

\begin_layout LyX-Code
dM_dt.fixed :=FALSE;
\end_layout

\begin_layout LyX-Code
M.fixed :=TRUE;
\end_layout

\begin_layout LyX-Code
Volume.fixed :=FALSE;
\end_layout

\begin_layout LyX-Code
output.fixed :=TRUE;
\end_layout

\begin_layout LyX-Code
END IF;
\end_layout

\begin_layout LyX-Code
END seqmod;
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD specify;
\end_layout

\begin_layout LyX-Code
input.fixed :=TRUE;
\end_layout

\begin_layout LyX-Code
RUN seqmod;
\end_layout

\begin_layout LyX-Code
END specify;
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD set_ode;
\end_layout

\begin_layout LyX-Code
(* set ODE_TYPE -1=independent variable,
\end_layout

\begin_layout LyX-Code
0=algebraic variable, 1=state variable,
\end_layout

\begin_layout LyX-Code
2=derivative *)
\end_layout

\begin_layout LyX-Code
t.ode_type :=-1;
\end_layout

\begin_layout LyX-Code
dM_dt.ode_type :=2;
\end_layout

\begin_layout LyX-Code
M.ode_type :=1;
\end_layout

\begin_layout LyX-Code
(* Set ODE_ID *)
\end_layout

\begin_layout LyX-Code
dM_dt.ode_id :=1;
\end_layout

\begin_layout LyX-Code
M.ode_id :=1;
\end_layout

\begin_layout LyX-Code
END set_ode;
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD set_obs;
\end_layout

\begin_layout LyX-Code
(* Set OBS_ID to any integer value greater 
\end_layout

\begin_layout LyX-Code
than 0, the variable will be recorded 
\end_layout

\begin_layout LyX-Code
(i.e., observed) *)
\end_layout

\begin_layout LyX-Code
M.obs_id :=1;
\end_layout

\begin_layout LyX-Code
Volume.obs_id :=2;
\end_layout

\begin_layout LyX-Code
input.obs_id :=3;
\end_layout

\begin_layout LyX-Code
output.obs_id :=4;
\end_layout

\begin_layout LyX-Code
END set_obs;
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD values;
\end_layout

\begin_layout LyX-Code
Volume :=5 {m^3};
\end_layout

\begin_layout LyX-Code
input :=100 {mole/s}; 
\end_layout

\begin_layout LyX-Code
END values;
\end_layout

\begin_layout LyX-Code
END tank; 
\end_layout

\begin_layout Standard
Our model definition has the following structure for it so far:
\end_layout

\begin_layout Itemize
MODEL statement
\end_layout

\begin_layout Itemize
list of variables we intend to use in the type definition
\end_layout

\begin_layout Itemize
equations
\end_layout

\begin_layout Itemize
METHODS
\end_layout

\begin_layout Itemize
END statement
\end_layout

\begin_layout Standard
While we have put the statements in this order, we could mix them up and
 intermix the middle two types of statements, even going to the extreme
 of defining the variables after we first use them.
 Once the 
\family typewriter
METHODS
\family default
 section is started no new equations or variables can be declared.
 The 
\family typewriter
MODEL
\family default
 and 
\family typewriter
END
\family default
 statements begin and end the type definition.
\end_layout

\begin_layout Standard
There are two new methods added to a dynamic model that you would not see
 in a steady state model, and they are the 
\family typewriter
set_ode
\family default
 and 
\family typewriter
set_obs
\family default
 methods.
 The 
\family typewriter
set_ode
\family default
 method is used to setup the model for integration.
 The 
\family typewriter
set_obs
\family default
 method is used to tell ASCEND which variables you would like to observe
 in the output of the integration.
\end_layout

\begin_layout Standard
Now we need to discuss the how and why of the two new methods.
 The 
\family typewriter
set_ode
\family default
 method is used to set up the equations and variables described in the model
 for integration by LSODE
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
LSODE
\end_layout

\end_inset

.
 In order for LSODE to be able to integrate the model, it needs to know
 which variable is the independent variable - in this case 
\family typewriter
t
\family default
 (time), which variables are the derivatives, and which are the states.
 The way we do this is we have to add a few extra attributes to each variable.
 In Section
\begin_inset space ~
\end_inset


\begin_inset CommandInset ref
LatexCommand ref
reference "sec:model1.converting-the-word"

\end_inset


\color none
, the idea of an atom was discussed with its units, default value, bounds
 etc.
 We need to add 5 more of this type of parameter.
 These attributes
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
attributes, ODE variables
\end_layout

\end_inset

 are 
\family typewriter
\color black
ode_type
\family default
\color none
, 
\family typewriter
ode_id
\family default
, 
\family typewriter
obs_id
\family default
, 
\family typewriter
ode_rtol
\family default
 and 
\family typewriter
ode_atol
\family default
.
 
\end_layout

\begin_layout Standard
This now brings us to the reason there is a 
\family typewriter
system.a4l
\family default
 and an 
\family typewriter
ivpsystem.a4l
\family default

\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
ivpsystem.a4l
\end_layout

\end_inset

.
 For a steady state model the new attributes discussed above are not needed,
 and would take up memory and introduce confusion; therefore, they are excluded
 for the system library.
 If a dynamic simulations is to be loaded and solved, the ivpsystem library
 needs to be loaded instead of the system library so the extra attributes
 will be present with each part.
\end_layout

\begin_layout Standard
We will now go through the purpose of each of these attributes.
 First 
\family typewriter
ode_type
\family default
 is to tell the system what type of variable it is.
 A value of -1 for 
\family typewriter
ode_type
\family default
 means the variable is the independent variable, 0 means it is an algebraic
 variable (default), 1 means it is a state variable, and finally 2 means
 it is a derivative.
 
\end_layout

\begin_layout Standard
The attribute 
\family typewriter
ode_id
\family default
 is used to match the state variables with their derivatives and only needs
 to be used if the variable is a state or derivative.
 In the example 
\family typewriter
M
\family default
 is a state and 
\family typewriter
dM_dt
\family default
 is the derivative.
 Therefore they both need to have the same 
\family typewriter
ode_id
\family default
 so ASCEND will know that they belong together.
 Each state and derivative pair needs to have a different 
\family typewriter
ode_id
\family default
; however, it does not matter what the number is as long as it is a positive
 integer and no other state and derivative pair has the same number.
 
\end_layout

\begin_layout Standard
Next 
\family typewriter
obs_id
\family default
 is used by the user to flag a variable for observation while integrating.
 For any integer value of 
\family typewriter
obs_id
\family default
 greater then 0 the variable will be observed.
 The result of flagging a variable for observation is that its values will
 be in a data column in one of two output files.
 One of the files of data produced with each integration contains the values
 of the states and the second the values of the variables flagged for observatio
n.
 The default file names are 
\family typewriter
y.dat
\family default
 and 
\family typewriter
obs.dat
\family default
 respectfully; however, they can be changed in the solver options
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
options, solver
\end_layout

\end_inset

 general menu.
 
\end_layout

\begin_layout Standard
Last, but not least, are the error control attributes for LSODE: 
\family typewriter
ode_rtol
\family default
 and 
\family typewriter
ode_atol
\family default
.
 Both of these come directly from the LSODE attributes rtol and atol which
 are the local relative and absolute error tolerances for the variable respectiv
ely.
\end_layout

\begin_layout Standard
There is one other thing about methods that we need to discuss before moving
 on and that is the 
\family typewriter
seqmod
\family default
 method.
 If you have not already noticed, it is a little different from the other
 examples as it has an IF statement in it.
 This is an important part of the dynamic simulation.
 It switches the degrees of freedom depending on if we are computing an
 initial condition or performing an integration step.
 We use the boolean 
\family typewriter
dynamic
\family default

\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
dynamic, boolean variable
\end_layout

\end_inset

 to control whether we are going to solve the model as a steady state model
 (
\family typewriter
dynamic := FALSE;
\family default
) or as a dynamic model (
\family typewriter
dynamic := TRUE;
\family default
).
 For the current example, we have a simple tank and, for steady state, we
 would like to calculate the number of moles and output flow rate for a
 fixed tank volume and input flow rate.
 Also, for the model to be at steady state, we have to fix the derivative
 and set it equal to zero, 
\family typewriter
(dM_dt.fixed :=TRUE; dM_dt :=0 {mole/s};.

\family default
 The derivative is normally set to zero in the 
\family typewriter
default_self
\family default
 method to prepare the model to solve for initial steady-state conditions.)
 If we then want to integrate this model for a fixed output flow (as when
 pumping the liquid out under flow control), we would free up the volume
 and fix the output flow rate.
 The model will then compute how the liquid volume will change with time.
 
\end_layout

\begin_layout Standard
In dynamic simulation, an initial value integration package, such as LSODE,
 repeatedly asks the model to compute the time derivatives for the state
 variables, given fixed values for the states.
 Using values for 
\family typewriter
dM_dt
\family default
 computed by the model, the integration package will then update the state
 variable, 
\family typewriter
M
\family default
, to its new value.
 To accommodate this calculation, we therefore fix the state variable, 
\family typewriter
M
\family default
, and free up the derivative, 
\family typewriter
dM_dt
\family default
.
\end_layout

\begin_layout Section
Solving an ASCEND instance
\end_layout

\begin_layout Standard
We are now ready to read in and compile an instance of our tank model.
 We are assuming that you understand how to use the scripting window, and
 we will show how to go about reading, compiling, solving and integrating
 a dynamic model using the following script.
\end_layout

\begin_layout Subsubsection*
Script code
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
script, solve dynamic model
\end_layout

\end_inset


\end_layout

\begin_layout LyX-Code
DELETE TYPES;
\end_layout

\begin_layout LyX-Code
READ FILE "example.a4c";
\end_layout

\begin_layout LyX-Code
COMPILE ex OF tank;
\end_layout

\begin_layout LyX-Code
BROWSE ex;
\end_layout

\begin_layout LyX-Code
RUN {ex.default_self};
\end_layout

\begin_layout LyX-Code
RUN {ex.reset};
\end_layout

\begin_layout LyX-Code
RUN {ex.values};
\end_layout

\begin_layout LyX-Code
SOLVE ex WITH QRSlv;
\end_layout

\begin_layout LyX-Code
RUN {ex.check_all};
\end_layout

\begin_layout LyX-Code
ASSIGN {ex.dynamic} TRUE;
\end_layout

\begin_layout LyX-Code
RUN {ex.reset};
\end_layout

\begin_layout LyX-Code
RUN {ex.set_ode};
\end_layout

\begin_layout LyX-Code
RUN {ex.set_obs};
\end_layout

\begin_layout LyX-Code
# User will need to edit the next line to correct path 
\end_layout

\begin_layout LyX-Code
# to the models directory
\end_layout

\begin_layout LyX-Code
source "$env(ASCENDDIST)/models/set_intervals.tcl";
\end_layout

\begin_layout LyX-Code
set_int 500 10 {s};
\end_layout

\begin_layout LyX-Code
INTEGRATE ex FROM 0 TO 50 WITH BLSODE;
\end_layout

\begin_layout LyX-Code
ASSIGN {ex.input} 120 {mole/s};
\end_layout

\begin_layout LyX-Code
INTEGRATE ex FROM 50 TO 499 WITH BLSODE;
\end_layout

\begin_layout LyX-Code
# In order to view integration results for both the
\end_layout

\begin_layout LyX-Code
# integrations the user will have to go to the solver 
\end_layout

\begin_layout LyX-Code
# window, select options, general and turn off the 
\end_layout

\begin_layout LyX-Code
# overwrite integrator logs toggle.
\end_layout

\begin_layout LyX-Code
# (NOTE: If you were then to run a different model or this 
\end_layout

\begin_layout LyX-Code
# same simulation again it would still write to the same 
\end_layout

\begin_layout LyX-Code
# files)
\end_layout

\begin_layout LyX-Code
# In order to see both sets of data at the same time on
\end_layout

\begin_layout LyX-Code
# one plot you will have to merge the two sets of data in
\end_layout

\begin_layout LyX-Code
# the file.
 This is done with following command.
\end_layout

\begin_layout LyX-Code
asc_merge_data_file ascend new_obs.dat obs.dat;
\end_layout

\begin_layout LyX-Code
# This command can also be used to convert data into a
\end_layout

\begin_layout LyX-Code
# format that can be loaded into matlab for further work.
\end_layout

\begin_layout LyX-Code
asc_merge_data_file matlab matlab_obs.m obs.dat;
\end_layout

\begin_layout LyX-Code
# This command can also be used to convert data into a
\end_layout

\begin_layout LyX-Code
# format that can be loaded into excel as a tab delimited
\end_layout

\begin_layout LyX-Code
# text file.
\end_layout

\begin_layout LyX-Code
asc_merge_data_file excel excel_obs.txt obs.dat;
\end_layout

\begin_layout Standard
First of all reading and compiling an instance of a dynamic model is the
 same as a steady state model except, as stated earlier, we must load 
\family typewriter
ivpsystem.a4l
\family default
 instead of 
\family typewriter
system.a4l
\family default
.
 The file containing 
\family typewriter
example.a4c
\family default
 in the first version of the code has 
\family typewriter
REQUIRE
\family default
 statements to load the right system file and the file 
\family typewriter
atoms.a4l
\family default
.
 
\end_layout

\begin_layout Standard
Now it is time to solve the model, and this is where things start to change.
 We must first solve the model for its initial conditions.
 We set the boolean variable 
\family typewriter
dynamic
\family default
 to 
\family typewriter
FALSE
\family default
 (in the 
\family typewriter
default_self
\family default
 method) and run the 
\family typewriter
reset
\family default
 method to get a well-posed steady-state model.
 We also need to run the 
\family typewriter
values
\family default
 method to set the fixed values of the initial conditions.
 Finally we are solve, getting as the solution the initial conditions for
 our model.
\end_layout

\begin_layout Standard
After solving for the initial conditions
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
initial conditions
\end_layout

\end_inset

, we set things up for the dynamic simulation.
 We set the boolean variable 
\family typewriter
dynamic
\family default
 to 
\family typewriter
TRUE
\family default
 and then run the 
\family typewriter
seqmod
\family default
 method to give a well-posed dynamic model.
 We now have to establish which variables are the independent variables,
 the state variables and their corresponding derivatives, and tell which
 variables we would like to observe; we run 
\family typewriter
set_ode
\family default
 and 
\family typewriter
set_obs
\family default
 methods described above.
\end_layout

\begin_layout Standard
In order for ASCEND and LSODE to know what step size and how many steps
 we want to observe, we must load a Tcl file that defines a new script command.
 The file we need to load is called 
\family typewriter
set_intervals.tcl
\family default
, and it is found in the models subdirectory of the ASCEND distribution.
 The command source comes from Tcl and is used to read and execute the a
 set of commands in a file.
 The file in this case is 
\family typewriter
set_intervals.tcl
\family default
 and the commands within it setup a new script command 
\family typewriter
set_int
\family default
.
 Once we have loaded this file, we can use the new command 
\family typewriter
set_int
\family default
 to set up the number of possible steps and their maximum size.
 Now we are ready to integrate.
 The way we do this is to use the 
\family typewriter
INTEGRATE
\family default
 command in the script.
 The syntax for these command is as follows.
\end_layout

\begin_layout Subsubsection*
Syntax for 
\family typewriter
set_int
\end_layout

\begin_layout LyX-Code
set_int number_of_steps step_size
\end_layout

\begin_layout LyX-Code
     {units of step size(time)};
\end_layout

\begin_layout Subsubsection*
Syntax for 
\family typewriter
INTEGRATE
\family default
 
\end_layout

\begin_layout LyX-Code
INTGRATE compiled_model_name 
\end_layout

\begin_layout LyX-Code
   FROM initial_step 
\end_layout

\begin_layout LyX-Code
   TO final_step 
\end_layout

\begin_layout LyX-Code
   WITH BLSODE;
\end_layout

\begin_layout Standard
The command is set up with the initial and final step so that you can integrate
 for a number of steps, then make step changes, and then continue to integrate
 another number of steps.
\end_layout

\begin_layout Section
Viewing Simulation Results
\end_layout

\begin_layout Standard
To view the simulation results, open the ASCPLOT
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
ASCPLOT
\end_layout

\end_inset

 window using the Tools menu on the Script window.
 To view a plot, first use the File menu to load the data using Load data
 set.
 Depending on what you want to look at, you can load the file containing
 the states or the file containing the variables you flagged for observation.
 Once the data file is loaded, you can double click on the file name in
 the top window to get a list of the variables in the file.
 This list will appear in the left window named Unused variables
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
variables, unused
\end_layout

\end_inset

 below where you just double clicked.
 As you will notice on the line below, the independent variable has already
 been set to time.
 The way we select the variables we want to plot vs.
 time is to highlight them from the list in the left window and, using the
 top arrow button, move them over to the plotted variables window on the
 right.
 We then use the View plot file command from the Execute menu to view the
 plot.
 
\end_layout

\begin_layout Standard
If we now want to plot something else, we simply highlight those variables
 that we do not want to plot in the plotted variables window, use the other
 arrow to move them back to the unused variable window and then move new
 variables to the plotted variables window.
 
\end_layout

\begin_layout Standard
If we want to change the independent variable, we select the variable we
 want to be the new independent variable from the list in either the unused
 variable window or the plotted variable window and then use the appropriate
 down arrow to move that variable down to become the independent variable.
\end_layout

\begin_layout Subsection
Graphing options
\end_layout

\begin_layout Standard
Now that you are able to view a plot, you might want to add titles or change
 the axis scale, line colors, and so forth.
 Adding titles can be done by selecting set 
\shape italic
titles
\shape default
 under the 
\shape italic
Display
\shape default
 menu, a new window will open in which you will have the option to add a
 plot title and axis labels.
 To change the axis scale, line color and many other features select see
 options from the 
\shape italic
Options
\shape default
 menu.
\end_layout

\begin_layout Subsubsection*
Graphing in Windows
\end_layout

\begin_layout Standard
Under MS Windows
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
MS Windows
\end_layout

\end_inset

 the default graph program Tkxgraph
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
Tkxgraph
\end_layout

\end_inset

 gives you full control of the options without having to go through the
 ASCPLOT Options menu.
 Tkxgraph is also available for UNIX, but xgraph
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
xgraph
\end_layout

\end_inset

 does a much better job drawing dashed lines with X11 than Tkxgraph does.
\end_layout

\begin_layout Standard
If you decide you do not like the plotting tools described above, you have
 two more options, and they are to convert the ASCEND output data files
 so that they can be loaded by Matlab or a spreadsheet.
 To convert the data files a new script command needs to be introduced and
 the command is 
\family typewriter
asc_merge_data_file
\family default

\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
asc
\begin_inset ERT
status collapsed

\begin_layout Plain Layout


\backslash
_
\end_layout

\end_inset

merge
\begin_inset ERT
status collapsed

\begin_layout Plain Layout


\backslash
_
\end_layout

\end_inset

data
\begin_inset ERT
status collapsed

\begin_layout Plain Layout


\backslash
_
\end_layout

\end_inset

file
\end_layout

\end_inset

.
 
\end_layout

\begin_layout Subsubsection*
Syntax for 
\family typewriter
asc_merge_data_file
\family default
 command
\end_layout

\begin_layout LyX-Code
asc_merge_data_file convert_to 
\backslash

\end_layout

\begin_layout LyX-Code
   output_file_name input_file_names
\end_layout

\begin_layout Standard
The syntax for the 
\family typewriter
asc_merge_data_file
\family default
 command is as follows.
 First of all the 
\family typewriter
convert_to
\family default
 is the format you want the data converted to.
 There are three options matlab, excel or ascend.
 The 
\family typewriter
output_file_name
\family default
 is exactly that, the name of the file in which you want the converted data
 to be put.
 The 
\family typewriter
input_file_names
\family default
 is also exactly that, the file name or names that you want converted.
 If more than one input file is given the data is combined into one output
 file.
\end_layout

\begin_layout Standard
If the matlab
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
matlab
\end_layout

\end_inset

 option is used the output file extension should be 
\family typewriter
m
\family default
, if excel is used the extension should be 
\family typewriter
txt
\family default
 as it is a tab delimited text file and for ascend the extension should
 be 
\family typewriter
dat
\family default
 for use with ASCPLOT.
\end_layout

\begin_layout Standard
You maybe wondering what exactly is this 
\family typewriter
asc_merge_data_file
\family default
 command doing.
 In the next three paragraphs we will give a brief explanation of each of
 the options.
\end_layout

\begin_layout Subsubsection*
Matlab conversion
\end_layout

\begin_layout Standard
When the data is converted to be used in matlab the first thing that is
 done is the header of the ascend data file is placed in the output file
 but is commented out.
 This is so the user can still tell when the data was created.
 The next thing is does is put all the data into a matrix that has the same
 name as the output file with var added to the end.
 All variable names from the ascend data file are then converted to matlab
 legal names by replacing the all dots and brackets with underscores(_).
 The new variable names are then set equal to there corresponding column
 of data in the matrix.
 Each variable then becomes a vector.
 When the file is run all the data is loaded and set equal to the new variable
 names and can easily be plotted using matlab commands.
\end_layout

\begin_layout Subsubsection*
Excel
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
Excel
\end_layout

\end_inset

 conversion
\end_layout

\begin_layout Standard
When the data is converted to be used in Excel the only thing that happens
 is instead of the list of variables and units being a column it is turn
 into rows.
 When the data is loaded into Excel as a tab delimited text file all the
 data will be in columns with the first row being the units of the data
 and the second being the ascend variable name.
 The data is then easily plotted using the Excel graphing package.
\end_layout

\begin_layout Subsubsection*
Ascend conversion
\end_layout

\begin_layout Standard
This is not so much a conversion as a merge and is the origin of the command.
 It is only useful if there are multiple headers in a file or more than
 one input file is given.
 Multiple headers in the file occur when stopping and starting integrations
 with the overwrite option turned off.
 This conversion removes all subsequent headers that are the same as the
 first, whether in one file or multiple, to leave one output file with what
 looks like one data set for plotting.
 If the headers are different the data will just be combined into one file
 and when loaded in ASCPLOT will still look like different data sets.
\end_layout

\begin_layout Section
Preparing a model for reuse
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
reuse, model
\end_layout

\end_inset


\end_layout

\begin_layout Standard
There are four major ways to prepare a model for reuse as described in Chapter
\begin_inset space ~
\end_inset


\begin_inset CommandInset ref
LatexCommand ref
reference "cha:model2"

\end_inset

.
 All of what is said there about reusable models applies to dynamic models.
 However, there is one thing that we think should be repeated to make clear
 for dynamic models, and that is parameterizing a model.
\end_layout

\begin_layout Subsection
Parameterizing
\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
parameterizing
\end_layout

\end_inset

 the tank model
\end_layout

\begin_layout Standard
As stated in Section
\begin_inset space ~
\end_inset


\begin_inset CommandInset ref
LatexCommand vref
reference "sec:model2.parameterizingVessel"

\end_inset


\color none
, parameterizing a model type definition alerts a future user as to which
 parts of this model you deem to be the most likely to be shared.
 An instance of a parameterized model is then created from previously defined
 types.
\end_layout

\begin_layout Standard
The new thing that needs to be repeated is that the 
\family typewriter
ode_id
\family default
's of derivative and state pairs must be different even if they are in different
 part of a larger model.
 If for instance we wanted to have two tanks in series we could parameterize
 the tank model and connect the two tanks together with the outlet of the
 first tank being the feed to the second tank.
 However, with the 
\family typewriter
set_ode
\family default

\begin_inset Index idx
status collapsed

\begin_layout Plain Layout
set
\begin_inset ERT
status collapsed

\begin_layout Plain Layout


\backslash
_
\end_layout

\end_inset

ode
\end_layout

\end_inset

 method, as we have currently written it, the derivative and state pairs
 for both tanks would have the same 
\family typewriter
ode_id
\family default
's.
 Our way around this is to introduce an 
\family typewriter
ode_counter
\family default
 that is used to set the 
\family typewriter
ode_id
\family default
's and is incremented after each derivative and state pair is set.
 The 
\family typewriter
ode_counter
\family default
 becomes one of the model parameters and is, therefore, the same in all
 models.
 We will now give an example of this to help explain.
\end_layout

\begin_layout Subsubsection*

\family typewriter
set_ode
\family default
 method for parameterized tank model
\end_layout

\begin_layout LyX-Code
METHOD set_ode;
\end_layout

\begin_layout LyX-Code
(* set ODE_TYPE -1=independent variable,
\end_layout

\begin_layout LyX-Code
0=algebraic variable, 1=state variable,
\end_layout

\begin_layout LyX-Code
2=derivative *)
\end_layout

\begin_layout LyX-Code
t.ode_type :=-1;
\end_layout

\begin_layout LyX-Code
dM_dt.ode_type :=2;
\end_layout

\begin_layout LyX-Code
M.ode_type :=1;
\end_layout

\begin_layout LyX-Code
(* Set ODE_ID *)
\end_layout

\begin_layout LyX-Code
dM_dt.ode_id := ode_offset;
\end_layout

\begin_layout LyX-Code
M.ode_id := ode_offset;
\end_layout

\begin_layout LyX-Code
ode_offset := ode_offset+1;
\end_layout

\begin_layout LyX-Code
END set_ode;
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout Subsubsection*

\family typewriter
set_ode
\family default
 method for larger model with two tank models being used as parts
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
METHOD set_ode;
\end_layout

\begin_layout LyX-Code
RUN tank_1.set_ode;
\end_layout

\begin_layout LyX-Code
RUN tank_2.set_ode;
\end_layout

\begin_layout LyX-Code
END set_ode;
\end_layout

\begin_layout Standard
The parameterized tank 
\family typewriter
set_ode
\family default
 method is almost the same as the original one we wrote except it now uses
 
\family typewriter
ode_offset
\family default
, an 
\family typewriter
ode_counter
\family default
, to set the 
\family typewriter
ode_id
\family default
s.
 It may be obvious, but this is how it works.
 When the larger model 
\family typewriter
set_ode
\family default
 is run, the 
\family typewriter
set_ode
\family default
 for 
\family typewriter
tank_1
\family default
 is run, the 
\family typewriter
ode_id
\family default
s are set to the current value of 
\family typewriter
ode_offset
\family default
, the counter is then incremented and 
\family typewriter
set_ode
\family default
 is run for 
\family typewriter
tank_2
\family default
 which then gets the incremented 
\family typewriter
ode_offset
\family default
 so the values are now different.
 You can now hopefully see that we can string as may tanks together as we
 like, and all the derivative and state pairs 
\family typewriter
ode_id
\family default
 will be different.
\end_layout

\begin_layout Standard
This same idea can be applies to setting the observed variables.
 The reason this is a good idea is that the variables are placed in the
 output files in order of there 
\family typewriter
obs_id
\family default
 value.
 This way we can keep all variables flagged for observation from one part
 of a model together.
\end_layout

\begin_layout Standard
The important thing that needs to be stressed for a dynamic system is that
 the time variable, dynamic boolean, and ode and obs counters must be in
 the parameter list.
 All these variable need to be the same in each model to be consistent and
 to make sure the model gets setup correctly when the 
\family typewriter
set_ode
\family default
 method is executed.
\end_layout

\begin_layout Section
In conclusion
\end_layout

\begin_layout Standard
We have just led you step by step through the process of creating a small
 dynamic ASCEND model and the basics on how to view the results.
\end_layout

\end_body
\end_document