rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
lin_evol_rb_operators.m
1 function [LL_I, LL_E, bb, K_II, K_IE, K_EE, m_I, m_E, m] = ...
2  lin_evol_rb_operators(model, detailed_data)
3 %function [LL_I, LL_E, bb, K_II, K_IE, K_EE, m_I, m_E, m] = ...
4 % lin_evol_rb_operators(model, [detailed_data])
5 %
6 % function computing the time-dependent reduced basis operators and
7 % vectors.
8 %
9 %Function supports affine decomposition, i.e. different operation modes
10 % guided by optional field decomp_mode in params. See also the
11 % contents.txt for general explanation
12 %
13 % Required fields of model
14 % operators_algorithm: name of function for computing the
15 % L_E,L_I,b-operators with arguments (grid, params)
16 % example fv_operators_implicit
17 %
18 %
19 % Optional fields of model:
20 % mu_names : names of fields to be regarded as parameters in vector mu
21 % decomp_mode: operation mode of the function
22 % -0= 'complete' (default): no parameter dependence or decomposition is
23 % performed. output is as described above.
24 % -1= 'components': For each output argument a cell array of output
25 % arguments is returned representing the q-th component
26 % independent of the parameters given in mu_names
27 % -2= 'coefficients': For each output argument a cell array of output
28 % arguments is returned representing the q-th coefficient
29 % dependent of the parameters given in mu_names
30 %
31 % In 'coefficients' mode the detailed data is empty.
32 
33 % Bernard Haasdonk 23.7.2006
34 
35 % determine affine_decomposition_mode as integer
36 decomp_mode = model.decomp_mode;
37 
38 
39 if decomp_mode == 0 % complete: simple projection on RB
40 
41  %eval('u0 = ',params.init_value_algorithm,'(grid,params)']);
42  [L_I, L_E, b] = model.operators_ptr(model,detailed_data);
43 
44  % apply all operator contributions to RB:
45  L_E_RB = L_E * detailed_data.RB;
46  L_I_RB = L_I * detailed_data.RB;
47 
48  % fill output quantities
49  % LL_I : matrix
50  A = detailed_data.W;
51 
52  LL_I = detailed_data.RB' * A * L_I_RB;
53 
54  % LL_E : matrix
55  LL_E = detailed_data.RB' * A * L_E_RB;
56 
57  % bb : vector
58  bb = detailed_data.RB' * A * b;
59 
60  % K_II : matrix
61  K_II = L_I_RB' * A * L_I_RB;
62 
63  % K_IE : matrix
64  K_IE = L_I_RB' * A * L_E_RB;
65 
66  % K_EE : matrice
67  K_EE = L_E_RB' * A * L_E_RB;
68 
69  % m_I : vector
70  m_I = L_I_RB' * A * b;
71 
72  % m_E : vector
73  m_E = L_E_RB' * A * b;
74 
75  % m : scalar
76  m = b' * A * b;
77 
78 elseif decomp_mode == 1
79 
80  %eval('u0 = ',params.init_value_algorithm,'(grid,params)']);
81  [L_I, L_E, b] = model.operators_ptr(model, detailed_data);
82 
83  Q_L_I = size(L_I,1);
84  Q_L_E = size(L_E,1);
85  Q_b = length(b);
86 
87  Nmax = size(detailed_data.RB,2);
88  H = size(detailed_data.RB,1);
89  A = detailed_data.W;
90 
91  % init output quantities
92  % scalars:
93  m = cell(Q_b*Q_b,1);
94  m(:) = {zeros(1,1)};
95  % vectors:
96  m_I = cell(Q_L_I*Q_b,1);
97  m_I(:) = {zeros(Nmax,1)};
98  m_E = cell(Q_L_E*Q_b,1);
99  m_E(:) = {zeros(Nmax,1)};
100  bb = cell(Q_b,1);
101  bb(:) = {zeros(Nmax,1)};
102  % matrices:
103  K_II = cell(Q_L_I*Q_L_I,1);
104  K_II(:) = {zeros(Nmax,Nmax)};
105  K_IE = cell(Q_L_I*Q_L_E,1);
106  K_IE(:) = {zeros(Nmax,Nmax)};
107  K_EE = cell(Q_L_E*Q_L_E,1);
108  K_EE(:) = {zeros(Nmax,Nmax)};
109  LL_I = cell(Q_L_I,1);
110  LL_I(:) = {zeros(Nmax,Nmax)};
111  LL_E = cell(Q_L_E,1);
112  LL_E(:) = {zeros(Nmax,Nmax)};
113 
114  % apply all operator contributions to RB:
115  L_E_RB = cell(Q_L_E,1);
116  L_E_RB(:) = {zeros(H,Nmax)};
117  L_I_RB = cell(Q_L_I,1);
118  L_I_RB(:) = {zeros(H,Nmax)};
119  for q=1:Q_L_E
120  L_E_RB{q}(:,:)= L_E{q} * detailed_data.RB;
121  end;
122  for q=1:Q_L_I
123  L_I_RB{q}(:,:)= L_I{q} * detailed_data.RB;
124  end;
125 
126  % fill output quantities
127  % LL_I : matrices
128  for q = 1:Q_L_I;
129  LL_I{q} = detailed_data.RB' * A * L_I_RB{q};
130  end;
131 
132  % LL_E : matrices
133  for q = 1:Q_L_E;
134  LL_E{q} = detailed_data.RB' * A * L_E_RB{q};
135  end;
136 
137  % bb : vectors
138  for q = 1:Q_b;
139  bb{q} = detailed_data.RB' * A * b{q};
140  end;
141 
142  % K_II : matrices
143  for q1 = 1:Q_L_I;
144  for q2 = 1:Q_L_I;
145  K_II{ (q1-1)*Q_L_I + q2}(:,:) = ...
146  L_I_RB{q1}' * A * L_I_RB{q2};
147  end;
148  end;
149 
150  % K_IE : time sequence of matrices
151  % K_IE{1} = Gram matrix of L_I_RB{1} and L_E_RB{1}
152  % K_IE{2} = Gram matrix of L_I_RB{1} and L_E_RB{2}
153  % so L_E is "inner loop". This must fit to the sigma-ordering
154  for q1 = 1:Q_L_I;
155  for q2 = 1:Q_L_E;
156  K_IE{ (q1-1)*Q_L_E + q2} = ...
157  L_I_RB{q1}' * A * L_E_RB{q2};
158  end;
159  end;
160 
161  % K_EE : matrices
162  for q1 = 1:Q_L_E;
163  for q2 = 1:Q_L_E;
164  K_EE{ (q1-1)*Q_L_E + q2} = ...
165  L_E_RB{q1}' * A * L_E_RB{q2};
166  end;
167  end;
168 
169  % m_I : vectors
170  for q1 = 1:Q_L_I;
171  for q2 = 1:Q_b;
172  m_I{ (q1-1)*Q_b + q2} = ...
173  L_I_RB{q1}' * A * b{q2};
174  end;
175  end;
176 
177  % m_E : vectors
178  for q1 = 1:Q_L_E;
179  for q2 = 1:Q_b;
180  m_E{ (q1-1)*Q_b + q2} = ...
181  L_E_RB{q1}' * A * b{q2};
182  end;
183  end;
184 
185  % m : scalars
186  for q1 = 1:Q_b;
187  for q2 = 1:Q_b;
188  m{ (q1-1)*Q_b + q2} = ...
189  b{q1}' * A * b{q2};
190  end;
191  end;
192 
193 else % decomp_mode== 2 -> coefficients
194  [L_I, L_E, b] = model.operators_ptr(model,[]);
195 
196  Q_L_I = length(L_I(:));
197  Q_L_E = length(L_E(:));
198  Q_b = length(b(:));
199 
200  % rb-operator coefficients can simply be forwarded
201  LL_E = L_E;
202  LL_I = L_I;
203  bb = b;
204 
205  % pairs: products of sigmas:
206  K_II = repmatrows(L_I(:), Q_L_I) .* repmat(L_I(:), Q_L_I, 1);
207  K_IE = repmatrows(L_I(:), Q_L_E) .* repmat(L_E(:), Q_L_I, 1);
208  K_EE = repmatrows(L_E(:), Q_L_E) .* repmat(L_E(:), Q_L_E, 1);
209  m_I = repmatrows(L_I(:), Q_b) .* repmat(b(:) , Q_L_I, 1);
210  m_E = repmatrows(L_E(:), Q_b) .* repmat(b(:) , Q_L_E, 1);
211  m = repmatrows(b(:) , Q_b) .* repmat(b(:) , Q_b , 1);
212 
213 end;
214