2 % Thermal Block example similar as described in the book of
3 % A.T. patera and G. Rozza (just one parameter more)
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
11 % where Omega = [0,1]^2 is divided into B1 * B2 blocks
12 % QA := B1*B2. The heat conductivities are given by mu_i:
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 % -------------------------
27 % `Gamma_D =` upper edge
28 % `Gamma_N = boundary(Omega)\Gamma_D`
30 % `a(x) = mu_i(x) if x\in B_i`
33 % `g_N = 1` on lower edge, 0 otherwise
34 % `l(u)` = average over lower edge
36 % S. Langhof and B. Haasdonk 26.2.2011
39 descr = lin_stat_model_default;
43 descr.set_mu = @thermalblock_set_mu;
44 descr.get_mu = @(descr) descr.mus(:);
49 % descr.default = '3x3 demo version';
51 % number of blocks in X and Y direction
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
61 mu_names = [mu_names,{[
'mu1']},{[
'mu2']}];%[mu_1,mu_2]
63 for p = 1:descr.number_of_mu
65 mu_ranges = [mu_ranges,{mu_range}];
67 descr.mu_names = mu_names;
68 descr.mu_ranges = mu_ranges;
70 %
default values 1 everywhere
71 descr.mus = ones(descr.number_of_mu,1);
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;
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);
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);
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),...
100 descr.diffusivity_tensor = @(glob,params) ...
101 eval_affine_decomp_general(...
102 @thermalblock_diffusivity_tensor_components, ...
103 diffusivity_tensor_coefficients, glob,params);
105 % only useful
for detailed simulation or nonlinear outputs:
106 %descr.output_functional = @output_functional_boundary_integral;
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);
117 descr.output_integral_qdeg = 2; %
119 %%%%%%%%%% discretization settings
121 if ~isfield(params,
'numintervals_per_block')
122 params.numintervals_per_block = 5;
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];
131 if ~isfield(params,'pdeg')
135 if ~isfield(params,'qdeg')
140 descr.pdeg = params.pdeg; % degree of polynomial functions
141 descr.qdeg = params.qdeg; % quadrature degree
142 descr.dimrange = 1; % scalar solution
144 descr.boundary_type = @thermalblock_boundary_type;
145 %descr.normals = @my_normals;
147 % new plot routine, additional block boundaries are plotted
149 descr.compute_output_functional = 1;
150 descr.yscale_uicontrols = 0.2;
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;
158 % local data functions:
163 descr.distance_function = @euclidean_distance;
166 %%%%%%% auxiliary functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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!');
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);
180 i = find(glob(:,1)>=1-1e-10);
182 i = find(glob(:,2)<=1e-10);
184 i = find(glob(:,2)>=1-1e-10);
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);
195 function res = thermalblock_diffusivity_tensor_components(glob,params)
196 % diffusivity tensor component
function
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);
205 % xi: range 0 ... B1-1
206 yi = floor(glob(:,2)*params.B2);
207 i = find(yi>=params.B2);
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;
216 i = find(block_index==q);
225 %
for q=1:params.number_of_blocks;
226 % block = block + res{q};
228 %disp(
'check diffusivity matrix!')
231 function alpha = thermalblock_coercivity_alpha(descr)
232 % returns coercivity constant
233 alpha = min(descr.get_mu(descr));
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.
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.
function res = thermalblock(step, params)
thermalblock example