Ticket #62: prob07.mso

File prob07.mso, 4.3 KB (added by Rodolfo Rodrigues, 15 years ago)

Problema 07

Line 
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* 7. Diffusion with Chemical Reaction in a One Dimensional Slab
17*----------------------------------------------------------------------
18*
19*   Description:
20*      This problem is part of a collection of 10 representative
21*       problems in Chemical Engineering for solution by numerical methods
22*       developed for Cutlip (1998).
23*
24*   Subject:
25*       * Mass Transfer
26*
27*       Mathematical model:
28*               * Simultaneous ODE’s with split boundary conditions
29*
30*       Numerical method:
31*               * Finite difference
32*
33*   Reference:
34*               * CUTLIP et al. A collection of 10 numerical problems in
35*       chemical engineering solved by various mathematical software
36*       packages. Comp. Appl. in Eng. Education. v. 6, 169-180, 1998.
37*       * http://www.polymath-software.com/ASEE
38*
39*----------------------------------------------------------------------
40* Author: Rodolfo Rodrigues
41* $Id$
42*--------------------------------------------------------------------*#
43using "types";
44
45
46Model problem
47        PARAMETERS
48outer N as Integer      (Brief="Number of discrete points", Lower=3);
49       
50        Co              as conc_mol             (Brief="Constant concentration at the surface");
51        D               as diffusivity  (Brief="Binary diffusion coefficient");
52        k               as Real                 (Brief="Homogeneous reaction rate constant", Unit='1/s');
53        L               as length               (Brief="Bottom surface");
54       
55       
56        VARIABLES
57        C(N+2)  as conc_mol             (Brief="Concentration of reactant");
58        z(N+2)  as length               (Brief="Distance", Default=1e-3);
59        dz              as length_delta (Brief="Distance increment");   
60
61
62        EQUATIONS
63        "Discrete interval"
64        dz = (z(N+2) - z(1))/(N+1);
65       
66        for i in [2:(N+1)]
67        "Concentration of reactant"     
68                (C(i+1) - 2*C(i)+ C(i-1))/(z(i) - z(i-1))^2
69                        = (k/D)*C(i);
70               
71        "Discrete length"
72                z(i) = z(i-1) + dz;
73        end
74
75        # Boundary conditions
76        "Initial and boundary condition" # z = 0
77        C(1) = Co;
78       
79        "Upper boundary" # z = L
80        (C(N+2) - C(N+1))/(z(N+2) - z(N+1)) = 0*'kmol/m^4';
81       
82       
83        SET
84        Co= 0.2*'kmol/m^3';
85        D = 1.2e-9*'m^2/s';
86        k = 1e-3/'s';
87        L = 1e-3*'m';
88end
89
90
91
92FlowSheet numerical_solution
93        PARAMETERS
94        N               as Integer;
95       
96       
97        DEVICES
98        reac    as problem;
99       
100       
101        SET
102        N = 10; # Number of discrete points
103       
104       
105        SPECIFY
106        "Lower boundary"
107        reac.z(1) = 0*'m';
108
109        "Upper boundary"
110        reac.z(N+2) = reac.L;
111
112
113        OPTIONS
114        Dynamic = false;
115end
116
117
118
119FlowSheet comparative
120        PARAMETERS
121        N               as Integer;
122       
123       
124        VARIABLES
125        C_(N+2) as conc_mol     (Brief="Concentration of reactant by analytical solution");
126       
127        r_              as Real         (Brief="Pearson product-moment correlation coefficient");
128       
129        Cm              as conc_mol     (Brief="Arithmetic mean of calculated C");
130        C_m             as conc_mol     (Brief="Arithmetic mean of analytical C");
131       
132       
133        DEVICES
134        reac    as problem;
135       
136       
137        SET
138        N = 10; # Number of discrete points
139       
140       
141        EQUATIONS
142        "Analytical solution"
143        C_ = reac.Co*cosh(reac.L*sqrt(reac.k/reac.D)*(1 - reac.z/reac.L))
144        /cosh(reac.L*sqrt(reac.k/reac.D));
145
146        "Pearson correlation coefficient" # used by softwares like MS Excel
147        r_ = (sum((reac.C - Cm)*(C_ - C_m)))/sqrt(sum((reac.C - Cm)^2)*sum((C_ - C_m)^2));
148       
149        "Arithmetic mean of C"
150        Cm = sum(reac.C)/(N+1);
151       
152        "Arithmetic mean of C_"
153        C_m = sum(C_)/(N+1);
154       
155       
156        SPECIFY
157        "Lower boundary"
158        reac.z(1) = 0*'m';
159
160        "Upper boundary"
161        reac.z(N+2) = reac.L;
162
163
164        OPTIONS
165        Dynamic = false;
166end
167
168
169FlowSheet analytical_solution
170        PARAMETERS
171        Co              as conc_mol;
172        L               as length;
173        k               as Real(Unit='1/s');
174        D               as diffusivity;
175       
176       
177        VARIABLES
178        C               as conc_mol             (Default=0.2);
179        z               as length               (Default=1e-3);
180       
181       
182        EQUATIONS
183        "Change time in z"
184        z = time*'m/s';
185       
186        "Analytical solution"
187        C = Co*cosh(L*sqrt(k/D)*(1 - z/L))/cosh(L*sqrt(k/D));
188       
189       
190        SET
191        Co= 0.2*'kmol/m^3';
192        D = 1.2e-9*'m^2/s';
193        k = 1e-3/'s';
194        L = 1e-3*'m';
195       
196       
197        OPTIONS
198        TimeStart = 0;
199        TimeStep = 1e-6;
200        TimeEnd = 1e-3;
201end