1 classdef
IModel < dynamicprops
2 % This is the common
interface for all models, detailed and reduced ones.
7 % This constant can be used
for a consistency check of time evolution
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'}} ...
18 properties (Access =
public)
19 % The number of CPUs used
for parallel sessions.
21 % @todo: This flag should move to the FakeMPI sigleton control structure.
25 properties (Abstract, Dependent)
26 % Decomposition operation mode
28 % A scalar flag indicating the operation mode of functions:
29 % - 0 (complete) : no affine parameter dependence or decomposition
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
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'.
40 % This flag is only needed
if the detailed model makes use of @ref datafunc
41 %
"affinely parameter dependent functions".
45 properties (Abstract, SetAccess =
private, Dependent)
46 % cell array of strings describing the parameters of the model
49 % cell array of vectors of size two defining the allowed interval range
for
50 % the parameter components
53 % an integer defining the verbosity level of information output during
57 % an integer defining the debugging level controlling error output and
58 % extra tests during basis generation
65 %
function model_data = gen_model_data(
this)
66 % generates large model data.
68 % This
function generates e.g. a grid, which is not to be stored in the
69 % model, but required
for numerics.
72 % model_data: Matlab structure of type
ModelData storing high dimensional
73 % data needed by detailed_simulation().
74 model_data = gen_model_data(
this);
76 %
function sim_data = detailed_simulation(
this, model_data)
77 % executes a detailed simulation
for a given parameter
79 % This
function computes a numerical scheme defined by a
ModelDescr for the
80 % parameter set via the set_mu() method.
83 % sim_data: structure holding the `H`-dimensional simulation data.
84 sim_data = detailed_simulation(this, model_data);
86 % function this = set_mu(this, mu, propagate)
87 % sets the active parameter vector `\mu \in {\cal M}`
89 % The parameter set here, is used by the detailed_simulation() function.
92 % mu: The parameter vector `\boldsymbol\mu`.
96 this = set_mu(this, mu);
98 % function mu = get_mu(this)
99 % returns the active parameter vector `\boldsymbol\mu \in {\cal M}`
102 % mu: The parameter vector `\boldsymbol\mu`
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
113 % This function can be used to check whether the structure 'descr' fulfills
114 % some constraints defined by the second argument 'checks'
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
137 % descr: The structure to be checked.
138 % checks: A structure defining which of the above described checks shall
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)'.
158 % ok:
boolean flag indicating whether all checks passed.
160 fns = fieldnames(checks);
161 for i = 1:length(fns)
163 if ~isfield(descr, fns{i})
164 disp([
'Field ', fns{i},
' is not defined in descr.']);
167 elseif isempty(descr.(fns{i}))
168 disp([
'Field ', fns{i},
' is empty!']);
171 mval = descr.(fns{i});
173 checkdef = checks.(fns{i});
175 if length(checkdef) > 1 && ~isempty(checkdef{1}) && ~checkdef{1}(mval)
176 disp([
'Field ', fns{i},
' failed the type check ', func2str(checkdef{1}),
'.']);
181 while cdi <= length(checkdef) && ok
182 switch(checkdef{cdi})
184 values = checkdef{cdi+1};
185 if isempty(intersect(mval, values))
186 disp(['Field ', fns{i},
' needs to be one of:']);
188 celldisp(values, 'values');
190 fprintf('%s ', values{:});
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),
'.']);
203 testfun = checkdef{cdi+1};
204 message = checkdef{cdi+2};
206 disp(['Field ', fns{i},
' failed a consistency check:']);
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
This is the common interface for all models, detailed and reduced ones.
static function ok = struct_check(descr, checks)
executes checks on the fields of a structure object
Struct with control fields for the analytical PDE functions, the discretization and the parametrizati...
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.