1 function inner_product_matrices = comsol_calculate_inner_product_matrices_MULTI(model,model_data)
2 %
function [L2, L2_full, H1, H1_full] = comsol_get_inner_product_matrices(comsol_model)
4 % THIS FUNCTION DOES THE SAME AS comsol_calculate_inner_product_matrices_default
5 % BUT CAN ALSO BE USED FOR COMSOL COEFFICIENT FORM MODELS with more than
6 % ONE
"PHYSICS-FEATURE", FOR EXAMPLE FOR COUPLED SYSTEMS ON DIFFERENT
9 %
function returns the L2 and H1 inner product matrices
using a comsol
10 % coefficient form pde model. This is done by setting the parameters of the
12 % a=1, all others=0 --> L2-matrix
13 % a=c=1, all others=0 --> H1-matrix
16 % comsol_model: a comsol coefficient PDE form model
19 % L2, L2_full, H1, H1_full: L2 and H1 inner product matrices (full and
20 % eliminated versions)
23 % 1.)
get all the original parameter and store them.
24 % 2.) set the reactin (L2) or reaction and diffusion (H1) parameters to 1
26 % 3.) extract the stiffness matrix str.K (and str.Kc)
27 % 4.) set back all the parameters to their original values
28 % so that the comsol model is the same as it was when this function is
34 comsol_model=model_data.comsol_model;
36 ptag_matrix = model.comsol_tags.physics;
38 for k=1:size(ptag_matrix,1)
39 ptag{k} = strrep(ptag_matrix(k,:),
' ',
''); %
delete blanks!
43 for ptag_ind =1:length(ptag)
44 %
get number of cfeq
's used in the comsol model
45 feature_tags{ptag_ind} = char(comsol_model.physics(ptag{ptag_ind}).feature.tags);
46 nr_cfeq{ptag_ind} = 0;
47 for k=1:size(feature_tags{ptag_ind},1)
48 if strfind(feature_tags{ptag_ind}(k,:), 'cfeq
')
49 nr_cfeq{ptag_ind} = nr_cfeq{ptag_ind} + 1;
55 %get all original parameters
56 for ptag_ind = 1:length(ptag)
57 for k=1:nr_cfeq{ptag_ind}
58 c_coeff{ptag_ind, k} = cellstr(char(comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).getStringMatrix('c
')));
59 a_coeff{ptag_ind, k} = cellstr(char(comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).getStringMatrix('a
')));
60 f_coeff{ptag_ind, k} = cellstr(char(comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).getStringMatrix('f
')));
61 ea_coeff{ptag_ind, k} = cellstr(char(comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).getStringMatrix('ea
')));
62 da_coeff{ptag_ind, k} = cellstr(char(comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).getStringMatrix('da
')));
63 al_coeff{ptag_ind, k} = cellstr(char(comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).getStringMatrix('al
')));
64 be_coeff{ptag_ind, k} = cellstr(char(comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).getStringMatrix('be
')));
65 ga_coeff{ptag_ind, k} = cellstr(char(comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).getStringMatrix('ga
')));
68 %reset the coefficients to a=1, all others=0 --> L2-inner-product-matrix
69 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('c
', mat2cell(num2str(zeros(size(c_coeff{k}))), ones(size(c_coeff{k},1),1)));
70 %comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('c
', {'0
' '0
' '0
' '0
'});
71 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('a
', '1
');
72 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('f
', '0
');
73 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('ea
', '0
');
74 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('da
', '0
');
75 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('al
', mat2cell(num2str(zeros(size(al_coeff{ptag_ind,k}))), ones(size(al_coeff{ptag_ind,k},1),1)));
76 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('be
', mat2cell(num2str(zeros(size(be_coeff{ptag_ind,k}))), ones(size(be_coeff{ptag_ind,k},1),1)));
77 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('ga
', mat2cell(num2str(zeros(size(ga_coeff{ptag_ind,k}))), ones(size(ga_coeff{ptag_ind,k},1),1)));
82 str = mphmatrix(comsol_model,'sol1
','Out
',{'K
','Kc
'});
83 inner_product_matrices.L2 = str.K;
84 inner_product_matrices.L2_eliminated = str.Kc;
86 %set c=a=1, all others 0 --> H1-inner-product-matrix
87 for ptag_ind = 1:length(ptag)
88 for k=1:nr_cfeq{ptag_ind}
89 comsol_model.physics(ptag{ptag_ind}).feature(['cfeq
' num2str(k)]).set('c
', {'1
'});
90 %comsol_model.physics(ptag).feature('cfeq1
').set('c
', {'1
' '0
' '0
' '1
'});
93 str = mphmatrix(comsol_model,'sol1
','Out
',{'K
','Kc
'});
94 inner_product_matrices.H1 = str.K;
95 inner_product_matrices.H1_eliminated = str.Kc;
97 %change back to original values:
98 for ptag_ind = 1:length(ptag)
99 for k=1:nr_cfeq{ptag_ind}
100 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('c
', c_coeff{ptag_ind,k});
101 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('a
', a_coeff{ptag_ind,k});
102 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('f
', f_coeff{ptag_ind,k});
103 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('ea
', ea_coeff{ptag_ind,k});
104 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('da
', da_coeff{ptag_ind,k});
105 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('al
', al_coeff{ptag_ind,k});
106 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('be
', be_coeff{ptag_ind,k});
107 comsol_model.physics(ptag(ptag_ind)).feature(['cfeq
' num2str(k)]).set('ga
', ga_coeff{ptag_ind,k});