Você está na página 1de 7

1 1

BMEn 3101 Spring 2010


Biomedical Transport Processes
Computer Lab 3
Assigned Fri April 2
CL3-0 due at the start of recitation
CL3-1,2, due Wednesday April 14 (in lecture)
Goals:
Investigate the behavior of a simple parabolic PDE, or IBVP, namely the
"diffusion equation" using RK4_IBVP1D.m
Investigate the numerical stability properties of the method of lines
Modify RK4_IBVP1D.m for a derivative BC and validate the modified code
Reinforce ways to minimize execution time

Steps:

CL3-0a. Consider the following mass transport problem involving the diffusion equation:

cC
ct
= D
c
2
C
cx
2
, IC : C(0, x) = C
L
, BC : C(t,0) = C
0
, D
cC
cx
x=L
= k C(t, L) C
L
( )


In dimensionless form (using the usual scalings for the membrane diffusion problem, i.e.
C* = (C-C
L
)/(C
0
-C
L
), x*=x/L, etc.), it is as follows upon omitting * from all the variables:

(1)
cC
ct
=
c
2
C
cx
2
, IC : C(0, x) = 0, BC : C(t,0) =1,
cC
cx
x=1
= Bi C(t,1)

This problem differs from that for which RK4_IBVP1D.m is coded due to the Robbin (flux-
matching) BC at x=1 rather than the standard Dirichlet BC, C(t,1) = 0 . Determine how you will
modify the code to compute a solution to this problem, i.e. what are the appropriate
modifications to evalf.m? Note that in what follows, the program variable y can be considered
the species concentration C. Also recall that (1) models the diffusion of an uncharged solute
across a membrane separated by two infinite volume compartments, i.e. with constant
compartmental concentrations, with perfect stirring in the left compartment and imperfect in the
right, as measured by the Biot number. Think physically about your results in this recitation!

CL3-0b. What are the initial values for y
1
, y
2
, , y
11
that you will enter in Step 2 when the
program prompts you to enter them?

1. Copy the CL3 files from WebCT to your IT Labs folder. It contains the files
RK4_IBVP1D.m and evalf.m. Create the folder saveddata in that folder.

2. RK4_IBVP1D.m is currently coded to solve the diffusion equation with Dirichlet BC. Run
it for n = 11, xl = 0, xr = 1, t
0
= 0, t
f
= 0.2, h = 0.005, the (uniform) IC y(t=0,x) = 0, and the
(Dirichlet) BC y(t,x=xl) = 1, y(t,x=xr) = 0. Plot the profile with y-axis range 0 to 1 at
intermediate times of t = 0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.1, 0.2. RK4_IBVP1D.m as coded is
essentially solving the problem of diffusion across a membrane, so there should be no surprises
here.

3. Run RK4_IBVP1D.m as in Step 2 but for the IC y(t=0,x) = 0.5 and t
f
= 0.4 (also plot the
profiles at t = 0.3, 0.4).

2 2

CL3-1. Do your results in Steps 2 & 3 depend on the IC you choose? Explain.

4. Run the original RK4_IBVP1D.m (i.e., Dirichlet BC at both boundaries) with the inputs n =
15, xl = 0, xr = 1, t
0
= 0, t
f
= 0.2, h = 0.005, the IC y(t=0,x) = 0, the Dirichlet BC y(t,x=xl) = 1,
y(t,x=xr) = 0, and 11 profiles at equi-spaced times (same parameters as Step 2 except n = 15
instead of 11).

5. Run the original RK4_IBVP1D.m with the same inputs as above in Step 4 but with h
adjusted (decreased) so that h/Ax
2
has the same value as in Step 2.

CL3-2a. What is the new value of h used for step 5? Explain what is going on in Steps 4 & 5.
CL3-2b. Why would one bother to make n larger anyway (thereby having to deal with choosing
h)?

6. Modify evalf.m to compute a solution for the case of a Neumann ("no flux") BC at x = 1, i.e.
cy/cx = 0. Run your modified program twice using the input (different IC's) of Steps 2 & 3.
Think carefully about what to enter when prompted for the initial/boundary value for y
n
!

CL3-3a. How does y
s
depend on x in Step 6 in each case? Do your results depend on the IC?
CL3-3b. Could you have predicted your finding in Step 6? (Hint: determine the analytical
solution for y
s
(x)).

7. Modify RK4_IBVP1D.m to compute a solution to (1). It is always good practice to validate
your code by running a case with a known solution, when possible. For Bi, (1) yields a
solution for which you should be able to predict the qualitative features. After you have
modified the code, compute a solution for Bi=100 as a test of your modified program.

CL3-4. Submit separate plots from your results from Step 7 for Bi=100 and Bi=1, which cover
the time period until steady-state is reached. Explain how and why these results are what you
would expect. Also, include the modified code of evalf.m used to generate these results.

8. Note the following ways to minimize program run time:

Minimize all input/output. This includes:
- keyboard input of parameters that are never varied (imagine if you were inputting n =
51, xl = 0, xr = 1, t
0
= 0, t
f
= 2, the IC y(t=0,x) = 0.5, and the Dirichlet BC
y(t,x=xl) = 0, y(t,x=xr) = 1 every time!)
- Printing to screen (imagine if values for 101 nodes had been printed every time!)
- Writing to files (frequency, i.e. number of time profiles, and amount, e.g. only a
few significant figures rather than the entire double precision value)
- Graphics (frequency, i.e. number of time profiles and points per profile)

Use the most efficient choice of algorithms (e.g. use a banded matrix solver when possible) and
parameters (e.g. minimize the number of nodes, maximize the time step size that still give
acceptable precision in results, etc.).

CL3-5. (worth 2x) Problem 8.7 in your DCM text. A program listing must be attached for any
credit.


3 3
CL3-6. (worth 2x) A chemotherapeutic agent X is known to be lethal to tumor cells at a
concentration of 1.8 x 10
-10
mole/cm
3
. It is used to treat a patient with metastatic tumors of
average radius 500 m. However, X is degraded by enzymes within the tumor cells according to
Michaelis-Menton kinetics, where R
max
= 1.5 x 10
-15
mole/cm
3
/s and K
m
= 1 x 10
-10
mole/cm
3
.
D
eff, X
= 2.5 x 10
-9
cm
2
/s in the tissue and the radial outward flow of exudate from leaky
neovessels in the tumor v = 0.18 m/hr. Assume spherical symmetry and that the cells
comprising the medium need not be considered as discrete objects (i.e. the tumor is considered a
homogenous sphere of cell cytoplasm )
1) How long does it take for complete kill of the average tumor if the concentration of X at
the tumor surface is maintained at 3 x 10
-7
M?
2) 2) What must the surface concentration be maintained at to kill the tumor within 2 days?
A program listing must be attached for any credit.



4 4
% RK4_IBVPID
% To solve nonlinear initial-boundary value problems (parabolic
% PDEs) for y(t,x) on x = (x1,xr), t = (to,tf) with Dirichlet,
% Neumann, or Robin BCs. The general method of solution is the
% method of lines, with centered finite-differencing of spatial
% partial derivatives and numerical integration of the resultant
% ODE system in time with the fourth order Runge-Kutta. A plot
% of the profile vs time is generated
%
% Specifically, it is currently coded to solve the diffusion equation
% dy/dt = d^2y/dx^2 with Dirichlet BC - see function evalf

clc;
% Check if this was the last program run to use previous values of input
if(exist('prgname') == 1)
if(strcmp(prgname,'RK4_IBVP1D') ~= 1)
clear;
else
clear x y t t0 tf tinc tinter tplot v tplots f rk;
end
end
prgname = 'RK4_IBVP1D';
% End Check

scrsz = get(0,'ScreenSize');
h = figure('Position',[3 (scrsz(4)/2.2) scrsz(3)/2 scrsz(4)/2],
'Name','Fourth-order Runga-Kutta','NumberTitle','off','Resize','off');
xlabel('x');
ylabel('y');
title('MOL of \partialy/\partialt = \partial^2y/\partialx^2');

nmax = 100;
prompt = {'Total number of spatial nodes:','Spatial Domain Boundaries
(x1):','Spatial Domain Boundaries (xr):','Initial time:','Final time:','Time
step size'};
if(exist('def1') == 0)
def1 = {'11','0','1','0','0.2','0.005'};
end
S = inputdlg(prompt,'RK4',1,def1);
def1 = S;

n = str2double(S(1));
xl = str2double(S(2));
xr = str2double(S(3));
t0 = str2double(S(4));
tf = str2double(S(5));
h = str2double(S(6));

x(1) = xl;
x(n) = xr;
dx = (xr-xl) / (n-1);
r = 1.0 /dx^2;
for i = 1:1:n
x(i) = xl + (i-1) * dx;

5 5
if (i > 1 & i < n)
prompt(i) = {strcat('Enter the initial value y', int2str(i))};
else
prompt(i) = {strcat('Enter the initial/boundary value y', int2str(i))};
end
end

if(exist('def2') == 0)
def2(1) = {'0'};
for i = 2:(n-1)
def2(i) = {'0.5'};
end
def2(n) = {'1'};
else
num = size(def2);
num = num(1);
if(num < n)
for i = (num+1):n
def2{i} = '0';
end
else
def2 = def2(1:n);
end
end

% Split into multiple dialogs
nodectr = 1;
while((nodectr+12) <= n)
S(nodectr:nodectr+11) =
inputdlg(prompt(nodectr:nodectr+11),'RK4',1,def2(nodectr:nodectr+11));
nodectr = nodectr + 12;
end
if(nodectr <= n)
S(nodectr:n) = inputdlg(prompt(nodectr:n),'RK4',1,def2(nodectr:n));
end
def2 = S;

for(i = 1:1:n)
y(i) = str2double(S(i));
end

if(exist('def3') == 0)
def3 = {'0','1','8'};
end
prompt = {'Range of y-axis for the plot (ymin)','Range of y-axis for the plot
(ymax)','Desired number of time profiles (<=11) for printing/plotting for times
> t0'};
S = inputdlg(prompt,'RK4',1,def3);
def3 = S;
ymin = str2double(S(1));
ymax = str2double(S(2));
tplots = str2double(S(3));

man = questdlg('Enter times manually?','RK4','Yes','No','Yes');

6 6

if(exist('def4') == 0)
for i = 1:n
def4(i) = {'0'};
end
else
num = size(def4);
num = num(1);
if(num < n)
for i = (num+1):n
def4{i} = '0';
end
else
def4 = def4(1:n);
end
end

if(strcmp(man,'Yes') == 1)
for(i = 1:1:tplots)
prompt(i) = {strcat('Time for profile', int2str(i))};
end
S = inputdlg(prompt,'RK4',1,def4);
def4 = S;
for(i = 1:1:tplots)
tplo = str2double(S(i));
tplot(i) = uint16((tplo - t0)/h);
end
else
tinc = uint16((tf - t0)/tplots/h);
for (i = 1:1:tplots)
tplot(i) = uint16(i * double(tinc));
end
end

xlplot = xl;
xrplot = xr;
xlim([xlplot,xrplot]);
ylim([ymin,ymax]);
hold on;

plot(x,y,'-bo');

disp('Plot data: ');
disp(sprintf(' t \t\t\t\t\t\t y at x =\n\t'));
fprintf(' ');
disp(sprintf('%.2f ',x));
disp(sprintf('\n'));

% Subroutine RK4
iout = 1;
t = t0;
f=0;
disp(sprintf('%.2f %.2f ',t,y));
while(t < tf + h)

7 7
f = evalf(n,r,y,f);

for(i = 1:1:n)
rk(1,i) = f(i);
v(i) = y(i) + h*rk(1,i)/2.0;
end

tinter = t + h/2.0;
f = evalf(n,r,v,f);

for(i = 1:1:n)
rk(2,i) = f(i);
v(i) = y(i) + h*rk(2,i)/2.0;
end

tinter = t + h/2.0;
f = evalf(n,r,v,f);

for(i = 1:1:n)
rk(3,i) = f(i);
v(i) = y(i) + h*rk(3,i);
end

tstep = t + h;
f = evalf(n,r,v,f);

for(i = 1:1:n)
rk(4,i) = f(i);
y(i) = y(i) + h*(rk(1,i) + 2.0*rk(2,i) + 2.0*rk(3,i) + rk(4,i))/6.0;
end

if(uint16((t-t0)/h) == tplot(iout))
disp(sprintf('%.2f %.2f ',t,y));
plot(x,y,'-bo');
iout = iout + 1;
end
t = t + h;
end
-------------------------------------------------------------------------------------------------------------------------
function evalf = evalf(n,r,y,f)
f = zeros(n);
for i = 2:1:n-1
f(i) = r*(y(i+1) - 2*y(i) + y(i-1));
end
f(1) = 0;
f(n) = 0;
evalf = f;

Você também pode gostar