rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
comsol_thermal_block_calculate_inner_product_matrices.m
1 function inner_product_matrices = comsol_thermal_block_calculate_inner_product_matrices(model,model_data)
2 %function inner_product_matrices = comsol_thermal_block_calculate_inner_product_matrices(model,model_data)
3 %
4 % This function computes the L2 and H1-inner-product-matrices for the
5 % comsol_thermal_block_model. Since the model is a coefficient for model,
6 % it sets the reaction coefficient a=1, all others to 0 for the L2-Matrix.
7 % For the H1-Matrix reaction and diffusion coefficients are set to 1, all
8 % others to 0: a=r=1;
9 %
10 % Input:
11 % - model
12 % - model_data
13 %
14 % Output:
15 % - inner_product_matrices: struct containing the L2- and H1-inner
16 % product matrices in full and eliminated version.
17 %
18 % Oliver Zeeb, 2013/11/21
19 
20 
21 comsol_model=model_data.comsol_model;
22 %get all tags of the coefficient forms (so that this file works with all
23 %thermal block models no matter which dimension they are
24 all_feature_tags = cellstr(char(comsol_model.physics('c').feature.tags));
25 nr_cfeq=0;
26 for k = 1:length(all_feature_tags)
27  feature_type = char(comsol_model.physics('c').feature(all_feature_tags{k}).getType());
28  if strcmp(feature_type, 'CoefficientFormPDE')
29  nr_cfeq=nr_cfeq+1;
30  cfeq_tag{nr_cfeq} = all_feature_tags{k};
31  end
32 end
33 
34 if nr_cfeq==0
35  warning('No CoefficientFormPDE found in the model!')
36  keyboard
37 end
38 
39 %get all original parameters
40 for k=1:nr_cfeq
41  c_coeff{k} = cellstr(char(comsol_model.physics('c').feature(cfeq_tag{k}).getStringMatrix('c')));
42  a_coeff{k} = cellstr(char(comsol_model.physics('c').feature(cfeq_tag{k}).getStringMatrix('a')));
43  f_coeff{k} = cellstr(char(comsol_model.physics('c').feature(cfeq_tag{k}).getStringMatrix('f')));
44  ea_coeff{k} = cellstr(char(comsol_model.physics('c').feature(cfeq_tag{k}).getStringMatrix('ea')));
45  da_coeff{k} = cellstr(char(comsol_model.physics('c').feature(cfeq_tag{k}).getStringMatrix('da')));
46  al_coeff{k} = cellstr(char(comsol_model.physics('c').feature(cfeq_tag{k}).getStringMatrix('al')));
47  be_coeff{k} = cellstr(char(comsol_model.physics('c').feature(cfeq_tag{k}).getStringMatrix('be')));
48  ga_coeff{k} = cellstr(char(comsol_model.physics('c').feature(cfeq_tag{k}).getStringMatrix('ga')));
49 end
50 
51 %reset the coefficients to a=1, all others=0 for all coefficient forms!--> L2-inner-product-matrix
52 for k=1:nr_cfeq
53  comsol_model.physics('c').feature(cfeq_tag{k}).set('c', '0');
54  comsol_model.physics('c').feature(cfeq_tag{k}).set('a', '1');
55  comsol_model.physics('c').feature(cfeq_tag{k}).set('f', '0');
56  comsol_model.physics('c').feature(cfeq_tag{k}).set('ea', '0');
57  comsol_model.physics('c').feature(cfeq_tag{k}).set('da', '0');
58  comsol_model.physics('c').feature(cfeq_tag{k}).set('al', {'0' '0'});
59  comsol_model.physics('c').feature(cfeq_tag{k}).set('be', {'0' '0'});
60  comsol_model.physics('c').feature(cfeq_tag{k}).set('ga', {'0' '0'});
61 end
62 
63 %get L2 matrix:
64 str = mphmatrix(comsol_model,'sol1','Out',{'K','Kc'});
65 inner_product_matrices.L2 = str.K;
66 inner_product_matrices.L2_eliminated = str.Kc;
67 
68 %set c=a=1, all others 0 --> H1-inner-product-matrix
69 for k=1:nr_cfeq
70  comsol_model.physics('c').feature(cfeq_tag{k}).set('c', {'1' '0' '0' '1'});
71 end
72 
73 %get H1 matrix:
74 str = mphmatrix(comsol_model,'sol1','Out',{'K','Kc'});
75 inner_product_matrices.H1 = str.K;
76 inner_product_matrices.H1_eliminated = str.Kc;
77 
78 
79 %change back to original values:
80 for k=1:nr_cfeq
81  comsol_model.physics('c').feature(cfeq_tag{k}).set('c', c_coeff{k});
82  comsol_model.physics('c').feature(cfeq_tag{k}).set('a', a_coeff{k});
83  comsol_model.physics('c').feature(cfeq_tag{k}).set('f', f_coeff{k});
84  comsol_model.physics('c').feature(cfeq_tag{k}).set('ea', ea_coeff{k});
85  comsol_model.physics('c').feature(cfeq_tag{k}).set('da', da_coeff{k});
86  comsol_model.physics('c').feature(cfeq_tag{k}).set('al', al_coeff{k});
87  comsol_model.physics('c').feature(cfeq_tag{k}).set('be', be_coeff{k});
88  comsol_model.physics('c').feature(cfeq_tag{k}).set('ga', ga_coeff{k});
89 end