rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
lin_evol_opt_detailed_simulation.m
1 function sim_data = lin_evol_opt_detailed_simulation(model,model_data)
2 %function sim_data = lin_evol_opt_detailed_simulation(model,model_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 (grid, params)
10 % example: init_values_cog
11 % operators_algorithm: name of function for computing the
12 % L_E,L_I,b-operators with arguments (grid, params)
13 % example operators_conv_diff
14 % data_const_in_time : if this optional field is 1, the time
15 % evolution is performed with constant operators,
16 % i.e. only the initial-time-operators are computed
17 % and used throughout the time simulation.
18 % compute_output_functional: flag indicating, whether output
19 % functional is to be computed
20 %
21 % return fields of sim_data:
22 % U : sequence of DOF vectors
23 % y : sequence of output functional values (if activated)
24 
25 % Markus Dihlmann 15.10.10
26 
27 if model.verbose >= 9
28  disp('entered detailed simulation ');
29 end;
30 
31 if isempty(model_data)
32  model_data = gen_model_data(model);
33 end;
34 
35 model.decomp_mode = 0; % == complete;
36 model.t = 0;
37 
38 if isfield(model,'save_time_indices')
39  save_time_index = zeros(1,model.nt+1);
40  save_time_index(model.save_time_indices(:)+1) = 1;
41  save_time_indices = find(save_time_index==1)-1;
42 else
43  save_time_index = ones(1,model.nt+1);
44  save_time_indices = 1:(model.nt+1);
45 end;
46 
47 % initial values by midpoint evaluation
48 Ut = model.init_values_algorithm(model,model_data);
49 
50 % preallocate U
51 U = zeros(length(Ut),length(save_time_indices));
52 time_indices = zeros(1,length(save_time_indices));
53 time = zeros(1,length(save_time_indices));
54 
55 model.dt = model.T/model.nt;
56 operators_required = 1;
57 %if ~isfield(model,'data_const_in_time')
58 % model.data_const_in_time = 0;
59 %end,
60 
61 % get operator components
62 if model.affinely_decomposed
63  old_decomp_mode = model.decomp_mode;
64  model.decomp_mode = 1;
65  [L_I_comp, L_E_comp, b_comp] = model.operators_ptr(model, model_data);
66  model.decomp_mode = old_decomp_mode;
67 end;
68 
69 t_column = 1; % next column index to be filled in output
70 t_ind = 0; % t_ind between 0 and nt
71 t = 0; % absolute time between 0 and T
72 
73 % store init data
74 if save_time_index(t_ind+1)
75  U(:,t_column) = Ut;
76  time_indices(t_column) = t_ind;
77  time(t_column) = t;
78  t_column = t_column + 1;
79 end;
80 
81 if ~isfield(model,'compute_output_functional')
82  model.compute_output_functional = 0;
83 end,
84 
85 %model.plot(U0,model_data.grid,params);
86 
87 % loop over fv-steps
88 for t_ind = 1:model.nt
89  t = (t_ind-1)*model.dt;
90  if model.verbose >= 10
91  disp(['entered time-loop step ',num2str(t_ind)]);
92  end;
93  if model.verbose == 9
94  fprintf('.');
95  end;
96  % get matrices and bias-vector
97 
98  if operators_required
99 
100  model.t = t;
101 
102  % new assembly in every iteration
103  if ~model.affinely_decomposed
104  [L_I, L_E, b] = model.operators_ptr(model, model_data);
105  else
106  % or simple assembly based on affine parameter decomposition
107  % => turns out to be slower for few components
108 
109  % test affine decomposition
110  if model.debug
111  disp('test affine decomposition of operators')
112  test_affine_decomp(model.operators_ptr,3,1,model,model_data);
113  disp('OK')
114  end;
115  model.decomp_mode = 2;
116  [L_I_coeff, L_E_coeff, b_coeff] = model.operators_ptr(model, ...
117  model_data);
118  model.decomp_mode = old_decomp_mode;
119  L_I = lincomb_sequence(L_I_comp, L_I_coeff);
120  L_E = lincomb_sequence(L_E_comp, L_E_coeff);
121  b = lincomb_sequence(b_comp, b_coeff);
122  end;
123 
124  if model.data_const_in_time
125  operators_required = 0;
126  end;
127 
128  end;
129 
130  %rhs = L_E * Ut + b;
131  rhs = (speye(size(L_E)) + model.dt*L_E) * Ut + model.dt*b;
132 
133 
134  if isempty(find(L_I, 1))%isequal(L_I, speye(size(L_I)))
135  Ut = rhs;
136  else
137  % solve linear system
138  % disp('check symmetry and choose solver accordingly!');
139  % keyboard;
140  % nonsymmetric solvers:
141  % [U(:,t+1), flag] = bicgstab(L_I,rhs,[],1000);
142  % [U(:,t+1), flag] = cgs(L_I,rhs,[],1000);
143  %
144  % symmetric solver, non pd:
145  % omit symmlq:
146  % see bug_symmlq.mat for a very strange bug: cannot solve identity system!
147  % reported to matlab central, but no solution up to now.
148  % [U(:,t+1), flag] = symmlq(L_I,rhs,[],1000);
149  %
150  % [U(:,t+1), flag] = minres(L_I,rhs,[],1000);
151  % symmetric solver, pd:
152  %[U(:,t+1), flag] = pcg(L_I,rhs,[],1000);
153  % bicgstab works also quite well:
154  %[U(:,t+1), flag] = bicgstab(L_I,rhs,[],1000);
155  Ut = (speye(size(L_I))-model.dt*L_I)\rhs;%Ut + model.dt*(L_I \ rhs);
156 
157  % if flag>0
158  % disp(['error in system solution, solver return flag = ', ...
159  % num2str(flag)]);
160  % keyboard;
161  % end;
162 
163  end;
164 
165  if save_time_index(t_ind+1)
166  U(:,t_column) = Ut;
167  time_indices(t_column) = t_ind;
168  time(t_column) = t;
169  t_column = t_column + 1;
170  end;
171 
172 end;
173 
174 if model.verbose == 9
175  fprintf('\n');
176 end;
177 
178 sim_data.U = U;
179 sim_data.time = time;
180 sim_data.time_indices = time_indices;
181 
182 if model.compute_output_functional
183  % get operators
184  v = model.operators_output(model,model_data);
185  sim_data.y = (v(:)') * U;
186 end;
187 
188 %| \docupdate
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
Definition: verbose.m:17