rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
nonlin_evol_detailed_rb_proj_simulation.m
1 function [sim_data, fl] = nonlin_evol_detailed_rb_proj_simulation(model,detailed_data, refU)
2 %function sim_data = nonlin_evol_detailed_rb_proj_simulation(model,detailed_data)
3 %
4 % required fields of model:
5 % T : final time
6 % nt : number of time-intervals until T, i.e. nt+1
7 % solution slices are computed
8 % init_values_algorithm : name of function for computing the
9 % initvalues-DOF with arguments (model, model_data)
10 % example: fv_init_values
11 % data_const_in_time : if this optional field is 1, the time
12 % evolution is performed with constant operators,
13 % i.e. only the initial-time-operators are computed
14 % and used throughout the time simulation.
15 % L_E_local_ptr : function pointer to the local space-discretization
16 % operator evaluation with syntax
17 %
18 % INC_local = L_local(U_local_ext, ind_local,
19 % grid_local_ext)
20 % where *_local indicates results on a set of
21 % elements, *_local_ext includes information including
22 % their neighbours, i.e. the grid must be known
23 % also for the neighbours, the values of the
24 % previous timstep must be known on the
25 % neighbours. The subset of elements, which are
26 % to be computed are given in ind_local and the
27 % values produced are INC_local.
28 % A time-step can then be realized by
29 % NU_local = U_local_ext(ind_local) - dt * INC_local
30 % example: fv_conv_explicit_space
31 
32 % Martin Drohmann 14.04.2007 based on detailed_nonlin_evol_simulation.m by
33 % Bernard Haasdonk
34 
35 if nargin ~= 3
36  error('wrong number of parameters!');
37 end;
38 
39 if model.verbose >= 9
40  disp('entered detailed simulation ');
41 end;
42 
43 % for a detailed simulation we do not need the affine parameter
44 % decomposition
45 model.decomp_mode = 0;
46 
47 % initial values by midpoint evaluation
48 U0 = model.init_values_algorithm(model,detailed_data);
49 
50 digits(60);
51 %digits(60);
52 %U0 = vpa(U0);
53 
54 %Nm = model.Nm;
55 %Np = model.Np;
56 %N = model.Np + model.Nm;
57 %RBp = detailed_data.RBp;
58 %RBm = detailed_data.RBm;
59 N = model.N;
60 %RB = [detailed_data.RBp,detailed_data.RBm];
61 RB = detailed_data.RB;
62 %RB = RBp + RBm;
63 disp(size(RB));
64 W = model.get_inner_product_matrix(detailed_data);
65 
66 %U = vpa(zeros(length(U0(:)),model.nt+1));
67 U = zeros(length(U0(:)),model.nt+1);
68 a = zeros(N, model.nt+1);
69 
70 %a(1:Np,1) = RBp' * W * U0(:);
71 %U0min = U0(:) - RBp * a(1:Np,1);
72 %a(Np+1:N,1) = RBm' * W * U0min;
73 
74 a = RB' * W * U0(:);
75 
76 %a = RBp' * W * U0(:) + RBm' * W * U0(:);
77 
78 U(:,1) = RB * a(:,1);
79 
80 %disp(norm(U(:,1)-U0(:)));
81 
82 if ~isfield(model,'data_const_in_time')
83  model.data_const_in_time = 0;
84 end,
85 
86 fl = cell(model.nt, 1);
87 % loop over fv-steps
88 if model.fv_impl_diff_weight ~= 0
89  % diffusive part is computed implicitly.
90  clear_all_caches;
91  [L_diff_I, const_diff_I] = model.implicit_operators_algorithm(model, detailed_data, []);
92  clear_all_caches;
93 end
94 
95 model.dt = model.T / model.nt;
96 
97 for t = 1:model.nt
98  model.t = (t-1)*model.dt;
99  model.tstep = t;
100  if model.verbose > 19
101  disp(['entered time-loop step ',num2str(t), ' for non linear evolution equation']);
102  elseif model.verbose > 9
103  fprintf('.');
104  end;
105 
106  [inc, fluxes] = model.L_E_local_ptr(model, detailed_data, U(:,t), []);
107  [refinc, dummy] = model.L_E_local_ptr(model, detailed_data, refU(:,t), []);
108 
109  if model.debug == 1
110  fl{t} = fluxes;
111  end
112  if all([model.fv_impl_conv_weight, model.fv_impl_diff_weight, model.fv_impl_react_weight] == [0, 0, 0])
113  % purely explicit scheme
114 % a(:,t+1) = a(:,t) - model.dt * ainc;
115  a(:,t+1) = a(:,t) - model.dt * inc;
116  else % scheme with implicit parts
117 
118  inc = inc + const_diff_I;
119 % inc = double(single(inc));
120  refinc = refinc + const_diff_I;
121 % refres(t) = (inc-refinc)' * W * (inc-refinc);
122 
123  ainc = RB' * W * inc;
124 % ainc = RBp' * W * inc + RBm' * W * inc;
125 % ainc = zeros(N,1);
126 
127 % ainc(1:Np) = RBp' * W * inc;
128 % incminus = inc - RBp * ainc(1:Np);
129 % ainc(Np+1:N) = RBm' * W * incminus;
130 
131  L_I = L_diff_I;
132  L_I = L_I * model.dt + speye(size(L_I));
133 % L_I = sparse(double(single(full(L_I))));
134  aL_I = RB' * W * L_I * RB;
135 % aL_Ip = RBp' * W * L_I * RBp + RBm' * W * L_I * RBm;
136 % aL_Im = RBm' * W * L_I * RBp + RBp' * W * L_I * RBm;
137 % aL_I = [aL_Ip, aL_Im; aL_Im, aL_Ip];
138  %aL_I = RBp' * W * L_I * RBp + RBp' * W * L_I * RBm + RBm' * W * L_I * RBp + RBm' * W * L_I * RBm;
139 % L_I = speye(size(L_diff_I));
140 
141  arhs = a(:,t) - model.dt * ainc; % + model.dt * L_diff_I * U(:,t);
142 % rhs = U(:,t) - model.dt * RB * ainc; % + model.dt * L_diff_I * U(:,t);
143 % rhsdiff = U(:,t) - model.dt * inc - refU(:,t) + model.dt * refinc;
144 % rhsres(t) = rhsdiff' * W * rhsdiff;
145  if size(RB,2) == 20
146 % keyboard;
147  end
148 % U(:,t+1) = rhs;
149 % U(:,t+1) = L_I \ rhs;
150 % atemp = aL_I \ [arhs; zeros(size(arhs))];
151 % a(:,t+1) = atemp(1:length(arhs)) + atemp(length(arhs)+1:end);
152  a(:,t+1) = aL_I \ arhs;
153 % [a(:,t+1), flag] = bicgstab(aL_I, arhs, 100*eps, 1000);
154 % a(:,t+1) = aL_I \ arhs;
155 % LIresi = RB * a(:,t+1) - (RB*RB')*W*U(:,t+1);
156 % a(:,t+1) = aL_I \ arhs;
157 % residuum = aL_I * a(:,t+1) - arhs;
158 % residuum = residuum' * residuum;
159 % disp(residuum);
160 % U(:,t+1) = L_I \ rhs;
161 % disp(condest(L_I));
162  U(:,t+1) = RB * a(:,t+1);
163 % residuum = L_I * U(:,t+1) - U(:,t) + model.dt * inc;
164 % res(t) = sqrt(residuum' * W * residuum);
165 % LIres(t) = sqrt(LIresi' * W * LIresi);
166 % Urefres(t+1) = sqrt((U(:,t+1)-refU(:,t+1))' * W * (U(:,t+1)-refU(:,t+1)));
167 % disp(['res: ', num2str(res(t))]);
168 % disp(['inc: ', num2str(refres(t))]);
169 % disp(['rhs: ', num2str(rhsres(t))]);
170 % disp(['LI: ', num2str(LIres(t))]);
171 % disp(['err: ', num2str(Urefres(t))]);
172 % pause
173 % U(U(:,t+1)<0,t+1);
174 % a(:,t+1) = RB' * W * U(:,t+1);
175 % U(:,t+1) = RB * a(:,t+1);
176  if flag>0
177  disp(['error in system solution, solver return flag = ', ...
178  num2str(flag)]);
179  keyboard;
180  end;
181  end
182 end
183 
184 % disp(['res: max=', num2str(max(res)), ' sum=', num2str(sum(res))]);
185 % disp(['inc: max=', num2str(max(refres)), ' sum=', num2str(sum(refres))]);
186 % disp(['rhs: max=', num2str(max(rhsres)), ' sum=', num2str(sum(rhsres))]);
187 % disp(['LI: max=', num2str(max(LIres)), ' sum=', num2str(sum(LIres))]);
188 
189 sim_data.U = U;
190 sim_data.a = a;
191 
192 get_mu(model)
193 
194 if model.verbose > 9
195  fprintf('\n');
196 end;
197 
198 %| \docupdate
function INC = fv_conv_explicit_space(U, NU_ind,gridbase grid, params)
fv_conv_explicit_space(U,NU_ind,grid,params) function applying an FV-space-discretization operator st...