1 function str = get_assembled_matrices(model)
2 %
function str = get_assembled_matrices(model)
4 % This
function returns the assembled matrices from comsol.
5 % Therefore an
"assemble-feature" model.sol(
'sol1').feature(
'a1')
6 % must exist in the comsol model!
9 % -model = a comsol model
11 % -str = a
struct containing the assemble matrices that were extracted
14 % Oliver Zeeb, 2013/11/21
16 model.sol(
'sol1').feature(
'v1').set(
'scaleval',
'1');
17 model.sol(
'sol1').feature(
'v1').set(
'scalemethod',
'manual');
18 model.sol(
'sol1').feature(
't1').active(
false);
19 model.sol(
'sol1').feature(
'a1').active(
true);
20 model.sol(
'sol1').feature(
'a1').set(
'Nullf',
true);
21 model.sol(
'sol1').feature(
'a1').set(
'Null',
true);
22 model.sol(
'sol1').feature(
'a1').set(
'Lc',
true);
23 model.sol(
'sol1').feature(
'a1').set(
'ud',
true);
24 model.sol(
'sol1').feature(
'a1').set(
'Kc',
true);
25 model.sol(
'sol1').feature(
'a1').set(
'Ec',
true);
26 model.sol(
'sol1').feature(
'a1').set(
'uscale',
true);
27 model.sol(
'sol1').feature(
'a1').set(
'Dc',
true);
29 model.study(
'std1').run;
31 str_Null = mphmatrix(model,
'sol1',
'out',{
'Null'});
32 str.Null = str_Null.Null;
34 %create Matlab-sparse matrix from the vectors extracted from comsol
35 str.DcCol = 1+double(model.sol(
'sol1').feature(
'a1').getSparseMatrixCol(
'Dc'));
36 %
"1+..." is needed since the indices returned by comsol start at 0, not at 1 as in matlab
37 str.DcRow = 1+double(model.sol(
'sol1').feature(
'a1').getSparseMatrixRow(
'Dc'));
38 str.DcVal = model.sol(
'sol1').feature(
'a1').getSparseMatrixVal(
'Dc');
39 str.Dc = sparse(size(str.Null,2),size(str.Null,2));
40 for k=1:length(str.DcRow)
41 str.Dc(str.DcRow(k), str.DcCol(k)) = str.DcVal(k);
43 str.KcCol = 1+
double(model.sol('sol1').feature('a1').getSparseMatrixCol('Kc'));
44 str.KcRow = 1+
double(model.sol('sol1').feature('a1').getSparseMatrixRow('Kc'));
45 str.KcVal = model.sol('sol1').feature('a1').getSparseMatrixVal('Kc');
46 str.Kc = sparse(size(str.Null,2),size(str.Null,2));
47 for k=1:length(str.KcRow)
48 str.Kc(str.KcRow(k), str.KcCol(k)) = str.KcVal(k);
50 str.Lc = model.sol('sol1').feature('a1').getVector('Lc');
51 str.ud = model.sol('sol1').feature('a1').getVector('ud');
52 str.uscale = model.sol('sol1').feature('a1').getVector('uscale');