rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
demo_explicit_FV.m
Go to the documentation of this file.
1 % demo of a explicit FV scheme for advection-diffusion
2 %
3 % Simple transport-diffusion problem: square domain with parabolic
4 % velocity profile, flow from left to right (or vice versa, depending on
5 % the sign of the specified velocity)
6 % upper half of the square is neuman-boundary with noflow conditions,
7 % lower half is dirichlet-boundary.
8 %
9 % A simulation for a square and a triangular grid is performed. For
10 % the triangular grid a more restrictive time-step is required, so
11 % 4 times as many time-slices are computed.
12 
13 % Bernard Haasdonk 18.4.2006
14 
16 
17 model = lin_evol_model_default;
18 gparams = {struct('gridtype','rectgrid'),...
19  struct('gridtype','triagrid')};
20 
21 %%% 1. common parameters
22 disp('Full FV-simulation:');
23 disp('-------------------');
24 disp('setting parameters');
25 
26 model.xrange = [0,1]; % grid x-coordinate range
27 model.yrange = [0,1]; % grid y-coordinate range
28 model.xnumintervals = 100; % number of grid cells in x-direction
29 model.ynumintervals = 100; % number of grid cells in y-direction
30 
31 % set everything to dirichlet (first column)
32 % then the upper half boundary to neuman (second column)
33 model.bnd_rect_corner1 = [-1, -1; ...
34  -1, 0.5];
35 model.bnd_rect_corner2 = [ 2 , 2; ...
36  2 , 2];
37 model.bnd_rect_index = [-1, -2]; % first is dirichlet, second neuman
38 
39 % output options:
40 model.verbose = 20; % 0 : no output,
41  % >9 : informative output
42  % >19 : verbose informative output
43  % >29 : debug output
44  % >99 : desperate debug output, with dbstops
45 
46 model.T = 0.25; % maximum time
47 
48 %model.nt = 250; % number of time steps
49 
50 nt{1} = 125;% first for rectgrid, second for triagrid
51 nt{2} = 500;
52 
53 % alternatively generate triagrid: smaller dt required for stability
54 %model.nt = model.nt*4;
55 
56 % set data functions and simulation information
57 model.dirichlet_values_ptr = @dirichlet_values_homogeneous;
58 model.neumann_values_ptr = @neumann_values_homogeneous;
59 model.c_dir = 1.0;
60 model.c_neu = 0.0;
61 
62 % parameters inducing "affine dependency" into the problem
63 model.diffusivity_ptr = @diffusivity_homogeneous;
64 model.num_diff_flux_ptr = @fv_num_diff_flux_gradient;
65 model.k = 0.004; % diffusion coefficient 0 to 0.004 is OK
66  % although CFL condition is not completely
67  % met for highest value
68 model.laplacian_ptr = @(glob, U, model) U;
69 model.laplacian_derivative_ptr = @(glob, U, model) ones(length(U),1);
70 
71 model.conv_flux_ptr = @conv_flux_linear;
72 model.conv_flux_derivative_ptr = @conv_flux_forward_difference;
73 model.velocity_ptr = @velocity_parabola;
74 model.flux_linear = 1;
75 model.num_conv_flux_ptr = @fv_num_conv_flux_engquist_osher;
76 model.c = -2; % maximum velocity 0 to 2 is OK
77 model.flux_quad_degree = 1;
78 
79 model.init_values_ptr = @init_values_blobs;
80 model.beta = 0.25; % weighting of Gauss-blobs 0 to 1 is reasonable
81 model.gamma = 100; % 100-1000 width of Gauss-blob of initial values
82 model.radius = 0.1; % radius of cutoff-function
83 
84 plot_params.show_colorbar = 1;
85 plot_params.no_lines = 1;
86 plot_params.axis_equal = 1;
87 plot_params.plot = @plot_element_data;
88 model.mu_names = [];
89 model.debug = 10000;
90 
91 %%% 2. "complete" simulation, complexities and plot
92 
93 gridnames = {'rectangular','triangular'};
96 for g = 1:2
97  disp(['starting full simulation for ',gridnames{g},' grid and ',...
98  ' numerical flux ',func2str(fluxes{g})]);
99  tic;
100  model.num_conv_flux_ptr = fluxes{g};
101  model.nt = nt{g};
102  model = model_default(model);
103  model = structcpy(model, gparams{g});
104  model_data = gen_model_data(model);
105  if g == 2
106  % use standard unit-square grid ...
107  model_data.grid = triagrid;
108  % ... and update boundary data
109  model_data.grid = set_boundary_types(model_data.grid, model);
110  end
111  U = fv_conv_diff(model,model_data);
112  t = toc;
113  disp(['===> Computation time of full simulation : ',num2str(t)]);
114  disp(['===> Memory requirement for full simulation : ', ...
115  num2str(numel(U)*8/(1024*1024)), ' MB']);
116  % U = rand(model.nx*model.ny,model.nt+1);
117 
118  model.title = ['Simulation ',gridnames{g},' grid, ',...
119  func2str(fluxes{g}),' numerical flux.'];
120 
121  plot_sequence(U, model_data.grid, plot_params);
122 end;
123 
124 
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
Definition: verbose.m:17
function [ vel , lambda ] = velocity_parabola(glob, params)
parabolic velocity field
function num_flux_mat = fv_num_diff_flux_gradient(model, model_data, U, NU_ind)
computes a numerical diffusive flux for a diffusion problem
A triangular conforming grid in two dimensions.
Definition: triagrid.m:17
function model = model_default(model, T, nt)
model = model_default(model)
Definition: model_default.m:17
function demo_explicit_FV()
demo of a explicit FV scheme for advection-diffusion
function [ flux_lin , lambda ] = conv_flux_forward_difference(glob, U, params)
function computing the derivative of a convective flux by forward difference.
function Udirichlet = dirichlet_values_homogeneous(glob, params)
function computing homogeneous dirichlet-values by pointwise evaluations
function p = plot_sequence(varargin)
plotting a sequence of data slices on polygonal 2d grid (constructed from params if empty) and provid...
Definition: plot_sequence.m:17
A cartesian rectangular grid in two dimensions with axis parallel elements.
Definition: rectgrid.m:17
function s1 = structcpy(s1, s2)
copies the fields of structure s2 into structure s1. If the field to be copied does not exist in s1 y...
Definition: structcpy.m:17
function num_flux = fv_num_conv_flux_lax_friedrichs(model, model_data, U, NU_ind)
Function computing a numerical convective Lax-Friedrichs flux matrix.
function num_flux = fv_num_conv_flux_engquist_osher(model, model_data, U, NU_ind)
Function computing a numerical convective Engquist-Osher flux matrix.
function [ flux , lambda ] = conv_flux_linear(glob, U, params)
function computing the convective flux of a convection problem.