1 % This Script computes the comsol 2D-evol-ThermalBlock_weak_form model
2 % in detailed form and reduced form and compares the errors!
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"!
9 % Oliver Zeeb, 2013/11/21
11 fprintf(
'loading evol_TB_2D_weak_form_model...\n')
12 model = evol_TB_2D_weak_form_model;
15 fprintf('generating model_data...\n')
16 model_data = gen_model_data(model);
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!!!)
25 fprintf('generating detailed_data...\n')
26 detailed_data = gen_detailed_data(model,model_data);
29 fprintf('generating reduced_data...\n')
30 reduced_data = gen_reduced_data(model,detailed_data);
34 fprintf(['calculating detailed solution for mu = ' num2str(mu),'...\n']);
35 model = set_mu(model,mu);
36 sim_data = detailed_simulation(model,model_data);
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);
46 fprintf('comparing the L2-error Udet - Ured.\n')
49 U_diff = abs(Udet-Ured);
50 L2_error = diag(U_diff' * model_data.inner_product_matrices.L2 * U_diff);
52 title('L_2 error Udet - Ured')
54 fprintf('comparing the output error: sdet - sred.\n')
59 plot(sim_data.s-(rb_sim_data.s)','g')
60 title('detailed and reduced output')
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));
69 fprintf('Plotting the detailed simulation.\n')
71 %after the rb_reconstruction plotting of the rb_sim_data can be done via:
function p = plot_sim_data(model, model_data, sim_data, plot_params)
function performing the plot of the simulation results as specified in model.