rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
DetailedData.m
1 classdef DetailedData < AbstractModel.DetailedData & matlab.mixin.Copyable
2 % Implementation of the detailed data interface for the ARE
3 %
4 % This class keeps the reduced basis and the information about the
5 % calculation of \gamma.
6 %
7 % Andreas Schmidt, 2016
8 
9  properties
10  % Store the reduced basis:
11  RB_V;
12  RB_W;
13 
14  % The size of the reduced basis
15  RB_size;
16 
17  % Information that was returned by the basis generation algorithm
18  info;
19 
20  % Handler for the norm of the inverse operator norm ||L^{-1}||
21  % The field gamma is filled by the corresponding gamma_calculation
22  gamma = {}; % Information returned by gen_detailed_data from the gamma interface
23  gamma_mode; % Name of the gamma mode, stored within this detailed data instance
24 
25  % Model data handle, just for the easier calculation of the reduced
26  % matrices:
27  model_data;
28  end
29 
30  properties(SetAccess=protected)
31  % This is a handle to the gamma calculation interface. This can be
32  % any class that implements the GAMMACALCULATORINTERFACE class.
33  algorithm;
34 
35  gamma_initialized = false;
36  gamma_calculation;
37  end
38 
39  methods
40  function this = DetailedData(model, model_data)
41  % DETAILEDATA Constructor for the DetailedData class
42  this.model_data = model_data;
43  this.algorithm = Greedy.LRFG.Algorithm(model, model_data);
44 
45  if ~isempty(model.RB_gamma_mode)
46  this.set_gamma_mode(model);
47  end
48  end
49 
50  function s = get_rb_size(this)
51  % GET_RB_SIZE returns the size of the reduced basis
52  s = this.RB_size;
53  end
54 
55  function set_gamma_mode(this, model)
56  % SET_GAMMA_CALCULATION set the mode for the gamma calculation
57  % If you change the gamam mode, the state will be set to
58  % uninitialized, which means you first have to run
59  % INITIAILIZE_GAMMA in order to be able to calculate
60  mode = model.RB_gamma_mode;
61  if isempty(mode) || strcmp(mode, 'none')
62  this.gamma_calculation = [];
63  this.gamma_initialized = true;
64  return
65  end
66 
67  this.gamma_calculation = eval([model.problem_type(), ...
68  '.GammaCalculation.', mode, '()']);
69 
70  this.gamma_initialized = false;
71  this.gamma_mode = mode;
72  end
73 
74  function this = initialize_gamma(this, model, model_data)
75  % INITIALIZE_GAMMA Call the gen_detailed_data method in the
76  % gamma calculation interface and populate the data to the
77  % field in detailed_data
78  if isempty(this.gamma_calculation)
79  error('Cannot initialize since no gamma calculation is defined');
80  end
81 
82  this.gamma = this.gamma_calculation.gen_detailed_data(model, ...
83  model_data, this);
84  this.gamma_initialized = true;
85  end
86 
87  function dd = extract_subbasis(this, N)
88  % EXTRACT_SUBBASIS Extract a part of the basis
89  if length(N) == 1
90  N = 1:N;
91  end
92 
93  dd = copy(this);
94  dd.RB_V = dd.RB_V(:, N);
95  dd.RB_W = dd.RB_W(:, N);
96  end
97  end
98 
99  methods(Static)
100  function this = initialize_with_bgen(model, model_data)
101  % This function is used in the gen_detailed_data function and
102  % creates an instance of the DetailedData class and
103  % instantiates the basis building procedure:
104  pt = model.problem_type();
105  this = eval([pt,'.DetailedData(model, model_data)']);
106 
107  % Set the parameters, if there are any:
108  if ~isempty(model.RB_M_train)
109  M_train = model.RB_M_train;
110  if isa(M_train, 'char')
111  M_train = eval(['ParameterSampling.',M_train,'()']);
112  elseif isa(M_train, 'ParameterSampling.Interface')
113  elseif ismatrix(M_train)
114  M_train = ParameterSampling.Prescribed(M_train);
115  else
116  error(['Please set the property RB_M_train to a valid ', ...
117  'value!']);
118  end
119  % And finally, set the M_train value
120  this.algorithm.M_train = M_train;
121  end
122 
123  % Run the actual algorithm
124  [V,W,info] = this.algorithm.run();
125 
126  this.RB_V = V;
127  this.RB_W = W;
128  this.RB_size = size(V,2);
129  this.info = info;
130 
131  % Initialize the gamma stuff:
132  this.set_gamma_mode(model);
133  if ~this.gamma_initialized
134  this.initialize_gamma(model, model_data);
135  end
136  end
137 
138  end
139 
140 end
Abstract OOP model implementation interface.
Implementation of the detailed data interface for the ARE.
Definition: DetailedData.m:18
Parameter sampling sets.
Definition: Interface.m:1
Implementation of the parametric algebraic Riccati equation.
Customizable implementation of an abstract greedy algorithm.
Definition: DuneRBLeafNode.m:1