rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
DetailedData.m
1 classdef DetailedData < Greedy.User.IDetailedData
2  % class generating the reduced basis space for the LinEvol problem with a
3  % Greedy algorithm.
4  %
5  % Parameters given by the constructor argument 'bg_descr'
6  % can control the
7  % - trainings sample (#train_sample_mode, #train_num_intervals, #train_seed)
8  % - trainings sample refinement (#refinement_mode, #max_refinement_level,
9  % #refinement_theta, #val_size, #val_seed, #stop_max_val_train_ratio)
10  % - general EI extension controls (#noof_ei_extensions) and
11  % - general greedy controls (#stop_Nmax, #stop_Mmax, #stop_timeout,
12  % #stop_epsilon, #stop_max_val_train_ratio)
13 
14  properties (Dependent, SetAccess=private)
15  % a basis generation algorithm of type Greedy.Interface used to generated
16  % the reduced basis space.
17  bg_algorithm;
18  end
19 
20  properties (Access=private)
21  rb_generator;
22 
23  ei_generators = {};
24  end
25 
26  properties
27  % flag indicating whether the parameter sampling for the training set
28  % `M_{\text{train}}` type.
29  %
30  % Possible values:
31  % - 'uniform': (default) for a ParameterSampling.Uniform
32  % - 'random': for a ParameterSampling.Random
33  % - 'single': constructs a basis from a single trajectory of solution
34  % snapshots (cog of parameter sampling set).
35  train_sample_mode = 'uniform';
36 
37  % number of intervals in the ParameterSampling.Uniform respectively number
38  % of vectors in the ParameterSampling.Random for the training set
39  % `M_{\text{train}}` of the parameter space `{\cal M}`.
40  train_num_intervals = 3;
41 
42  % If 'train_sample_mode == random', a ParameterSampling.Random is generated
43  % for the training set `M_{\text{val}}` with size #train_num_intervals and
44  % seed 'train_seed'.
45  train_seed = 4321;
46 
48  %
49  % Possible values are:
50  % - 'uniform': the parameter sampling is refined uniformly
51  % - 'adaptive': the parameter sampling is refined adaptively, such that
52  % only regions of the parameter space with high estimated
53  % errors are refined.
54  % - 'none': no Greedy.TrainingSetAdaptation object is created
55  refinement_mode = 'adaptive';
56 
58  %
60  max_refinement_level = 5;
61 
63  %
65  refinement_theta = 0.2;
66 
67  % If this value is non-zero, a ParameterSampling.Random is generated for the
68  % validation set `M_{\text{val}}` with size #val_size and seed #val_seed.
69  val_size = 10;
70 
71  % If the value of 'val_size' is non-zero, a ParameterSampling.Random is
72  % generated for the validation set `M_{\text{val}}` with size #val_size
73  % and seed 'val_seed'.
74  val_seed = 1234;
75 
76  % sets the Greedy.Plugin.EI.stop_Mmax option
77  stop_Mmax = 200;
78 
79  % sets the Greedy.Plugin.PODEI.stop_Nmax option
80  stop_Nmax = 50;
81 
82  % sets the Greedy.Algorithm.stop_epsilon option
83  stop_epsilon = 1e-5;
84 
86  stop_max_val_train_ratio = 1.2;
87 
88  % sets the Greedy.Algorithm.stop_timeout option
89  stop_timeout = 12*60*60;
90 
91  % sets the number of ei extensions
92  %
93  % See Greedy.Plugin.EI.noof_ei_extensions for details.
94  noof_ei_extensions = 1;
95 
96  pca = false;
97  end
98 
99  methods
100  function dd = DetailedData(rmodel, model_data, checkpoint)
101  % function dd = DetailedData(rmodel, model_data)
102  % constructor constructing the reduced basis spaces and storing it in a
103  % DataTree.
104  %
105  % Parameters:
106  % rmodel: of type LinEvol.ReducedModel
107 
108  if nargin == 2
109  checkpoint = [];
110  end
111 
112  dd = dd@Greedy.User.IDetailedData(rmodel.bg_descr, model_data);
113 
114  dd.rb_generator = SnapshotsGenerator.Trajectories(rmodel.detailed_model);
115 
116  dmodel = rmodel.detailed_model;
117  descr = dmodel.descr;
118 
119  Lsat_ei_gen = SnapshotsGenerator.SpaceOpEvals(dmodel, 'L_saturation', ...
120  dd.rb_generator, descr.L_saturation);
121  Lvel_ei_gen = SnapshotsGenerator.SpaceOpEvals(dmodel, 'L_velocity', ...
122  dd.rb_generator, descr.L_velocity);
123 
124  Ldiv_rb_gen = SnapshotsGenerator.SpaceOpEvals(dmodel, 'L_divergence', ...
125  dd.rb_generator, descr.L_divergence);
126  dd.ei_generators = { Lsat_ei_gen, Lvel_ei_gen, Ldiv_rb_gen };
128  if isequal(dd.train_sample_mode, 'single_deim')
129  dd.datatree = gen_single_deim_detailed_data(dd, rmodel, model_data, checkpoint);
130  elseif isequal(dd.train_sample_mode, 'single')
131  dd.datatree = gen_single_detailed_data(dd, rmodel, model_data, checkpoint);
132  else
133  error('no basis generation algorithm for RB implemented yet, use train_sample_mode = {single_deim, single}!');
134 % dd.datatree = gen_detailed_data(dd.bg_algorithm, rmodel, model_data, checkpoint);
135  end
136  end
137 
138  end
139 
140  methods
141 
142  function datatree = gen_single_deim_detailed_data(this, rmodel, model_data, checkpoint)
143  if nargin <=3 || isempty(checkpoint)
144  [ei_dd_map, checkpoint] = Greedy.Checkpoint.restore_latest_if_available(rmodel, 'ei_data');
145  else
146  ei_dd_map = restore_detailed_data(checkpoint, rmodel);
147  end
148 
149  M_train = ParameterSampling.Single;
150  M_train.init_sample(rmodel.detailed_model);
151 
152  set_mu(rmodel, M_train.sample(end,:));
153 
154 
155  end
156 
157  function datatree = gen_single_detailed_data(this, rmodel, model_data, checkpoint)
158 
159  % M_train = ParameterSampling.Uniform(10);
160 
161  if nargin <=3 || isempty(checkpoint)
162  [ei_dd_map, checkpoint] = Greedy.Checkpoint.restore_latest_if_available(rmodel, 'ei_data');
163  else
164  ei_dd_map = restore_detailed_data(checkpoint, rmodel);
165  end
166 
167  M_train = ParameterSampling.Single;
168  M_train.init_sample(rmodel.detailed_model);
169 
170  set_mu(rmodel, M_train.sample(end,:));
171 
172  if ~get(checkpoint, 'ei_generated', false)
173  ei_plugin_sat = Greedy.Plugin.EI(this.ei_generators{1});
174  ei_plugin_vel = Greedy.Plugin.EI(this.ei_generators{2});
175  ei_plugin_sat.ei_target_error = 'interpol';
176  ei_plugin_vel.ei_target_error = 'interpol';
177  ei_greedy_sat = Greedy.Algorithm(ei_plugin_sat, M_train, []);
178  ei_greedy_vel = Greedy.Algorithm(ei_plugin_vel, M_train, []);
179  ei_greedy_sat.stop_epsilon = 1e-7;
180  ei_greedy_vel.stop_epsilon = 1e-7;
181 
182  ei_dd_vel = gen_detailed_data(ei_greedy_vel, rmodel, model_data);
183  ei_dd_sat = gen_detailed_data(ei_greedy_sat, rmodel, model_data);
184 
185  ei_dd_map = Greedy.DataTree.Detailed.IdMapNode({'L_saturation', 'L_velocity'});
186  set(ei_dd_map, 1, ei_dd_sat);
187  set(ei_dd_map, 2, ei_dd_vel);
188  end
189  checkpoint.store(rmodel, ei_dd_map, 'ei_data', struct('ei_generated', true));
190 
191  disp(num2str(get_mu(rmodel)));
192  [sim_data, tictoc] = this.rb_generator.generate(rmodel.detailed_model, model_data);
193  [Pdiv, tictoc] = this.ei_generators{3}.generate(rmodel.detailed_model, model_data);
194 
195 % RBS = sim_data.S;
196 % RBU = sim_data.U(:,2:end);
197 % RBP = Pdiv;
198 
199  if this.pca
200  RBS = PCA_fixspace([sim_data.S], [], model_data.W, inf, 'qr', 1e-7);
201  RBU = PCA_fixspace([sim_data.U], [], model_data.diamondWinv, inf, 'qr', 1e-6);
202  RBP = PCA_fixspace([sim_data.P, Pdiv], [], model_data.W, inf, 'qr', 1e-6);
203  else
204  RBS = orthonormalize_qr([sim_data.S], model_data.W, 1e-6);
205  RBU = orthonormalize_qr([sim_data.U], model_data.diamondWinv, 1e-6);
206  RBP = orthonormalize_qr([sim_data.P, Pdiv], model_data.W, 1e-6);
207  end
208 
209  rb_dd_sat = Greedy.DataTree.Detailed.RBLeafNode(model_data, 'saturation');
210  rb_dd_vel = Greedy.DataTree.Detailed.RBLeafNode(model_data, 'velocity');
211  rb_dd_prs = Greedy.DataTree.Detailed.RBLeafNode(model_data, 'pressure');
212 % rb_dd_sat.RB = [ei_dd_sat.QM, PCA_fixspace(sim_data.S(:,1), ei_dd_sat.QM, model_data.W, inf, 'qr')];
213 % rb_dd_vel.RB = ei_dd_vel.QM;
214  rb_dd_sat.RB = RBS;
215  rb_dd_vel.RB = RBU;
216  rb_dd_prs.RB = RBP;
217 
218  rb_dd_map = Greedy.DataTree.Detailed.IdMapNode({'saturation', 'velocity', 'pressure'});
219  set(rb_dd_map, 1, rb_dd_sat);
220  set(rb_dd_map, 2, rb_dd_vel);
221  set(rb_dd_map, 3, rb_dd_prs);
222 
223  datatree = TwoPhaseFlow.DetailedLeafNode(model_data);
224  datatree.ei = ei_dd_map;
225  datatree.rb = rb_dd_map;
226 
227  rmodel.N = create_tree(rb_dd_map, DataTree.ScalarCreator(@(X) get_rb_size(X)));
228  rmodel.M = create_tree(ei_dd_map, DataTree.ScalarCreator(@(X) get_ei_size(X)));
229  end
230 
231  function basis_gen = get.bg_algorithm(this)
232  % generates a default @ref Greedy.Interface "basis generation object" for
233  % linear evolution problems as given by a DetailedModel.
234  %
235  % This function generates a Greedy.Interface implementation, with either
236  % a subsequent generation of empirical interpolation bases spaces for all
237  % operators and a reduced basis space afterwards, @b or a combined
238  % generation of all reduced spaces with the Greedy.Plugin.PODEI variant
239  % of the Greedy.Algorithm.
240  %
241 
242  basis_gen = [];
243  end
244 
245  function rb_size = get_rb_size(this, rmodel)
246  leaf_dd = get_leaf(this, rmodel);
247  rb_size = get_rb_size(leaf_dd);
248  end
249 
250  end
251 end
252 
Interface class for all kind of reduced basis generation algorithms
Definition: Interface.m:18
reduced model for linear evolution problems as given by a LinEvol.DetailedModel.
Definition: ReducedModel.m:18
refinement_mode
string specifying the method type for the adaptation of the parameter sampling. uniform or adaptive ...
IDetailedModel detailed_model
an object which shall be reduced
max_refinement_level
maximum number of refinement levels in the refineable trainings parameter set
Implementation of a SnapshotsGenerator.Cached for reduced basis generation. The generate() method ret...
Definition: Trajectories.m:18
stop_max_val_train_ratio
positive double value specifying the maximum ratio between the maximum error indicator over the valid...
Definition: Algorithm.m:135
refinement_theta
ratio of elements which are refined during an adaptive refinement step
Reduced basis implementation for linear evolution equations.
Parameter sampling sets.
Definition: Interface.m:1
stop_epsilon
double specifying the maximum error indicator for which the basis generation shall be stopped...
Definition: Algorithm.m:115
Implementation of a SnapshotsGenerator.Cached for empirical basis generation. The generate() method r...
Definition: SpaceOpEvals.m:18
stop_timeout
integer specifying the number of seconds after which the basis generation shall be stopped...
Definition: Algorithm.m:125
Parameter sampling class with uniformly distributed parameters in the parameter space.
Definition: Uniform.m:18
descr
The description structure holding information about the analytical parametrized problem and its discr...
an interface specialization for detailed data objects used with the Greedy algorithm.
Definition: IDetailedData.m:19
Interface classes to be implemented by the Greedy.Algorithm user.
Cacheable generators of detailed data snapshots.
Definition: Cached.m:1
class generating the reduced basis space for the LinEvol problem with a Greedy algorithm.
Definition: DetailedData.m:18
Plugin for the Greedy.Algorithm class generating a collateral reduced basis space plus interpolation ...
Definition: EI.m:19
BasisGenDescr bg_descr
a structure defining the basis generation routines and data structures.
Parameter sampling class producing randomly distributed parameter samples in sparameter space ...
Definition: Random.m:18
greedy basis generation extension which adaptively refines the trainings parameter set...
stop_Mmax
maximum number of generated collateral reduced basis vectors.
Definition: EI.m:71
Customizable implementation of an abstract greedy algorithm.
Definition: DuneRBLeafNode.m:1