1 %step = 1; % single detailed simulation and plot
2 %step = 2; % affine decomposition of FEM-matrix and RHS
3 step = 3; % reduced problem
9 params.B1 = 4; params.B2 = 3;
12 model = model.set_mu(model,ones(params.B1*params.B2-1,1)); % 1 in each block
13 % model = model.set_mu(model,rand(size(model.get_mu(model)))+0.1); % 1 in each block
15 % the following is parameter-independent
16 model_data = gen_model_data(model);
18 % the following is parameter-dependent
20 sim_data = detailed_simulation(model,model_data);
22 if model.plot_solution == 1
29 % params.B1 = 2; params.B2 = 2;
31 % model_data = gen_model_data(model);
32 % mu = model.get_mu(model);
34 % model = model.set_mu(model,mu);
35 % sim_data = detailed_simulation(model,model_data);
49 model.plot_solution = 0;
51 % the following is parameter-independent
52 model_data = gen_model_data(model);
54 %number of simulations (NOS)
56 M = rand_uniform(NOS,model.mu_ranges);
60 % the following is parameter-dependent
63 % random parameters in model.mu_ranges!!
64 model = model.set_mu(model,M(:,k));
65 %model.mus = model.mus';
66 sim_data = detailed_simulation(model,model_data);
68 if model.plot_solution == 1
73 %U(:,k)=sim_data.u_no_stiff_springs;
77 % Orthonormierung von U bzgl. H1 Skalarprodukt
78 % .. Skalarprodukt-Matrix: G_ij = int_Omega grad(phi_i(x)) grad(phi_j(x))
80 % RB = PCA_fixspace(U,[],G);
93 % Amat = sim_data.A_matlab;
94 % Fmat = sim_data.F_matlab;
95 % Bmat = sim_data.B_matlab;
99 u_tmp = sim_data.u_tmp;
101 % K = sim_data.K_matlab;
102 % M = sim_data.M_matlab;
103 % F = sim_data.F_matlab;
106 % Q = sim_data.Q_matlab;
107 % G = sim_data.G_matlab;
109 % H = sim_data.H_matlab;
110 % B = sim_data.B_matlab;
112 diri_values=find(p(2,:)==1);
115 ZERO=sparse(length(p), length(p));
123 % check: f(x,y) = x*(1-x)*y*(1-y)
124 % H10_norm per hand und DOF-Vektor F durch Punktauswertungen
125 % f = @(x,y) x.*(1-x).*y.*(1-y);
126 % F = f(p(1,:),p(2,:));
127 % H10_norm = F
'* G * F;
128 % should be identical to hand-calculation
130 RB = PCA_fixspace(U,[],G);
132 % % % => Ergebnis RB' * G * RB = eye;
135 % check=RB
'*G*RB; %should be eye(NOS);
136 % % trace_check=trace(check); %should be NOS
137 % % matrix_check=sum(sum(check)); %should be NOS
138 % err = max(max(abs(check - eye(NOS))));
143 % disp('RB problem
');
147 check=RBcheck(RB,G,NOS);
154 detailed_data.RB = RB;
156 % PARAMETERUNABHAENGIG
158 % % fem-systemmatrix: komponenten zerlegung, spaerliche Matrizen
161 % % glob = dreiecksmittelpunkte
162 glob = get_triangle_midpoints(p,t);
163 % % {c1...c_Qc} = model.diffusivity_components_ptr(glob,model);
164 [C,Cmatrix]=model.diffusivity_components_ptr(glob,model);
166 % % K1 = assema(c1,...)
168 % % K_QK = assema(c_QK,...)
170 % %K_components = { K1, ... KQK};
173 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
174 % %%%adding spring constant
176 % d1=full(diag(H*H'));
178 % d1(l)=Inf*ones(size(l));
179 % id1=diag(sparse(1./d1));
180 % % Form normal equations
184 % % Incorporate constraints (Dirichlet conditions)
185 % % Find a positive spring constant of suitable size.
188 % tscale=1/sqrt(np); % Triangle size
189 % kscale=max(max(abs(K)));
190 % mscale=max(max(abs(M)));
191 % qscale=max(max(abs(Q)));
195 % spc=max(max(kscale*tscale^2,mscale),qscale*tscale)/(hscale*tscale^3);
201 % [K,dummy1,dummy2]=assema(p,t,sim_data.c,a,f);
202 % => K mit loescher der Dirichlet Zeilen und Spalten
206 K_comp=cell(1,size(C,2));
209 [K,dummy1,dummy2]=assema(p,t,C{1,i}
',a,f);
218 K_comp{1,i}=K1; %vorher K
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 % A_fem_components = {K_compo, M_components, Q_components};
226 % later: M_comp and Q_comp for general elliptic problems
227 %thermalblock case M,Q are zero
232 A_comp = [Zero_comp,K_comp, Q_comp, M_comp];
235 % % fem-rechte Seite: komponenten zerlegung
237 %G_i = int_boundary g phi_i
239 differentneumannvalues=1; %neumann value 1 at the bottom
240 g_comp=cell(1,length(differentneumannvalues));
241 for i=1:differentneumannvalues
242 [dummy1,G,dummy2,dummy3]=assemb(BM,p,e); %BM depends on differentneumannvalues
246 g_comp{1,i}=M1; %M1 war vorher G
250 %[G]=model.neumann_components_ptr(glob,model);
252 % G wie vorher, nur in cell array packen:
256 %thermalblock f is zero
259 B_comp = [G_comp, F_comp];
261 % reduced_data darf keine hochdimensionalen Daten enthalten
262 detailed_data.A_components = A_comp;
263 detailed_data.B_components = B_comp;
265 % % check if affine decomposition works:
267 % set mu arbitrary and multiply, different:
268 % model = model.set_mu(...)
269 % sim_data = detailed_simulation(...);
273 theta_A = model.diffusivity_coefficients_ptr([],model);
274 theta_A = [theta_A,1];
276 theta_A = [1,theta_A];
278 theta_G = model.neumann_value_coefficients([],model);
280 theta_B = [theta_G, theta_F];
282 % A = lincomb_sequence(A_comp, theta_A(mu));
283 A = lincomb_sequence(A_comp, theta_A);
286 B = lincomb_sequence(B_comp, theta_B);
291 pdeplot(p,e,t,'xydata
',u,'colormap
','jet
','contour
','on
')
293 figure,pdeplot(p,e,t,'xydata
',u2,'colormap
','jet
','contour
','on
')
298 % % Goal: u2 == sim_data.u;
302 % error('solutions not equal...
');
305 % checkB=abs(R-Fmat);
306 % if find(checkB > 1e-10) %shoud be an empty matrix
307 % disp('Problem with B
') %when true, some values are above our limit
309 % disp('Eureka! Right hand sides are nearly equal
')
312 % checkA=abs(A-Amat);
313 % if find(checkA > 1e-10) %shoud be an empty matrix
314 % disp('Problem with A
') %when true, some values are above our limit
316 % disp('Eureka! Matrices are nearly equal
')
320 % if find(checku > 1e-10) %shoud be an empty matrix
321 % disp('Problem with solution
') %when true, some values are above our limit
323 % disp('Eureka! Solution are nearly equal
')
328 % reduzierte Daten erzeugen:
329 for q = 1:length(A_comp)
330 reduced_data.AN_components{q} = RB'*A_comp{q}*RB;
332 reduced_data.BN_components = {B_comp{1}
'*RB};
335 % reduzierte Simulation:
336 % AN = linearcomb(reduced_data.AN_components, theta_A);
337 % BN = linearcomb(reduced_data.BN_components, theta_B);
340 AN = lincomb_sequence(reduced_data.AN_components, theta_A);
341 BN = lincomb_sequence(reduced_data.BN_components, theta_B);
346 % % reduced output sN = ...
348 % if (u2==sim_data.u) && (A == sim_data.A) && (B == sim_data.B)
351 % error('solutions not equal...
');
354 % % rb_sim_data = rb_simulation(model,reduced_data);
355 % % in elliptic_compliant_rb_simulation
356 % % ... koeffizientenfunktionen auswerten
357 % % ... linearkombinationen bilden
360 % %model.RB_generation_mode = 'from_detailed_data
';
361 % % detailed_data = gen_detailed_data(model,model_data)
364 % % reduzierte basis generieren
368 % %model = thermalblock_model(params); % struktur, die Einstellungen enthaelt
370 % %model = thermalblock_model; % struktur, die Einstellungen enthaelt
371 % %model_data = gen_model_data(model); % Gitter anlegen und in model_data speichern
372 % %sim_data = detailed_simulation(model,model_data)
374 % %pdeplot(model_data.grid.p,model_data.grid.e,model_data.grid.t,'xydata
', sim_data.u);