rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
IModel.m
1 classdef IModel < dynamicprops
2  % This is the common interface for all models, detailed and reduced ones.
3  %
4 
5  properties (Constant)
6 
7  % This constant can be used for a consistency check of time evolution
8  % members in the ModelDescr with help of IModel.struct_check()
9  time_checks = struct('t', {{@isscalar}}, ...
10  'tstep', {{@isscalar}}, ...
11  'nt', {{@isscalar}}, ...
12  'dt', {{@isscalar, ...
13  'own', @(model) model.dt == model.T/model.nt,...
14  'model.dt ~= model.T/model.nt'}} ...
15  );
16  end
17 
18  properties (Access = public)
19  % The number of CPUs used for parallel sessions.
20  %
21  % @todo: This flag should move to the FakeMPI sigleton control structure.
22  num_cpus = 4;
23  end
24 
25  properties (Abstract, Dependent)
26  % Decomposition operation mode
27  %
28  % A scalar flag indicating the operation mode of functions:
29  % - 0 (complete) : no affine parameter dependence or decomposition
30  % is performed.
31  % - 1 (components) : for each output argument a cell array of output
32  % matrices is returned representing the `q`-th
33  % component independent of the parameters given
34  % in 'mu_names'.
35  % - 2 (coefficients) : returns a vector where each coordinate represents
36  % the `q`-the coefficient
37  % `\boldsymbol\sigma_{\cdot}^{q}(\boldsymbol\mu)`
38  % dependent on the parameters given in 'mu_names'.
39  %
40  % This flag is only needed if the detailed model makes use of @ref datafunc
41  % "affinely parameter dependent functions".
42  decomp_mode;
43  end
44 
45  properties (Abstract, SetAccess = private, Dependent)
46  % cell array of strings describing the parameters of the model
47  mu_names;
48 
49  % cell array of vectors of size two defining the allowed interval range for
50  % the parameter components
51  mu_ranges;
52 
53  % an integer defining the verbosity level of information output during
54  % basis generation
55  verbose;
56 
57  % an integer defining the debugging level controlling error output and
58  % extra tests during basis generation
59  debug;
60  end
61 
62 
63  methods (Abstract)
64 
65  % function model_data = gen_model_data(this)
66  % generates large model data.
67  %
68  % This function generates e.g. a grid, which is not to be stored in the
69  % model, but required for numerics.
70  %
71  % Return values:
72  % model_data: Matlab structure of type ModelData storing high dimensional
73  % data needed by detailed_simulation().
74  model_data = gen_model_data(this);
75 
76  % function sim_data = detailed_simulation(this, model_data)
77  % executes a detailed simulation for a given parameter
78  %
79  % This function computes a numerical scheme defined by a ModelDescr for the
80  % parameter set via the set_mu() method.
81  %
82  % Return values:
83  % sim_data: structure holding the `H`-dimensional simulation data.
84  sim_data = detailed_simulation(this, model_data);
85 
86  % function this = set_mu(this, mu, propagate)
87  % sets the active parameter vector `\mu \in {\cal M}`
88  %
89  % The parameter set here, is used by the detailed_simulation() function.
90  %
91  % Parameters:
92  % mu: The parameter vector `\boldsymbol\mu`.
93  %
94  % Return values:
95  % this: handle of type IDetailedModel to the changed DetailedModel
96  this = set_mu(this, mu);
97 
98  % function mu = get_mu(this)
99  % returns the active parameter vector `\boldsymbol\mu \in {\cal M}`
100  %
101  % Return values:
102  % mu: The parameter vector `\boldsymbol\mu`
103  mu = get_mu(this);
104 
105  end
106 
107  methods (Static, Hidden)
109  function ok = struct_check(descr, checks)
110  % function ok = struct_check(descr, checks)
111  % executes checks on the fields of a structure object
112  %
113  % This function can be used to check whether the structure 'descr' fulfills
114  % some constraints defined by the second argument 'checks'
115  %
116  % The following checks can be executed:
117  % - 'def(fn)': Checks whether a field 'fn'
118  % exists and is set to a non-empty value.
119  % - 'type(fn, typecheck)': Checks whether the field 'fn' fullfils
120  % a typecheck defined by a function
121  % 'isokay = typecheck(X)' Useful choices
122  % for 'typecheck' are e.g. <tt> @@isscalar,
123  % @@iscell, @@isstruct </tt>
124  % - 'values(fn, candidates)': Checks whether the field 'fn' is set to
125  % one of the values given by the cell
126  % array of strings 'candidates'
127  % - 'minmax(fn, range)': Checks whether the field 'fn' is set to
128  % a value in a given range 'range', which
129  % is a 2-dimensional vector.
130  % - 'own(fn, usr_check, msg)': Checks whether the field 'fn' is set to
131  % a value that fulfills a user-defined
132  % check 'isokay = usr_check(descr)'. If
133  % it fails, a message 'msg' is printed
134  % for explanation.
135  %
136  % Parameters:
137  % descr: The structure to be checked.
138  % checks: A structure defining which of the above described checks shall
139  % be executed.
140  % - All fieldnames 'fn' of this structure are used for
141  % definition checks 'def(fn)'.
142  % - The field values must be set to a cell array whose first
143  % element is set to a function pointer 'typecheck' used for a
144  % mandatory check 'type(fn, typecheck)'.
145  % - The following fields of the cell array are strings defining
146  % a check followed by an optional and fixed number of
147  % arguments for this check. Possible command strings are:
148  % - 'values' followed by one argument 'candidates' executing
149  % the check 'values(fn, candidates)'.
150  % - 'minmax' followed by one argument 'range' executing the
151  % check 'minmax(fn, range)'.
152  % - 'own' followed by two arguments 'usr_check' and 'msg'
153  % executing the check 'own(fn, usr_check, msg)'.
154  % .
155  % .
156  %
157  % Return values:
158  % ok: boolean flag indicating whether all checks passed.
159  ok = true;
160  fns = fieldnames(checks);
161  for i = 1:length(fns)
162  % definition checks
163  if ~isfield(descr, fns{i})
164  disp(['Field ', fns{i}, ' is not defined in descr.']);
165  ok = false;
166 
167  elseif isempty(descr.(fns{i}))
168  disp(['Field ', fns{i}, ' is empty!']);
169  ok = false;
170  else
171  mval = descr.(fns{i});
172  % further checks:
173  checkdef = checks.(fns{i});
174  % 1. type check:
175  if length(checkdef) > 1 && ~isempty(checkdef{1}) && ~checkdef{1}(mval)
176  disp(['Field ', fns{i}, ' failed the type check ', func2str(checkdef{1}), '.']);
177  ok = false;
178  end
179 
180  cdi = 2;
181  while cdi <= length(checkdef) && ok
182  switch(checkdef{cdi})
183  case 'values'
184  values = checkdef{cdi+1};
185  if isempty(intersect(mval, values))
186  disp(['Field ', fns{i}, ' needs to be one of:']);
187  if ~iscell(values)
188  celldisp(values, 'values');
189  else
190  fprintf('%s ', values{:});
191  end
192  ok = false;
193  end
194  cdi = cdi + 2;
195  case 'minmax'
196  range = checkdef{cdi+1};
197  if mval < range(1) || mval > range(2)
198  disp(['Field ', fns{i}, ' does not lie in range ', num2str(range), '.']);
199  ok = false;
200  end
201  cdi = cdi + 2;
202  case 'own'
203  testfun = checkdef{cdi+1};
204  message = checkdef{cdi+2};
205  if ~testfun(descr)
206  disp(['Field ', fns{i}, ' failed a consistency check:']);
207  disp(message);
208  ok = false;
209  end
210  cdi = cdi + 3;
211  end
212  end
213  end
214  end
215  end
216  end
217 end
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
Definition: verbose.m:17
This is the common interface for all models, detailed and reduced ones.
Definition: IModel.m:17
static function ok = struct_check(descr, checks)
executes checks on the fields of a structure object
Definition: IModel.m:210
Struct with control fields for the analytical PDE functions, the discretization and the parametrizati...
Definition: dummyclasses.c:15
This is the interface for a detailed model providing methods to compute high dimensional simulation s...
Struct with high dimensional data needed for a high dimensional simulation.
Definition: dummyclasses.c:1