rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
advection_diffusion_fv_model.m
1 function model = advection_diffusion_fv_model(params);
2 %function model = advection_diffusion_fv_model(params);
3 %
4 % advection-diffusion model
5 % two overlapping divergence free velocity fields, uniform
6 % diffusivity. weight of x-velocity-field and diffusivity
7 % are the parameters.
8 % Pure explicit discretization of convection with fv
9 % discretization, implicit discretization of diffusion.
10 % In contrast to the advection_fv_output_model,
11 % the velocity field is constant in time (but parameter
12 % dependent). The boundary conditions are decaying in time.
13 % see rb_tutorial steps 11 - end for usage
14 % Model to be used for the Luminy book chapter
15 %
16 % possible fields of params:
17 % coarse_factor: coarsening factor between 1 and 8
18 % time-steps, gridsize are scaled down with this.
19 %
20 
21 % B. Haasdonk 10.2.2014
22 
23 model = [];
24 if (nargin ==1) & (isfield(params,'coarse_factor'))
25  coarse_factor = params.coarse_factor;
26 else
27  coarse_factor = 1;
28 end;
29 
30 model = lin_evol_model_default;
31 model.name = 'advection_diffusion_model';
32 
33 % RB information:
34 %model.mu_names = {'vx_weight','k'};
35 model.mu_names = {'mu1','mu2'};
36 model.mu_ranges = {[0 1],[0,1]};
37 
38 % specification of the time information
39 model.T = 1;
40 model.nt = 1024/coarse_factor;
41 %model.save_time_indices = 0:16/coarse_factor:model.nt;
42 model.save_time_indices = 0:4/coarse_factor:model.nt;
43 %disp('nt to be adjusted later!');
44 model.dt = model.T/model.nt;
45 model.verbose = 9;
46 model.debug = 0;
47 %model.debug = 1; %
48 %if model.debug
49 % disp('model with debugging turned on.');
50 %end;
51 model.axis_equal = 1;
52 model.error_estimation = 1;
53 
54 % grid information
55 %model.grid_initfile = 'rectangle_triagrid.mat';
56 model.gridtype = 'rectgrid';
57 model.xnumintervals = 256/coarse_factor;
58 model.ynumintervals = 128/coarse_factor;
59 model.xrange = [0,2];
60 model.yrange = [0,1];
61 % set completely dirichlet boundary on 4 edges
62 %model.bnd_rect_corner1 = [0,0;0,0;0,1;2,0]'-2*eps;
63 %model.bnd_rect_corner2 = [0,1;2,0;2,1;2,1]'+2*eps;
64 %model.bnd_rect_index = [-1,-1,-1,-1];
65 model.bnd_rect_corner1 = [0,0]'-2*eps;
66 model.bnd_rect_corner2 = [2,1]'+2*eps;
67 model.bnd_rect_index = [-1];
68 
69 % set Dirichlet on upper and left, set outflow on bottom and right
70 %model.bnd_rect_corner1 = [0,0;0,0;0,1;2,0]'-2*eps;
71 %model.bnd_rect_corner2 = [0,1;2,0;2,1;2,1]'+2*eps;
72 %model.bnd_rect_index = [-1,-2,-1,-2];
73 
74 model.element_quadrature = @triaquadrature;
75 model.intersection_quadrature = @intervalquadrature;
76 model.dim_U = model.xnumintervals * model.ynumintervals * 2;
77 
78 % Dirichlet and Initial data
79 model.dirichlet_values_ptr = @dirichlet_values_affine_decomposed;
80 model.dirichlet_values_coefficients_ptr = @my_dirichlet_values_coefficients;
81 model.dirichlet_values_components_ptr = @my_dirichlet_values_components;
82 % dummy one dirichlet_values:
83 %model.dirichlet_values_coefficients_ptr = @(params) 1;
84 %model.dirichlet_values_components_ptr = @(glob,params) {ones(1, ...
85 % size(glob,2))};
86 %model.neumann_values_ptr = @neumann_values_outflow;
87 model.init_values_ptr = @init_values_affine_decomposed;
88 model.init_values_coefficients_ptr = @my_dirichlet_values_coefficients_t0;
89 model.init_values_components_ptr = @my_dirichlet_values_components;
90 model.cone_number = 3; % number of components = cones
91 model.cone_range = [0,1]; % x-range of cone-support
92 model.cone_weight = 1; % leftmost cone with full weight
93 model.cone_amplitude = 1; % full amplitude
94 model.velocity_ptr = @velocity_affine_decomposed;
95 model.velocity_coefficients_ptr = @my_velocity_coefficients;
96 model.velocity_components_ptr = @my_velocity_components;
97 %model.vx_weight = 1.0;
98 %model.vx_weight = 0.75;
99 %model.vy_weight = 1.0;
100 model.vy_weight = 0.75;
101 model.conv_flux_ptr = @conv_flux_linear;
102 model.diffusivity_ptr = @diffusivity_homogeneous;
103 %model.k = 1e-2;
104 
105 model.rb_init_data_basis = @RB_init_data_basis;
106 
107 % POD-Greedy settings:
108 model.RB_generation_mode = 'greedy_uniform_fixed';
109 model.RB_extension_algorithm = @RB_extension_PCA_fixspace;
110 model.RB_stop_epsilon = 1e-9;
111 model.RB_stop_timeout = 60*60; % 1 hour
112 model.RB_stop_Nmax = 50;
113 %model.RB_stop_max_val_train_ratio = inf;
114 model.filecache_ignore_fields_in_model = {'N','Nmax'};
115 model.filecache_ignore_fields_in_detailed_data = {'RB_info'};
116 
117 % decide, whether estimator or true error is error-indicator for greedy
118 % params.RB_error_indicator = 'error'; % true error
119 model.RB_error_indicator = 'estimator'; % Delta from rb_simulation
120 % choose a 5x5 uniform grid
121 model.RB_numintervals = 4 * ones(size(model.mu_names));
122 
123 % test parameters
124 %model.RB_detailed_test_savepath = 'test_data_100';
125 %model.RB_test_size = 1000;
126 
127 % perhaps these are redundant later...
128 model.divclean_mode = 0;
129 model.flux_quad_degree = 1;
130 model.flux_linear = 1;
131 
132 model.init_values_algorithm = @disc_init_values;
133 model.init_values_qdeg = 0;
134 model.pdeg = 0; % FV schemes with piecewise constant ansatz functions
135 model.evaluate_basis = @fv_evaluate_basis;
136 model.l2project = @l2project;
137 model.local_mass_matrix = @fv_local_mass_matrix_tria; % triangular grid
138 model.mass_matrix = @fv_mass_matrix;
139 model.ndofs_per_element = 1;
140 model.plot = @fv_plot; % then also plot_sequence will work
141 model.set_mu = @my_set_mu;
142 
143 % for use of old datafunctions, use the following:
144 
145 %model.operators_ptr = @fv_operators_implicit_explicit;
146 % for use of new data function access, use now
147 model.operators_conv_explicit = @fv_operators_conv_explicit_engquist_osher;
148 model.operators_conv_implicit = @fv_operators_zero;
149 model.operators_diff_explicit = @fv_operators_zero;
150 model.operators_neumann_implicit = @fv_operators_zero;
151 model.operators_neumann_explicit = @fv_operators_zero;
152 model.operators_diff_implicit = @fv_operators_diff_implicit_gradient;
153 %model.operators_neumann_explicit = @fv_operators_neumann_explicit;
154 %model.operators_output = @fv_operators_output;
155 
156 %model.flux_linear = 1;
157 model.data_const_in_time = 0; % time varying data...
158 %model.diffusivity_ptr = ...;
159 %model.neumann_value_ptr = @...
160 model.affinely_decomposed = 1; % data functions allow affine
161  % parameter decomposition
162 
163 model.compute_output_functional = 0; % turn off computation of output
164 %model.output_function_ptr = @output_function_box_mean;
165 %model.sbox_xmin = 1;
166 %model.sbox_xmin = 1;
167 %model.sbox_xmax = 2;
168 %model.sbox_ymin = 0;
169 %model.sbox_ymax = 0.5;
170 %model.sbox_ymax = 0.5;
171 
172 %model.disc_element_mean_ptr = @fv_element_mean;
173 
174 model = model.set_mu(model,[0,0]);
175 
176 return;
177 
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 %%%%% auxiliary functions used as pointers above:
180 %%%%% check later, if they are of general interest to be exported
181 %%%%% as standalone functions
182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 
184 % new function syntax: global coordinates as rows in glob_coord,
185 % time and parameter variables in params
186 
187 % dirichlet-data: convex combination of equidistant cones, decaying
188 % in time
189 function res = my_dirichlet_values_coefficients_t0(params);
190 params.t = 0;
191 res = my_dirichlet_values_coefficients(params);
192 
193 function res = my_dirichlet_values_coefficients(params);
194 % res is a vector of coefficients
195 res = (1-params.t);
196 
197 function res = my_dirichlet_values_components(glob,params);
198 % res is a cell-array of row-vectors of global evaluations
199 Q_0 = 3;
200 delta_cone = (params.cone_range(2)-params.cone_range(1))/(Q_0+1);
201 cone_pos_x = delta_cone * (1:Q_0)+ params.cone_range(1);
202 q = 2;
203 res = cell(1,1);
204 res{1} = 1-min(sqrt((glob(:,1)-cone_pos_x(q)).^2+...
205  (glob(:,2)-1).^2)*(Q_0+1),1);
206 res{1} = res{1} * params.cone_amplitude;
207 
208 % velocity field: overlap of y- and x parabolic profiles
209 function res = my_velocity_coefficients(params);
210 %res = [params.vx_weight, params.vy_weight]*(1-params.t);
211 res = [params.vx_weight, params.vy_weight]*0.5; %*(1-params.t);
212 
213 function res = my_velocity_components(glob,params);
214 resx = [5*(1-glob(:,2).^2),...
215  zeros(size(glob,1),1)];
216 %resy = [zeros(1,size(glob,2));...
217 % -2*((1-glob(1,:).^2 .*(glob(1,:)>=0) & (glob(1,:)<=1)...
218 % ))];
219 resy = [zeros(size(glob,1),1),...
220  -1*((4-glob(:,1).^2))];
221 res = {resx, resy};
222 
223 % realize coupling of mu1 => vweight, mu2*0.03 => k
224 function model = my_set_mu(varargin)
225 model = set_mu_default(varargin{:});
226 model.vx_weight = model.mu1;
227 model.k = model.mu2*0.03;
228 
function res = intervalquadrature(poldeg, func, varargin)
integration of function func over reference interval == unit interval. by Gaussian quadrature exactly...
function [ RBext , dummy ] = RB_extension_PCA_fixspace(model, detailed_data)
function computing a RB basis extension for given parameters by the POD-Greedy algorithm.
function [ L_I_diff , bdir_I_diff ] = fv_operators_diff_implicit_gradient(model, model_data, U, NU_ind)
computes diffusion contributions to finite volume time evolution matrices, or their Frechet derivati...
function [ L_E_conv , bdir_E_conv ] = fv_operators_conv_explicit_engquist_osher(model, model_data, U, NU_ind)
computes convection contribution to finite volume time evolution matrices, or their Frechet derivati...
function Udirichlet = dirichlet_values(model, X, Y)
UDIRICHLET = DIRICHLET_VALUES([X],[Y], MODEL) Examples dirichlet_values([0,1,2],[1,1,1],struct(name_dirichlet_values, homogeneous, ... c_dir, 1)) dirichlet_values([0:0.1:1],[0],struct(name_dirichlet_values, xstripes, ... c_dir, [0 1 2], ... dir_borders, [0.3 0.6])) dirichlet_values([0:0.1:1],[0],struct(name_dirichlet_values, box, ... c_dir, 1, ... dir_box_xrange, [0.3 0.6], ... dir_box_yrange, [-0.1 0.1]))
function [ L_E_neu , b_E_neu ] = fv_operators_neumann_explicit(model, model_data, U, NU_ind)
computes a neumann contribution matrix for finite volume time evolution operators, or their Frechet derivative
function p = fv_plot(gridbase grid, dofs, params)
routine plotting a single fv function of fv_functions.
Definition: fv_plot.m:17
function [ v , l2norm ] = fv_operators_output(model, model_data)
function returning components, coefficients, and complete operator for a linear output functional on ...
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
function Umean = fv_element_mean(model, model_data, U, I)
function computing the element averages of a discrete function U in the grid elements with indices I...
Customizable implementation of an abstract greedy algorithm.
Definition: DuneRBLeafNode.m:1
function [ flux , lambda ] = conv_flux_linear(glob, U, params)
function computing the convective flux of a convection problem.