rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
TpartNode.m
1 classdef TpartNode < DataTree.DefaultNode
2  % Data Tree element which can be filtered by time instants.
3  %
4  % The children branches of this data tree node are all tagged with a time
5  % interval, either discrete (time steps) or continuous (time instants).
6  %
7  % The branches can then be accessed via the 'nt' argument of the get_index()
8  % method.
9  %
10 
11  properties (SetAccess = protected)
12  % an object of type XPartMap holding the time intervals.
13  tpart_map;
14  end
15 
16  properties (Constant)
17  % Data node type identifier
18  data_node_type = 'TPart';
19  end
20 
21  properties (Access = protected)
22  % struct mapping between time instants and indices of children. (?)
23  invmap;
24 
25  % an optional argument specifying whether the time slices overlap, and how
26  % much they do...
27  overlap = 0;
28 % refiner = [];%DefaultRefiner;
29  end
30 
31  methods
32  function tpdn = TpartNode(tpart_map, initvalues, overlap)
33  % function tpdn = TpartNode(tpart_map, initvalues, overlap)
34  % constructor of initializing a TpartNode
35  %
36  % Paramters:
37  % tpart_map: the T-partitioning map of type XPartMap.
38  % initivalues: a cell array of DataTree.INode objects for the initial
39  % values of the children.
40  % overlap: initial value for #overlap property.
41 
42  if nargin >= 3
43  tpdn.overlap = overlap;
44  end
45  if isempty(tpart_map)
46  tpart_map = XPartMap(1);
47  elseif isnumeric(tpart_map)
48  tpart_map = XPartMap(1, 2, tpart_map([1,end]), tpart_map');
49  else
50  tpart_map = copy(tpart_map);
51  end
52  tpdn.tpart_map = tpart_map;
53  tpdn.values = cell(1,tpart_map.siz);
54 
55  if nargin >= 2;
56  assert(length(initvalues) == length(tpdn.values))
57  tpdn.values = initvalues;
58  end
59  end
60 
61  function tstop = index_valid_till(this, index)
62  % function tstop = index_valid_till(this, index)
63  % returns the last valid time instance of a given entity in the
64  % #tpart_map.
65  %
66  % Parameters:
67  % index: index of the T-Partitioning interval.
68  %
69  % Return values:
70  % tstop: time instance when the requested time interval ends.
71 
72  if ~isempty(index)
73  gid = this.tpart_map.leaf_enum(index);
74  interval = get_coords(this.tpart_map, gid);
75  tstop = interval(2);
76  tstop = min(tstop, index_valid_till(get(this, index(1)), index(2:end)));
77  else
78  tstop = Inf;
79  end
80  end
81 
82  %% interface methods
83 
84  function index = get_index(this, id, mu, nt)
85  % function index = get_index(this, id, mu, nt)
86  % @copybrief DataTreeINodeget_index()
87  %
88  % @copydetails DataTreeINodeget_index()
89  if isempty(nt)
90  index = [];
91  else
92  index = coords2elem(this.tpart_map, nt);
93 
94  if index == -1
95  index = [];
96  end
97  end
98  end
99 
100  function indices = get_indices_in_region(this, ids, mu_geo, tslice)
101  % function indices = get_indices_in_region(this, ids, mu_geo, tslice)
102  % needs to be implemented... @todo implement
103  end
104 
105  function tree = create_tree(this, creator, ids, mu_cube, tslice, basepath)
106  % function tree = create_tree(this, creator, ids, mu_cube, tslice, basepath)
107  % @copybrief DataTreeINodecreate_tree()
108  %
109  % @copydetails DataTreeINodecreate_tree()
110  %
111  % Calls DataTreeCreator.create_tpart_node() to build new elements.
112 
113  if nargin < 3
114  ids = [];
115  end
116  if nargin < 4
117  mu_cube = [];
118  end
119  if nargin < 5
120  tslice = [];
121  end
122  if nargin < 6
123  basepath = [];
124  end
125  if isempty(tslice)
126  tslice = [-inf; inf];
127  end
128 
129  [stm, old_leaf_enum] = sub_xpart_map(this.tpart_map, tslice);
130 
131  initvalues = cell(1, length(old_leaf_enum));
132  for i = 1:length(old_leaf_enum)
133  % crop local tslice if necessary
134  new_tslice = stm.get_coords(stm.leaf_enum(i));
135  old_child = get(this, old_leaf_enum(i));
136  old_bp = [basepath, old_leaf_enum(i)];
137  initvalues{i} = create_tree(old_child, creator, ids, mu_cube, new_tslice, old_bp);
138  end
139 
140  if length(old_leaf_enum) == 1
141  tree = initvalues{1};
142  elseif isempty(old_leaf_enum)
143  throw('Merge of trees failed because given time region was not found!');
144  else
145  tree = create_tpart_node(creator, stm, initvalues);
146  end
147  end
148 
149  %% Other methods
150  function refine(this, indices, midpoints)
151  % function refine(this, indices, midpoints)
152  % refines the T-Partitioning by refining the #tpart_map.
153  %
154  % Parameters:
155  % indices: indices of partitioning intervals to be refined.
156  % midpoints: optional parameter for the refinement method
157  % XPartMap.refine() specifying how the geometries shall be
158  % split. (default = '[]')
159  if nargin < 3
160  midpoints = [];
161  end
162  [co, new] = tpart_refine(this, this.storage2lid(indices), midpoints);
163  oldvalues = this.values(co);
164 
165  this.values = [this.values(setdiff(1:length(this.values), co)),...
166  cell(1,length(new(:)))];
167  this.values(new(1,:)) = oldvalues;
168  end
169  end
170 end
Interface for a node in a DataTree.
Definition: INode.m:18
Default implementation for a DataTree.INode.
Definition: DefaultNode.m:18
a geometric tree where every nodes has geometry information attached.
Definition: XPartMap.m:17
Data Tree element which can be filtered by time instants.
Definition: TpartNode.m:18