rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
nonlin_evol_detailed_local_ei_simulation.m
1 function ei_sim_data = nonlin_evol_detailed_local_ei_simulation(model, detailed_data)
2 %function ei_sim_data = nonlin_evol_detailed_local_ei_simulation(model, detailed_data)
3 %
4 % function performing a general time evolution and computing the
5 % solution DOF-vector ei_sim_data.U(:,t) for all times t=1,...,nt+1
6 % instead of the real explicit operator, the empirical
7 % interpolation operator given in detailed_data is used.
8 % So this function can be used for testing the stability of the
9 % empirical interpolation operator. The coefficient vectors of the
10 % empirical interpolation of the space operator are returned as
11 % columns of ei_sim_data.c
12 %
13 % In contrast to the nonlin_evol_detailed_ei_simulation, here, the
14 % ei_operator is evaluated locally.
15 %
16 % required fields of model:
17 % T : final time
18 % nt : number of time-intervals until T, i.e. nt+1
19 % solution slices are computed
20 % init_values_algorithm: name of function for computing the
21 % initvalues-DOF with arguments (grid)
22 % example: init_values_cog
23 % implicit_operators_algorithm: name of function for computing the
24 % L_I, b_I-operators with arguments (grid)
25 % example fv_operators_implicit
26 % data_const_in_time : if this optional field is 1, the time
27 % evolution is performed with constant operators,
28 % i.e. only the initial-time-operators are computed
29 % and used throughout the time simulation.
30 % L_E_local_ptr : function pointer to the local space-discretization
31 % operator evaluation with syntax
32 %
33 % INC_local = L_local(U_local_ext, ind_local,
34 % grid_local_ext)
35 % where *_local indicates results on a set of
36 % elements, *_local_ext includes information including
37 % their neighbours, i.e. the grid must be known
38 % also for the neighbours, the values of the
39 % previous timstep must be known on the
40 % neighbours. The subset of elements, which are
41 % to be computed are given in ind_local and the
42 % values produced are INC_local.
43 % A time-step can then be realized by
44 % NU_local = U_local_ext(ind_local) - dt * INC_local
45 % M : number of colateral basis vectors, that will be used for
46 % empirical inteprolation of the explicit operator
47 
48 % Bernard Haasdonk 24.6.2006
49 
50 if nargin ~= 2
51  error('wrong number of parameters!');
52 end;
53 
54 if model.verbose >= 9
55  disp(['entered detailed simulation with interpolation ',...
56  'of the explicit operator']);
57 end;
58 
59 %grid = detailed_data.grid;
60 
61 if ~iscell(detailed_data.BM)
62  detailed_data.BM = { detailed_data.BM, detailed_data.BM, detailed_data.BM };
63  detailed_data.QM = { detailed_data.QM, detailed_data.QM, detailed_data.QM };
64  detailed_data.TM = { detailed_data.TM, detailed_data.TM, detailed_data.TM };
65 end
66 
67 M = min(model.M, max(cellfun(@(X)(size(X,2)), detailed_data.BM)));
68 
69 if model.separate_CRBs
70  Mexpl = min(model.M, size(detailed_data.BM{detailed_data.explicit_crb_index},2));
71 else
72  Mexpl = M;
73 end
74 
75 for oi=1:length(detailed_data.BM)
76  M = min(model.M, max(size(detailed_data.BM{oi},2)));
77  % prepare online-data for online-ei-components (e.g. varying M)
78  QM{oi} = detailed_data.QM{oi}(:,1:M);
79  BM{oi} = detailed_data.BM{oi}(1:M,1:M);
80  TM{oi} = detailed_data.TM{oi}(1:M);
81  BMinv{oi} = inv(BM{oi});
82 end
83 
84 % test of the effect of magic-point exchange
85 %TM = TM(randperm(model.M));
86 
87 model.decomp_mode = 0;
88 
89 % initial values by midpoint evaluation
90 U0 = model.init_values_algorithm(model, detailed_data);
91 
92 U = zeros(length(U0(:)),model.nt+1);
93 U(:,1) = U0(:);
94 
95 c = zeros(Mexpl,model.nt);
96 
97 model.dt = model.T/model.nt;
98 operators_required = 1;
99 if isempty(model.data_const_in_time')
100  model.data_const_in_time = 0;
101 end
102 
103 impl_CRB_ind = detailed_data.implicit_crb_index;
104 expl_CRB_ind = detailed_data.explicit_crb_index;
105 
106 % loop over fv-steps
107 for t = 1:model.nt
108  if model.verbose > 19
109  disp(['entered time-loop step ',num2str(t)]);
110  elseif model.verbose > 9
111  fprintf('.');
112  end;
113  % get matrices and bias-vector
114  if operators_required
115  model.t = (t-1)*model.dt;
116  model.tstep = t;
117  if isfield(model,'model_type') && ...
118  isequal(model.model_type, 'implicit_nonaffine_linear')
119  tmpmodel = model;
120  tmpmodel.decomp_mode = 0;
121  clear_all_caches;
122  [L_I_red, b_I_red] = ...
123  model.implicit_operators_algorithm(tmpmodel, detailed_data, []);
124  clear_all_caches;
125  LL_I = QM{impl_CRB_ind} * BMinv{impl_CRB_ind} ...
126  * L_I_red(TM{impl_CRB_ind},:);
127  bb_I = QM{impl_CRB_ind} * BMinv{impl_CRB_ind} ...
128  * b_I_red(TM{impl_CRB_ind});
129  LL_I = sparse(LL_I);
130  else
131  tmpmodel = model;
132  tmpmodel.decomp_mode = 0;
133  [LL_I, bb_I] = ...
134  model.implicit_operators_algorithm(tmpmodel, detailed_data, []);
135  end;
136  if model.data_const_in_time
137  operators_required = 0;
138  end;
139  end;
140  model.tstep = t;
141  L_I = LL_I * model.dt + speye(size(LL_I));
142 
143  % compute real explicit operator result, but only use the
144  % magic-point entries and perform an empirical interpolation instead
145  %inc = model.L_E_local_ptr(model, detailed_data, U(:,t), []);
146  %inc_local = inc(TM{expl_CRB_ind});
147 
148  % local evaluation:
149 
150  % keyboard;
151 
152  grid = detailed_data.grid;
153  eind = TM{1};
154  eind_ext = index_ext(grid,...
155  eind,...
156  model.local_stencil_size);
157  U_local_ext = U(eind_ext,t);
158  % exp_ind_ext = ...
159  % exp_ind_local = ...
160  % U_local_ext = ...
161  tmp = zeros(1,grid.nelements);
162  tmp(eind_ext) = 1:length(eind_ext);
163  eind_local = tmp(eind)
164 
165  if ~isfield(detailed_data,'grid_local_ext');
166  detailed_data.grid_local_ext = {...
167  gridpart(grid,eind_ext)};
168  end;
169 
170  inc_local = model.L_E_local_ptr(model, detailed_data, ...
171  U_local_ext, eind_local);
172 
173  % ei_coefficients = BM \ inc_local;
174  % ei_inc = detailed_data.QM(:,1:model.M)*ei_coefficients;
175  % c(:,t) = BM{expl_CRB_ind} \ inc_local;
176 
177  ei_inc = QM{expl_CRB_ind} * (BM{expl_CRB_ind} \ inc_local);
178 
179  rhs = U(:,t) - model.dt * ei_inc - model.dt * bb_I;
180 
181 % disp('check rhs and inc!!');
182 % keyboard;
183 
184  if isequal(L_I, speye(size(L_I)))
185  U(:,t+1) = rhs;
186  else
187  % solve linear system
188  % disp('check symmetry and choose solver accordingly!');
189  % keyboard;
190  % nonsymmetric solvers:
191  % [U(:,t+1), flag] = bicgstab(L_I,rhs,[],1000);
192  % [U(:,t+1), flag] = cgs(L_I,rhs,[],1000);
193  %
194  % symmetric solver, non pd:
195  % omit symmlq:
196  % see bug_symmlq.mat for a very strange bug: cannot solve identity system!
197  % reported to matlab central, but no solution up to now.
198  % [U(:,t+1), flag] = symmlq(L_I,rhs,[],1000);
199  %
200  % [U(:,t+1), flag] = minres(L_I,rhs,[],1000);
201  % symmetric solver, pd:
202  U(:,t+1) = L_I \ rhs;
203 % [U(:,t+1), flag] = bicgstab(L_I,rhs,[],1000);
204  if flag>0
205  disp(['error in system solution, solver return flag = ', ...
206  num2str(flag)]);
207  keyboard;
208  end;
209  end;
210 % plot_element_data(grid,U(:,t));
211 
212 end;
213 if model.verbose > 9
214  fprintf('\n');
215 end;
216 
217 ei_sim_data.U = U;
218 ei_sim_data.c = c;
219 %| \docupdate