rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
disc_init_values.m
1 function res = disc_init_values(model,model_data)
2 %function res = disc_init_values(model,model_data)
3 %
4 % function computing the init-value discrete function by
5 % l2projection of the init value function on the discrete function space
6 %
7 % in 'complete' mode a singe discrete function is produced,
8 % in 'components' mode, it is a cell array of discrete functions
9 % in 'coefficients' mode it is a vector of coefficients.
10 
11 % Bernard Haasdonk 22.7.2006
12 
13 if nargin ~= 2
14  error('wrong number of parameters!');
15 end;
16 
17 % affine decomposition is supported by init_data, so automatically
18 % satisfied.
19 
20 decomp_mode = model.decomp_mode;
21 
22 if decomp_mode == 2 % = coefficients
23  res = model.init_values_ptr([],model);
24 elseif decomp_mode == 1 % = components
25  % idea for improvement: method l2_project sequence: integration of a sequence
26  % of functions
27 
28  % the following is an expensive workaround
29  params = model;
30  params.nelements = model_data.grid.nelements;
31  params.pdeg = model.pdeg;
32  % determine dimrange
33  tmp = model.init_values_ptr([0,0],model);
34  params.dimrange = size(tmp{1},1); % possibly vectorial function
35 
36  Q_u0 = length(tmp);
37  res = cell(1,Q_u0);
38  for q = 1:Q_u0
39  params.single_comp_index = q;
40  f = @(einds,loc,grid,params) get_single_comp(...
41  model.init_values_ptr(...
42  local2global(grid,einds,loc,params),...
43  params),...
44  params);
45  res{q} = model.l2project(f,model.init_values_qdeg,model_data.grid, ...
46  params);
47  end;
48 
49 else % decomp_mode = 0 == complete
50  params = model;
51  params.nelements = model_data.grid.nelements;
52  params.pdeg = model.pdeg;
53  % determine dimrange
54  tmp = model.init_values_ptr([0,0],model);
55  params.dimrange = size(tmp,1); % possibly vectorial function
56  % f = @(einds,loc,grid,params) model.init_values_ptr(...
57  % local2global(grid,einds,loc,params),params);
58  f = @my_f;
59  res = model.l2project(f, model.init_values_qdeg, model_data.grid, ...
60  params);
61 end;
62 
63 % extract single array from cell array
64 function res = get_single_comp(cellarr,params)
65 res = cellarr{params.single_comp_index};
66 
67 function res = my_f(einds,loc,grid,params)
68  res = params.init_values_ptr(local2global(grid,einds,loc,params),params);
69