rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
advection_fv_output_model.m
1 function model = advection_fv_output_model(params);
2 %function model = advection_fv_output_model(params);
3 %
4 % model for the new advection model with functional output
5 % two overlapping velocity fields and boundary value modification
6 % are the parameters. Output functional is average concentration
7 % in subdomain. Pure explicit discretization of convection with ldg
8 % discretization
9 %
10 % example of a model not as class but as structure plus function pointers
11 % goal: library works with structure- or class-models
12 %
13 % possible fields of params:
14 % coarse_factor: coarsening factor between 1 and 8
15 % time-steps, gridsize are scaled down with this.
16 %
17 % (To be used as base model for initial results of RBEvolOpt...)
18 
19 % B. Haasdonk 26.8.2009
20 
21 model = [];
22 if (nargin ==1) & (isfield(params,'coarse_factor'))
23  coarse_factor = params.coarse_factor;
24 else
25  coarse_factor = 1;
26 end;
27 
28 % specification of the time information
29 model.T = 1;
30 model.nt = 2048/coarse_factor;
31 %model.save_time_indices = 0:16/coarse_factor:model.nt;
32 model.save_time_indices = 0:8/coarse_factor:model.nt;
33 disp('nt to be adjusted later!');
34 model.dt = model.T/model.nt;
35 model.verbose = 9;
36 model.debug = 0;
37 %model.debug = 1; %
38 %if model.debug
39 % disp('model with debugging turned on.');
40 %end;
41 model.axis_equal = 1;
42 model.error_estimation = 1;
43 
44 % grid information
45 %model.grid_initfile = 'rectangle_triagrid.mat';
46 model.gridtype = 'triagrid';
47 model.xnumintervals = 256/coarse_factor;
48 model.ynumintervals = 128/coarse_factor;
49 model.xrange = [0,2];
50 model.yrange = [0,1];
51 % set completely dirichlet boundary
52 model.bnd_rect_corner1 = [0,0]-eps;
53 model.bnd_rect_corner2 = [2,1]+eps;
54 %model.opts.bnd_rect_index = [-1];
55 model.element_quadrature = @triaquadrature;
56 model.intersection_quadrature = @intervalquadrature;
57 model.dim_U = model.xnumintervals * model.ynumintervals * 2;
58 
59 % Main global function pointers expected in every model
60 model.gen_model_data = @lin_evol_gen_model_data;
61 model.gen_detailed_data = @lin_evol_gen_detailed_data;
62 model.gen_reduced_data = @lin_evol_gen_reduced_data;
63 model.detailed_simulation = @lin_evol_detailed_simulation;
64 model.rb_simulation = @lin_evol_rb_simulation;
65 model.rb_reconstruction = @rb_reconstruction_default;
66 model.plot_sim_data = @lin_evol_plot_sim_data;
67 
68 % Dirichlet and Initial data
69 model.dirichlet_values_ptr = @dirichlet_values_affine_decomposed;
70 model.dirichlet_values_coefficients_ptr = @my_dirichlet_values_coefficients;
71 model.dirichlet_values_components_ptr = @my_dirichlet_values_components;
72 % dummy one dirichlet_values:
73 %model.dirichlet_values_coefficients_ptr = @(params) 1;
74 %model.dirichlet_values_components_ptr = @(glob,params) {ones(1, ...
75 % size(glob,2))};
76 model.rb_operators = @lin_evol_rb_operators;
77 model.error_norm = 'l2';
78 model.L_I_inv_norm_bound = 1;
79 model.L_E_norm_bound = 1;
80 model.rb_init_data_basis = @RB_init_data_basis;
81 model.rb_init_values = @rb_init_values_default;
82 model.init_values_ptr = @init_values_affine_decomposed;
83 model.init_values_coefficients_ptr = @my_dirichlet_values_coefficients_t0;
84 model.init_values_components_ptr = @my_dirichlet_values_components;
85 model.init_values_algorithm = @fv_init_values;
86 model.cone_number = 3; % number of components = cones
87 model.cone_range = [0,1]; % x-range of cone-support
88 model.cone_weight = 1; % leftmost cone with full weight
89 model.velocity_ptr = @velocity_affine_decomposed;
90 model.velocity_coefficients_ptr = @my_velocity_coefficients;
91 model.velocity_components_ptr = @my_velocity_components;
92 %model.vx_weight = 1.0;
93 model.vx_weight = 0.75;
94 %model.vy_weight = 1.0;
95 model.vy_weight = 0.75;
96 model.conv_flux_ptr = @conv_flux_linear;
97 model.set_rb_in_detailed_data = @(detailed_data,RB) ...
98  setfield(detailed_data,'RB',RB);
99 model.get_rb_size = @(model,detailed_data)size(detailed_data.RB,2);
100 % set parameter setting function
101 model.set_time = @set_time_default; % not set_time!!!
102 model.set_mu = @set_mu_default;
103 model.get_mu = @get_mu_default;
104 
105 % perhaps these are redundant later...
106 model.divclean_mode = 0;
107 model.flux_quad_degree = 1;
108 model.flux_linear = 1;
109 
110 %model.init_values_algorithm = @disc_init_values;
111 model.init_values_qdeg = 0;
112 model.pdeg = 0; % FV schemes with piecewise constant ansatz functions
113 model.evaluate_basis = @fv_evaluate_basis;
114 model.l2project = @l2project;
115 model.local_mass_matrix = @fv_local_mass_matrix_tria; % triangular grid
116 model.mass_matrix = @fv_mass_matrix;
117 model.ndofs_per_element = 1;
118 model.plot = @fv_plot; % then also plot_sequence will work
119 
120 % for use of old datafunctions, use the following:
121 %model.operators_ptr = @fv_operators_implicit_explicit;
122 %model.operators_conv_explicit = @fv_operators_conv_explicit;
123 %model.operators_conv_implicit = @fv_operators_conv_implicit;
124 %model.operators_diff_explicit = @fv_operators_diff_explicit;
125 %model.operators_diff_implicit = @fv_operators_diff_implicit;
126 %model.operators_neumann_explicit = @fv_operators_neumann_explicit_old;
127 %model.operators_neumann_implicit = @fv_operators_neumann_implicit;
128 
129 model.operators_ptr = @fv_operators_implicit_explicit;
130 % for use of new data function access, use now
131 model.operators_conv_explicit = @fv_operators_conv_explicit_engquist_osher;
132 model.operators_conv_implicit = @fv_operators_zero;
133 model.operators_diff_explicit = @fv_operators_zero;
134 model.operators_diff_implicit = @fv_operators_zero;
135 model.operators_neumann_implicit = @fv_operators_zero;
136 model.operators_neumann_explicit = @fv_operators_zero;
137 model.operators_output = @fv_operators_output;
138 model.orthonormalize= @model_orthonormalize_gram_schmidt; %new
139 %model.operators_diff_implicit = @fv_operators_diff_implicit_gradient;
140 %model.operators_neumann_explicit = @fv_operators_neumann_explicit;
141 
142 %model.flux_linear = 1;
143 model.data_const_in_time = 0; % time varying data...
144 %model.diffusivity_ptr = ...;
145 %model.neumann_value_ptr = @...
146 model.affinely_decomposed = 1; % data functions allow affine
147  % parameter decomposition
148 
149 model.compute_output_functional = 1; % turn on computation of output
150 model.output_function_ptr = @output_function_box_mean;
151 %model.sbox_xmin = 1;
152 model.sbox_xmin = 1;
153 model.sbox_xmax = 2;
154 model.sbox_ymin = 0;
155 %model.sbox_ymax = 0.5;
156 model.sbox_ymax = 0.5;
157 
158 %model.disc_element_mean_ptr = @fv_element_mean;
159 
160 % RB information:
161 %model.mu_names = {'cone_weight','vx_weight','vy_weight'};
162 model.mu_names = {'vx_weight','vy_weight'};
163 %model.mu_ranges = {[0 1],[0 1],[0,1]};
164 model.mu_ranges = {[0 1],[0 1]};
165 
166 model.random_seed=1234;
167 %model.RB_numintervals = [2,2,2];
168 %model.RB_numintervals = [2];
169 model.RB_generation_mode = 'greedy_refined';%'greedy_uniform_fixed'; %
170 model.RB_refinement_mode = 'adaptive';
171 model.RB_error_indicator = 'estimator';%'error';%'estimator';
172 model.RB_detailed_train_savepath = fullfile(rbmatlabtemp,'dump');
173 model.RB_extension_algorithm = @RB_extension_PCA_fixspace;
174 model.RB_stop_epsilon = 1e-2;%1e-1;
175 model.RB_stop_timeout = 24*60*60; % 1 minute
176 model.RB_stop_Nmax = 20;
177 model.RB_stop_max_val_train_ratio = 1;
178 model.RB_refinement_theta = 0.2;
179 model.RB_val_rand_seed = 543;
180 model.RB_M_val_size = 10;
181 model.RB_max_refinement_level = 5;
182 model.RB_element_indicator_mode='nodes_cogs_skippedrefs';
183 model.RB_element_indicator_s_max = 1;
184 model.RB_mixed_sensitivity_basis_generation =0;
185 
186 model.get_inner_product_matrix = @(model_data)model_data.W;
187 model.inner_product_matrix_algorithm = @(model,model_data)model_data.W;
188 model.get_estimator_from_sim_data = @(sim_data)sim_data.Delta(end);
189 model.get_dofs_from_sim_data = @(sim_data) sim_data.U;
190 model.filecache_ignore_fields_in_model = {'N','Nmax','mu_ranges'};
191 model.filecache_ignore_fields_in_detailed_data = {'RB_info'};
192 model.get_rb_from_detailed_data = @(detailed_data) detailed_data.RB;
193 model.set_rb_in_detailed_data = @(detailed_data,RB) ...
194  setfield(detailed_data,'RB',RB);
195 model.PCA_fixspace = @PCA_fixspace;
196 model.reduced_data_subset = @lin_evol_reduced_data_subset;%@(model, reduced_data)reduced_data; %evtl. replace?!?
197 %return; % temporary end
198 
199 %model.L_I_inv_norm_bound = 1; % bounds for implicit/explicit operator
200 %model.L_E_norm_bound = 1;
201 
202 %model.neumann_values_ptr = 0;
203 
204 %model.name_init_values = 'decomp_function_ptr';
205 % implement below!!
206 %model.init_values_coefficients_ptr = @my_init_values_coefficients;
207 %model.init_values_components_ptr = @my_init_values_components;
208 
209 %model.name_diffusive_num_flux = 'none';
210 
211 
212 %name_diffusive_num_flux = 'gradient';
213  % precomputed, divcleaned velocity field
214 % name_flux = 'gdl2';
215 %
216 % lambda = 2.0e-7; % v = - lambda * grad p
217 % name_convective_num_flux = 'lax-friedrichs';
218 % inner_product_matrix_algorithm = @fv_inner_product_matrix;
219 % verbose = 5;
220 %
221 %model.rb_init_values = @rb_init_values;
222 %
223 %% further method pointers, which are specific to model:
224 model.orthonormalize = @model_orthonormalize_gram_schmidt;
225 model.inner_product = @fv_inner_product;
226 %model.PCA = @model_PCA_fixspace;
227 %model.cached_detailed_simulation = @cached_detailed_simulation;
228 %model.save_detailed_simulations = @save_detailed_simulations;
229 %model.load_detailed_simulation = @load_detailed_simulation;
230 %model.use_velocity_matrixfile = 1;
231 %model.divclean_mode = 'none'; % file is already cleaned by optimization
232 
233 % set matrix-file name for optional generation or reading of file
234 %model.velocity_matrixfile = ['vel_', model.name_flux,'_',...
235 % num2str( model.xnumintervals),'x',...
236 % num2str( model.ynumintervals),...
237 % '_l',num2str( model.lambda),'.mat'];%
238 %
239 %model.lxf_lambda = 1.0194e+003;
240 
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242 %%%%% auxiliary functions used as pointers above:
243 %%%%% check later, if they are of general interest to be exported
244 %%%%% as standalone functions
245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 
247 % new function syntax: global coordinates as rows in glob_coord,
248 % time and parameter variables in params
249 
250 % dirichlet-data: convex combination of equidistant cones, decaying
251 % in time
252 function res = my_dirichlet_values_coefficients_t0(params);
253 params.t = 0;
254 res = my_dirichlet_values_coefficients(params);
255 
256 function res = my_dirichlet_values_coefficients(params);
257 % res is a vector of coefficients
258 Q_0 = params.cone_number;
259 res = zeros(1,Q_0);
260 max_pos = params.cone_weight * (Q_0-1)+1;
261 t = params.t;
262 for q = 1:Q_0
263  res(q) = (1-(max_pos-q))*(1-t) * ((max_pos>=q) && (max_pos < q+1)) ...
264  + (1+(max_pos-q))*(1-t) * ((max_pos>=q-1) && (max_pos < q));
265 end;
266 
267 function res = my_dirichlet_values_components(glob,params);
268 % res is a cell-array of row-vectors of global evaluations
269 Q_0 = params.cone_number;
270 res = cell(1,Q_0);
271 %delta_cone = 1/(Q_0+1);
272 delta_cone = (params.cone_range(2)-params.cone_range(1))/(Q_0+1);
273 cone_pos_x = delta_cone * (1:Q_0)+ params.cone_range(1);
274 for q = 1:Q_0
275  res{q} = 1-min(sqrt((glob(:,1)-cone_pos_x(q)).^2+...
276  (glob(:,2)-1).^2)*(Q_0+1),1);
277 end;
278 
279 % velocity field: overlap of y- and x parabolic profiles
280 function res = my_velocity_coefficients(params);
281 res = [params.vx_weight, params.vy_weight]*(1-params.t);
282 
283 function res = my_velocity_components(glob,params);
284 resx = [5*(1-glob(:,2).^2),...
285  zeros(size(glob,1),1)];
286 %resy = [zeros(1,size(glob,2));...
287 % -2*((1-glob(1,:).^2 .*(glob(1,:)>=0) & (glob(1,:)<=1)...
288 % ))];
289 resy = [zeros(size(glob,1),1),...
290  -1*((4-glob(:,1).^2))];
291 res = {resx, resy};
292 
293 %function res = my_velocity_coefficients2(params);
294 %res = 1;
295 
296 %function res = my_velocity_components2(glob,params);
297 %res = {repmat([0;-1],1,size(glob,2))};
298 
299 %| \docupdate
function [ sim_data , tictoc ] = load_detailed_simulation(m, savepath, params)
load single trajectory of previously saved results.
function res = intervalquadrature(poldeg, func, varargin)
integration of function func over reference interval == unit interval. by Gaussian quadrature exactly...
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 [ 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 rb_sim_data = rb_reconstruction_default(model, detailed_data, rb_sim_data)
(trivial) function computing a detailed reconstruction by linear combination of the coefficients in t...
function p = fv_plot(gridbase grid, dofs, params)
routine plotting a single fv function of fv_functions.
Definition: fv_plot.m:17
function a0 = rb_init_values_default(model, detailed_data)
function computing the reduced basis initial values. If the decomposition mode is coefficients...
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 save_detailed_simulations(model, model_data, M, savepath)
perform loop over detailed simulations and save results or check consistency with existing saved resu...
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...
function reduced_data_subset = lin_evol_reduced_data_subset(model, reduced_data)
method which modifies reduced_data, which is the data, that will be passed to the online-simulation a...
function [ flux , lambda ] = conv_flux_linear(glob, U, params)
function computing the convective flux of a convection problem.