1 function inner_product_matrices = comsol_ThermalBlock3D_calculate_inner_product_matrices(model,model_data)
2 %
function inner_product_matrices = comsol_ThermalBlock3D_calculate_inner_product_matrices(model,model_data)
4 % This
function computes the inner product matrices (L2 and H1)
for the
5 % comsol 3D Thermal Block model! It can be used
for all thermal block models,
6 % no matter how many Parameters are specified.
7 % For the L2-Matrix, the
function sets the reaction coefficient a of the
8 % model = 1 and extracts the stiffness matrix from comsol. For the
9 % H1-Matrix, the reaction coefficient a and the diffusion coefficient c
11 % After extracting the Matrices
this function sets the parameters in the
12 % Comsol model to the values they had before
this function changed them.
14 % Input: model, model_data
15 % Output:
struct containing the inner product matrices
17 % Oliver Zeeb, 08/2013
19 comsol_model = model_data.comsol_model;
21 %
get all tags of the coefficient forms (so that
this file works with all
22 %thermal block models no matter which dimension they are
23 all_feature_tags = cellstr(
char(comsol_model.physics(
'c').feature.tags));
25 for k = 1:length(all_feature_tags)
26 feature_type =
char(comsol_model.physics('c').feature(all_feature_tags{k}).getType());
27 if strcmp(feature_type,
'CoefficientFormPDE')
29 cfeq_tag{nr_cfeq} = all_feature_tags{k};
34 warning(
'No CoefficientFormPDE found in the model!')
38 %get all original parameters
40 c_coeff{k} = cellstr(
char(comsol_model.physics(
'c').feature(cfeq_tag{k}).getStringMatrix(
'c')));
41 a_coeff{k} = cellstr(
char(comsol_model.physics(
'c').feature(cfeq_tag{k}).getStringMatrix(
'a')));
42 f_coeff{k} = cellstr(
char(comsol_model.physics(
'c').feature(cfeq_tag{k}).getStringMatrix(
'f')));
43 ea_coeff{k} = cellstr(
char(comsol_model.physics(
'c').feature(cfeq_tag{k}).getStringMatrix(
'ea')));
44 da_coeff{k} = cellstr(
char(comsol_model.physics(
'c').feature(cfeq_tag{k}).getStringMatrix(
'da')));
45 al_coeff{k} = cellstr(
char(comsol_model.physics(
'c').feature(cfeq_tag{k}).getStringMatrix(
'al')));
46 be_coeff{k} = cellstr(
char(comsol_model.physics(
'c').feature(cfeq_tag{k}).getStringMatrix(
'be')));
47 ga_coeff{k} = cellstr(
char(comsol_model.physics(
'c').feature(cfeq_tag{k}).getStringMatrix(
'ga')));
50 %reset the coefficients to a=1, all others=0
for all coefficient forms!--> L2-inner-product-matrix
52 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'c',
'0');
53 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'a',
'1');
54 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'f',
'0');
55 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'ea',
'0');
56 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'da',
'0');
57 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'al', {
'0' '0' '0'});
58 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'be', {
'0' '0' '0'});
59 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'ga', {
'0' '0' '0'});
63 comsol_model.sol(
'sol1').feature(
'v1').set(
'scalemethod',
'none');
64 comsol_model.sol(
'sol1').feature(
's1').active(
false);
65 str = mphmatrix(comsol_model,
'sol1',
'Out',{
'K',
'Kc'},
'initmethod',
'init',
'initsol',
'zero');
66 inner_product_matrices.L2 = str.K;
67 inner_product_matrices.L2_eliminated = str.Kc;
69 %set c=a=1, all others 0 --> H1-inner-product-matrix
71 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'c',
'1');
75 comsol_model.sol(
'sol1').feature(
'v1').set(
'scalemethod',
'none');
76 comsol_model.sol(
'sol1').feature(
's1').active(
false);
77 str = mphmatrix(comsol_model,
'sol1',
'Out',{
'K',
'Kc'},
'initmethod',
'init',
'initsol',
'zero');
78 inner_product_matrices.H1 = str.K;
79 inner_product_matrices.H1_eliminated = str.Kc;
82 %change back to original values:
84 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'c', c_coeff{k});
85 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'a', a_coeff{k});
86 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'f', f_coeff{k});
87 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'ea', ea_coeff{k});
88 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'da', da_coeff{k});
89 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'al', al_coeff{k});
90 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'be', be_coeff{k});
91 comsol_model.physics(
'c').feature(cfeq_tag{k}).set(
'ga', ga_coeff{k});