rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
comsol_ThermalBlock3D_script.m
Go to the documentation of this file.
2 %
3 % This script creates the data needed for a detailed and reduced simulation
4 % of the Comsol-3D-Thermal-Block model.
5 % It can be used for testing or just for gettin an overview of the comsol
6 % functions.
7 %
8 % Oliver Zeeb, 2012
9 
10 %load the model:
11 fprintf('loading comsol_ThermalBlock3D_model...\n')
12 model = comsol_ThermalBlock3D_model;
13 fprintf('done!\n')
14 
15 %create the data needed for simulation
16 fprintf('generating model_data...\n')
17 model_data=gen_model_data(model);
18 fprintf('done!\n')
19 
20 %after generation of model data all the needed matrices are stored in
21 %model_data --> now Comsol is only needed for plotting the results but no
22 %longer for calculating! Using Matlab instead of Comsol for the calculation
23 %speeds up things (really much, especially on a Mac!!!)
24 model.use_comsol=0;
25 
26 fprintf('generating detailed_data...\n')
27 detailed_data = gen_detailed_data(model,model_data);
28 fprintf('done!\n')
29 
30 fprintf('generating reduced_data...\n')
31 reduced_data = gen_reduced_data(model,detailed_data);
32 
33 %check how many parameters there are.
34 mu_old = get_mu(model);
35 switch length(mu_old)
36  case 3
37  mu = [1,3,9]
38  case 8
39  mu = [1,2,3,4,5,6,7,8]
40  case 125
41  mu = 1:125
42  otherwise
43  error('length of mu doesnt fit to this script!')
44 end
45 model=set_mu(model,mu);
46 
47 %run a reduced Simulation
48 fprintf(['calculating reduced solution for mu = ' num2str(mu),'...\n']);
49 rb_sim_data=rb_simulation(model,reduced_data);
50 rb_sim_data=rb_reconstruction(model,detailed_data,rb_sim_data);
51 fprintf('done!\n')
52 figure(1)
53 plot_sim_data(model,model_data,rb_sim_data,[])
54 title('reduced solution');
55 
56 %run a detailled solution
57 fprintf(['calculating detailed solution for mu = ' num2str(mu),'...\n']);
58 sim_data=detailed_simulation(model,model_data);
59 fprintf('done!\n')
60 figure(2)
61 plot_sim_data(model,model_data,sim_data,[])
62 title('detailed solution')
63 
64 %compare the errors:
65 fprintf('comparing the L2-error Udet - Ured.\n')
66 Udet = sim_data.U;
67 Ured = rb_sim_data.U;
68 U_diff = abs(Udet-Ured);
69 L2_error = sqrt(U_diff' * model_data.inner_product_matrices.L2 * U_diff);
70 fprintf(['\n\nL2-Error is: ', num2str(L2_error),'\n'])
function comsol_ThermalBlock3D_script()
comsol_ThermalBlock3D_script
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