rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
lin_stat_gen_reduced_data.m
1 function reduced_data = lin_stat_gen_reduced_data(model,detailed_data)
2 %function reduced_data = lin_stat_gen_reduced_data(model,detailed_data)
3 %
4 % function computing reduced data.
5 
6 % B. Haasdonk 22.2.2011
7 
8 reduced_data = [];
9 
10 %Q_A = length(detailed_data.A_comp);
11 Q_A = size(detailed_data.A_comp,2);
12 reduced_data.Q_A = Q_A;
13 %Q_f = length(detailed_data.f_comp);
14 Q_f = size(detailed_data.f_comp,2);
15 H = size(detailed_data.f_comp,1); % number of DOFs
16 reduced_data.Q_f = Q_f;
17 N = model.get_rb_size(model,detailed_data);
18 reduced_data.N = N;
19 
20 % for error estimation:
21 Q_r = Q_f + N * Q_A;
22 K_v_r = zeros(H,Q_r);
23 K_v_r(:,1:Q_f) = detailed_data.f_comp;
24 
25 % store reduced system matrix components as column vector
26 reduced_data.AN_comp = zeros(N^2,Q_A);
27 %Aq_times_RB = zeros(H,Q_A);
28 for q = 1:Q_A
29  % reconstruct sparse system matrix from coeffs+sparsity-pattern:
30  Aq_vec = detailed_data.A_comp(:,q);
31  i = detailed_data.A_row_indices;
32  j = detailed_data.A_column_indices;
33  siz = detailed_data.A_size;
34  Aq = sparse(i,j,Aq_vec, siz(1), siz(2));
35  AqRB = Aq*detailed_data.RB;
36  AN_comp_q = detailed_data.RB'*AqRB;
37  reduced_data.AN_comp(:,q) = AN_comp_q(:);
38  col_ind = Q_f+(q-1)*N+1;
39  K_v_r(:,(col_ind):(col_ind+N-1)) = AqRB;
40 end;
41 
42 reduced_data.fN_comp = zeros(N,Q_f);
43 for q = 1:Q_f
44  reduced_data.fN_comp(:,q) = ...
45  detailed_data.RB' * detailed_data.f_comp(:,q);
46 end;
47 
48 if model.compute_output_functional
49 % l_comp = ...
50 % model.operators_output(model,detailed_data);
51  Q_l = length(detailed_data.l_comp);
52  reduced_data.lN_comp = detailed_data.RB' * detailed_data.l_comp;
53 end;
54 
55 K = model.get_inner_product_matrix(detailed_data);
56 v_r = K \ K_v_r;
57 G = v_r' * K_v_r;
58 
59 %%% If we implement improvement of Stephan Rave:
60 %v = VecMat.gram_schmidt_reiterate(v_r, K, 1e-12);
61 %G = v' * K_v_r;
62 %%% then also in rb_simulation a change must be applied:
63 % %without orthonormalization:
64 
65 reduced_data.G = G;
66 
67 % plus error estimation quantities
68 % G = (v_r^q, v_r^q) = v_r^q' * K * v_r^q
69 % with {v_r^q}_q = (v_f^q, v_a^q'n)_{q'n}
70 % G = [Gff, Gfa; Gfa', Gaa];
71 %
72 % (v_f^q,v_f^q') = v_f^q' * K * v_f^q
73 % matrices of coefficient vectors of Riesz-representers:
74 % K * v_f^q = f^q (coefficient vector equations)
75 
76 % old:
77 %v_f = zeros(size(detailed_data.RB,1),Q_f);
78 %K_v_f = zeros(size(detailed_data.RB,1),Q_f);
79 %for q = 1:Q_f
80 % K_v_f(:,q) = f_comp{q};
81 % v_f(:,q) = K \ f_comp{q};
82 %end;
83 %v_a = cell(N,1);
84 %K_v_a = cell(N,1);
85 %for n = 1:N
86 % K_v_a{n} = zeros(size(K,1),Q_A);
87 % v_a{n} = zeros(size(K,1),Q_A);
88 % for q = 1:Q_A
89 % K_v_a{n}(:,q) = (A_comp{q}*detailed_data.RB(:,n));
90 % v_a{n}(:,q) = K \ K_v_a{n}(:,q);
91 % end;
92 %end;
93 % compute matrix G components = [G_ff, G_fa{n}; G_fa{n}', G_aa{n}];
94 %reduced_data.Gff = v_f' * K_v_f;
95 %reduced_data.Gfa = cell(1,N);
96 %for n = 1:N
97 % reduced_data.Gfa{n} = v_f' * K_v_a{n};
98 %end;
99 %reduced_data.Gaa = cell(N,N);
100 %for n1 = 1:N
101 % for n2 = 1:N
102 % reduced_data.Gaa{n1,n2} = v_a{n1}' * K_v_a{n2};
103 % end;
104 %end;
105 % finally assemble G = [G_ff, G_fa{n}; G_fa{n}', G_aa{n}];
106 %Q_r = Q_f + N * Q_A;
107 %G = zeros(N,N);
108 %G(1:Q_f,1:Q_f) = reduced_data.Gff;
109 %for n = 1:N
110 % G(1:Q_f,Q_f+(n-1)*Q_A +(1:Q_A)) = ...
111 % reduced_data.Gfa{n};
112 % G(Q_f+(n-1)*Q_A +(1:Q_A),1:Q_f) = ...
113 % reduced_data.Gfa{n}';
114 %end;
115 %for n1 = 1:N
116 % for n2 = 1:N
117 % G(Q_f+(n1-1)*Q_A+(1:Q_A),Q_f+(n2-1)*Q_A +(1:Q_A)) = ...
118 % reduced_data.Gaa{n1,n2};
119 % end;
120 %end;
121 %reduced_data.G = G;
122 
123 if model.use_scm % when scm shall be used generate offline data here
124  if ~isfield(detailed_data, 'A_comp')
125  error('The components are required for the SCM to work.');
126  % detailed_data.A_comp = A_comp; % the components are required for the SCM to work
127  end
128  % Note by Dominik Garmatter 20.09 2012 regarding a problem with this
129  % implementation:
130  % It makes sense to compute the scm_offline_data in gen_reduced_data, but
131  % when generating a reduced basis there might be a call of gen_reduced_data
132  % in every step of the basis generation. This will result in multiple
133  % generations of scm_offline_data but scm_offline_data is not dependant on
134  % the reduced basis and therefore it would be sufficient to compute it only
135  % once. But there is no real solution to this problem yet, because one
136  % might need the SCM while basis generation (i.e. to compute the error
137  % indicators). Otherwise one could disable the SCM while basis generation
138  % (model.use_scm = 0) and enable it after basis generation.
139  reduced_data.scm_offline_data = scm_offline(model, detailed_data);
140 end