rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
dictionary_gen_detailed_data.m
Go to the documentation of this file.
1 function detailed_data = dictionary_gen_detailed_data(model,model_data)
2 % simply random parameter set and snapshot generation
3 %
4 % B. Haasdonk 5.3.2015
5 
6 tic;
7 sim_data = detailed_simulation(model,model_data);
8 uh = model.get_dofs_from_sim_data(sim_data);
9 ndofs = length(uh);
10 if ~isfield(model,'RB_train_data_mode')
11  model.RB_train_data_mode = 'random';
12 end;
13 
14 detailed_data = model_data;
15 
16 if ~isequal(model.RB_train_data_mode,'offline_greedy')
17  %%%% Lagrangian Dictionary for random or equidistant points
18  if isequal(model.RB_train_data_mode,'random')
19  mus = rand_uniform(model.RB_train_size,model.mu_ranges);
20  elseif isequal(model.RB_train_data_mode,'equidistant')
21  % equidistant
22  mu_dim = length(get_mu(model));
23  mus = zeros(mu_dim, model.RB_train_size);
24  for i=1:mu_dim
25  mu_range = model.mu_ranges{i};
26  mus(i,:) = linspace(mu_range(1),mu_range(2),model.RB_train_size);
27  end;
28  elseif isequal(model.RB_train_data_mode,'points_given')
29  mus = model.Mtrain;
30  else
31  error('RB_train_dat_mode unknown');
32  end;
33  RB = zeros(ndofs,model.RB_train_size);
34  for mui = 1:model.RB_train_size;
35  model = model.set_mu(model,mus(:,mui));
36  sim_data = detailed_simulation(model,model_data);
37  RB(:,mui) = model.get_dofs_from_sim_data(sim_data);
38  fprintf('.');
39  end;
40  fprintf('\n');
41 else
42  %%%%%%%%%%%%%%%%%%%%%%%%% Offline Greedy
43  Mtrain = model.Mtrain;
44  ntrain = size(Mtrain,2);
45  RB = zeros(ndofs,0);
46  Delta_max = [];
47  tmp_detailed_data = model_data;
48  model.decomp_mode = 1; % == components
49  [tmp_detailed_data.A_comp, tmp_detailed_data.f_comp] = ...
50  model.operators(model,detailed_data);
51  tmp_detailed_data.RB = RB;
52  mu_indices = [];
53  mus = zeros(size(Mtrain,1),0);
54  Deltas_max = [];
55 
56  % take first basis vector arbitrary
57  %i0 = 1;
58  %model = set_mu(model,Mtrain(:,i0));
59  %sim_data = detailed_simulation(model,model_data);
60  %RB = [RB,model.get_dofs_from_sim_data(sim_data)];
61  %mus = Mtrain(:,i0);
62  %mu_indices = [i0];
63 
64  reduced_data = gen_reduced_data(model,tmp_detailed_data);
65 
66  for N = 1:model.RB_stop_Nmax;
67  disp(['processing offline greedy extension ',num2str(N)]);
68  Delta_max = 0;
69  for i=1:ntrain;
70  model = set_mu(model,Mtrain(:,i));
71  sim_data = rb_simulation(model,reduced_data);
72  % if res.res_norms(end)>res_max
73  % res_max = res.res_norms(end);
74  % end;
75  Delta = sim_data.Delta;
76  if Delta>Delta_max
77  Delta_max = Delta;
78  i_max = i;
79  end;
80  end;
81  % take snapshot for worst parameter into basis
82  disp(['maximum Delta ',num2str(Delta_max)]);
83  if N>1 & Delta_max > Deltas_max(end)
84  disp('inspect workspace due to non-monotonicity!');
85  keyboard;
86  end;
87  Deltas_max = [Deltas_max, Delta_max];
88  model = model.set_mu(model,Mtrain(:,i_max));
89  mu_indices = [mu_indices, i_max];
90  sim_data = detailed_simulation(model,model_data);
91  RB = [RB,model.get_dofs_from_sim_data(sim_data)];
92  tmp_detailed_data.RB = RB;
93  reduced_data = dictionary_extend_reduced_data(...
94  model,reduced_data,tmp_detailed_data);
95  end; % loop over N
96 % res.hs_res_norms_max = hs_res_norms_max;
97  detailed_data.RB_info.Mtrain = model.Mtrain;
98  detailed_data.RB_info.mu_indices = mu_indices;
99  detailed_data.RB_info.Deltas_max = Deltas_max;
100  %%%%%%%%%%%%%%%%%%%%%%%%% End Offline Greedy
101 end;
102 
103 detailed_data.RB_info.mus = mus;
104 detailed_data.RB_info.time = toc;
105 detailed_data.RB = RB;
106 
function detailed_data = dictionary_gen_detailed_data(model, model_data)
simply random parameter set and snapshot generation
Customizable implementation of an abstract greedy algorithm.
Definition: DuneRBLeafNode.m:1