1 function model = hmm_micro_local_model(params)
2 %
function model = hmm_micro_local_model(params)
4 %
function generating a RBmatlab model to be used
for reduction of
5 % the micromodel with local
operator. Params is currently ignored
7 % prototype is the following Situation:
9 % Makromodell: u_t +f(u)_x = 0 auf I=(a,\infty), f(u) = u^3
11 % u(x,0) = u_L,U_R (,so dass die Loesung eine
12 % nichtklassische Welle ist)
13 % u(a,t) = a(t) (Stoerfunktion, so dass "viele"
14 % verschiedene Riemannprobleme
15 % am nichklassischen Schock geloest
20 % u^\eps_t+f(u^\eps)_x = \eps u^\eps_{xx} + \gamma \eps^2 u^\eps_{xxx}
27 %specify default parameters of Frederikes Model:
28 mm.Time = 2.24*10^(-5); % endtime of micromodel
29 if isfield(params,'Time')
32 mm.ul = 4; % left state
33 mm.ur = -2; % right state
34 mm.alpha = 4; % alpha parameter of regularization
35 mm.n_x = 300; % number of space steps
36 if isfield(params,'n_x')
37 mm.n_x = params.n_x; % number of space steps
39 mm.epsilon = 10^(-5); % regularization parameter
40 mm.dx=2*mm.epsilon/5; % space step width
42 if isfield(params,'dt_factor')
43 mm.dt_factor = params.dt_factor;
45 %mm.w = max(abs(mm.ul),abs(mm.ur));
46 w = 4; % maximum to be expected value of u
47 mm.dt = mm.dt_factor*min([mm.dx/(3*w^2), ...
48 mm.dx^2/(2*mm.epsilon), ...
49 mm.dx^3/(3*mm.alpha*mm.epsilon^2)]);
50 % Zeitschrittweite fuer ul<-4 vorne 0.06 durch 0.01 ersetzen!!!
51 mm.n_t=round(mm.Time/mm.dt); % Anzahl Zeitschritte
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 % generate RBmatlab model from Frederikes
56 model = nonlin_evol_model_default;
57 model.base_model = mm;
59 % specify parametrization
60 model.mu_names = {
'ul',
'ur'};
61 %model.mu_ranges = {[1,4],[-5,-1]};
62 model.mu_ranges = {[1,4],[-3,-1]};
63 % explanation Frederike: smaller values of ul: too slow evolution
64 % other values of ur: Oscillations
65 % Bernard: changed to {[1,4],[-3,-1]}; in order to prevent
68 % copy some fields from base model to model:
69 model.epsilon = mm.epsilon;
70 model.alpha = mm.alpha;
79 model.name = [
'hmm_micro_local_',num2str(model.nt)];
81 model.xrange = [-40*model.dx, -40*model.dx+(model.nx-1)* ...
83 model.xnumintervals = model.nx-1;
85 % set further fields of nonlin_evol_model:
86 model.inner_product_matrix_algorithm = @(model,model_data) ...
90 model.plot = @my_plot;
94 % only used
for plotting:
95 model.range_lim = [-6,6];
96 model.gridtype =
'onedgrid';
98 % clip values after local evaluation
99 model.enable_range_limiting = 0;
100 model.enable_error_estimator = 0;
101 model.implicit_nonlinear = 0;
102 model.newton_solver = 0;
105 model.gen_model_data = @my_gen_model_data;
107 model.init_values_algorithm = @my_init_values_algorithm;
108 %model.init_values_algorithm = @init_values_affine_decomposed;
109 model.init_values_coefficients_ptr = @my_init_values_coefficients;
110 model.init_values_components_ptr = @my_init_values_components;
112 % local time stepping
operator:
113 model.L_E_local_ptr = @my_L_E_local;
114 model.local_stencil_size = 2;
116 model.l2_error_sequence_algorithm = @my_l2_error_sequence_algorithm;
117 model.error_algorithm = @my_linftyl2_error_algorithm;
119 %@(U1,U2,grid,params) ...
120 % sqrt(max(sum((U1-U2).^2),0));
121 % empirical interpolation data:
122 %model.ei_numintervals = [4,4];
123 model.ei_numintervals = [1,1];
124 model.Mmax = 300; % should be exact then
125 %model.Mmax = 160; % take 150
for sim, 10
for error-est
126 model.Mstrich = 0; % no error estimation
128 model.ei_detailed_savepath = [model.name,
'_detailed'];
129 model.ei_operator_savepath = [model.name,
'ei_operator_'];
130 model.ei_time_indices = 1:model.nt+1;
132 model.CRB_generation_mode =
'param-time-space-grid';
133 model.ei_target_error =
'interpol';
135 % fields
for RB-generation:
136 model.error_norm =
'l2';
137 %
'RB_extension_max_error_snapshot'};
138 model.RB_stop_timeout = 3*60*60; % 2 hours
139 model.RB_stop_epsilon = 1e-5;
140 model.RB_error_indicator =
'error'; %
true error
141 %model.RB_error_indicator =
'estimator'; % Delta from rb_simulation
142 model.RB_stop_Nmax = 30;
143 model.RB_generation_mode =
'greedy_uniform_fixed';
144 model.RB_numintervals = model.ei_numintervals;
145 model.RB_detailed_train_savepath = model.ei_detailed_savepath;
146 model.orthonormalize = @model_orthonormalize_qr;
148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 function model_data = my_gen_model_data(model)
151 model_data = nonlin_evol_gen_model_data(model);
152 %params.X = (-40*model.dx:model.dx:-40*model.dx+(model.nx-1)* ...
154 %model_data.grid =
onedgrid(params);
155 %model_data.grid.nelements = model.nx;
156 % neighbour indices of 1D grid:
157 %model_data.grid.A = model.dx * ones(1,model.nx);
159 function res = my_init_values_algorithm(model,model_data)
161 if model.decomp_mode < 2
162 glob = model_data.grid.X(:);
164 res = init_values_affine_decomposed(glob,model);
166 function ucomp = my_init_values_components(x,model)
167 % indicator function for left and right state regions
168 u1 = zeros(length(x),1);
181 function usigma = my_init_values_coefficients(model)
182 usigma = [model.ul; model.ur];
184 function [inc,dummy] = my_L_E_local(model,model_data,ulocal_ext,index_local)
185 % index_local: vector of indeces of ulocal_ext, in which increment
186 % values are desired.
187 if isempty(index_local) % global evaluation
188 %inc = Phasen_lokal_space(ulocal,model.epsilon,model.alpha,index,...
189 % model.dx,model.dt);
190 u_new = Phasen_lokal(ulocal_ext,...
191 model.epsilon,model.alpha,...
192 index_local,model.dx,model.dt);
193 inc = -(u_new - ulocal_ext)/model.dt;
195 else % local evaluation
196 index_ext = model_data.grid_local_ext{1}.
global_eind;
197 [u_new,u_index] = Phasen_lokal(ulocal_ext,model.epsilon,...
198 model.alpha,index_ext,model.dx, ...
201 [index_local_sorted, sort_index] = sort(index_local);
202 % => index_local(sort_index) = index_local_sorted;
205 % invert_sort_index = ...;
206 invert_sort_index = zeros(size(sort_index));
207 invert_sort_index(sort_index) = 1:length(sort_index);
208 if ~isequal(index_local_sorted(invert_sort_index),index_local)
209 error('sorting is buggy!!');
211 index = index_ext(index_local_sorted);
212 % index = sort(index);
213 if length(u_index)==length(index)
217 % u_new and u_index are possibly "too" large, pick out target
219 posi = zeros(1,max(u_index));
220 posi(u_index) = 1:length(u_index);
222 u_new_M = u_new(posi2);
223 u_index_M = u_index(posi2);
226 if ~isequal(u_index_M,index)
227 error('u_index_M and index not identical!!!!');
230 if isfield(model,'enable_range_limiting') && model.enable_range_limiting
231 i = find(u_new_M<model.range_lim(1));
233 u_new_M(i) = model.range_lim(1);
234 disp('performed range limiting!');
236 i = find(u_new_M>model.range_lim(2));
238 u_new_M(i) = model.range_lim(2);
242 inc = -(u_new_M(invert_sort_index) - ulocal_ext(index_local))/model.dt;
246 if ~isempty(find(isnan(inc))) && isempty(find(isnan(ulocal_ext)))
247 warning('nan occuring!');
249 %[u,index_n]=Phasen_lokal(u_sicher,epsilon,alpha,index,dx,dt);
251 % Kontrolle/ global Loesung zum Zeitpunkt T+dt
252 %[u_kontrolle]=Phasen_lokal(u_sicher,epsilon,alpha,[],dx,dt);
253 % Fehler zwischen globaler und lokaler Loesung
254 %fehler = max(abs(u_kontrolle(index_n)-u));
257 function p = my_plot(d,grid,params)
258 p = plot(grid.X,d,'LineWidth',2);
260 if isfield(params,'range_lim') && isnumeric(params.range_lim)
261 set(gca,'Ylim',params.range_lim);
263 set(gca,'Ylim',[min(d),max(d)]);
267 function res = my_l2_error_sequence_algorithm(U1,U2,grid,params)
268 res = sqrt(max(sum((U1-U2).^2),0));
272 function res = my_linftyl2_error_algorithm(U1,U2,grid,params)
273 res = max(sqrt(max(sum((U1-U2).^2),0)));
a one dimensional grid implementation
global_eind
global enumeration of entity indices [1:nelements]