rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
ReducedData.m
1 classdef ReducedData < IReducedData & DataTree.CreatorDefault
2  % a default reduced data implementation which stores a
3  % @ref .DataTree.INode "data tree" object copying the structure of a
4  % Greedy.User.IDetailedData.datatree as returned by the
5  % @ref Greedy.Interface "greedy algorithm objects".
6  %
7  % This is also a .DataTree.CreatorDefault object which copies the tree
8  % structure of detailed data tree. The user only needs to define how the leaf
9  % elements of this reduced data tree storing the actual reduced matrices and
10  % vectors shall be constructed. Such leaf elements should be derived from
12  %
13  % See also: Greedy.DataTree.Detailed.INode for more details on the
14  % detailed data tree.
15 
16  properties(Dependent, SetAccess=private)
17  % number of reduced basis vectors stored in this data node.
18  N;
19 
20  % number of collateral reduced basis vectors stored in this data node.
21  M;
22 
23  % number of collateral reduced basis vectors used for error estimation.
24  Mstrich;
25  end
26 
27  properties
28  % the actual data tree of type .DataTree.INode
29  %
30  % The leaf elements have are objects of the class type
32  datatree;
33  end
34 
35  properties(Transient, Hidden=true)
36  % struct with transient options for the create_leaf_node() method.
37  create_tree_opts;
38  end
39 
40  methods
41  function rd = ReducedData(rmodel, detailed_data)
42  % function rd = ReducedData(rmodel, detailed_data)
43  % constructor either constructing a reduced data object from a
44  % @ref Greedy.User.IDetailedData "detailed data" object or copying a
45  % @ref Greedy.User.ReducedData "reduced data" object and extracting
46  % smaller reduced vectors and matrices.
47  %
48  % The two possible synopsis for this functions:
49  % -# 'reduced_data = Greeedy.User.ReducedData(rmodel, detailed_data)' and
50  % -# 'rd_subset = Greeedy.User.ReducedData(rmodel, reduced_data)'
51  %
52  % Parameters:
53  % rmodel: an object of type Greedy.User.IReducedModel describing the
54  % reduced numerical scheme.
55  % - For synopsis (1) it defines via the option
56  % @ref IReducedModel.bg_descr "bg_descr.reduced_data_constructor"
57  % the type of the leaf elements in the reduced data tree and
58  % - for synopsis (2) it defines the size of the reduced
59  % matrices and vectors in the copied object by the member
60  % variables @ref IReducedModel.N "N", and in case of
61  % @ref IReducedModel.crb_enabled "enabled empirical interpolation"
62  % also by @ref IReducedModel.M "M" and
63  % @ref IReducedModel.Mstrich "Mstrich".
64  % .
65  % detailed_data: By default, this is a detailed data object of type .Greedy.User.IDetailedData
66  % @b or in case of synposis (2) a
67  % .Greedy.User.ReducedData object to be copied.
68 
69  if nargin == 0
70  error('Greedy.ReducedData constructor two arguments');
71  elseif nargin == 2 && isa(detailed_data, 'IReducedData')
72  copy = detailed_data;
73  fns = properties(copy);
74  fns = setdiff(fns, {'datatree', 'create_tree_opts', 'N', 'M', 'Mstrich'});
75 
76  for i = 1:length(fns)
77  rd.(fns{i}) = copy.(fns{i});
78  end
79  rd.create_tree_opts.rmodel = rmodel;
80  rd.create_tree_opts.mode = 'copy_extract';
81  rd.datatree = create_tree(copy.datatree, rd);
82 
83  elseif nargin == 2
84  fill_data(rd, rmodel, detailed_data);
85  else
86  error('Did not find constructor for your arguments.');
87  end
88  end
89 
90  function subset_reduced_data = extract_reduced_data_subset(this, rmodel)
91  % function subset_reduced_data = extract_reduced_data_subset(this, rmodel)
92  % @copybrief .IReducedData.extract_reduced_data_subset()
93  %
94  % @copydetails .IReducedData.extract_reduced_data_subset()
95  %
96  % Parameters:
97  % rmodel: of type .Greedy.User.ReducedData
98  %
99  % Return values:
100  % subset_reduced_data: a copy of type Greedy.User.ReducedData of
101  % this object with (possibly) smaller reduced matrices and
102  % vectors. If the reduced magnitudes are unchanged, the
103  % leaf elements are not copied but are references to the
104  % original leafs.
105 
106  subset_reduced_data = Greedy.User.ReducedData(rmodel, this);
107  end
109  function conds = get_conds(this)
110  warning('RBmatlab:Greedy:general', 'You should call get_conds on a leaf of the reduced data tree');
111  conds = [];
112  end
113 
114  function reduced_data_leaf = get_leaf(this, rmodel)
115  % function reduced_data_leaf = get_leaf(this, rmodel)
116  % returns the @ref .Greedy.User::IReducedDataNode "reduced data tree leaf node"
117  % for a specific combination of parameters and time indices given by the
118  % @ref ::IReducedModel "reduced model".
119  %
120  % Parameters:
121  % rmodel: of type .Greedy.User::IReducedModel
122  %
123  % Return values:
124  % reduced_data_leaf: object of type .Greedy.User::IReducedDataNode which
125  % actually stores the reduced vectors and matrices
126  % needed for online simulations.
127 
128  dmodel = rmodel.detailed_model;
129 
130  if isfield(dmodel.descr, 'nt')
131  nt = dmodel.descr.nt;
132  else
133  nt = [];
134  end
135 
136  reduced_data_leaf = get_by_description(this.datatree, [], get_mu(rmodel), nt);
137  end
138 
139  end
140 
141  methods
142 
143  function node = create_leaf_node(this, arg_node, basepath, mu_cube, tslice)
144  % function create_leaf_node(this, arg_node, basepath, mu_cube, tslice)
145  % This creates the actual reduced data leafs implementing the
146  % .Greedy.User::IReducedDataNode interface.
147  %
148  % @copydetails .DataTree.ICreator.create_leaf_node()
149  %
150  % Return values:
151  % node: of type .Greedy.User::IReducedDataNode
152  %
153  % @note The 'arg_node' argument can be either a
154  % .Greedy.User::IDetailedData implementation @b or a
155  % .Greedy.User::IReducedDataNode object. (c.f.
156  % @ref Greedy.User::ReducedDataReducedData() "constructor description"
157  % for more information on these two variants)
158 
159  rmodel = this.create_tree_opts.rmodel;
160  % NOTE: detailed_data can also be a reduced data node... In this case,
161  % the mode should be 'copy_extract'
162  if isequal(this.create_tree_opts.mode, 'copy_extract') ...
163  && ~needs_subset_copy(arg_node, rmodel)
164  node = arg_node;
165  else
166  node = rmodel.bg_descr.reduced_data_constructor(rmodel, arg_node);
167  end
168  end
169 
170  function N = get.N(this)
171 
172  N = this.datatree.N;
173  end
174 
175  function M = get.M(this)
176 
177  M = this.datatree.M;
178  end
179 
180  function Mstrich = get.Mstrich(this)
182  Mstrich = this.datatree.Mstrich;
183  end
184 
185 
186  end
187 
188  methods (Access = protected)
189  function fill_data(this, rmodel, detailed_data)
190  % function fill_data(this, rmodel, detailed_data)
191  % defines how the #datatree member is being filled with data.
192  %
193  % If not overwritten, this method copies the tree structure of the given
194  % detailed data object and computes the reduced matrices and vectors in
195  % the leaf elements.
196  %
197  % @note The second arguments does not need to wrap a detailed data tree,
198  % as the .Greedy.User.IDetailedData objects do. If no tree is given, a
199  % reduced data tree with only a root element is created.
200  %
201  % Parameters:
202  % rmodel: of type .Greedy.User.IReducedModel
203  %
204  % Optional fields of detailed_data:
205  % datatree: @copybrief .Greedy.User.IDetailedData.datatree
206 
207  this.create_tree_opts.rmodel = rmodel;
208  this.create_tree_opts.mode = 'normal';
209 
210  if isa(detailed_data, 'Greedy.User.IDetailedData')
211  dd = detailed_data.datatree;
212  if isa(dd, 'Greedy.DataTree.Detailed.IdMapNode')
213  dd = get_by_description(dd, 'rb');
214  end
215  this.datatree = create_tree(dd, this);
216  else
217  this.datatree = create_leaf_node(this, detailed_data);
218  end
219 
220  end
221  end
222 
223 end