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.
pa = '/Users/hubatsch/ownCloud/Dropbox_Lars_Christoph/DropletFRAP/FRAP_paper/';
a = -1;
e_g0 = 0.16;
o_g0 = 0.2;
%%
g0 = gamma0(x, a, b, e_g0, o_g0);

Lars Hubatsch
committed
%% Make useful mesh (by inverting the tanh profile and using this as spacing)
x = linspace(-a-1, -a+1, 3000);
g = gamma0(x, a, 1*b, e_g0, o_g0);

Lars Hubatsch
committed
g_unique = unique(g);
x = linspace(g_unique(1), g_unique(end-1), 300);
g_inv = spacing(x, a, 2*b, e_g0, o_g0);

Lars Hubatsch
committed
g_inv = g_inv(2:end-1);
x = [linspace(-a-1, g_inv(2), 30), g_inv(3:end-2), ...
linspace(g_inv(end-1), -a+1, 30), linspace(-a+1.1, 300, 300)];

Lars Hubatsch
committed
%% Solve pde

Lars Hubatsch
committed
tic
t = linspace(0.001, 0.5, 250);
fh_ic = @(x) flory_ic(x, a, u0);
fh_bc = @(xl, ul, xr, ur, t) flory_bc(xl, ul, xr, ur, t, u0);
fh_pde = @(x, t, u, dudx) flory_hugg_pde(x, t, u, dudx, a, b, e, c, u0,...
e_g0, o_g0);

Lars Hubatsch
committed
sol = pdepe(2, fh_pde, fh_ic, fh_bc, x, t);

Lars Hubatsch
committed
toc

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

Lars Hubatsch
committed
for i = 1:length(t)
cla; xlim([-a-1, -a+3]); ylim([0, 0.7]);
ax = gca;
ax.FontSize = 16;
xlabel('position'); ylabel('volume fraction');
plot(x, phi_tot(x, a, b, e, u0), 'LineWidth', 2, 'LineStyle', '--');
plot(x, sol(i, :), 'LineWidth', 2); pause();
% % print([num2str(i),'.png'],'-dpng')

Lars Hubatsch
committed
end

Lars Hubatsch
committed
%% Figures
% Time course
figure; hold on;
xlim([49, 53]); ylim([0, 0.5]);
ax = gca;
ax.FontSize = 16;
xlabel('position'); ylabel('volume fraction');
plot(x, sol(1:2:300, :), 'LineWidth', 2, 'Color', [135/255 204/255 250/255]);
plot(x, phi_tot(x, a, b, e, u0), 'LineWidth', 4, 'LineStyle', '--', 'Color',...
[247/255, 139/255, 7/255]);
% print([pa, 'ternary_time_course'], '-depsc');

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

Lars Hubatsch
committed
x = linspace(40, 60, 100000);
plot(x, phi_tot(x, a, b, e, u0));
plot(x, gradient_analytical(x, a, b, e));
plot(x(1:end-1)+mean(diff(x))/2, ...
diff(phi_tot(x, a, b, e, u0)/mean(diff(x))));
plot(x, gamma0(x, a, b, e));

Lars Hubatsch
committed
figure; plot(gamma0(x, a, b, e), spacing(gamma0(x, a, b, e), a, b, e));

Lars Hubatsch
committed
%% Function definitions for pde solver
function [c, f ,s] = flory_hugg_pde(x, t, u, dudx, a, b, e, c_p, u0,...

Lars Hubatsch
committed
% Solve with full ternary model. Analytical derivatives.
% pt ... phi_tot
% gra_a ... analytical gradient of phi_tot
pt = phi_tot(x, a, b, e, u0);
gra_a = gradient_analytical(x, a, b, e);
g0 = gamma0(x, a, b, e_g0, o_g0);
f = g0*(1-pt)/pt*(pt*dudx-u*gra_a);

Lars Hubatsch
committed
s = 0;

Lars Hubatsch
committed
end
function u = flory_ic(x, a, u0)

Lars Hubatsch
committed
% FRAP initial condition
if x < -a; u = 0.0; else; u = u0; end

Lars Hubatsch
committed
% Peak outside initial condition
% if (x < -a+0.2) && (x > -a+0.1); u = 10; else; u = 0; end

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

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

Lars Hubatsch
committed
pl = 0;
ql = 1;

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

Lars Hubatsch
committed
qr = 0;

Lars Hubatsch
committed
end
function g0 = gamma0(x, a, b, e_g0, o_g0)
g0 = e_g0*(tanh((x+a)/b)+1)/2+o_g0;
function sp = spacing(x, a, b, e_g0, o_g0)
sp = b*atanh(2/(e_g0)*(x-o_g0)-1)-a;

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

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