rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups 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' of type
6  % BasisGenDescr can control the
7  % - trainings sample (#train_sample_mode, #train_num_intervals, #train_seed)
8  % - trainings sample refinement (#refinement_mode, #val_size, #val_seed,
9  % #stop_max_val_train_ratio)
10  % - the error indicator (#indicator_mode)
11  % - general greedy controls (#Nmax, #stop_timeout, #stop_epsilon)
12 
13  properties (Dependent, SetAccess=private)
14  % a basis generation algorithm of type Greedy.Interface used to generated
15  % the reduced basis space.
16  bg_algorithm;
17  end
18 
19  properties (Access=private)
20  rb_generator;
21  end
22 
23  properties
24 
25  % flag indicating whether the parameter sampling for the training set
26  % `M_{\text{train}}` type.
27  %
28  % Possible values:
29  % - 'uniform': (default) for a ParameterSampling.Uniform
30  % - 'random': for a ParameterSampling.Random
31  train_sample_mode = 'uniform';
32 
33  % number of intervals in the ParameterSampling.Uniform for the training
34  % set `M_{\text{train}}` of the parameter space `{\cal M}`.
35  train_num_intervals = 3;
36 
37  % If 'train_sample_mode == random', a ParameterSampling.Random is generated
38  % for the training set `M_{\text{val}}` with size 'train_num_intervals' and
39  % seed 'train_seed'.
40  train_seed = 1234;
41 
42  % If this value is non-zero, a ParameterSampling.Random is generated for the
43  % validation set `M_{\text{val}}` with size 'val_size' and seed 'val_seed'.
44  val_size = 100;
45 
46  % If the value of 'val_size' is non-zero, a ParameterSampling.Random is
47  % generated for the validation set `M_{\text{val}}` with size 'val_size'
48  % and seed 'val_seed'.
49  val_seed = 1234;
50 
51  % @copybrief Greedy.Plugin.POD.stop_Nmax
52  Nmax = 20;
53 
54  % error indicator used for the Greedy.Plugin.POD algorithm.
55  %
57  indicator_mode = 'estimator';
58 
60  stop_timeout = 60*60;
61 
63  stop_epsilon = 1e-9;
64 
66  %
67  % If this value is set to something less than 'inf', parameter sampling
68  % adaptation should be activated, by setting the 'refinement_mode' to
69  % 'adaptive' or 'uniform'.
70  stop_max_val_train_ratio = 1;
71 
73  %
74  % Possible values are:
75  % - 'uniform': the parameter sampling is refined uniformly
76  % - 'adaptive': the parameter sampling is refined adaptively, such that
77  % only regions of the parameter space with high estimated
78  % errors are refined.
79  % - 'none': no Greedy.TrainingSetAdaptation object is created
80  refinement_mode = 'adaptive';
81 
82  dune_mode = false;
83  end
84 
85  methods
86  function dd = DetailedData(rmodel, model_data)
87  % function dd = DetailedData(rmodel, model_data)
88  % constructor constructing the reduced basis spaces and storing it in a
89  % DataTree.
90  %
91  % Parameters:
92  % rmodel: of type LinEvol.ReducedModel
93 
94  dd = dd@Greedy.User.IDetailedData(rmodel.bg_descr, model_data);
95 
96  dd.rb_generator = SnapshotsGenerator.Trajectories(rmodel.detailed_model);
97 
98  if isa(rmodel, 'LinEvolDune.ReducedModel')
99  dd.dune_mode = true;
100  end
101 
102  dd.datatree = gen_detailed_data(dd.bg_algorithm, rmodel, model_data);
103 
104  end
105 
106  end
107 
108  methods
109 
110  function basis_gen = get.bg_algorithm(this)
111  % generates a default @ref Greedy.Interface "basis generation object" for
112  % linear evolution problems as given by a DetailedModel.
113  %
114  % This function generates a Greedy.Interface implementation, with at least
115  % a POD-Greedy extension algorithm for the reduced basis.
116  %
117 
118  if isequal(this.train_sample_mode, 'uniform')
119  M_train = ParameterSampling.Uniform(this.train_num_intervals);
120  elseif isequal(this.train_sample_mode, 'random')
121  M_train = ParameterSampling.Random(this.train_num_intervals, this.train_seed);
122  else
123  error('unknown train_sample_mode');
124  end
125  if this.val_size > 0
126  M_val = ParameterSampling.Random(this.val_size, this.val_seed);
127  else
128  M_val = [];
129  end
130 
131  if this.dune_mode
132  rb_extension = Greedy.Plugin.PODDune(this.rb_generator);
133  else
134  rb_extension = Greedy.Plugin.POD(this.rb_generator);
135  end
136  rb_extension.stop_Nmax = this.Nmax;
137  % decide, whether estimator or true error is error-indicator for greedy
138  rb_extension.indicator_mode = this.indicator_mode; %'estimator'; % Delta from rb_simulation
139 
140  pod_greedy = Greedy.Algorithm(rb_extension, M_train, M_val);
141  pod_greedy.stop_timeout = this.stop_timeout; % 60*60;
142  pod_greedy.stop_epsilon = this.stop_epsilon; % 1e-9; % 0.003 is already realized by init data!!
143  pod_greedy.stop_max_val_train_ratio = this.stop_max_val_train_ratio; % 1.00;
145  if ~isequal(this.refinement_mode, 'none')
146  basis_gen = Greedy.TrainingSetAdaptation(pod_greedy);
147  basis_gen.refinement_mode = this.refinement_mode;
148  else
149  basis_gen = pod_greedy;
150  end
151 
152  end
154  function rb_size = get_rb_size(this, rmodel)
155  leaf_dd = get_leaf(this, rmodel);
156  rb_size = get_rb_size(leaf_dd);
157  end
158 
159  end
160 end