rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
multiscale_thermalblock_model.m
1 function model = multiscale_thermalblock_model(params)
2 %
3 % A thermalblock model, the parameters of which are
4 % coupled to give overall params.Qa instead of params.B1*params.B2
5 % many parameters.
6 %
7 % The coupling can be prescribed by a vector params.parameter_mapping
8 % e.g. for B1=B2=3 and desired Qa=4:
9 % params.parameter_mapping = [4 2 3 1 2 1 3 1 1];
10 %
11 % If this mapping is not given, a deterministically
12 % random ordering is prescribed
13 %
14 % a field Qa is required in params to indicate the number of
15 % desired components in a
16 
17 % B. Haasdonk 7.3.2012
18 
19 model = thermalblock_model(params);
20 model.base_model = model;
21 model.base_Qa = length(model.mu_names);
22 model.Qa = params.Qa;
23 Qa = params.Qa;
24 
25 % deterministic random assignment
26 if isfield(params,'parameter_mapping')
27  model.parameter_mapping = params.parameter_mapping;
28 else
29  defaultStream = RandStream.getDefaultStream;
30  savedState = defaultStream.State;
31  RandStream.setDefaultStream(RandStream('mt19937ar','seed',100000));
32  model.parameter_mapping = floor(Qa * rand(1,model.base_Qa))+1;
33  defaultStream.State = savedState;
34  RandStream.setDefaultStream(defaultStream);
35 end;
36 parameter_first_ids = [];
37 for i = 1:Qa
38  parameter_first_ids = [parameter_first_ids, ...
39  min(find(model.parameter_mapping==i))];
40 end;
41 
42 % assign new model parts:
43 model.parameter_first_ids = parameter_first_ids;
44 model.mu_names = model.mu_names(parameter_first_ids);
45 model.mu_ranges = model.mu_ranges(parameter_first_ids);
46 model.set_mu = @my_set_mu;
47 model.get_mu = @my_get_mu;
48 model.mus = model.mus(model.parameter_first_ids);
49 %model.operators = @my_operators;
50 model.name = 'multiscale_thermalblock';
51 
52 % default params for demo_rb_gui
53 model.axis_tight = 1;
54 model.yscale_uicontrols = 1.0;
55 
56 %keyboard;
57 
58 multiscale_diffusivity_tensor_coefficients = @(dummy,params) ...
59  params.get_mu(params);
60 model.global_diffusivity_tensor = @(glob,params) ...
61  eval_affine_decomp_general(...
62  @multiscale_diffusivity_tensor_components, ...
63  multiscale_diffusivity_tensor_coefficients, glob,params);
64 model.diffusivity_tensor = @(varargin) ...
65  discrete_volume_values(model.global_diffusivity_tensor,varargin{:});
66 
67 model = elliptic_discrete_model(model);
68 
69 function mu = my_get_mu(model)
70 mu = model.mus;
71 
72 function model = my_set_mu(model,mu)
73 base_mu = mu(model.parameter_mapping);
74 model.base_model = model.base_model.set_mu(model.base_model,base_mu);
75 model.mus = mu;
76 %model = set_mu_default(model,mu);
77 
78 %function [A,b] = my_operators(model,glob)
79 %%model.base_model.decomp_mode = model.decomp_mode;
80 %%[A,b] = model.base_model.operators(model.base_model,glob);
81 %[A,b] = model.operators(model,glob);
82 %if model.decomp_mode == 0
83 % % do nothing
84 %elseif model.decomp_mode == 1
85 % % reduce number of A components
86 % A_comp_new = cell(model.Qa,1);
87 % for q = 1:model.Qa
88 %% A_comp_new{q} = zeros(size(A{q})); % initialize with 0;
89 % A_comp_new{q} = 0*A{q}; % initialize with 0, sparse if required
90 % end;
91 % for q = 1:model.base_Qa
92 % q2 = model.parameter_mapping(q);
93 % A_comp_new{q2} = A_comp_new{q2} + A{q};
94 % end;
95 % A = A_comp_new;
96 %else
97 % % select correct Qa coefficients
98 % A = A(model.parameter_first_ids);
99 %end;
100 
101 function res = multiscale_diffusivity_tensor_components(glob,params)
102 % diffusion tensor: each row four entries a11,a_21,a_12,a_22.
103 % a11(x)=a22(x) = mu_i if x in block i, a12=a21 = 0.
104 % for each point in glob find global block number
105 % xi: range 0 ... B1-1
106 xi = floor(glob(:,1)*params.B1);
107 i = find(xi>=params.B1);
108 if ~isempty(i)
109  xi(i) = params.B1-1;
110 end;
111 % xi: range 0 ... B1-1
112 yi = floor(glob(:,2)*params.B2);
113 i = find(yi>=params.B2);
114 if ~isempty(i);
115  yi(i) = params.B2-1;
116 end;
117 block_index = yi*params.B1+xi+1;
118 mu_index = params.parameter_mapping(block_index);
119 zeroblock = zeros(size(glob,1),4);
120 %res = cell(1,params.number_of_blocks);
121 res = cell(1,params.Qa);
122 %for q = 1:params.number_of_blocks;
123 for q = 1:params.Qa;
124  block = zeroblock;
125  i = find(mu_index==q);
126  if ~isempty(i)
127  block(i,1) = 1;
128  block(i,4) = 1;
129  end;
130  res{q} = block;
131 end;
function demo_rb_gui(varargin)
reduced basis demo with sliders
Definition: demo_rb_gui.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 res = discrete_volume_values(func, varargin)
Convert a volume function with global evaluation to local evaluation.
function model = thermalblock_model(params)
Thermal Block example similar as described in the book of A.T. patera and G. Rozza (just one paramete...
function res = thermalblock(step, params)
thermalblock example
Definition: thermalblock.m:17