rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
evol_TB_2D_weak_form_model_script.m
Go to the documentation of this file.
1 % This Script computes the comsol 2D-evol-ThermalBlock_weak_form model
2 % in detailed form and reduced form and compares the errors!
3 %
4 % It shall show two things:
5 % 1. How evolution problems can be treated using COMSOL and rbmatlab.
6 % 2. Not only a "COMSOL coefficient form model" can be used but also a
7 % "COMSOL weak form model"!
8 %
9 % Oliver Zeeb, 2013/11/21
10 
11 fprintf('loading evol_TB_2D_weak_form_model...\n')
12 model = evol_TB_2D_weak_form_model;
13 fprintf('done!\n')
14 
15 fprintf('generating model_data...\n')
16 model_data = gen_model_data(model);
17 fprintf('done!\n')
18 
19 %after generation of model data all the needed matrices are stored in
20 %model_data --> now Comsol is only needed for plotting the results but no
21 %longer for calculating! Using Matlab instead of Comsol for the calculation
22 %speeds up things (really much, especially on a Mac!!!)
23 model.use_comsol=0;
24 
25 fprintf('generating detailed_data...\n')
26 detailed_data = gen_detailed_data(model,model_data);
27 fprintf('done!\n')
28 
29 fprintf('generating reduced_data...\n')
30 reduced_data = gen_reduced_data(model,detailed_data);
31 fprintf('done!\n')
32 
33 mu=[1,2,1,2];
34 fprintf(['calculating detailed solution for mu = ' num2str(mu),'...\n']);
35 model = set_mu(model,mu);
36 sim_data = detailed_simulation(model,model_data);
37 fprintf('done!\n')
38 
39 
40 fprintf(['calculating reduced solution for mu = ' num2str(mu),'...\n']);
41 rb_sim_data = rb_simulation(model,reduced_data);
42 rb_sim_data = rb_reconstruction(model,detailed_data,rb_sim_data);
43 fprintf('done!\n')
44 
45 
46 fprintf('comparing the L2-error Udet - Ured.\n')
47 Udet = sim_data.U;
48 Ured = rb_sim_data.U;
49 U_diff = abs(Udet-Ured);
50 L2_error = diag(U_diff' * model_data.inner_product_matrices.L2 * U_diff);
51 plot(L2_error);
52 title('L_2 error Udet - Ured')
53 
54 fprintf('comparing the output error: sdet - sred.\n')
55 figure
56 plot(rb_sim_data.s)
57 hold on
58 plot(sim_data.s,'r')
59 plot(sim_data.s-(rb_sim_data.s)','g')
60 title('detailed and reduced output')
61 
62 
63 fprintf('adding the initial values to the (rb_)sim_data.\n')
64 sim_data_with_init_values = sim_data;
65 rb_sim_data_with_init_values = rb_sim_data;
66 sim_data_with_init_values.U=sim_data.U + repmat(model_data.operators.init_values,1,size(sim_data.U,2));
67 rb_sim_data_with_init_values.U=rb_sim_data.U + repmat(model_data.operators.init_values,1,size(sim_data.U,2));
68 
69 fprintf('Plotting the detailed simulation.\n')
70 plot_sim_data(model,model_data,sim_data,[]);
71 %after the rb_reconstruction plotting of the rb_sim_data can be done via:
72 %plot_sim_data(model,model_data,rb_sim_data,[]);
function p = plot_sim_data(model, model_data, sim_data, plot_params)
function performing the plot of the simulation results as specified in model.
Definition: plot_sim_data.m:17