rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
ThermalBlock_3D_5x5x5_LinLagr_Einfluss_unten_8Params.m
1 function out = model
2 %
3 % ThermalBlock_3D_5x5x5_LinLagr_Einfluss_unten_8Params.m
4 %
5 
6 
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
12 mu_init = ones(8,1);
13 
14 nr_blocks = 125;
15 
16 %zufallszahlen fuer das modell generieren! verwende seed, damit immer die
17 %gleichen zahlen beim model generieren verwendet werden
18 seed = 1;
19 rng(seed);
20 block_mu_index = randi([1 length(mu_init)],nr_blocks,1); %random
21 
22 
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 % Generation of the Comsol Model
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 
29 import com.comsol.model.*
30 import com.comsol.model.util.*
31 
32 model = ModelUtil.create('Model');
33 
34 model.modelPath('/Users/oliverzeeb/Documents/MATLAB/rbmatlab_COMSOL/COMSOL_rbmatlab/models/ThermalBlock/3D_stat');
35 
36 model.name('ThermalBlock_3D_5x5x5_LinLagr_Einfluss_unten_8Params.mph');
37 
38 model.baseSystem('none');
39 
40 for k=1:length(mu_init)
41  model.param.set(['mu',num2str(k)], num2str(mu_init(k)));
42 end
43 
44 model.modelNode.create('mod1');
45 
46 model.geom.create('geom1', 3);
47 %Bloecke generieren
48 for k=1:nr_blocks
49  eval_string = ['model.geom(''geom1'').feature.create(''blk' num2str(k), ''', ''Block'');'];
50  eval(eval_string);
51 end
52 % model.geom('geom1').feature.create('blk1', 'Block');
53 % model.geom('geom1').feature.create('blk2', 'Block');
54 % ...
55 
56 %groesse der bloecke setzen
57 counter = zeros(3,1);
58 for k=1:nr_blocks
59  %position festlegen
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''});'];
62  eval(pos_string);
63 
64  size_string = ['model.geom(''geom1'').feature(''blk', num2str(k), ''').set(''size'', {''1/5'' ''1/5'' ''1/5''});'];
65  eval(size_string);
66 
67  if k<nr_blocks
68  counter = increase_counter(5,1,counter);
69  end
70 end
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'});
73 % ...
74 
75 model.geom('geom1').run;
76 
77 model.physics.create('c', 'CoefficientFormPDE', 'geom1');
78 for k=2:nr_blocks
79  create_string = ['model.physics(''c'').feature.create(''cfeq' num2str(k) ''', ''CoefficientFormPDE'', 3);'];
80  eval(create_string);
81  selection_string = ['model.physics(''c'').feature(''cfeq' num2str(k) ''').selection.set([' num2str(k) ']);'];
82  eval(selection_string);
83 end
84 % model.physics('c').feature.create('cfeq2', 'CoefficientFormPDE', 3);
85 % model.physics('c').feature('cfeq2').selection.set([2]);
86 % ...
87 
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]);
94 
95 model.mesh.create('mesh1', 'geom1');
96 model.mesh('mesh1').feature.create('ftet1', 'FreeTet');
97 
98 model.view('view1').set('renderwireframe', true);
99 
100 model.physics('c').prop('ShapeProperty').set('order', '1');
101 
102 % koeffizienten der PDE setzen
103 for k=1:nr_blocks
104  set_f_string = ['model.physics(''c'').feature(''cfeq' num2str(k) ''').set(''f'', ''0'');'];
105  eval(set_f_string)
106  set_da_string = ['model.physics(''c'').feature(''cfeq' num2str(k) ''').set(''da'', ''0'');'];
107  eval(set_da_string)
108 end
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});
113 end
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');
117 % ...
118 
119 %model.mesh('mesh1').run;
120 
121 model.frame('material1').sorder(1);
122 
123 model.study.create('std1');
124 model.study('std1').feature.create('stat', 'Stationary');
125 
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');
134 
135 % Ausgabefuntional
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');
140 
141 model.result.create('pg1', 'PlotGroup3D');
142 model.result('pg1').feature.create('slc1', 'Slice');
143 
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;
149 
150 model.result('pg1').feature('slc1').set('unit', '1');
151 
152 out = model;
153 
154 end
155 
156 
157 
158 
159 
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!
165  counter(pos) = 0;
166  counter = increase_counter(basis, pos+1,counter);
167  else
168  counter(pos) = counter(pos)+1;
169  end
170 end