Newer
Older

Lars Hubatsch
committed
% Numerical solution of ternary FRAP model with solvent, bleached and
% unbleached species. Model is assumed to be equilibrated
% (bleached+unbleached=const.=pt). Then bleached species initial
% conditions are introduced. Integration of model via pdepe.
%% Solve pde

Lars Hubatsch
committed
x = linspace(49, 80, 700);

Lars Hubatsch
committed
t = linspace(0, 100, 1000);

Lars Hubatsch
committed
sol = pdepe(0, @flory_hugg_a, @flory_ic, @flory_bc, x, t);

Lars Hubatsch
committed
%% Plotting
figure(1); hold on;

Lars Hubatsch
committed
for i = 1:500

Lars Hubatsch
committed
cla; xlim([49, 53]); ylim([0, 1.5]);

Lars Hubatsch
committed
plot(x, phi_tot(x, -50, 0.25)); plot(x, sol(i, :)); pause(0.01);

Lars Hubatsch
committed
end
%% Plot and check derivatives of pt
figure; hold on;

Lars Hubatsch
committed
x = linspace(40, 60, 100);
plot(x, phi_tot(x, -50, 0.25));
plot(x, gradient_analytical(x, -50, 0.25));

Lars Hubatsch
committed
%% Function definitions for pde solver

Lars Hubatsch
committed
function [c, f ,s] = flory_hugg_a(x, t, u, dudx)
% Solve with full ternary model. Analytical derivatives.
% pt ... phi_tot
% gra_a ... analytical gradient of phi_tot

Lars Hubatsch
committed
pt = phi_tot(x, -50, 0.25);
gra_a = gradient_analytical(x, -50, 0.25);
c = 1/100;
f = (1.3-pt)/pt*(pt*dudx-u*gra_a);
s = 0;

Lars Hubatsch
committed
end
function u0 = flory_ic(x)

Lars Hubatsch
committed
if x<50

Lars Hubatsch
committed
u0 = 0.0;
else

Lars Hubatsch
committed
u0 = 0.3;

Lars Hubatsch
committed
end

Lars Hubatsch
committed
% u0 = 0.3;

Lars Hubatsch
committed
% u0 = phi_tot(x, -50, 1);

Lars Hubatsch
committed
end
function [pl,ql,pr,qr] = flory_bc(xl,ul,xr,ur,t)
pl = 0;
ql = 1;

Lars Hubatsch
committed
% % No flux
% pr = 0;%ur - 0.01;
% qr = 1;
% Dirichlet BC
pr = ur- 0.3;
qr = 0;

Lars Hubatsch
committed
end

Lars Hubatsch
committed
function p = phi_tot(x, a, b)
p = (tanh(-(x+a)/b)+1)/2+0.3;

Lars Hubatsch
committed
end

Lars Hubatsch
committed
function grad = gradient_analytical(x, a, b)
grad = -(1-tanh(-(x+a)/b).^2)*1/b*0.5;