Project 1, Problem #2 - math.la.asu.educhris/APM52617/Project1/RALPHS.pdf · 2 Δ𝑡 Δ𝑥2 ≤1...

Post on 08-Aug-2020

3 views 0 download

Transcript of Project 1, Problem #2 - math.la.asu.educhris/APM52617/Project1/RALPHS.pdf · 2 Δ𝑡 Δ𝑥2 ≤1...

Project 1, Problem #2

APM 526

Matthew Ralphs

2𝑏Δ𝑡

Δ𝑥2≤ 1

Δ𝑡 ≤Δ𝑥2

2𝑏

Δ𝑡 ≤0.05 2

2 1

Δ𝑡 ≤ 0.00125

𝑎 ≤2b

Δ𝑥

𝑎 ≤2(1)

(0.05)

𝑎 ≤ 40

1 ≤ 40

CFL Conditions

𝑎 ≤Δ𝑥

Δt

DoD

𝑎 ≤0.05

0.00125

1 ≤ 40

#2 #1

Δ𝑡 = 0.0013

Δ𝑡 = 0.00125

+1 (0) ½ -2 = 0

Δ𝑡 = 0.0012

2𝑏Δ𝑡

Δ𝑥2= 0.96

Δ𝑡 = 0.0010

2𝑏Δ𝑡

Δ𝑥2= 0.80

Δ𝑡 = 0.0008

2𝑏Δ𝑡

Δ𝑥2= 0.64

Δ𝑡 = 0.0006

2𝑏Δ𝑡

Δ𝑥2= 0.48

Δ𝑡 = 0.0001

2𝑏Δ𝑡

Δ𝑥2= 0.08

decreasing Δ𝑡

The solution - u(x,t):

Close up on the solution

Questions?

clear all

format compact

format long

a = -1;

b = 1;

L = 0.5;

T = 1;

dx = 0.05;

dt = 0.0001;

sizex = (2*L / dx)+3;

sizet = round((T/dt) + 2);

x = 0:dx:2*L;

t = 0:dt:T;

2*b*dt/dx^2 % CFL condition 2

2*b/dx % CFL condition 1

u0 = zeros(sizex,1);

u = zeros(sizex,sizet);

u0((sizex+1)/2) = 1/dx; % initial condition

u(:,1) = u0; % initialize u with initial condition

for j = 2:sizet

for i = 2:sizex-1

u(i,j) = u(i,j-1) - (a*dt/(2*dx)*(u(i+1,j-1)-u(i-1,j-1))) + ...

(b*dt/dx^2 * (u(i+1,j-1)-2*u(i,j-1)+u(i-1,j-1)));

end

u(1,j) = u(sizex-1,j); % ghost points

u(sizex,j) = u(2,j); % ghost points

end

colormap(flipud(hot))

% colormap((hot))

tmax = floor(sizet/2);

tmin = floor(sizet/4);

zmin = 0.952;

zmax = 0.953;

figure (1)

set(gcf, 'units','inches','position',[1 3 5 3],'color','w')

hold off

h = surf(u);

az = 60; %60

el = 24; %24

view([az,el])

shading interp

rotate3d on

set(h,'edgecolor','none')

colorbar

caxis([zmin zmax])

ax = gca;

axis([tmin tmax 2 sizex-1 zmin zmax])

ax.YTick = ([2 12 22]);

ax.YTickLabel = [-0.5 0 0.5];

% ax.XTick = [tmin tmax/2 tmax-1];

ax.XTick = [tmin tmax];

% ax.XTickLabel = [(tmin-1)*dt (((tmax/2)-1)*dt) (tmax-2)*dt];

ax.XTickLabel = [(tmin)*dt (tmax-1)*dt];

xlabel('t (s)')

ylabel('x')