2 % a
DataTree.
INode extension
for data nodes that can store information on
3 % their generation process.
6 % a dynamically growing structure of information fields
9 % a cell array of strings describing why the generation of
this node
16 function append_field(
this, fieldname, value)
17 %
function append_field(
this, fieldname, value)
18 % appends a value to an information field storing a vector
21 % fieldname: the name of the information field
22 % value: the value to be appended (scalar or column vector)
24 if ~isfield(this.fields, fieldname)
25 this.fields.(fieldname) = [];
27 this.fields.(fieldname) = [ this.fields.(fieldname), value ];
30 function set_field(this, fieldname, value)
31 % function set_field(this, fieldname, value)
32 % sets an information field
35 % fieldname: the name of the information field
36 % value: the new value
38 this.fields.(fieldname) = value;
41 function value = get_field(this, fieldname, default)
42 % function value = get_field(this, fieldname, default)
43 % returns the value of an information field
46 % fieldname: the name of the information field
47 % default: optional default value in case the information field does
51 % value: the stored value
53 assert(isfield(this.fields, fieldname))
55 if isfield(this.fields, fieldname)
56 value = this.fields.(fieldname);
59 this.fields.(fieldname) = default;
63 function value = get_field_on_active_child(this, fieldname, model,
id)
64 % function value = get_field_on_active_child(this, fieldname, model,
id)
65 % returns the value of an information field from the active
leaf node
68 % fieldname: the name of the information field
69 % model: a reduced or detailed model of type ::
IModel holding
70 % information about the selected parameters and maybe the time
72 %
id: optional parameter defining a special ID that shall be
73 % attached to the
leaf element.
75 % Optional fields of model:
76 % t: the current time step
79 % value: the stored value
83 if isfield(model, 't')
91 leaf_index = get_index(this,
id, mu, nt);
98 value = get_field(cur_elem, fieldname, []);
99 if iind <= length(leaf_index)
100 cur_elem = get(cur_elem, leaf_index(iind));
109 % function set_field_on_all_leaves(this, field, value)
114 function set_fields(this, other, fns)
115 % function set_fields(this, other, fns)
116 % copies fields from another struct
119 % other: another struct whose fields shall be copied as information
121 % fns: a cell array of strings which acts as a filter for the field
124 real_fns = intersect(fieldnames(other), fns);
125 for i=1:length(real_fns)
126 this.fields.(real_fns{i}) = other.(real_fns{i});
130 function set_stop_flag(
this, flag, on_off)
131 %
function set_stop_flag(
this, flag, on_off)
132 % sets the stop flag in
this node
135 % flag: the flag name,
136 % on_off:
boolean flag specifying whether the flag shall set or unset.
138 if nargin <=2 || isempty(on_off) || on_off
139 this.stop_flags =
union(this.stop_flags, {flag});
141 this.stop_flags = setdiff(this.stop_flags, {flag});
145 function propagate_stop_flag(
this, flag, on_off)
146 %
function propagate_stop_flag(
this, flag, on_off)
147 % updates the stop flag in all children nodes of the current one.
150 % flag: the flag name,
151 % on_off:
boolean flag specifying whether the flag shall set or unset.
157 set_stop_flag(
this, flag, on_off);
159 for i = 1:length(
this)
160 child = get(this, i);
161 propagate_stop_flag(child, flag, on_off);
166 function stopped_flags = stopped_on_active_child(this, flags, model,
id)
167 % function stopped_flags = stopped_on_active_child(this, flags, model,
id)
168 % returns stop flags set on the active child
171 % flags: a cell array of flag strings for filtering
172 % model: a reduced or detailed model of type ::
IModel holding
173 % information about the selected parameters and maybe the time
175 %
id: optional parameter defining a special ID that shall be
176 % attached to the
leaf element.
178 % Optional fields of model:
179 % t: the current time step
182 % stopped_flags: a cell array of stop flags found after filtering. If
183 % only one flag is given in the argument 'flags', a
184 %
boolean value is returned, indicating whether the flag
190 if isfield(model, 't')
202 leaf_index = get_index(
this,
id, mu, nt);
205 stopped_flags = intersect(this.stop_flags, flags);
207 for iind = 1:length(leaf_index)
208 cur_elem = get(cur_elem, leaf_index(iind));
209 stopped_flags = union(stopped_flags, intersect(cur_elem.stopped_flags, flags));
212 if length(flags) == 1
213 stopped_flags = ~isempty(stopped_flags);
217 function stopped_flags = stopped_on_any_child(this, flags)
218 % function stopped_flags = stopped_on_any_child(this, flags)
219 % returns stop flags set on any child of the current node
222 % flags: a cell array of flag strings for filtering
225 % stopped_flags: a cell array of stop flags found after filtering. If
226 % only one flag is given in the argument 'flags', a
227 %
boolean value is returned, indicating whether the flag
235 stopped_flags = intersect(this.stop_flags, flags);
237 for i = 1:length(
this);
238 child =
get(
this, i);
239 stopped_flags =
union(stopped_flags, intersect(child.stopped_flags, flags));
242 if length(flags) == 1
243 stopped_flags = ~isempty(stopped_flags);
247 function stopped_flags = stopped_on_all_leafs(
this, flags)
248 %
function stopped_flags = stopped_on_all_leafs(
this, flags)
249 % returns stop flags set on all children nodes of the current node
252 % flags: a cell array of flag strings
for filtering
255 % stopped_flags: a cell array of stop flags found after filtering. If
256 % only one flag is given in the argument
'flags', a
257 %
boolean value is returned, indicating whether the flag
265 stopped_flags = intersect(this.stop_flags, flags);
267 stopped_flags = flags;
268 for i = 1:length(
this)
269 child = get(this, i);
270 stopped_flags = intersect(stopped_flags, stopped_on_all_children(child, flags));
273 if length(flags) == 1
274 stopped_flags = ~isempty(stopped_flags);
This is the common interface for all models, detailed and reduced ones.
Interface for a node in a DataTree.