Skip to content
Snippets Groups Projects
Commit ad18b356 authored by Lars Hubatsch's avatar Lars Hubatsch
Browse files

Automatic distinction between client and constituent equations.

parent 329c9e43
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,8 @@ classdef Ternary_model < handle
properties
pa = '~/Desktop/DropletFRAP/Latex/Figures/FigModel/';
geometry = 2; % 2 ... Radial, 1 ... Cylindrical, 0 ... Slab
ic = 'FRAP'
ic %'FRAP', 'Gauss', 'Uniform'
mode % 'Constituent': LLPS molecules move. 'Client': client moves
precision = 5;
sol
t
......@@ -30,18 +31,19 @@ classdef Ternary_model < handle
function T = Ternary_model(geometry, ic, params, t, prec)
T.geometry = geometry;
T.ic = ic;
T.t = t;
T.precision = prec;
T.t = t;
if ~isempty(params)
T.a = params(1);
T.b = params(2);
T.u0 = params(3);
T.e = params(4);
T.e_g0 = params(5);
T.u_g0 = params(6);
T.system_size = params(7);
T.x0 = params(8);
T.v = params(9);
T.a = params{1};
T.b = params{2};
T.u0 = params{3};
T.e = params{4};
T.e_g0 = params{5};
T.u_g0 = params{6};
T.system_size = params{7};
T.x0 = params{8};
T.v = params{9};
T.mode = params{10};
end
T.create_mesh();
T.phi_t = Ternary_model.phi_tot(T.x, T.a, T.b, T.e, T.u0, 0);
......
......@@ -2,34 +2,37 @@ function create_mesh(T)
%CREATE_MESH creates mesh for solving Ternary_model.
% Mesh density larger for steeper gradients.
if strcmp(T.mode, 'Constituent')
% Start with left side of mesh, at r=0/x=0, with a given step size
x = [0, 0.01/T.precision/10];%/10
x = linspace(0, 0.75, 40);
x = [x, x(end)+0.01/T.precision/10];%/10
while x(end)<-T.a
x_temp = x(end)-x(end-1);
phi_nm1 = T.phi_tot(x(end), T.a, T.b, T.e, T.u0, 0);
phi_n = T.phi_tot(x(end)+x_temp, T.a, T.b, T.e, T.u0, 0);
while phi_nm1-phi_n > 0.002/T.precision
x_temp = x_temp/2;
x = [0, 0.01/T.precision/10];%/10
x = linspace(0, 0.75, 40);
x = [x, x(end)+0.01/T.precision/10];%/10
while x(end)<-T.a
x_temp = x(end)-x(end-1);
phi_nm1 = T.phi_tot(x(end), T.a, T.b, T.e, T.u0, 0);
phi_n = T.phi_tot(x(end)+x_temp, T.a, T.b, T.e, T.u0, 0);
while phi_nm1-phi_n > 0.002/T.precision
x_temp = x_temp/2;
phi_n = T.phi_tot(x(end)+x_temp, T.a, T.b, T.e, T.u0, 0);
end
x = [x, x(end)+x_temp];
end
x = [x, x(end)+x_temp];
end
x = [x, x(end)+cumsum(fliplr(diff(x)))];
x_middle = linspace(-2*T.a+x(end)-x(end-1), -10*T.a, 100*T.precision);
x_right = linspace(-10*T.a+0.1, T.system_size, 100*T.precision);
T.x = [x, x_middle, x_right];
T.x = T.x(1:find(T.x-T.system_size>=0, 1)-1);
x = [x, x(end)+cumsum(fliplr(diff(x)))];
x_middle = linspace(-2*T.a+x(end)-x(end-1), -10*T.a, 100*T.precision);
x_right = linspace(-10*T.a+0.1, T.system_size, 100*T.precision);
T.x = [x, x_middle, x_right];
T.x = T.x(1:find(T.x-T.system_size>=0, 1)-1);
% Fine mesh close to x0 if ic = 'Gauss'
[~, ind] = min(abs(T.x-T.x0));
if T.x(ind+20)-T.x(ind) > 0.1
T.x = [T.x(1:ind-21), linspace(T.x(ind-20), T.x(ind+20),...
ceil((T.x(ind+20)-T.x(ind-20))*200)),...
T.x(ind+21:end)];
% Fine mesh close to x0 if ic = 'Gauss'
[~, ind] = min(abs(T.x-T.x0));
if T.x(ind+20)-T.x(ind) > 0.1
T.x = [T.x(1:ind-21), linspace(T.x(ind-20), T.x(ind+20),...
ceil((T.x(ind+20)-T.x(ind-20))*200)),...
T.x(ind+21:end)];
end
elseif strcmp(T.mode, 'Client')
% T.x = [linspace(3, 5., 500), linspace(5.05, 6.05, 3000),...
% linspace(6.06, 7.1, 500), linspace(7.15, 20, 3000)];
T.x = linspace(0, 20, 8000);
end
% T.x = [linspace(3, 5., 500), linspace(5.05, 6.05, 3000),...
% linspace(6.06, 7.1, 500), linspace(7.15, 20, 3000)];
% T.x = linspace(0, 20, 8000);
end
......@@ -11,8 +11,8 @@ if strcmp(mode, 'mov')
figure(20); hold on;
for i = 1:nth:length(T.t)
cla; xlim([-T.a-1, -T.a+3]);
xlim([0, 10]);
ylim([0, 0.4]);
xlim([-10, 10]);
ylim([0, 4]);
ax = gca;
ax.FontSize = 12;
xlabel('position'); ylabel('probability [not normalized]');
......
......@@ -4,26 +4,30 @@ function solve_tern_frap(T)
fh_ic = @(x) flory_ic(x, T.a, T.u0, T.e, T.ic, T.x0);
fh_bc = @(xl, ul, xr, ur, t) flory_bc(xl, ul, xr, ur, t, T.u0, T.e);
fh_pde = @(x, t, u, dudx) flory_hugg_pde(x, t, u, dudx, T.a, T.b, T.e,...
T.u0, T.e_g0, T.u_g0, T.v);
T.u0, T.e_g0, T.u_g0, T.v,...
T.mode);
T.sol = pdepe(T.geometry, fh_pde, fh_ic, fh_bc, T.x, T.t);
end
%% Function definitions for pde solver
function [c, f ,s] = flory_hugg_pde(x, t, u, dudx, a, b, e, u0,...
e_g0, u_g0, v)
e_g0, u_g0, v, mode)
% Solve with full ternary model. Analytical derivatives.
% pt ... phi_tot
% gra_a ... analytical gradient of phi_tot
pt = Ternary_model.phi_tot(x, a, b, e, u0, v*t);
gra_a = Ternary_model.gradient_analytical(x, a, b, e, v*t);
g0 = Ternary_model.gamma0(x, a+t*v, b, e_g0, u_g0, v*t);
% g0 = 0.5;
c = 1;
f = g0*(1-pt)/pt*(pt*dudx-u*gra_a);
% chi_phi = -4.530864768482371;
% f = g0*(dudx+chi_phi*u*gra_a);
s = 0;
c = 1;
if strcmp(mode, 'Constituent')
g0 = Ternary_model.gamma0(x, a+t*v, b, e_g0, u_g0, v*t);
f = g0*(1-pt)/pt*(pt*dudx-u*gra_a);
elseif strcmp(mode, 'Client')
g0 = 0.5;
chi_phi = -4.530864768482371;
f = g0*(dudx+chi_phi*u*gra_a);
end
end
function u = flory_ic(x, a, u0, e, ic, x0)
......
......@@ -44,16 +44,34 @@ x_right = linspace(0, 4, 1000);
%% Moving boundary
t = linspace(0, 10, 300);
tic
T_mov = Ternary_model(0, 'Uniform', [-10, b(7/3, 10^-6), 0.5, e(7/3),...
0, 1, 10, 7, 0.5], t, 0.02);
T_mov = Ternary_model(0, 'Uniform', {-10, b(7/3, 10^-6), 0.5, e(7/3),...
0, 1, 10, 7, 0.5, 'Client'}, t, 0.02);
T_mov.solve_tern_frap();
toc
%%
csvwrite('MovingBound.csv', [T_mov.x', T_mov.sol(1, :)', T_mov.sol(end, :)'])
%% Flux moving boundary
chi_phi = -4.530864768482371;
i = 300;
x_interp = (T_mov.x(1:end-1)+T_mov.x(2:end))/2;
u = T_mov.sol(i, :);
u_interp = (u(1:end-1)+u(2:end))/2;
gra_a = Ternary_model.gradient_analytical(x_interp, T_mov.a, T_mov.b,...
T_mov.e, T_mov.v*T_mov.t(i));
dudx = diff(u)./diff(T_mov.x);
f = dudx+chi_phi.*u_interp.*gra_a;
figure; hold on;
plot(0:10, zeros(1, 11), 'LineWidth', 2);
plot(x_interp, f, 'LineWidth', 2)
set(gca,'fontsize', 18)
make_graph_pretty(['x [' char(956) 'm]'], 'flux', '', [0, 10, -0.1, 5.2])
% breakyaxis([0.6, 4.5])
% s = '~/Nextcloud/Langevin_vs_MeanField/Data_Figs_FokkPla/Mov_Bou_Flux.csv';
% csvwrite(s, [x_interp; f])
%% FRAP jump length
t = linspace(0, 5, 300);
T_mov = Ternary_model(0, 'FRAP', [-5, b(7/3, 10^-6), 0.5, e(7/3),...
0, 1, 10, 7, 0], t, 0.2);
T_mov = Ternary_model(0, 'FRAP', {-5, b(7/3, 10^-6), 0.5, e(7/3),...
0, 1, 10, 7, 0, 'Constituent'}, t, 0.2);
T_mov.solve_tern_frap();
% csvwrite('FRAP.csv', [T_mov.x', T_mov.sol(1, :)', T_mov.sol(end, :)'])
......@@ -70,11 +88,12 @@ gra_a = Ternary_model.gradient_analytical(x_interp, T_mov.a, T_mov.b,...
g0 = Ternary_model.gamma0(x_interp, T_mov.a+T_mov.v*T_mov.t(i), T_mov.b,...
T_mov.e_g0, T_mov.u_g0, T_mov.v*T_mov.t(i));
dudx = diff(u)./diff(T_mov.x);
f = g0.*(1-pt)./pt.*(pt.*dudx-u_interp.*gra_a);
hold on; cla;
plot(x_interp, g0.*(1-pt)./pt.*(pt.*dudx-u_interp.*gra_a))
plot(x_interp, f)
pause()
end
% csvwrite('FRAP.csv', [T_mov.x', T_mov.sol(1, :)', T_mov.sol(end, :)'])
csvwrite('FRAP_Flux.csv', [x_interp; f])
%% Plot with full ternary model
T_temp = T_mov;
D_m = 1*(1-T_temp.u0-T_temp.e); % to make equal to ternary FRAP
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment