2 %
class generating the reduced basis space for the
LinEvol problem with a
5 % Parameters given by the constructor argument
'bg_descr'
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)
14 properties (Dependent, SetAccess=
private)
15 % a basis generation algorithm of type
Greedy.
Interface used to generated
16 % the reduced basis space.
20 properties (Access=
private)
27 % flag indicating whether the parameter sampling
for the training set
28 % `M_{\text{train}}` type.
33 % -
'single': constructs a basis from a single trajectory of solution
34 % snapshots (cog of parameter sampling set).
35 train_sample_mode =
'uniform';
39 % `M_{\text{train}}` of the parameter space `{\cal M}`.
40 train_num_intervals = 3;
43 %
for the training set `M_{\text{val}}` with size #train_num_intervals and
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
55 refinement_mode =
'adaptive';
60 max_refinement_level = 5;
65 refinement_theta = 0.2;
68 % validation set `M_{\text{val}}` with size #val_size and seed #val_seed.
72 % generated
for the validation set `M_{\text{val}}` with size #val_size
73 % and seed
'val_seed'.
79 % sets the Greedy.Plugin.PODEI.stop_Nmax option
86 stop_max_val_train_ratio = 1.2;
89 stop_timeout = 12*60*60;
91 % sets the number of ei extensions
94 noof_ei_extensions = 1;
102 % constructor constructing the reduced basis spaces and storing it in a
117 descr = dmodel.
descr;
120 dd.rb_generator, descr.L_saturation);
122 dd.rb_generator, descr.L_velocity);
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);
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);
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
');
146 ei_dd_map = restore_detailed_data(checkpoint, rmodel);
149 M_train = ParameterSampling.Single;
150 M_train.init_sample(rmodel.detailed_model);
152 set_mu(rmodel, M_train.sample(end,:));
157 function datatree = gen_single_detailed_data(this, rmodel, model_data, checkpoint)
159 % M_train = ParameterSampling.Uniform(10);
161 if nargin <=3 || isempty(checkpoint)
162 [ei_dd_map, checkpoint] = Greedy.Checkpoint.restore_latest_if_available(rmodel, 'ei_data
');
164 ei_dd_map = restore_detailed_data(checkpoint, rmodel);
167 M_train = ParameterSampling.Single;
168 M_train.init_sample(rmodel.detailed_model);
170 set_mu(rmodel, M_train.sample(end,:));
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;
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);
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);
189 checkpoint.store(rmodel, ei_dd_map, 'ei_data
', struct('ei_generated
', true));
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);
196 % RBU = sim_data.U(:,2:end);
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);
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);
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;
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);
223 datatree = TwoPhaseFlow.DetailedLeafNode(model_data);
224 datatree.ei = ei_dd_map;
225 datatree.rb = rb_dd_map;
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)));
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.
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.
245 function rb_size = get_rb_size(this, rmodel)
246 leaf_dd = get_leaf(this, rmodel);
247 rb_size = get_rb_size(leaf_dd);
Interface class for all kind of reduced basis generation algorithms
reduced model for linear evolution problems as given by a LinEvol.DetailedModel.
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...
stop_max_val_train_ratio
positive double value specifying the maximum ratio between the maximum error indicator over the valid...
refinement_theta
ratio of elements which are refined during an adaptive refinement step
Reduced basis implementation for linear evolution equations.
stop_epsilon
double specifying the maximum error indicator for which the basis generation shall be stopped...
Implementation of a SnapshotsGenerator.Cached for empirical basis generation. The generate() method r...
stop_timeout
integer specifying the number of seconds after which the basis generation shall be stopped...
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.
Interface classes to be implemented by the Greedy.Algorithm user.
Cacheable generators of detailed data snapshots.
class generating the reduced basis space for the LinEvol problem with a Greedy algorithm.
Plugin for the Greedy.Algorithm class generating a collateral reduced basis space plus interpolation ...
BasisGenDescr bg_descr
a structure defining the basis generation routines and data structures.
Parameter sampling class producing randomly distributed parameter samples in sparameter space ...
greedy basis generation extension which adaptively refines the trainings parameter set...
stop_Mmax
maximum number of generated collateral reduced basis vectors.
Customizable implementation of an abstract greedy algorithm.