1 function inner_product_matrices = comsol_calculate_inner_product_matrices_default(model,model_data)
2 %
function [L2, L2_full, H1, H1_full] = comsol_get_inner_product_matrices(comsol_model)
4 %
function returns the L2 and H1 inner product matrices
using a comsol
5 % coefficient form pde model. This is done by setting the parameters of the
7 % a=1, all others=0 --> L2-matrix
8 % a=c=1, all others=0 --> H1-matrix
11 % comsol_model: a comsol coefficient PDE form model
14 % L2, L2_full, H1, H1_full: L2 and H1 inner product matrices (full and
15 % eliminated versions)
18 % 1.)
get all the original parameter and store them.
19 % 2.) set the reactin (L2) or reaction and diffusion (H1) parameters to 1
21 % 3.) extract the stiffness matrix str.K (and str.Kc)
22 % 4.) set back all the parameters to their original values
23 % so that the comsol model is the same as it was when this function is
31 comsol_model=model_data.comsol_model;
32 ptag = model.comsol_tags.physics;
34 % get number of cfeq's used in the comsol model
35 feature_tags =
char(comsol_model.physics(ptag).feature.tags);
37 for k=1:length(feature_tags)
38 if strfind(feature_tags(k,:), 'cfeq')
39 nr_cfeq = nr_cfeq + 1;
45 %get all original parameters
47 c_coeff{k} = cellstr(
char(comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).getStringMatrix(
'c')));
48 a_coeff{k} = cellstr(
char(comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).getStringMatrix(
'a')));
49 f_coeff{k} = cellstr(
char(comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).getStringMatrix(
'f')));
50 ea_coeff{k} = cellstr(
char(comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).getStringMatrix(
'ea')));
51 da_coeff{k} = cellstr(
char(comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).getStringMatrix(
'da')));
52 al_coeff{k} = cellstr(
char(comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).getStringMatrix(
'al')));
53 be_coeff{k} = cellstr(
char(comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).getStringMatrix(
'be')));
54 ga_coeff{k} = cellstr(
char(comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).getStringMatrix(
'ga')));
57 %reset the coefficients to a=1, all others=0 --> L2-inner-product-matrix
58 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'c', mat2cell(num2str(zeros(size(c_coeff{k}))), ones(size(c_coeff{k},1),1)));
59 %comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'c', {
'0' '0' '0' '0'});
60 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'a',
'1');
61 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'f',
'0');
62 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'ea',
'0');
63 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'da',
'0');
64 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'al', mat2cell(num2str(zeros(size(al_coeff{k}))), ones(size(al_coeff{k},1),1)));
65 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'be', mat2cell(num2str(zeros(size(be_coeff{k}))), ones(size(be_coeff{k},1),1)));
66 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'ga', mat2cell(num2str(zeros(size(ga_coeff{k}))), ones(size(ga_coeff{k},1),1)));
71 str = mphmatrix(comsol_model,
'sol1',
'Out',{
'K',
'Kc'});
72 inner_product_matrices.L2 = str.K;
73 inner_product_matrices.L2_eliminated = str.Kc;
75 %set c=a=1, all others 0 --> H1-inner-product-matrix
77 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'c', {
'1'});
78 %comsol_model.physics(ptag).feature(
'cfeq1').set(
'c', {
'1' '0' '0' '1'});
80 str = mphmatrix(comsol_model,
'sol1',
'Out',{
'K',
'Kc'});
81 inner_product_matrices.H1 = str.K;
82 inner_product_matrices.H1_eliminated = str.Kc;
84 %change back to original values:
86 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'c', c_coeff{k});
87 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'a', a_coeff{k});
88 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'f', f_coeff{k});
89 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'ea', ea_coeff{k});
90 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'da', da_coeff{k});
91 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'al', al_coeff{k});
92 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'be', be_coeff{k});
93 comsol_model.physics(ptag).feature([
'cfeq' num2str(k)]).set(
'ga', ga_coeff{k});