1 function sim_data = lin_evol_opt_detailed_simulation(model,model_data)
2 %
function sim_data = lin_evol_opt_detailed_simulation(model,model_data)
4 % required fields of model:
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
21 %
return fields of sim_data:
22 % U : sequence of DOF vectors
23 % y : sequence of output functional values (
if activated)
25 % Markus Dihlmann 15.10.10
28 disp(
'entered detailed simulation ');
31 if isempty(model_data)
32 model_data = gen_model_data(model);
35 model.decomp_mode = 0; % == complete;
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;
43 save_time_index = ones(1,model.nt+1);
44 save_time_indices = 1:(model.nt+1);
47 % initial values by midpoint evaluation
48 Ut = model.init_values_algorithm(model,model_data);
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));
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;
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;
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
74 if save_time_index(t_ind+1)
76 time_indices(t_column) = t_ind;
78 t_column = t_column + 1;
81 if ~isfield(model,'compute_output_functional')
82 model.compute_output_functional = 0;
85 %model.plot(U0,model_data.grid,params);
88 for t_ind = 1:model.nt
89 t = (t_ind-1)*model.dt;
91 disp(['entered time-loop step ',num2str(t_ind)]);
96 % get matrices and bias-vector
102 % new assembly in every iteration
103 if ~model.affinely_decomposed
104 [L_I, L_E, b] = model.operators_ptr(model, model_data);
106 % or simple assembly based on affine parameter decomposition
107 % => turns out to be slower for few components
109 % test affine decomposition
111 disp('test affine decomposition of operators')
112 test_affine_decomp(model.operators_ptr,3,1,model,model_data);
115 model.decomp_mode = 2;
116 [L_I_coeff, L_E_coeff, b_coeff] = model.operators_ptr(model, ...
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);
124 if model.data_const_in_time
125 operators_required = 0;
131 rhs = (speye(size(L_E)) + model.dt*L_E) * Ut + model.dt*b;
134 if isempty(find(L_I, 1))%isequal(L_I, speye(size(L_I)))
137 % solve linear system
138 % disp('check symmetry and choose solver accordingly!');
140 % nonsymmetric solvers:
141 % [U(:,t+1), flag] = bicgstab(L_I,rhs,[],1000);
142 % [U(:,t+1), flag] = cgs(L_I,rhs,[],1000);
144 % symmetric solver, non pd:
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);
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);
158 % disp(['error in system solution, solver return flag = ', ...
165 if save_time_index(t_ind+1)
167 time_indices(t_column) = t_ind;
169 t_column = t_column + 1;
179 sim_data.time = time;
180 sim_data.time_indices = time_indices;
182 if model.compute_output_functional
184 v = model.operators_output(model,model_data);
185 sim_data.y = (v(:)') * U;
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...