rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
INode.m
1 classdef INode < DataTree.INode & Greedy.DataTree.Info
2  % %Interface class for general data tree nodes storing detailed data returned
3  % by Greedy.Interface.gen_detailed_data()
4  %
5  % Usually every Greedy.Interface instance creates a new node in the detailed
6  % data tree with new reduced basis functions or a logging information about
7  % the steps taken by the Greedy.Interface node.
8 
9 
10  properties
11 
12  % storage of history entries (c.f. snapshot() and format_snapshot() )
13  history;
14 
15  end
16 
17  properties (Access = private)
18 
19  history_ids = struct('id', {}, 'id_descr', {}, 'map', []);
20 
21  end
22 
23  methods
24 
25  function set_rb(this, RB)
26  % function set_rb(this, RB)
27  % sets the reduced basis space
28  %
29  % @todo is this correct or should it be in a specialization?
30  this.RB = RB;
31  end
32 
33  function RB = get_rb(this)
34  % function set_rb(this, RB)
35  % returns the reduced basis space
36  %
37  % @todo is this correct or should it be in a specialization?
38  RB = this.RB;
39  end
40 
41 
42 % function data = get_by_description(this, id, dmodel)
43 % % function data = get_by_description(this, id, model)
44 % % returns a leaf in the DataTree for a specific ID, parameter and time instant.
45 % %
46 % % Parameters:
47 % % dmodel: of type Greedy.User.IDetailedModel
48 % % id: a string specifying an optional ID restriction. (default = empty)
49 % %
50 % % Return values:
51 % % data: leaf element of type Greedy.DataTree.Detailed.ILeafNode.
52 % %
54 
55 % if nargin == 2
56 % mu = [];
57 % nt = [];
58 % else
59 % mu = get_mu(dmodel);
60 % nt = dmodel.descr.nt;
61 % end
62 % data = get_by_description@DataTree.INode(this, id, mu, nt);
63 % end
64 
65  function snapshot(this, id, id_text, snapshot_description)
66  % function snapshot(this, id, id_text, snapshot_description)
67  % creates a copy of the Greedy.Info element of the subtree rooted by this
68  % node and stores it in a history.
69  %
70  % The history is organized by short ID strings to whom a longer
71  % description text should be attached. Furthermore every history entry
72  % can be decribed by a Matlab struct. A Date tag is added automatically.
73  %
74  % A use-case for this feature is the Greedy.TrainingSetAdaptation class
75  % which refines the training parameter space several times. At all these
76  % time instants it creates a new history entry.
77  %
78  % Parameters:
79  % id: the id string under which the history entry shall be stored.
80  % id_text: a descriptive text for the id. This is only used at the
81  % first time a history entry for the 'id' is created.
82  % snapshot_description: a description of the history entry with
83  % arbitrary content.
84  [dummy, index] = intersect({this.history_ids.id}, id);
85  hist_index = length(this.history) + 1;
86  if isempty(index)
87  index = length(this.history_ids) + 1;
88  this.history_ids(index).id = id;
89  this.history_ids(index).map = hist_index;
90  else
91  this.history_ids(index).map = [this.history_ids(index).map, hist_index];
92  end
93 
94  if ~isempty(id_text)
95  this.history_ids(index).id_descr = id_text;
96  end
97 
98  dates = datestr(clock, 'dd.mm.yyyy HH:MM');
99 
100  if ~isempty(this.fields) || ~isempty(this.stop_flags)
101  this.history{hist_index}.description = snapshot_description;
102  this.history{hist_index}.date = dates;
103  if ~isempty(this.fields)
104  this.history{hist_index}.fields = this.fields;
105  end
106  if ~isempty(this.stop_flags)
107  this.history{hist_index}.stop_flags = this.stop_flags;
108  end
109  end
110 
111  snapshot_children(this, id, id_text, snapshot_description);
112  end
113 
114  function sl = get_snapshot_length(this, id)
115  % function sl = get_snapshot_length(this, id)
116  % returns the number of history entries stored for a specific id.
117  %
118  % Parameters:
119  % id: history ID
120  %
121  % Return values:
122  % sl: number of history entries
123  [dummy, index] = intersect(this.history_ids.id, id);
124  if isempty(index)
125  sl = 0;
126  else
127  sl = length(this.history_ids.id{index});
128  end
129  end
130 
131  function fs = format_snapshot(this, id, indices)
132  % function fs = format_snapshot(this, id, indices)
133  % retuns a formatted structure of a history item for several indices
134  %
135  % @todo: rewrite
136  [dummy, index] = intersect({this.history_ids.id}, id);
137  if isempty(index)
138  fs = '';
139  return;
140  end
141  if nargin == 2 || isempty(indices)
142  indices = 1:length(this.history_ids(index).map);
143  end
144 
145  fs.id = id;
146  fs.descr = this.history_ids(index).id_descr;
147  fs.history = this.history{this.history_ids(index).map(indices)};
148 
149  children = gather_children_format_snapshot(this, id, indices);
150  if ~isempty(children)
151  fs.children = children;
152  end
153  end
154 
155  end
156 
157  methods(Access = protected)
158 
159  function snapshot_children(this, id, id_text, snapshot_description)
160  % function snapshot_children(this, id, id_text, snapshot_description)
161  % forward the snapshot generation to the children
162  for i = 1:length(this)
163  snapshot_children(get(this, i), id, id_text, snapshot_description);
164  end
165  end
166 
167  function children = gather_children_format_snapshot(this, id, indices)
168  % function children = gather_children_format_snapshot(this, id, indices)
169  % helper function called by format_snapshot()
170  children = cell(1, length(this));
171  for i = 1:length(this)
172  children{i} = gather_children_format_snapshot(get(this, i), id, indices);
173  end
174  end
175  end
176 
177  methods (Abstract)
178 
179  % function siz = get_rb_size(this);
180  % returns the size of the reduced basis stored in this tree.
181  %
182  % Return values:
183  % siz: dimension of stored reduced basis space `{\cal W}_{\text{red}}`
184  siz = get_rb_size(this);
185 
186  % function siz = get_ei_size(this);
187  % returns the size of the collateral reduced basis stored in this tree.
188  %
189  % Return values:
190  % siz: a tree of nodes which are objects of type DataTree.IdMapNode
191  % of stored collateral reduced basis spaces `{\cal W}^{{\cal
192  % L}_h}_{\text{red}}` for operators `{\cal L}_h`
193  siz = get_ei_size(this);
194 
195  % function [ot1, ot2, ot3] = offtime(this, rmodel)
196  % returns up to three different offline time measurements
197  [ot1, ot2, ot3] = offtime(this, rmodel);
198  end
200 end