Example 5.2 rev1.mw

Example 5.2

Consider the heat conduction/mass transfer problem in a cylinder.[6] [9] [10] The governing equation in dimensionless form is

u(x,0) = 0 (5.1.19)

(0,t) = 0 and u(1,t) = 1

The nonhomogeneous boundary condition at x = 1 contributes to the forcing function vector b. However, in this case the b vector is a constant, and hence, equation (5.1.18) can be used. (Note that equation (5.1.17) is valid even when the b vector is a constant.) When the governing equation is applied at x = 0 in cylindrical or spherical coordinate, we have singularity at x = 0.[11] [12] This singularity is avoided in our semianalytical technique as we use the boundary condition at x = 0 (symmetry boundary condition) to eliminate the dependent variable. Equation (5.1.19) is solved in Maple below using the procedure described above.

> | restart;

> | with(linalg):with(plots):

> | ge:=diff(u(x,t),t)=diff(u(x,t),x$2)+1/x*diff(u(x,t),x);

| (1)

> | bc1:=diff(u(x,t),x);

| (2)

> | bc2:=u(x,t)-1;

| (3)

> | IC:=u(x,0)=0;

| (4)

> | N:=10;

| (5)

> | L:=1;

| (6)

> | 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;

| (7)

> | eq[N+1]:=bc2;

| (8)

> | 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)));

| (9)

> | u[N+1](t):=solve(eq[N+1],u[N+1](t));

| (10)

> | for i from 1 to N do eq[i]:=eval(eq[i]);od;

| (11)

> | eqs:=[seq(rhs(eq[j]),j=1..N)]:

> | Y:=[seq(u[i](t),i=1..N)];

| (12)

> | A:=genmatrix(eqs,Y,'b1'):

> | b:=matrix(N,1):for i to N do b[i,1]:=-eval(b1[i]);od:evalm(b);

| (13)

> | h:=eval(L/(N+1));

| (14)

> | A:=map(eval,A):

> | if N > 4 then A:=map(evalf,A);end:

> | evalm(A);

| (15)

> | 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);

| (16)

The nonhomogeneous solution (equation (5.17b)) is found and added to the homogeneous solution.

> | s1:=evalm(Y0+inverse(A)&*b):

> | Y:=evalm(mat&*s1-inverse(A)&*b):

> | Y:=map(simplify,Y):

The number of digits is decreased to five for brevity. However, for accuracy, one has to use a minimum of 10 digits, which is the default in Maple.

> | Digits:=5;

| (17)

> | 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;

| (18)

Hence, we have obtained a semianalytical solution (analytical in time and numerical in x). Next, plots are made:

> | for i from 0 to N+1 do p[i]:=plot(u[i](t),t=0..0.4,color=COLOR(HUE,i/(N+2)),thickness=3): end do:

> | arw:=arrow(<0.26,0.6>,<-0.2,0.3>,width=[1/300,relative],head_width=[5,relative],head_length=[1/20,relative]): pt:=textplot([[0.3,0.55,"Follow the arrow:"],seq([0.26,0.5-i*0.05,typeset(u[i],"(t)")],i=0..2),[0.26,0.35,"..."],[0.265,0.3,typeset(u[11],"(t)")]]):

> | display([seq(p[i],i=0..11),arw,pt],axes=boxed,labels=[t,"u"],title="Figure Exp. 5.5.");

> | tf:=0.2;

| (19)

> | M:=30;

| (20)

> | T1:=[seq(tf*i/M,i=0..M)];

| (21)

> | PP:=matrix(N+2,M+1);

| (22)

> | 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.6.",labels=[x,t,u],orientation=[-145,45]);

It is some times important to know how the temperature or concentration at the center of the cylinder changes with time. Analytical solutions for cylinders involve Bessel functions and an infinite series. With our semianalytical method, we can find how the temperature varies analytically with time. The time dependent variable at the center of the cylinder varies with time as:

> | u[0](t);

| (23)

We can find the time taken for the center of the cylinder to reach 0.5 (i.e., 50% of the steady state):

> | fsolve(u[0](t)-0.5,t=0..2);

| (24)

In this example temperature (or concentration) at the surface is fixed (u(1,t) = 1). With our semianalytical solution we can find how the flux at the surface varies as a function of time. This flux is given bya three point backward difference at x = 1.

> | flux:=dydxb;

| (25)

> |