rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
thermalblock_model_hp.m
Go to the documentation of this file.
1 function descr = thermalblock_model_hp(params)
2 % Thermal Block example similar as described in the book of
3 % A.T. patera and G. Rozza (just one parameter more)
4 %
5 % i.e.
6 % - div ( a(x) grad u(x)) = q(x) on Omega
7 % u(x)) = g_D(x) on Gamma_D
8 % a(x) (grad u(x)) n) = g_N(x) on Gamma_N
9 % s = l(u) linear output functional
10 %
11 % where Omega = [0,1]^2 is divided into B1 * B2 blocks
12 % QA := B1*B2. The heat conductivities are given by mu_i:
13 %
14 % this is a modified thermalblock model fpr hp test
15 % with only 2 paramerts and 9
16 % paramert domains and
17 % changed range (.04:1)
18 % also the location of mus is changed to:
19 % -------------------------
20 % | mu_1 | mu_2 | mu_1 |
21 % -------------------------
22 % | mu_2 | mu_1 | mu_2 |
23 % -------------------------
24 % | mu_1 | mu_2 | mu_1 |
25 % -------------------------
26 %
27 % `Gamma_D =` upper edge
28 % `Gamma_N = boundary(Omega)\Gamma_D`
29 %
30 % `a(x) = mu_i(x) if x\in B_i`
31 % `q(x) = 0`
32 % `g_D = 0` on top
33 % `g_N = 1` on lower edge, 0 otherwise
34 % `l(u)` = average over lower edge
35 
36 % S. Langhof and B. Haasdonk 26.2.2011
37 % I. Maier 26.04.2011
38 
39 descr = lin_stat_model_default;
40 descr.name = 'thermalblock';
41 descr.dmodel_constructor = @ThermalBlock.DetailedModel;
42 
43 descr.set_mu = @thermalblock_set_mu;
44 descr.get_mu = @(descr) descr.mus(:);
45 
46 if nargin == 0
47  params.B1=3;
48  params.B2=3;
49 % descr.default = '3x3 demo version';
50 end
51 % number of blocks in X and Y direction
52 descr.B1 = params.B1;
53 descr.B2 = params.B2;
54 descr.number_of_blocks = params.B1*params.B2;
55 descr.number_of_mu = 2;
56 % each block has a different heat conductivity
57 % upper left has conductivity 1
58 mu_names = {};
59 mu_ranges = {};
60 mu_range = [1/50,1];
61 mu_names = [mu_names,{['mu1']},{['mu2']}];%[mu_1,mu_2]
62 
63 for p = 1:descr.number_of_mu
64 
65  mu_ranges = [mu_ranges,{mu_range}];
66 end;
67 descr.mu_names = mu_names;
68 descr.mu_ranges = mu_ranges;
69 
70 %default values 1 everywhere
71 descr.mus = ones(descr.number_of_mu,1);
72 
73 
74 %%%%%%%%% set data functions
75 descr.has_diffusivity = 1;
76 descr.has_output_functional = 1;
77 descr.has_dirichlet_values = 1;
78 descr.has_neumann_values = 1;
79 
80 % zero dirichlet values, i.e. 1 component, Q_dir = 1
81 dirichlet_values_coefficients = @(dummy,params) [0];
82 dirichlet_values_components = @(glob,params) {zeros(size(glob,1),1)};
83 descr.dirichlet_values = @(glob,params) ...
84  eval_affine_decomp_general(dirichlet_values_components, ...
85  dirichlet_values_coefficients,glob,params);
86 
87 % 1/0 neumann values depending on edge, non parametric, i.e Q_neu = 1;
88 neumann_values_coefficients = @(dummy,params) 1; % single component
89 descr.neumann_values = @(glob,params) ...
90  eval_affine_decomp_general(@thermalblock_neumann_values_components, ...
91  neumann_values_coefficients, glob, params);
92 
93 % diffusion tensor: each row four entries a11,a_21,a_12,a_22.
94 % a11(x)=a22(x) = mu_i if x in block i, a12=a21 = 0.
95 diffusivity_tensor_coefficients = @(dummy,params) ...
96  [params.mus(1),params.mus(2),params.mus(1),params.mus(2),...
97  params.mus(1),params.mus(2),params.mus(1),params.mus(2),...
98  params.mus(1)];
99 %params.mus(:);
100 descr.diffusivity_tensor = @(glob,params) ...
101  eval_affine_decomp_general(...
102  @thermalblock_diffusivity_tensor_components, ...
103  diffusivity_tensor_coefficients, glob,params);
104 
105 % only useful for detailed simulation or nonlinear outputs:
106 %descr.output_functional = @output_functional_boundary_integral;
107 
108 descr.operators_output = @fem_operators_output_boundary_integral;
109 % output weight function: simply 1 on lower edge, 0 else => Ql = 1 component
110 output_function_components = @(glob,descr) {1.0*(glob(:,2)<eps)};
111 output_function_coefficients = @(glob,descr) 1;
112 descr.output_function = @(glob,params) ...
113  eval_affine_decomp_general(...
114  output_function_components,...
115  output_function_coefficients, glob,params);
116 
117 descr.output_integral_qdeg = 2; %
118 
119 %%%%%%%%%% discretization settings
120 
121 if ~isfield(params,'numintervals_per_block')
122  params.numintervals_per_block = 5;
123 end;
124 
125 descr.gridtype = 'triagrid';
126 descr.xnumintervals = params.numintervals_per_block*params.B1;
127 descr.ynumintervals = params.numintervals_per_block*params.B2;
128 descr.xrange = [0,1];
129 descr.yrange = [0,1];
130 
131 if ~isfield(params,'pdeg')
132  params.pdeg = 1;
133 end;
134 
135 if ~isfield(params,'qdeg')
136  params.qdeg = 2;
137 end;
138 
139 % numerics settings:
140 descr.pdeg = params.pdeg; % degree of polynomial functions
141 descr.qdeg = params.qdeg; % quadrature degree
142 descr.dimrange = 1; % scalar solution
143 
144 descr.boundary_type = @thermalblock_boundary_type;
145 %descr.normals = @my_normals;
146 
147 % new plot routine, additional block boundaries are plotted
148 descr.plot_sim_data = @thermalblock_plot_sim_data;
149 descr.compute_output_functional = 1;
150 descr.yscale_uicontrols = 0.2;
151 
152 % for error estimation:
153 descr.coercivity_alpha = @(descr) min(descr.mus(:));
154 descr.continuity_gamma = @(descr) max(descr.mus(:));
155 descr.enable_error_estimator = 1;
156 descr.get_estimator_from_sim_data = @(sim_data)sim_data.Delta;
157 
158 % local data functions:
159 descr = elliptic_discrete_model(descr);
160 
161 %hp-settings
162 %------------
163 descr.distance_function = @euclidean_distance;
164 
165 
166 %%%%%%% auxiliary functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 
168 function model = thermalblock_set_mu(model,mu)
169  % updates the parameter
170  if length(mu)~=model.number_of_mu
171  error('length of mu does not fit to number of blocks!');
172  end;
173  model.mus = [mu(:)];
174 
175 function res = thermalblock_boundary_type(glob,params)
176  % returns the boundary type
177 res = zeros(size(glob,1),1);
178 i = find(glob(:,1)<=1e-10);
179 res(i) = -2;
180 i = find(glob(:,1)>=1-1e-10);
181 res(i) = -2;
182 i = find(glob(:,2)<=1e-10);
183 res(i) = -2;
184 i = find(glob(:,2)>=1-1e-10);
185 res(i) = -1;
186 
187 
188 function comp = thermalblock_neumann_values_components(glob,params)
189  % Neumann values component function
190 res = zeros(size(glob,1),1);
191 i = find(glob(:,2)<eps);
192 res(i) = 1;
193 comp = {res};
194 
195 function res = thermalblock_diffusivity_tensor_components(glob,params)
196  % diffusivity tensor component function
197 
198 % for each point in glob find global block number
199 % xi: range 0 ... B1-1
200 xi = floor(glob(:,1)*params.B1);
201 i = find(xi>=params.B1);
202 if ~isempty(i)
203  xi(i) = params.B1-1;
204 end;
205 % xi: range 0 ... B1-1
206 yi = floor(glob(:,2)*params.B2);
207 i = find(yi>=params.B2);
208 if ~isempty(i);
209  yi(i) = params.B2-1;
210 end;
211 block_index = yi*params.B1+xi+1;
212 zeroblock = zeros(size(glob,1),4);
213 res = cell(1,params.number_of_blocks);
214 for q = 1:params.number_of_blocks;
215  block = zeroblock;
216  i = find(block_index==q);
217  if ~isempty(i)
218  block(i,1) = 1;
219  block(i,4) = 1;
220  end;
221  res{q} = block;
222 end;
223 % check!
224 %block = zeroblock;
225 %for q=1:params.number_of_blocks;
226 % block = block + res{q};
227 %end;
228 %disp('check diffusivity matrix!')
229 %keyboard;
230 
231 function alpha = thermalblock_coercivity_alpha(descr)
232  % returns coercivity constant
233 alpha = min(descr.get_mu(descr));
234 
235 
function descr = thermalblock_model_hp(params)
Thermal Block example similar as described in the book of A.T. patera and G. Rozza (just one paramete...
A triangular conforming grid in two dimensions.
Definition: triagrid.m:17
function local_model = elliptic_discrete_model(model)
function creating a model with local functions out of a model with global functions. See detailed description for explanation.
function p = plot_sim_data(model, model_data, sim_data, plot_params)
function performing the plot of the simulation results as specified in model.
Definition: plot_sim_data.m:17
function res = thermalblock(step, params)
thermalblock example
Definition: thermalblock.m:17