Example 5.5
Consider the diffusion of a gas (A) through a stagnant liquid (B) in a container.[2] A reacts with B according to the irreversible reaction.
Both dimensionless and dimensional plots are obtained.
| > | restart; |
| > | with(linalg):with(plots): |
| > | ge:=diff(u(x,t),t)=diff(u(x,t),x$2)+Phi^2*u(x,t); |
| (1) |
| > | k:=2e-7;Dab:=2e-9;ca0:=0.01;Lc:=10e-2; |
| (2) |
| > | Phi:=sqrt(k*Lc^2/Dab); |
| (3) |
| > | bc1:=u(x,t)-1; |
| (4) |
| > | bc2:=diff(u(x,t),x); |
| (5) |
| > | IC:=u(x,0)=0; |
| (6) |
| > | N:=10; |
| (7) |
| > | L:=1; |
| (8) |
| > | dydxf:=1/2*(-u[2](t)-3*u[0](t)+4*u[1](t))/h: |
| > | dydxb:=1/2*(u[N-1](t)+3*u[N+1](t)-4*u[N](t))/h: |
| > | dydx:=1/2/h*(u[m+1](t)-u[m-1](t)): |
| > | d2ydx2:=1/h^2*(u[m-1](t)-2*u[m](t)+u[m+1](t)): |
| > | bc1:=subs(diff(u(x,t),x)=dydxf,u(x,t)=u[0](t),x=0,bc1): |
| > | bc2:=subs(diff(u(x,t),x)=dydxb,u(x,t)=u[N+1](t),x=1,bc2): |
| > | eq[0]:=bc1; |
| (9) |
| > | eq[N+1]:=bc2; |
| (10) |
| > | for i from 1 to N do eq[i]:=diff(u[i](t),t)= subs(diff(u(x,t),x$2) = subs(m=i,d2ydx2),diff(u(x,t),x) = subs(m=i,dydx),u(x,t)=u[i](t),x=i*h,rhs(ge));od: |
| > | u[0](t):=(solve(eq[0],u[0](t))); |
| (11) |
| > | u[N+1](t):=solve(eq[N+1],u[N+1](t)); |
| (12) |
| > | for i from 1 to N do eq[i]:=eval(eq[i]);od: |
| > | eqs:=[seq(rhs(eq[j]),j=1..N)]: |
| > | Y:=[seq(u[i](t),i=1..N)]; |
| (13) |
| > | A:=genmatrix(eqs,Y,'b1'): |
| > | b:=matrix(N,1):for i to N do b[i,1]:=-eval(b1[i]);od:evalm(b); |
| (14) |
| > | h:=eval(L/(N+1)); |
| (15) |
| > | A:=map(eval,A): |
| > | if N > 4 then A:=map(evalf,A);end: |
| > | evalm(A); |
| (16) |
| > | mat:=exponential(A,t): |
| > | mat:=map(evalf,mat): |
| > | Y0:=matrix(N,1):for i from 1 to N do Y0[i,1]:=evalf(subs(x=i*h,rhs(IC)));od:evalm(Y0); |
| (17) |
| > | s1:=evalm(Y0+inverse(A)&*b): |
| > | Y:=evalm(mat&*s1-inverse(A)&*b): |
| > | Y:=map(simplify,Y): |
| > | Digits:=5; |
| (18) |
| > | for i from 1 to N do u[i](t):=evalf((Y[i,1]));od: |
| > | for i from 0 to N+1 do u[i](t):=eval(u[i](t));od; |
| (19) |
Semianalytical solutions are obtained in dimensionless form. The dimensionless concentration profiles are plotted as:
| > | setcolors(["Red", "Blue", "LimeGreen", "Goldenrod", "maroon", "DarkTurquoise", "coral", "aquamarine", "magenta", "khaki", "sienna", "orange", "yellow", "gray"]); |
| (20) |
| > | pp:=plot([seq(u[i](t),i=0..N+1)],t=0..0.4,thickness=4); |
| (21) |
| > | arw:=arrow(<0.1,1.01>,<0.1,-0.8>,width=[1/600,relative=false],head_width=[1/200,relative=false],head_length=[1/30,relative=false]):
pt:=textplot([[0.28,0.15,typeset("Follow the arrow: ",u[0],"(t), ..., ",u[N+1],"(t).")]]): |
| > | display([pp,pt,arw],title="Figure Exp. 5.13.",axes=boxed,labels=[t,"u"]); |
![]() |
| > | tf:=0.5; |
| (22) |
| > | M:=30; |
| (23) |
| > | T1:=[seq(tf*i/M,i=0..M)]; |
| (24) |
| > | PP:=matrix(N+2,M+1); |
| (25) |
| > | for i from 1 to N+2 do PP[i,1]:=evalf(subs(x=(i-1)*h,rhs(IC)));od: |
| > | for i from 1 to N+2 do for j from 2 to M+1 do PP[i,j]:=evalf(subs(t=T1[j],u[i-1](t)));od;od: |
| > | plotdata := [seq([ seq([(i-1)*h,T1[j],PP[i,j]], i=1..N+2)], j=1..M+1)]: |
| > | surfdata( plotdata, axes=boxed, title="Figure Exp. 5.14.",labels=[x,t,u],orientation=[-75,75]); |
![]() |
The mass transafer flux at x = 0 in dimensionless form is given by:
| > | flux:=-dydxf; |
| (26) |
| > | plot(flux,t=0..0.5,thickness=4,title="Figure 5.15.",axes=boxed,labels=[t,"flux"]); |
![]() |
Next, the concentraiton profiles are converted to dimensionless form as:
| > | for i from 0 to N+1 do ca[i](t):=u[i](t)*ca0;od: |
| > | for i from 0 to N+1 do ca[i](t1):=subs(t=t1*Dab/Lc^2,ca[i](t));od: |
| > | for i from 0 to N+1 do p[i]:=plot(ca[i](t1),t1=0..2e6,thickness=3);od: |
| > | pp:=plot([seq(ca[i](t1),i=0..N+1)],t1=0..2e6,thickness=4); |
| (27) |
| > | arw:=arrow(<0.1e6,0.0105>,<1.0e6,-0.0085>,width=[1/1.0e5,relative=false],head_width=[1/5.0e3,relative=false],head_length=[1/30,relative=true]):
pt:=textplot([[1.4e6,0.0015,typeset("Follow the arrow: ",ca[0],"(t), ..., ",ca[N+1],"(t).")]]): |
| > | display([pp,pt,arw],title="Figure Exp. 5.16.",axes=boxed,labels=[t1,"ca"]); |
![]() |
| > | tf:=2e6; |
| (28) |
| > | M:=30; |
| (29) |
| > | T1:=[seq(tf*i/M,i=0..M)]; |
| (30) |
| > | PP:=matrix(N+2,M+1); |
| (31) |
| > | for i from 1 to N+2 do PP[i,1]:=evalf(subs(x=(i-1)*h*Lc,0));od: |
| > | for i from 1 to N+2 do for j from 2 to M+1 do PP[i,j]:=evalf(subs(t1=T1[j],ca[i-1](t1)));od;od: |
| > | plotdata := [seq([ seq([(i-1)*h*Lc,T1[j],PP[i,j]], i=1..N+2)], j=1..M+1)]: |
| > | surfdata(plotdata,title="Figure Exp. 5.17.",axes=boxed, labels=[z,t1,"ca"],orientation=[-75,75]); |
![]() |
Next, the mass transfer flux is converted to dimensionless form as:
| > | Flux:=Dab*ca0/Lc*flux: |
| > | Flux:=subs(t=t1*Dab/Lc^2,Flux); |
| (32) |
| > | plot(Flux,t1=0..2e6,thickness=4,title="Figure Exp. 5.18.",axes=boxed,labels=[t,"Flux"]); |
![]() |
| > |