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

Slightly more efficient mesh by making spacing dependent on steepness of tanh profile.

parent b52412d8
No related branches found
No related tags found
No related merge requests found
......@@ -8,17 +8,29 @@ b = 0.025;
c = 1/100000;
u0 = 0.05;
e = 0.4;
%% Make useful mesh (by inverting the tanh profile and using this as spacing)
x = linspace(49.0, 51, 3000);
g = gamma0(x, a, 1*b, e);
g_unique = unique(g);
x = linspace(g_unique(1), g_unique(end-1), 300);
g_inv = spacing(x, a, 2*b, e);
g_inv = g_inv(2:end-1);
x = [linspace(49.0, g_inv(2), 30), g_inv(3:end-2), ...
linspace(g_inv(end-1), 51, 30), linspace(51.1, 200, 300)];
%% Solve pde
x = [linspace(49.0, 51, 3000), linspace(51.01, 200, 300)];
tic
% x = [linspace(49.0, 49.8, 30), linspace(49.81, 50.2, 1000), ...
% linspace(50.21, 51, 30) linspace(51.01, 200, 600)];
t = linspace(0.001, 1, 1000);
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);
sol = pdepe(0, fh_pde, fh_ic, fh_bc, x, t);
toc
%% Plotting
figure(1); hold on;
for i = 1:length(t)
% i = 800;
cla; xlim([49, 53]); ylim([0, 0.7]);
ax = gca;
ax.FontSize = 16;
......@@ -30,13 +42,13 @@ end
%% Plot and check derivatives of pt
figure; hold on;
x = linspace(40, 60, 10000);
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));
max(gamma0(x, a, b, e))/min(gamma0(x, a, b, e))
figure; plot(gamma0(x, a, b, e), spacing(gamma0(x, a, b, e), a, b, e));
%% Function definitions for pde solver
function [c, f ,s] = flory_hugg_pde(x, t, u, dudx, a, b, e, c_p, u0)
% Solve with full ternary model. Analytical derivatives.
......@@ -76,6 +88,10 @@ function g0 = gamma0(x, a, b, e)
g0 = 10*e*(tanh((x+a)/b)+1)/2+0.001;
end
function sp = spacing(x, a, b, e)
sp = b*atanh(2/(10*e)*(x-0.001)-1)-a;
end
function p = phi_tot(x, a, b, e, u0)
p = e*(tanh(-(x+a)/b)+1)/2+u0;
end
......
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