Commit 95d34e83 authored by Gidon Lucian Bauer's avatar Gidon Lucian Bauer 🏳
Browse files

+ mean initial condition

parent 94ecb1bc
%% Finite Volume method
function [u, t] = FVM(u0, flux, f, dx, tspan)
function [u, t] = FVM(u0, flux, f, xspan, tspan, N)
xsize = length(u0);
dx = (xspan(2) - xspan(1))/(N-1);
u = zeros(xsize, 1);
u(:, 1) = u0;
......
......@@ -27,18 +27,19 @@ F3 = @lax_wendroff_flux;
%% 1)
if choice == 1
%% Setup
N = 100;
tspan = [0; 1];
dx = 0.01;
xspan = [-1; 1];
x = (xspan(1):dx:xspan(2))';
u0 = initial_cond(x);
x = linspace(xspan(1), xspan(2), N);
u0 = mean_init_cond(@step_func, xspan, N);
%% Solving the advection equation
[u1a, t1a] = FVM(u0, F1, fa, dx, tspan);
[u2a, t2a] = FVM(u0, F2, fa, dx, tspan);
[u3a, t3a] = FVM(u0, F3, fa, dx, tspan);
[u1a, t1a] = FVM(u0, F1, fa, xspan, tspan, N);
[u2a, t2a] = FVM(u0, F2, fa, xspan, tspan, N);
[u3a, t3a] = FVM(u0, F3, fa, xspan, tspan, N);
figure(1);
tiledlayout(2,2);
......@@ -63,9 +64,9 @@ if choice == 1
%% Solving the burges equation
[u1b, t1b] = FVM(u0, F1, fb, dx, tspan);
[u2b, t2b] = FVM(u0, F2, fb, dx, tspan);
[u3b, t3b] = FVM(u0, F3, fb, dx, tspan);
[u1b, t1b] = FVM(u0, F1, fb, xspan, tspan, N);
[u2b, t2b] = FVM(u0, F2, fb, xspan, tspan, N);
[u3b, t3b] = FVM(u0, F3, fb, xspan, tspan, N);
figure(2);
tiledlayout(2,2);
......@@ -100,7 +101,7 @@ elseif choice == 2
x = linspace(xspan(1), xspan(2), N);
%% Exact solution Burgers equation
u0 = @initial_cond;
u0 = @step_func;
[xmin,u0min] = fminbnd(u0, xspan(1), xspan(2));
[xmax,u0max] = fminbnd(@(x) -u0(x), xspan(1), xspan(2));
......
%% Calculates the mean initial condition
function [init_mean] = mean_init_cond(func, xspan, N)
dx = (xspan(2) - xspan(1))/(N+1);
init_mean = zeros(N,1);
for i = 1:N
init_mean(i) = 1/dx * integral(func, xspan(1) + i*dx, xspan(1) + (i+1)*dx);
end
end
\ No newline at end of file
%% Periodic initial conditions
function [y] = initial_cond(x)
function [y] = step_func(x)
y = ones(size(x));
for i = 1:length(x)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment