rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
hmm_micro_local_model.m
1 function model = hmm_micro_local_model(params)
2 %function model = hmm_micro_local_model(params)
3 %
4 % function generating a RBmatlab model to be used for reduction of
5 % the micromodel with local operator. Params is currently ignored
6 %
7 % prototype is the following Situation:
8 %
9 % Makromodell:  u_t +f(u)_x = 0 auf I=(a,\infty), f(u) = u^3
10 %
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
16 % werden muessen)
17 %               
18 %
19 % Mikromodell: 
20 % u^\eps_t+f(u^\eps)_x = \eps u^\eps_{xx} + \gamma \eps^2 u^\eps_{xxx}
21 
22 mm = [];
23 if isempty(params)
24  params = [];
25 end;
26 
27 %specify default parameters of Frederikes Model:
28 mm.Time = 2.24*10^(-5); % endtime of micromodel
29 if isfield(params,'Time')
30  mm.Time= params.Time;
31 end;
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
38 end;
39 mm.epsilon = 10^(-5); % regularization parameter
40 mm.dx=2*mm.epsilon/5; % space step width
41 mm.dt_factor = 0.06;
42 if isfield(params,'dt_factor')
43  mm.dt_factor = params.dt_factor;
44 end;
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
52 
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 
55 % generate RBmatlab model from Frederikes
56 model = nonlin_evol_model_default;
57 model.base_model = mm;
58 
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
66 % divergent scheme
67 
68 % copy some fields from base model to model:
69 model.epsilon = mm.epsilon;
70 model.alpha = mm.alpha;
71 model.nt = mm.n_t;
72 model.T = mm.Time;
73 model.dt = mm.dt;
74 model.nx = mm.n_x;
75 model.dx = mm.dx;
76 model.ul = mm.ul;
77 model.ur = mm.ur;
78 
79 model.name = ['hmm_micro_local_',num2str(model.nt)];
80 
81 model.xrange = [-40*model.dx, -40*model.dx+(model.nx-1)* ...
82  model.dx];
83 model.xnumintervals = model.nx-1;
84 
85 % set further fields of nonlin_evol_model:
86 model.inner_product_matrix_algorithm = @(model,model_data) ...
87  eye(model.nx);
88 model.verbose = 10;
89 model.debug = 3;
90 model.plot = @my_plot;
91 model.no_lines = 0;
92 model.axis_equal = 0;
93 model.axis_tight = 0;
94 % only used for plotting:
95 model.range_lim = [-6,6];
96 model.gridtype = 'onedgrid';
97 
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;
103 
104 % initial values:
105 model.gen_model_data = @my_gen_model_data;
106 
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;
111 
112 % local time stepping operator:
113 model.L_E_local_ptr = @my_L_E_local;
114 model.local_stencil_size = 2;
115 
116 model.l2_error_sequence_algorithm = @my_l2_error_sequence_algorithm;
117 model.error_algorithm = @my_linftyl2_error_algorithm;
118 
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
127 
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;
131 
132 model.CRB_generation_mode = 'param-time-space-grid';
133 model.ei_target_error = 'interpol';
134 
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;
147 
148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 
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)* ...
153 % model.dx);
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);
158 
159 function res = my_init_values_algorithm(model,model_data)
160 glob = [];
161 if model.decomp_mode < 2
162  glob = model_data.grid.X(:);
163 end;
164 res = init_values_affine_decomposed(glob,model);
165 
166 function ucomp = my_init_values_components(x,model)
167 % indicator function for left and right state regions
168 u1 = zeros(length(x),1);
169 i = find(x<0);
170 u1(i) = 1;
171 u2 = 1-u1;
172 ucomp = {u1,u2};
173 %for i=1:length(x)
174 % if x(i)<0
175 % u(i) = ul;
176 % else
177 % u(i) = ur;
178 % end
179 %end
180 
181 function usigma = my_init_values_coefficients(model)
182 usigma = [model.ul; model.ur];
183 
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;
194 % keyboard;
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, ...
199  model.dt);
200 
201  [index_local_sorted, sort_index] = sort(index_local);
202  % => index_local(sort_index) = index_local_sorted;
203  % invert sorting:
204 % keyboard;
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!!');
210  end;
211  index = index_ext(index_local_sorted);
212 % index = sort(index);
213  if length(u_index)==length(index)
214  u_new_M = u_new;
215  u_index_M = u_index;
216  else
217  % u_new and u_index are possibly "too" large, pick out target
218  % values:
219  posi = zeros(1,max(u_index));
220  posi(u_index) = 1:length(u_index);
221  posi2 = posi(index);
222  u_new_M = u_new(posi2);
223  u_index_M = u_index(posi2);
224  end;
225  if model.debug
226  if ~isequal(u_index_M,index)
227  error('u_index_M and index not identical!!!!');
228  end;
229  end;
230  if isfield(model,'enable_range_limiting') && model.enable_range_limiting
231  i = find(u_new_M<model.range_lim(1));
232  if ~isempty(i)
233  u_new_M(i) = model.range_lim(1);
234  disp('performed range limiting!');
235  end;
236  i = find(u_new_M>model.range_lim(2));
237  if ~isempty(i)
238  u_new_M(i) = model.range_lim(2);
239  end;
240  end;
241 
242  inc = -(u_new_M(invert_sort_index) - ulocal_ext(index_local))/model.dt;
243 % keyboard;
244 
245 end;
246 if ~isempty(find(isnan(inc))) && isempty(find(isnan(ulocal_ext)))
247  warning('nan occuring!');
248 end;
249 %[u,index_n]=Phasen_lokal(u_sicher,epsilon,alpha,index,dx,dt);
250 %X = x(index_n);
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));
255 dummy = [];
256 
257 function p = my_plot(d,grid,params)
258 p = plot(grid.X,d,'LineWidth',2);
259 axis tight
260 if isfield(params,'range_lim') && isnumeric(params.range_lim)
261  set(gca,'Ylim',params.range_lim);
262 else
263  set(gca,'Ylim',[min(d),max(d)]);
264 end;
265 xlabel('x');
266 
267 function res = my_l2_error_sequence_algorithm(U1,U2,grid,params)
268 res = sqrt(max(sum((U1-U2).^2),0));
269 
270 %keyboard;
271 
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
Definition: onedgrid.m:17
global_eind
global enumeration of entity indices [1:nelements]
Definition: onedgrid.m:29