1 function res = burgers_examples(step)
2 %
function res = burgers_examples(step)
4 % Burgers equation with 1D finite difference discretization
5 % demonstrating rarefaction waves and shocks moving
7 % The steps demonstrate the movement of a shock, the development of
8 % a rarefaction wave
for different initial values and velocity directions,
9 % different ODE solvers, different inputs and initial conditions.
11 % As example solver I provide an implicit Euler solver and a visualization
12 % routine with the model. In step=6 I demonstrate that also matlab ODE
13 % solvers can be used (but are slower) than the implicit Euler scheme.
15 % The model is
"tough" from model reduction perspective, as it has a
16 % moving discontinuity
if a shock develops, which cannot very well be
17 % modelled by low-dimensional spaces.
19 % You can define the input signal u arbitrarily, also time-varying. In
20 % the examples I set it to constant-in-time values.
21 % However the implicit Euler solver has a time-step width set to be stable
22 %
for u in [0,1]^2. Similar the inital value can be chosen arbitrarily in
23 % x0 \in [0,1]^(n_xi+1) guaranteeing a stable implicit Euler discretization.
24 % So you should prevent input or initial value going beyond
this range.
26 % B. Haasdonk 8.6.2016
32 %%%% This parameter scales the spatial and time-domain resolution:
33 n_xi = 200; % choose between 10 and 1000 points
35 %%%%
do not change the following values, as these nicely result in
36 %%%% stable numerical scheme and give shock at boundary at end time:
41 case 1 % rarefaction wave
43 % model mainly makes sense with constant u corresponding to
46 disp(
'example of shock moving to the right');
52 u = @(t) [x_left, x_right]
';
56 X = model.explicit_euler_time_integration(model,x0,u,nt);
57 model.plot_results(model,X);
61 disp('example of rarefaction wave to the right
');
63 %%%% change the following values between [-1,1]:
67 model = burgers_1d_model(n_xi, T, x_left, x_right, v);
68 u = @(t) [x_left, x_right]';
70 X = model.explicit_euler_time_integration(model,x0,u,nt);
71 model.plot_results(model,X);
73 case 3 % same as 2 but reverted velocity
75 disp(
'example of shock wave to the left');
81 u = @(t) [x_left, x_right]
';
83 X = model.explicit_euler_time_integration(model,x0,u,nt);
84 model.plot_results(model,X);
88 disp('example of rarefaction wave to the left
');
93 model = burgers_1d_model(n_xi, T, x_left, x_right, v);
94 u = @(t) [x_left, x_right]';
96 X = model.explicit_euler_time_integration(model,x0,u,nt);
97 model.plot_results(model,X);
99 case 5 % use arbitrary input u
101 disp(
'arbitrary input (boundary values) 0.5:');
102 disp(
'result is shock and rarefaction wave');
110 X = model.explicit_euler_time_integration(model,x0,u,nt);
112 disp(['computation took
',num2str(t),' sec.
']);
113 model.plot_results(model,X);
115 case 6 % use matlab integrator for case 5
117 disp('same as step 5 (rarefaction wave + shock) but with ode45:
')
121 model = burgers_1d_model(n_xi, T, x_left, x_right, v);
125 odefun = @(t,x) model.f(x,u(t));
128 [tout, Xtransp] = ode45(odefun, tspan, x0);
130 disp([
'computation took ',num2str(t),
' sec.']);
131 model.plot_results(model,Xtransp
');
133 case 7 % use other initial value generating a shock
135 disp('development of shock
');
136 x_left = NaN; % not used
137 x_right = NaN; % not used if having external x0
139 model = burgers_1d_model(n_xi, T, x_left, x_right, v);
142 x0 = zeros(n_xi+1,1);
143 x0(20:40) = (0:20)/20;
144 x0(41:60) = (19:-1:0)/20;
146 X = model.explicit_euler_time_integration(model,x0,u,nt);
148 disp([
'computation took ',num2str(t),
' sec.']);
149 model.plot_results(model,X);
153 error(
'step unknown');
function model = burgers_1d_model(n_xi, T, x_left, x_right, v)
simple model for Burgers PDE $d/dt x + d/d_xi (1/2 * v * x^2) = 0$ on the unit square xi in [0...