3 % ThermalBlock_3D_5x5x5_LinLagr_Einfluss_unten_8Params.m
7 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9 % Set Properties of the model here!!!
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11 %mu_init = [1,1,1]; % [1,3,8,2] --> sets parameters: mu1=1, mu2=3, mu3=8, mu4=2
16 %zufallszahlen fuer das modell generieren! verwende seed, damit immer die
17 %gleichen zahlen beim model generieren verwendet werden
20 block_mu_index = randi([1 length(mu_init)],nr_blocks,1); %random
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 % Generation of the Comsol Model
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 import com.comsol.model.*
30 import com.comsol.model.util.*
32 model = ModelUtil.create(
'Model');
34 model.modelPath(
'/Users/oliverzeeb/Documents/MATLAB/rbmatlab_COMSOL/COMSOL_rbmatlab/models/ThermalBlock/3D_stat');
36 model.name(
'ThermalBlock_3D_5x5x5_LinLagr_Einfluss_unten_8Params.mph');
38 model.baseSystem(
'none');
40 for k=1:length(mu_init)
41 model.param.set(['mu',num2str(k)], num2str(mu_init(k)));
44 model.modelNode.create('mod1');
46 model.geom.create('geom1', 3);
49 eval_string = ['model.geom(''geom1'').feature.create(''blk' num2str(k), ''', ''Block'');'];
52 % model.geom('geom1').feature.create('blk1', 'Block');
53 % model.geom('geom1').feature.create('blk2', 'Block');
56 %groesse der bloecke setzen
60 pos_string = ['model.geom(''geom1'').feature(''blk', num2str(k) , ''').set(''pos'', {
'''...
61 num2str(counter(1))
'/5'' ''' num2str(counter(2)),
'/5'' ''', num2str(counter(3))
'/5''});'];
64 size_string = [
'model.geom(''geom1'').feature(''blk', num2str(k),
''').set(
''size
'', {
''1/5
'' ''1/5
'' ''1/5
''});
'];
68 counter = increase_counter(5,1,counter);
71 % model.geom('geom1
').feature('blk1
').set('pos
', {'0
' '0
' '0
'});
72 % model.geom('geom1
').feature('blk1
').set('size
', {'1/4
' '1/4
' '1/4
'});
75 model.geom('geom1
').run;
77 model.physics.create('c
', 'CoefficientFormPDE
', 'geom1
');
79 create_string = ['model.physics(
''c
'').feature.create(
''cfeq
' num2str(k) ''',
''CoefficientFormPDE
'', 3);
'];
81 selection_string = ['model.physics(
''c
'').feature(
''cfeq
' num2str(k) ''').selection.set([
' num2str(k) ']);
'];
82 eval(selection_string);
84 % model.physics('c
').feature.create('cfeq2
', 'CoefficientFormPDE
', 3);
85 % model.physics('c
').feature('cfeq2
').selection.set([2]);
88 model.physics('c
').feature.create('dir1
', 'DirichletBoundary
', 2);
89 model.physics('c
').feature('dir1
').selection.set([16, 32, 48, 64, 80, 101, 117, 133, 149, 165,...
90 186, 202, 218, 234, 250, 271, 287, 303, 319, 335, 356, 372, 388, 404, 420]);
91 model.physics('c
').feature.create('flux1
', 'FluxBoundary
', 2);
92 model.physics('c
').feature('flux1
').selection.set([3, 19, 35, 51, 67, 88, 104, 120, 136, 152,...
93 173, 189, 205, 221, 237, 258, 274, 290, 306, 322, 343, 359, 375, 391, 407]);
95 model.mesh.create('mesh1
', 'geom1
');
96 model.mesh('mesh1
').feature.create('ftet1
', 'FreeTet
');
98 model.view('view1
').set('renderwireframe
', true);
100 model.physics('c
').prop('ShapeProperty
').set('order
', '1
');
102 % koeffizienten der PDE setzen
104 set_f_string = ['model.physics(
''c
'').feature(
''cfeq
' num2str(k) ''').set(
''f
'',
''0
'');
'];
106 set_da_string = ['model.physics(
''c
'').feature(
''cfeq
' num2str(k) ''').set(
''da
'',
''0
'');
'];
109 model.physics('c
').feature('flux1
').set('g
', '50
');
110 for k=1:length(block_mu_index)
111 mu_string = ['mu
',num2str(block_mu_index(k))];
112 model.physics('c
').feature(['cfeq
',num2str(k)]).set('c
', {mu_string '0
' '0
' '0
' mu_string '0
' '0
' '0
' mu_string});
114 % model.physics('c
').feature('cfeq1
').set('c
', {'mu1
' '0
' '0
' '0
' 'mu1
' '0
' '0
' '0
' 'mu1
'});
115 % model.physics('c
').feature('cfeq1
').set('f
', '0
');
116 % model.physics('c
').feature('cfeq1
').set('da
', '0
');
119 %model.mesh('mesh1
').run;
121 model.frame('material1
').sorder(1);
123 model.study.create('std1
');
124 model.study('std1
').feature.create('stat
', 'Stationary
');
126 model.sol.create('sol1
');
127 model.sol('sol1
').study('std1
');
128 model.sol('sol1
').attach('std1
');
129 model.sol('sol1
').feature.create('st1
', 'StudyStep
');
130 model.sol('sol1
').feature.create('v1
', 'Variables
');
131 model.sol('sol1
').feature.create('s1
', 'Stationary
');
132 model.sol('sol1
').feature('s1
').feature.create('fc1
', 'FullyCoupled
');
133 model.sol('sol1
').feature('s1
').feature.remove('fcDef
');
136 model.result.numerical.create('int1
', 'IntSurface
');
137 model.result.numerical('int1
').selection.set([3, 19, 35, 51, 67, 88, 104, 120, 136, 152,...
138 173, 189, 205, 221, 237, 258, 274, 290, 306, 322, 343, 359, 375, 391, 407]);
139 model.result.numerical('int1
').set('probetag
', 'none
');
141 model.result.create('pg1
', 'PlotGroup3D
');
142 model.result('pg1
').feature.create('slc1
', 'Slice
');
144 model.sol('sol1
').feature('st1
').name('Compile Equations: Stationary {stat}
');
145 model.sol('sol1
').feature('st1
').set('studystep
', 'stat
');
146 model.sol('sol1
').feature('v1
').set('control
', 'stat
');
147 model.sol('sol1
').feature('s1
').set('control
', 'stat
');
148 %model.sol('sol1
').runAll;
150 model.result('pg1
').feature('slc1
').set('unit
', '1
');
160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 % Auxiliary functions
162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 function counter = increase_counter(basis, pos,counter)
164 if mod(counter(pos)+1,basis) == 0 %aktuelle pos auf null setzen, nächste pos um 1 erhöhen!
166 counter = increase_counter(basis, pos+1,counter);
168 counter(pos) = counter(pos)+1;