rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
Model.m
1 classdef Model < handle & matlab.mixin.Copyable
2 % MODEL Abstract model class
3 %
4 % This class represents abstract RB problems that define common
5 % interfaces.
6 %
7 % Andreas Schmidt, 2016
8 
9  properties(Abstract)
10  mu;
11  mu_names;
12  mu_ranges;
13  end
14 
15  methods(Abstract)
16  % DETAILED_SIMULATION
17  % The function DETAILED_SIMULATION returns an instance of
18  % SimData and
19  dsim = detailed_simulation(model, model_data);
20 
21  % REDUCED_SIMULATION
22  % This function should return a reduced simulation of type
23  % RBSimData
24  rsim = rb_simulation(model, reduced_data);
25  end
26 
27  methods
28  % Note: All of the following methods can be redefined by the
29  % subclasses and completely customized to fit the needs of your
30  % model!
31 
32  % GEN_MODEL_DATA
33  % Use this function in order to create a class of type
34  % ModelData which contains all the large-scale model data such
35  % as the discretized operators
36  function model_data = gen_model_data(this)
37  model_data = eval([this.problem_type(), '.ModelData(this)']);
38  end
39 
40  % GEN_DETAILED_DATA
41  % Call the basis generation algorithm.
42  function detailed_data = gen_detailed_data(this, model_data)
43  detailed_data = eval([this.problem_type(), '.DetailedData(this, model_data)']);
44  end
45 
46  % GEN_REDUCED_DATA
47  % Get the reduced data structures
48  function reduced_data = gen_reduced_data(this, detailed_data)
49  reduced_data = eval([this.problem_type(), '.ReducedData(this, detailed_data)']);
50  end
51 
52  % PROBLEM_TYPE
53  % Use this function to determine the problem type. So consider
54  % overwriting it if necessary!
55  function pt = problem_type(this)
56  % TODO: implement a smart interface that automatically
57  % generates the correct
58  c = class(this);
59  if isempty(find(c=='.'))
60  warning('Consider reimplementing problem_type method in class %s as the return value might be incorrect', c);
61  pt = c;
62  else
63  pt = c(1:max(find(c=='.')-1));
64  end
65  end
66  end
67 
68  % =====================================================================
69  % Standard functions
70  methods
71 
72  function mu = get_mu(this)
73  % Get the parameter values
74  mu = this.mu;
75  end
76 
77  function this = set_mu(this, mu)
78  % Set the parameter values
79  if length(mu) ~= length(this.mu_names)
80  error('Mu length wrong. This model expects %d parameters: %s', length(this.mu_names), strjoin(this.mu_names,', '));
81  end
82 
83  % Validate the parameter ranges
84  for i = 1:length(mu)
85  if mu(i) < this.mu_ranges{i}(1) || mu(i) > this.mu_ranges{i}(2)
86  error('The value for the parameter %s is wrong. The valid range is [%f, %f].\n', ...
87  this.mu_names{i}, this.mu_ranges{i}(1), this.mu_ranges{i}(2))
88  end
89  end
90 
91  this.mu = mu;
92  end
93 
94  end
95 
96 end