1 classdef INode < handle
4 % A
DataTree consists of nodes with an arbitrary number of children or
6 % non-leaf nodes can be one of:
7 % - DataTree.IdMapNode,
8 % - DataTree.TpartNode or
9 % - DataTree.PpartNode.
10 % and leaf elements are always of type DataTree.ILeafNode.
12 % Each of these nodes specify information about the data stored in the leaf
15 % Considering e.g. the tree configuration
18 % node [shape=record, fontname=Helvetica, fontsize=10];
19 % nIdMapNode [label="{DataTree.IdMapNode|{implicit|explicit}}"URL="\ref DataTree.IdMapNode"];
20 % nTpartNode [label="{DataTree.TpartNode|{[0:10]|[11:30]|[31:50]}}"URL="\ref DataTree.TpartNode"];
23 % l3 [label="Leaf",color=red];
25 % nIdMapNode -> nTpartNode [label = "1"];
26 % nIdMapNode -> l1 [label = "2"];
27 % nTpartNode -> l2 [label = "[1,1]"];
28 % nTpartNode -> l3 [label = "[1,2]"];
29 % nTpartNode -> l4 [label = "[1,3]"];
32 % the red leaf element is tagged with the id "implicit" and valid inside the
33 % time slice interval `[11,30]`. Children are numbered consecutively and can
34 % be received by using a concatenation of indices. The read leaf element
35 % could for example be reached via
37 % red_leaf = get(idmap_root, [1,2]);
40 % where the index vector is obtainable via a call to the get_index() method
42 % index = get_index(idmap_root, "implicit", [], 23);
45 % There exist generic specializations for DataTrees representing detailed
46 % data (Greedy.DataTree.Detailed.INode, Greedy.DataTree.Detailed.ILeafNode) and reduced data
47 % (Greedy.User.RbReducedDataDefault) which have no extra functionality for non-leaf node
52 % function data = get(this, index);
53 % Access to a child of the current node
55 % Access a children node by an index which is usually retrieved by a call
59 % index: vector describing the father-child relation
62 % data: the children node of type INode
63 data = get(this, index);
65 % function index = get_index(this, id, mu, nt);
66 % Obtains the leaf index vector that best fits the child description given
67 % by the three arguments.
69 % @todo add get_indices method returning indices in a range
71 % The leaf child description consists of an
73 % - a parameter vector and
74 % - a time step number.
77 % id: a string id filtered through an DataTree.IdMapNode in the tree hierarchy.
78 % mu: a parameter vector filtered through a DataTree.PpartNode instance in the
80 % nt: an integer corresponding to a time step index filtered through a
81 % DataTree.TpartNode instance in the tree hierarchy.
84 % index: the most-specific (longest possible) index vector leading to a
85 % DataTree.ILeafNode element matching the child description.
86 index = get_index(this, id, mu, nt);
88 % function tree = create_tree(this, creator, ids, mu_cube, tslice, basepath);
89 % Creates a new tree from a subtree specified by ids, parameter and time index
92 % The method creates a new DataTree for all nodes tagged by an id in
93 % \a ids, lying in the time slice given by \a tslice and inside the
94 % parameter space region given by \a mu_rect. At each of these nodes a
95 % method from a \a creator is called to build the tree.
98 % creator: an object of type DataTree.ICreator creating the new tree.
99 % ids: a cell array of ids which shall be filtered. An empty cell array
100 % means that all ids are accepted. (default = [])
101 % mu_cube: a '1x2
'-cell array of vectors '{ lower_left, upper_right }
'
102 % specifying the lower left and the upper right corner of a cube
103 % in the parameter space for filtering parameter vectors. An
104 % empty array disables the filtering (default = []).
105 % tslice: a 2D vector specifying an interval of time step indices for
106 % time slicing. An empty vector disables the filtering (default =
108 % basepath: a vector specifying the relation of the current node to the
109 % parent node at which the merge began.
112 % tree: the newly created tree of type DataTree.INode
113 tree = create_tree(this, creator, ids, mu_cube, tslice, basepath);
115 % function children = length(this);
116 % Returns the number of children of the node
118 % For leaf elements this method should return 0.
121 % children: the number of childres of the current node
122 children = length(this);
124 % function this = set(this, index, value);
125 % Sets a child at the given path in the tree hierarchy.
127 % Usually this method is used to set a leaf data node with attached data.
130 % index: the path index where the node shall be injected
131 % value: the node that shall be attached as a child
134 % this: the modified DataTree node.
135 this = set(this, index, value);
141 function leaf_func(this, funcptr, ids, mu_cube, tslice)
142 % applies a function to all leafs of a DataTree
145 % funcptr: function handle of the function to be applied to all leaf elements.
146 % ids: ID filter. See create_tree() for details.
147 % mu_cube: parameter filter. See create_tree() for details.
148 % tslice: time filter. See create_tree() for details.
163 create_tree(this, DataTree.NullCreator(funcptr), ids, mu_cube, tslice, basepath);
167 function tree = create_scalar_tree(this, funcptr, ids, mu_cube, tslice)
168 % function tree = create_scalar_tree(this, funcptr, ids, mu_cube, tslice)
169 % copies the current trees with different leafs. These leafs are computes
170 % by a function returning scalar values.
172 % For example, one can extract a field available in all leafs with this
173 % function, like the reduced basis size 'N
' in a reduced data structure.
176 % funcptr: function handle of the function to be applied to all leaf elements.
177 % ids: ID filter. See create_tree() for details.
178 % mu_cube: parameter filter. See create_tree() for details.
179 % tslice: time filter. See create_tree() for details.
192 tree = create_tree(this, DataTree.ScalarCreator(funcptr), ids, mu_cube, tslice, basepath);
195 function start_index = traverse_start(this)
196 % function start_index = traverse_start(this)
197 % Start iterator for a full traverse of the DataTree.
199 % Use this method to get a start index for a tree traversal.
200 % Subsequently, indices can be obtained by calls to traverse_next().
201 % Every node is touched during a traversal, until an empty index is
205 % start_index: the start index vector for tree traversal.
207 start_index = [1, traverse_start(get(this, 1))];
213 function next_index = traverse_next(this, this_index)
214 % function next_index = traverse_next(this, this_index)
215 % iterator for a full traverse of the DataTree.
217 % Use this method to get the next index for a tree traversal.
218 % Every node is touched during a traversal, until an empty index is
222 % this_index: previous index.
225 % next_index: the next index vector for tree traversal. Empty vector
226 % after the last node.
227 if length(this_index) > 1
228 next_index = [this_index(1), traverse_next(get(this, this_index(2)), this_index(2:end))];
229 if length(next_index) > 1
232 this_index = next_index;
235 next_index = [this_index, traverse_start(get(this, 1))];
236 if length(next_index) > 1
239 if this_index < length(this)
240 next_index = this_index + 1;
246 % function first = first_leaf_index(this, ids, mu_cube, tslice)
247 % % function first = first_leaf_index(this)
248 % % returns the first (left-most) index for an iteration of the leafs of the data tree.
250 % % For a full leaf iteration use next_leaf_index().
253 % % first: index of the first leaf element
269 % nextchild_index = get_first_index_match(this, ids, mu_cube, tslice);
270 % if nextchild_index == -1
274 % nextchild = get(this, nextchild_index);
276 % first = nextchild_index;
278 % next_part = first_leaf_index(nextchild, ids, mu_cube, tslice);
279 % first = [nextchild_index, next_part];
287 % function next = next_leaf_index(this, current, ids, mu_cube, tslice)
288 % % function next = next_leaf_index(this, current, ids, mu_cube, time_slice)
289 % % returns indices for a leaf element iteration
291 % % Get the first index with first_leaf_index()
294 % % current: index of last leaf element returned by next_leaf_index()
295 % % respectively first_leaf_index()
298 % % next: index of leaf element right of current.
312 % if isempty(current)
313 % % current is a root and leaf element => no more leafs
317 % % are we _not_ directly above the current leaf?
318 % if length(current) > 1
319 % next_tmp = next_leaf_index(get(this, current(1)), current(2:end-i), ids, mu_cube, tslice);
321 % next = [current(1), next_tmp];
326 % % 2. here we are: all children of current(1) are already iterated or
327 % % current(1) is a leaf, so we can find the next child of 'this'.
329 % % get the next candidate...
330 % nextchild_index = get_first_index_match(this, ids, mu_cube, tslice, current(1));
331 % if nextchild_index == -1
332 % % there is no candidate on this level...
335 % % get the candidate
336 % nextchild = get(this, nextchild_index);
339 % % it is a leaf element
340 % next = nextchild_index;
342 % % another tree, find all its leafs...
343 % next = [ nextchild_index, first_leaf_index(nextchild, ids, mu_cube, tslice) ];
351 % function indices = get_indices(this, ids, mu_cube, tslice)
364 % index = first_leaf_index(this, ids, mu_cube, tslice);
366 % indices = [indices, { index }];
367 % index = next_leaf_index(this, index, ids, mu_cube, tslice);
372 function description = get_active_leaf_description(this, model, ids)
373 % function description = get_active_leaf_description(this, model, ids)
374 % returns an enumeration of all leaves' basepath index vectors with a
375 % description of their parents.
378 % model: a reduced or detailed model of type .IModel holding
379 % information about the selected parameters and maybe the time
381 % ids: ID filter. See create_tree() for details.
383 % Optional fields of model:
384 % descr:
ModelDescr object specifying the problem discretization
385 % descr.t: current time step number
388 if isfield(model.descr, 't')
389 tslice = [model.descr.t, model.descr.t];
391 mu_cube = [get_mu(model), get_mu(model)];
399 function description = get_leaf_description(this, ids, mu_cube, tslice)
400 % function description = get_leaf_description(this, ids, mu_cube, tslice)
401 % returns an enumeration of all leaves' basepath index vectors with a
402 % description of their parents.
405 % ids: ID filter. See create_tree() for details.
406 % mu_cube: parameter filter. See create_tree() for details.
407 % tslice: time filter. See create_tree() for details.
420 description = create_tree(this,
DataTree.LeafDescription, ids, mu_cube, tslice, basepath);
423 % function leaf_func(this, funcptr, ids, mu_cube, time_slices)
425 % leaf_indices = get_indices(this, ids, mu_cube, time_slices);
426 % for i = 1:length(leaf_indices)
427 %
leaf = get(this, leaf_indices(i));
432 function tstop = index_valid_till(this, index)
433 % function tstop = index_valid_till(this, index)
434 % Returns the last valid time step index of a time slice
436 % This method can be used to obtain the last time slice index for the
437 % node given by 'get(this, index)'
440 % index: the index vector of the child for which the time slice shall be
444 % tstop: last valid time step index
446 tstop = index_valid_till(get(this, index(1)), index(2:end));
452 function data = get_by_description(this,
id, mu, nt)
453 % function data = get_by_description(this,
id, mu, nt)
454 % A combination of get_index() and get()
456 % This methods gets the child node described by \a
id, \a mu and \a nt.
462 % nt: an integer corresponding to a time step index filtered through a
466 % data: the children node of type
INode
474 data = get(this, get_index(this,
id, mu, nt));
477 function active_leaf_index = get_active_leaf_index(this, model,
id)
478 % function active_leaf_index = get_active_leaf_index(this, model[,
id])
479 % retuns the leaf element index for the current
IDetailedModel configuration.
482 % model: a reduced or detailed model of type ::
IModel holding
483 % information about the selected parameters and maybe the time
485 %
id: optional parameter defining a special ID that shall be
486 % attached to the leaf element.
489 % active_leaf_index: leaf element index to be returned.
491 % Optional fields of model:
492 % descr:
ModelDescr object specifying the problem discretization
493 % descr.t: current time step number
495 % @todo rename this method to get_leaf_index
497 if isfield(model.descr, 't')
503 active_leaf_index = get_by_description(this,
id, get_mu(model), nt);
506 function active_leaf = get_active_leaf(this, model,
id)
507 % function active_leaf = get_active_leaf(this, model[,
id])
508 % retuns the leaf element for the current
IDetailedModel configuration.
511 % model: a reduced or detailed model of type ::
IModel holding
512 % information about the selected parameters and maybe the time
514 %
id: optional parameter defining a special ID that shall be
515 % attached to the leaf element.
518 % active_leaf: leaf element of type ::
DataTreeLeafNode to be
521 % Optional fields of model:
522 % descr:
ModelDescr object specifying the problem discretization
523 % descr.t: current time step number
525 % @todo rename this method to get_leaf
528 if isfield(model.descr, 't')
534 active_leaf = get_active_leaf(get_by_description(this,
id, get_mu(model), nt), model);
537 function display(this, fn, basepath, name)
538 % function display(this, fn, basepath, name)
539 % overwrites the standard display method for
DataTree objects
542 % fn: Optional filename under which a dot-file depicting the tree
543 % structure is stored.
544 % basepath: only used in recursive calls of this method
545 % name: only used in recursive calls of this method
555 lines = disp_node(this, basepath, fn);
556 disp([repmat(' |', 1, length(basepath)),'-- <a href="matlab:
htdoc(''', class(this), ''')">', class(this), '</a>']);
559 disp([repmat(' |', 1, length(basepath)), ...
560 ' <a href="matlab: display(get(',...
561 name, ',', mat2str(basepath), ...
562 '))">get(', name, ',', mat2str(basepath), ')</a>']);
564 for i = 1:length(lines)
565 lfind = strfind(lines{1},
'<a href');
566 if i == 1 && lfind(1) == 1
569 disp([repmat(
' |', 1, length(basepath)),
' ', lines{i}]);
572 for i = 1:length(
this)
573 child = get(this, i);
575 display(child, fn, [basepath, i], name);
582 function lines = disp_node(this, basepath, fn)
583 % function lines = disp_node(this, basepath, fn)
584 % returns a cell array of strings with information on the node.
586 % The default implementation adds the output of the 'disp' command.
589 % basepath: the index path needed to reach this element from the root.
590 % fn: a file name
string for a dot file that can be generated
593 % lines: the cell array of strings
595 disp_text = evalc('disp(this)');
597 while(~isempty(disp_text))
598 [lines{lno}, disp_text] = strtok(disp_text, sprintf(
'\n'));
DataTree.ICreator implementation which does not create a tree, but a cell array of descriptions for a...
Data Tree element which can be filtered by ids
Interface for a leaf node of a data tree.
This is the common interface for all models, detailed and reduced ones.
function htdoc(topic)
opens mtoc++ documentation in a browser
Interface for a node in a DataTree.
Struct with control fields for the analytical PDE functions, the discretization and the parametrizati...
Data Tree element which can be filtered by time instants.
This is the interface for a detailed model providing methods to compute high dimensional simulation s...