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)
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
13 % In contrast to the nonlin_evol_detailed_ei_simulation, here, the
14 % ei_operator is evaluated locally.
16 % required fields of model:
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
33 % INC_local = L_local(U_local_ext, ind_local,
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
48 % Bernard Haasdonk 24.6.2006
51 error(
'wrong number of parameters!');
55 disp([
'entered detailed simulation with interpolation ',...
56 'of the explicit operator']);
59 %grid = detailed_data.grid;
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 };
67 M = min(model.M, max(cellfun(@(X)(size(X,2)), detailed_data.BM)));
69 if model.separate_CRBs
70 Mexpl = min(model.M, size(detailed_data.BM{detailed_data.explicit_crb_index},2));
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});
84 % test of the effect of magic-point exchange
85 %TM = TM(randperm(model.M));
87 model.decomp_mode = 0;
89 % initial values by midpoint evaluation
90 U0 = model.init_values_algorithm(model, detailed_data);
92 U = zeros(length(U0(:)),model.nt+1);
95 c = zeros(Mexpl,model.nt);
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;
103 impl_CRB_ind = detailed_data.implicit_crb_index;
104 expl_CRB_ind = detailed_data.explicit_crb_index;
108 if model.verbose > 19
109 disp(['entered time-loop step
',num2str(t)]);
110 elseif model.verbose > 9
113 % get matrices and bias-vector
114 if operators_required
115 model.t = (t-1)*model.dt;
117 if isfield(model,'model_type
') && ...
118 isequal(model.model_type, 'implicit_nonaffine_linear
')
120 tmpmodel.decomp_mode = 0;
122 [L_I_red, b_I_red] = ...
123 model.implicit_operators_algorithm(tmpmodel, detailed_data, []);
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});
132 tmpmodel.decomp_mode = 0;
134 model.implicit_operators_algorithm(tmpmodel, detailed_data, []);
136 if model.data_const_in_time
137 operators_required = 0;
141 L_I = LL_I * model.dt + speye(size(LL_I));
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});
152 grid = detailed_data.grid;
154 eind_ext = index_ext(grid,...
156 model.local_stencil_size);
157 U_local_ext = U(eind_ext,t);
159 % exp_ind_local = ...
161 tmp = zeros(1,grid.nelements);
162 tmp(eind_ext) = 1:length(eind_ext);
163 eind_local = tmp(eind)
165 if ~isfield(detailed_data,'grid_local_ext
');
166 detailed_data.grid_local_ext = {...
167 gridpart(grid,eind_ext)};
170 inc_local = model.L_E_local_ptr(model, detailed_data, ...
171 U_local_ext, eind_local);
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;
177 ei_inc = QM{expl_CRB_ind} * (BM{expl_CRB_ind} \ inc_local);
179 rhs = U(:,t) - model.dt * ei_inc - model.dt * bb_I;
181 % disp('check rhs and inc!!
');
184 if isequal(L_I, speye(size(L_I)))
187 % solve linear system
188 % disp('check symmetry and choose solver accordingly!
');
190 % nonsymmetric solvers:
191 % [U(:,t+1), flag] = bicgstab(L_I,rhs,[],1000);
192 % [U(:,t+1), flag] = cgs(L_I,rhs,[],1000);
194 % symmetric solver, non pd:
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);
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);
205 disp(['error in system solution, solver
return flag =
', ...
210 % plot_element_data(grid,U(:,t));