4 %
function demonstrating RB approach
for linear dynamical systems
5 % according to MATHMOD 2009 paper
7 % Method also demonstrates
new call of all reduced schemes:
9 % model_data = gen_model_data(model);
11 % sim_data = detailed_simulation(model,model_data);
12 % produces some structure with suitable fields, e.g DOF vector
13 % output sequence, reference to output files, simulation
14 % information, etc. Last parameter is model-struct, possibly
15 % precedent parameters, e.g. grid, etc.
16 % so not only DOF-vector is the return argument, but a structure
17 % detailed_data = gen_detailed_data(model,model_data);
18 % produce high-dimensional data, e.g. reduced basis, etc.
20 % reduced_data = gen_reduced_data(model,detailed_data);
21 % produce low-dimensional data, e.g. gram matrices between
22 % reduced basis vectors, subgrid extraction, etc.
23 % mu is not known (so is the previous offline-data or
24 % combination of offline and online data)
25 % rb_sim_data = rb_simulation(model,reduced_data)
26 % perform reduced simulation, i.e. mu known
27 % produces some structure with suitable fields, e.g DOF vector,
30 % Further routines "extending" datasets, e.g.:
31 % rb_sim_data = rb_reconstruction(rb_sim_data,model)
32 % reduced_data = extract_reduced_data_subset(reduced_data,model)
33 % detailed_sim_data = rb_basis_generation(detailed_data,model)
35 % Bernard Haasdonk 2.4.2009
37 %step = 1 % simulation and visualization of dynamical system
38 %step = 2 % reduced simulation and visualization of approximation
39 step =3 % detailed and reduced simulation and visualization of
43 model = lin_ds_model_default;
45 model.data_const_in_time = 1;
48 model.affinely_decomposed = 1;
49 model.A_function_ptr = @A_func;
50 % ratio of first to second ellipses axes
51 %model.A_axes_ratio = 2;
52 model.A_axes_ratio = 2;
53 model.B_function_ptr = @B_func;
54 model.C_function_ptr = @C_func;
55 model.D_function_ptr = @D_func;
56 model.x0_function_ptr = @x0_func;
57 % shift of x0 in third coordinate
59 model.u_function_ptr = @(model) 0.1; % define u constant
60 %model.u_function_ptr = @(model) sin(4*model.t);
61 %model.u_function_ptr = @(model) 0; % define u constant 0
62 %model.u_function_ptr = @(model) model.t; % define u = 1 * t
63 model.G_matrix_function_ptr = @(model,model_data) eye(3,3);
64 % the following lead to both larger C1 and C2!!!
65 %model.G_matrix_function_ptr = @(model) diag([2,0.5,1]);
66 %model.G_matrix_function_ptr = @(model) diag([0.5,2,1]);
68 % dummy parametrization:, parameter is not used...
69 model.mu_names = {
'A_axes_ratio',
'x0_shift'};
70 %model.mu_ranges = {[0.5,2],[0,1]};
71 model.mu_ranges = {[0.5,0.5],[1,1]};
72 model.affinely_decomposed = 1;
74 %
set function pointers to main model methods
75 %model.gen_model_data = @lin_ds_gen_model_data;
76 %model.detailed_simulation = @lin_ds_detailed_simulation;
77 %model.gen_detailed_data = @lin_ds_gen_detailed_data;
78 %model.gen_reduced_data = @lin_ds_gen_reduced_data;
79 %model.rb_simulation = @lin_ds_rb_simulation;
80 %model.plot_sim_data = @lin_ds_plot_sim_data;
81 %model.rb_reconstruction = @lin_ds_rb_reconstruction;
82 % determin model data, i.e. matrix components, matrix G
84 model_data = gen_model_data(model); % matrix components
86 % be sure to determine correct constants once,
if anything in the
87 % problem setting has changed!!
89 % the following only needs to be performed,
if the model are changed.
91 disp(
'Estimating continuity bound constants')
92 model.estimate_lin_ds_nmu = 10;
93 model.estimate_lin_ds_nX = 100;
94 model.estimate_lin_ds_nt = 100;
96 [C1,C2] = lin_ds_estimate_bound_constants(model,model_data)
97 model.state_bound_constant_C1 = C1;
98 model.output_bound_constant_C2 = C2;
100 model.state_bound_constant_C1 = 2;
101 model.output_bound_constant_C2 = sqrt(3);
103 model.error_estimation = 1;
104 model_data.RB = eye(3,2);
105 model.RB_generation_mode = 'from_detailed_data';
108 case 1 % simulation and visualization
109 % later: sim_data = detailed_simulation(model);
111 sim_data = detailed_simulation(model,model_data);
115 case 2 % reduced simulation
116 %define reduced basis of first two coordinates (i.e. error only
121 % produce high-dimensional data, e.g. reduced basis, etc.
123 detailed_data = gen_detailed_data(model,model_data);
125 % produce low-dimensional data, e.g. gram matrices between
126 % reduced basis vectors, subgrid extraction, etc.
127 % mu is not known (should comprise previous offline and online steps)
129 reduced_data = gen_reduced_data(model,detailed_data);
130 model.N = reduced_data.N;
132 % rb_sim_data = rb_simulation(reduced_data,model)
133 % perform reduced simulation, i.e. mu known
134 % produces some structure with suitable fields, e.g DOF vector
136 rb_sim_data = rb_simulation(model,reduced_data);
138 rb_sim_data = rb_reconstruction(model,detailed_data,rb_sim_data);
140 model.plot_title = 'reduced trajectory';
141 %model.plot_indices = 1:3; => default
145 case 3 % detailed and reduced simulation
147 %model.u_function_ptr = @(model) 0; % define u constant 0
148 % => leads to error 0 :-) if x0_shift = 0
150 %model.u_function_ptr = @(model) 0.1; % define u constant
151 %=> error linearly increasing
152 model.u_function_ptr = @(model) 0.3*sin(2*model.t)+0.002*model.t;
155 sim_data = detailed_simulation(model,model_data);
156 detailed_data = gen_detailed_data(model,model_data);
157 model.enable_error_estimator=1;
158 reduced_data = gen_reduced_data(model,detailed_data);
159 model.N = reduced_data.N;
160 rb_sim_data = rb_simulation(model,reduced_data);
161 rb_sim_data = rb_reconstruction(model,detailed_data, ...
164 figure, plot3(sim_data.X(1,:),...
170 plot3(rb_sim_data.X(1,:),...
171 rb_sim_data.X(2,:),...
172 rb_sim_data.X(3,:),...
175 title('exact and reduced trajectories');
176 legend({
'exact',
'reduced'});
179 error.X = sim_data.X-rb_sim_data.X;
180 error.Y = sim_data.Y-rb_sim_data.Y;
182 err = sqrt(sum((detailed_data.G * error.X).*error.X,1));
183 figure, plot([rb_sim_data.DeltaX(:),err(:)]),
184 Ylim =
get(gca,
'Ylim');
185 set(gca,
'Ylim',[0,max(Ylim)]);
186 title(
'rb state error and estimator');
187 legend({
'estimator',
'error'});
189 figure, plot([rb_sim_data.DeltaY(:),abs(error.Y(:))]);
190 title(
'rb output error and estimator');
191 Ylim =
get(gca,
'Ylim');
192 set(gca,
'Ylim',[0,max(Ylim)]);
193 legend({
'estimator',
'error'});
198 error(
'step unknown');
201 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 % functions defining the dynamical system and input/initial data
203 function A = A_func(model,model_data);
204 A = eval_affine_decomp(@A_components,@A_coefficients,...
207 % A_parameter: ratio of first to second axis of
208 function Acomp = A_components(model,model_data)
209 %Acomp = {[0 -0.25 0; 4 0 0 ; 0 0 0 ]};
210 %Acomp = {[0 -1 0; 1 0 0 ; 0 0 0 ]};
211 %Acomp = {[-0.01 0 0; 0 -0.9 0 ; 0 0 -0.001 ]};
212 Acomp = {[0 1 0; 0 0 0 ; 0 0 0 ],...
213 [0 0 0; 1 0 0 ; 0 0 0 ] ...
216 function Acoeff = A_coefficients(model)
217 Acoeff = [-model.A_axes_ratio, 1/model.A_axes_ratio];
219 function B = B_func(model,model_data)
220 B = eval_affine_decomp(@B_components,@B_coefficients,model,model_data);
222 function Bcomp = B_components(model,model_data)
225 function Bcoeff = B_coefficients(model)
228 function C = C_func(model,model_data)
229 C = eval_affine_decomp(@C_components,@C_coefficients,model,model_data);
231 function Ccomp = C_components(model,model_data)
233 %Ccomp = {[2,0,1],[0,2,1]};
235 function Ccoeff = C_coefficients(model)
237 %Ccoeff = [model.C_weight,1-model.C_weight];
239 function D = D_func(model,model_data)
240 D = 0; % no decomposition required for scheme
242 function x0 = x0_func(model,model_data)
243 x0 = eval_affine_decomp(@x0_components,@x0_coefficients,model,model_data);
245 function x0comp = x0_components(model,model_data)
246 x0comp = {[1;0;0],[1;0;1]};
248 function x0coeff = x0_coefficients(model)
249 x0coeff = [1-model.x0_shift,model.x0_shift];