1 | #*------------------------------------------------------------------- |
---|
2 | * EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC. |
---|
3 | * |
---|
4 | * This LIBRARY is free software; you can distribute it and/or modify |
---|
5 | * it under the therms of the ALSOC FREE LICENSE as available at |
---|
6 | * http://www.enq.ufrgs.br/alsoc. |
---|
7 | * |
---|
8 | * EMSO Copyright (C) 2004 - 2007 ALSOC, original code |
---|
9 | * from http://www.rps.eng.br Copyright (C) 2002-2004. |
---|
10 | * All rights reserved. |
---|
11 | * |
---|
12 | * EMSO is distributed under the therms of the ALSOC LICENSE as |
---|
13 | * available at http://www.enq.ufrgs.br/alsoc. |
---|
14 | * |
---|
15 | *-------------------------------------------------------------------- |
---|
16 | * FlowSheet showing how to use the 'if' conditional. |
---|
17 | * Ref: M.B. Carver (1978). Mathematics and Computers in Simulation |
---|
18 | * v.20, pp.190-196 |
---|
19 | *-------------------------------------------------------------------- |
---|
20 | * Author: Arge |
---|
21 | * $Id: $ |
---|
22 | *--------------------------------------------------------------------*# |
---|
23 | |
---|
24 | FlowSheet Carver1 |
---|
25 | VARIABLES |
---|
26 | x as Real; |
---|
27 | u as Real; |
---|
28 | |
---|
29 | EQUATIONS |
---|
30 | u = sin(8*asin(1)*time*'rad/s'); |
---|
31 | |
---|
32 | if u > 0 then |
---|
33 | diff(x) * 's' = x^2; |
---|
34 | else |
---|
35 | diff(x) * 's' = 0; |
---|
36 | end |
---|
37 | |
---|
38 | INITIAL |
---|
39 | x = 0.1; |
---|
40 | |
---|
41 | OPTIONS |
---|
42 | # TimeStep = 0.9; # for statistical purpose (Detailed Output) |
---|
43 | TimeStep = 0.01; # for graphical purpose |
---|
44 | TimeEnd = 0.9; |
---|
45 | TimeUnit = 's'; |
---|
46 | DAESolver (File = "dasslc", |
---|
47 | RelativeAccuracy = 1e-6, |
---|
48 | # RelativeAccuracy = 1e-4, |
---|
49 | AbsoluteAccuracy = 1e-6); |
---|
50 | end |
---|
51 | |
---|
52 | FlowSheet Carver2 |
---|
53 | PARAMETERS |
---|
54 | eps as Real (Default=1e-5); |
---|
55 | |
---|
56 | VARIABLES |
---|
57 | x as Real; |
---|
58 | u as Real; |
---|
59 | n as Real; |
---|
60 | |
---|
61 | EQUATIONS |
---|
62 | u = sin(8*asin(1)*time*'rad/s'); |
---|
63 | |
---|
64 | n = 0.5 * (1 + tanh(-u/eps)); # regularization function |
---|
65 | |
---|
66 | diff(x) * 's' = x^2 * (1-n); |
---|
67 | |
---|
68 | INITIAL |
---|
69 | x = 0.1; |
---|
70 | |
---|
71 | OPTIONS |
---|
72 | # TimeStep = 0.9; # for statistical purpose (Detailed Output) |
---|
73 | TimeStep = 0.01; # for graphical purpose |
---|
74 | TimeEnd = 0.9; |
---|
75 | TimeUnit = 's'; |
---|
76 | DAESolver (File = "dasslc", |
---|
77 | RelativeAccuracy = 1e-6, |
---|
78 | # RelativeAccuracy = 1e-4, |
---|
79 | AbsoluteAccuracy = 1e-6); |
---|
80 | end |
---|
81 | |
---|
82 | FlowSheet Carver3 |
---|
83 | PARAMETERS |
---|
84 | eps as Real (Default=1e-5); |
---|
85 | |
---|
86 | VARIABLES |
---|
87 | x as Real; |
---|
88 | u as Real; |
---|
89 | n as Real; |
---|
90 | |
---|
91 | EQUATIONS |
---|
92 | u = sin(8*asin(1)*time*'rad/s'); |
---|
93 | |
---|
94 | n = 0.5 * (1-(u/eps)/(sqrt(1+(u/eps)^2))); # regularization function |
---|
95 | |
---|
96 | diff(x) * 's' = x^2 * (1-n); |
---|
97 | |
---|
98 | INITIAL |
---|
99 | x = 0.1; |
---|
100 | |
---|
101 | OPTIONS |
---|
102 | # TimeStep = 0.9; # for statistical purpose (Detailed Output) |
---|
103 | TimeStep = 0.01; # for graphical purpose |
---|
104 | TimeEnd = 0.9; |
---|
105 | TimeUnit = 's'; |
---|
106 | DAESolver (File = "dasslc", |
---|
107 | RelativeAccuracy = 1e-6, |
---|
108 | # RelativeAccuracy = 1e-4, |
---|
109 | AbsoluteAccuracy = 1e-6); |
---|
110 | end |
---|
111 | |
---|
112 | FlowSheet Carver4 |
---|
113 | VARIABLES |
---|
114 | x as Real; |
---|
115 | u as Real; |
---|
116 | |
---|
117 | EQUATIONS |
---|
118 | |
---|
119 | if x > 0.5 then |
---|
120 | u = 0.5; |
---|
121 | else if x < -0.5 then |
---|
122 | u = 0.2; |
---|
123 | else |
---|
124 | u = 1.0; |
---|
125 | end |
---|
126 | end |
---|
127 | |
---|
128 | diff(x) * 's' = -u*x + sin(time*'rad/s'); |
---|
129 | |
---|
130 | INITIAL |
---|
131 | x = 0.0; |
---|
132 | |
---|
133 | OPTIONS |
---|
134 | TimeStart = 3.1415/4; |
---|
135 | # TimeStep = 12.5-3.1415/4; # for statistical purpose (Detailed Output) |
---|
136 | TimeStep = 0.01; # for graphical purpose |
---|
137 | TimeEnd = 12.5; |
---|
138 | TimeUnit = 's'; |
---|
139 | DAESolver (File = "dasslc", |
---|
140 | RelativeAccuracy = 1e-4, |
---|
141 | AbsoluteAccuracy = 1e-6); |
---|
142 | end |
---|
143 | |
---|
144 | FlowSheet Carver5 |
---|
145 | PARAMETERS |
---|
146 | eps as Real (Default=1e-5); |
---|
147 | |
---|
148 | VARIABLES |
---|
149 | x as Real; |
---|
150 | u as Real; |
---|
151 | n1 as Real; |
---|
152 | n2 as Real; |
---|
153 | |
---|
154 | EQUATIONS |
---|
155 | |
---|
156 | n1 = 0.5 * (1 + tanh((x-0.5)/eps)); # regularization function |
---|
157 | n2 = 0.5 * (1 + tanh(-(0.5+x)/eps)); # regularization function |
---|
158 | |
---|
159 | u = n1*(1-n2)*0.5+n2*(1-n1)*0.2+(1-n1)*(1-n2); |
---|
160 | |
---|
161 | diff(x) * 's' = -u*x + sin(time*'rad/s'); |
---|
162 | |
---|
163 | INITIAL |
---|
164 | x = 0.0; |
---|
165 | |
---|
166 | OPTIONS |
---|
167 | TimeStart = 3.1415/4; |
---|
168 | # TimeStep = 12.5-3.1415/4; # for statistical purpose (Detailed Output) |
---|
169 | TimeStep = 0.01; # for graphical purpose |
---|
170 | TimeEnd = 12.5; |
---|
171 | TimeUnit = 's'; |
---|
172 | DAESolver (File = "dasslc", |
---|
173 | RelativeAccuracy = 1e-4, |
---|
174 | AbsoluteAccuracy = 1e-6); |
---|
175 | end |
---|
176 | |
---|
177 | FlowSheet Carver6 |
---|
178 | PARAMETERS |
---|
179 | eps as Real (Default=1e-5); |
---|
180 | |
---|
181 | VARIABLES |
---|
182 | x as Real; |
---|
183 | u as Real; |
---|
184 | n1 as Real; |
---|
185 | n2 as Real; |
---|
186 | |
---|
187 | EQUATIONS |
---|
188 | |
---|
189 | n1 = 0.5 * (1+((x-0.5)/eps)/(sqrt(1+((x-0.5)/eps)^2))); # regularization function |
---|
190 | n2 = 0.5 * (1-((0.5+x)/eps)/(sqrt(1+((0.5+x)/eps)^2))); # regularization function |
---|
191 | |
---|
192 | u = n1*(1-n2)*0.5+n2*(1-n1)*0.2+(1-n1)*(1-n2); |
---|
193 | |
---|
194 | diff(x) * 's' = -u*x + sin(time*'rad/s'); |
---|
195 | |
---|
196 | INITIAL |
---|
197 | x = 0.0; |
---|
198 | |
---|
199 | OPTIONS |
---|
200 | TimeStart = 3.1415/4; |
---|
201 | # TimeStep = 12.5-3.1415/4; # for statistical purpose (Detailed Output) |
---|
202 | TimeStep = 0.01; # for graphical purpose |
---|
203 | TimeEnd = 12.5; |
---|
204 | TimeUnit = 's'; |
---|
205 | DAESolver (File = "dasslc", |
---|
206 | RelativeAccuracy = 1e-4, |
---|
207 | AbsoluteAccuracy = 1e-6); |
---|
208 | end |
---|