rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
ReducedModel.m
1 classdef ReducedModel < IReducedModel
2  % reduced model for linear stationary problems as given by a
4 
5  properties
6  enable_error_estimator = false;
7 
8  mu;
9  end
10 
11  methods
12  function rm = ReducedModel(dmodel, bg_descr)
13  % function rm = ReducedModel(detailed_model, basis_generator)
14  % Constructor for the reduced model.
15  %
16  % Parameters:
17  % dmodel: of type LinStatDune.DetailedModel
18 
19  rm = rm@IReducedModel(dmodel, bg_descr);
20  end
21 
22  function rb_sim_data = rb_simulation(rmodel, reduced_data)
23  % function rb_sim_data = rb_simulation(rmodel, reduced_data)
24  % reduced simulation for linear stationary finite volume schemes
25  descr = rmodel.detailed_model.descr;
26 
27  rb_sim_data = [];
28  cmu = get_mu(rmodel);
29  LI_coeff = descr.coeff_ops.LI(cmu);
30  f_coeff = descr.coeff_ops.f(cmu);
31 
32  LIN = lincomb_sequence(reduced_data.AN_comp, LI_coeff);
33  fN = lincomb_sequence(reduced_data.fN_comp, f_coeff);
34 
35  KII_coeff = kron(LI_coeff, LI_coeff);
36  mI_coeff = kron(LI_coeff, f_coeff);
37  m_coeff = kron(f_coeff, f_coeff);
38  KII = lincomb_sequence(reduced_data.KII, KII_coeff);
39  mI = lincomb_sequence(reduced_data.mI, mI_coeff);
40  m = lincomb_sequence(reduced_data.m, m_coeff);
41 
42  uN = LIN \ fN;
43 
44  rb_sim_data.uN = uN;
45 
46  res_norm_sqr = ...
47  uN' * KII * uN ...
48  - 2 * uN' * mI ...
49  + m;
50 
51  if res_norm_sqr >=0
52  res_norm = sqrt(res_norm_sqr);
53  else
54  res_norm = 0;
55  end
56 
57  Delta = descr.L_I_inv_norm_bound(cmu) * res_norm;
58 
59  rb_sim_data.Delta = Delta;
60  end
61 
62  function this = set_mu(this, mu)
63  % function this = set_mu(this, mu, propagate)
64  % sets the active parameter vector `\mu \in {\cal M}`
65  %
66  % The parameter set here, is used by the detailed_simulation() function.
67  %
68  % The default implementation sets all fieldnames 'descr.mu_names' in the
69  % #descr struct.
70  %
71  % Parameters:
72  % mu: The parameter vector `\boldsymbol\mu`.
73  %
74  % Return values:
75  % this: handle of type IDetailedModel to the changed DetailedModel
76 
77  assert(length(mu) == length(this.descr.mu_names));
78 
79  this.mu = mu;
80 % this.descr.mexptr('set_mu', mu);
81  end
82 
83  function mu = get_mu(this)
84  % function mu = get_mu(this)
85  % returns the active parameter vector `\boldsymbol\mu \in {\cal M}`
86  %
87  % The default implementation returns a vector of the values of the fields
88  % of the #descr structure with names 'descr.mu_names'.
89  %
90  % Return values:
91  % mu: The parameter vector `\boldsymbol\mu`
92 
93 
94  if isempty(this.mu)
95  this.mu = get_mu(this.detailed_model);
96  end
97  mu = this.mu;
98 
99 % mu = this.descr.mexptr('get_mu');
100  end
101 
102  function rb_sim_data = rb_reconstruction(this, detailed_data, rb_sim_data)
103  % function rb_sim_data = rb_reconstruction(this, detailed_data, rb_sim_data)
104  % @copybrief IReducedModel.rb_reconstruction()
105  %
106  % Parameters:
107  % detailed_data: of type LinEvol.DetailedData
108  % rb_sim_data: struct holding reduced simulation data returned by
109  % IReducedModel.rb_simulation() .
110  %
111  % Return values:
112  % rb_sim_data: struct holding the reduced simulation results and their
113  % reconstructions.
114  if isa(detailed_data, 'Greedy.User.IDetailedData')
115  dd_leaf = get_leaf(detailed_data, this);
116  else
117  dd_leaf = detailed_data;
118  end
119  dune_sim_data = this.descr.mexptr('rb_reconstruction', dd_leaf.model_data, rb_sim_data);
120  rb_sim_data = structcpy(rb_sim_data, dune_sim_data);
121  end
122 
123  function c = copy(this)
124  % function c = copy(this)
125  % @copybrief IReducedModelcopy()
126  %
127  % Return values:
128  % c: an object of type LinEvol.ReducedModel which is a deep copy of this object.
129  c = ReducedModel(this);
130  end
131 
132  end
133  methods (Static)
134  function Delta = get_estimators_from_sim_data(rb_sim_data)
135  % function Delta = get_estimators_from_sim_data(sim_data)
136  % @copybrief IReducedModelget_estimators_from_sim_data()
137  %
138  % @copydetails IReducedModelget_estimators_from_sim_data()
139  Delta = rb_sim_data.Delta;
140  end
141 
142  function Delta = get_estimator_from_sim_data(rb_sim_data)
143  % function Delta = get_estimator_from_sim_data(sim_data)
144  % @copybrief IReducedModelget_estimator_from_sim_data()
145  %
146  % @copydetails IReducedModelget_estimator_from_sim_data()
147  Delta = rb_sim_data.Delta(end);
148  end
149 
150  end
151 end
Reduced basis implementation for linear evolution equations.
Detailed model for a linear stationary problem with a discretization implemented in Dune-RB...
Definition: DetailedModel.m:18
This is the interface for a reduced model providing methods to compute low dimensional reduced simula...
Definition: IReducedModel.m:17
function s1 = structcpy(s1, s2)
copies the fields of structure s2 into structure s1. If the field to be copied does not exist in s1 y...
Definition: structcpy.m:17
This is the interface for a detailed model providing methods to compute high dimensional simulation s...
Customizable implementation of an abstract greedy algorithm.
Definition: DuneRBLeafNode.m:1
reduced model for linear stationary problems as given by a LinStatDune.DetailedModel.
Definition: ReducedModel.m:18
Interface class for the generation and storage of reduced basis spaces as described in Module (M2)...
Definition: IDetailedData.m:17