rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
EiReducedDataNode.m
1 classdef EiReducedDataNode < Greedy.User.IReducedDataNode
2  % Implementation of a Greedy.User.IReducedDataNode storing reduced data
3  % depending on collateral reduced basis space information only (e.g.
4  % interpolation DOFs and a local grid).
5 
6  properties
8  %
10  BM;
11 
13  %
15  grid_local_ext;
16 
18  %
20  TM_local;
21 
23  %
25  TM_global;
26 
28  %
30  Mmass;
31 
33  %
35  Mstrich = 0;
36 
37  % an object of type ILocalizedOperator for which the empirical
38  % interpolation basis was generated.
39  ophandle;
40 
41  id;
42 
43  gEI;
44 
45  gn_edges;
46 
47  gn_inner_edges;
48 
49  gn_boundary_edges;
50 
51  TM_global_args;
52 
53  TM_reduction_args = {};
54  end
55 
56  properties (SetAccess = private, Dependent)
58  %
60  M;
61 
63  %
65  grid;
66  end
67 
68  methods
69  function rd = EiReducedDataNode(rmodel, detailed_data)
70  % function rd = EiReducedDataNode(rmodel, detailed_data)
71  % constructor for the generation of the reduced data.
72  %
73  % Parameters:
74  % rmodel: of type TwoPhaseFlow.ReducedModel
75  % detailed_data: of type IDetailedData
76  %
77  % Alternative synopsis:
78  % @code EiReducedDataNode(rmodel, ei_reduced_data_node) @endcode copying
79  % a reduced data node and (optionally) extracting smaller matrices.
80  if nargin == 0
81  error('TwoPhaseFlow.EiReducedDataNode constructor needs an argument');
82  elseif nargin == 2 && isa(rmodel, 'IReducedModel') ...
83  && isa(detailed_data, 'TwoPhaseFlow.EiReducedDataNode')
84  copy = detailed_data;
85  copy_extract(rd, copy, rmodel);
86  elseif nargin == 2
87  fill_fields(rd, rmodel, detailed_data);
88  else
89  error('Did not find constructor for your arguments');
90  end
91  end
92 
93  function conds = get_conds(this)
94  if ~isempty(this.Mmass)
95  conds.Mmass = condest(this.Mmass);
96  end
97  if ~isempty(this.BM)
98  conds.BM = condest(this.BM);
99  end
100  end
101  function grid = get.grid(this)
102  grid = this.grid_local_ext;
103  end
104 
105  function M = get.M(this)
106  M = size(this.BM, 2) - this.Mstrich;
107  end
108 
109  function yesno = needs_subset_copy(this, rmodel)
110  % function yesno = needs_subset_copy(this, rmodel)
111  % @copybrief .Greedy.User.IReducedDataNode.needs_subset_copy()
112  %
113  % @copydetails .Greedy.User.IReducedDataNode.needs_subset_copy()
114  %
115  % Parameters:
116  % rmodel: of type TwoPhaseFlow.ReducedModel
117 
118  MM = get_by_description(rmodel.M, this.ophandle.id);
119  yesno = isempty(MM) || (this.M ~= MM);
120  end
121 
122  end
123  methods(Access=private)
124 
125  function fill_fields(this, rmodel, detailed_data)
126  model_data = detailed_data.model_data;
127  if size(model_data.W, 1) == size(detailed_data.QM, 1)
128  A = model_data.W;
129  else
130  A = model_data.diamondW;
131  end
132 
133  this.ophandle = detailed_data.ophandle;
134  MM = get_by_description(rmodel.M, this.ophandle.id);
135  this.BM = detailed_data.BM(1:MM,1:MM);
136 
137  [nmd, eind, eind_local] = this.ophandle.compute_TM_global(model_data, detailed_data.TM(1:MM));
138 
139  this.grid_local_ext = nmd.grid_local_ext;
140  this.TM_global_args = nmd.TM_global_args;
141  this.gEI = nmd.gEI;
142  this.gn_edges = nmd.gn_edges;
143  this.gn_inner_edges = nmd.gn_inner_edges;
144  this.gn_boundary_edges = nmd.gn_boundary_edges;
145  this.TM_global = eind;
146  this.TM_local = eind_local;
147 
148  this.Mmass = detailed_data.QM(:,1:MM)' * A * detailed_data.QM(:,1:MM);
149  end
150 
151  function copy_extract(this, reduced_data, rmodel)
152  this.ophandle = reduced_data.ophandle;
153  this.id = reduced_data.id;
154 
155  MM = get_by_description(rmodel.M, this.ophandle.id);
156 
157  grid = reduced_data.grid_local_ext;
158 
159  % new version with external routine index_ext:
160  [nmd, eind, eind_local] = this.ophandle.compute_TM_global(reduced_data, reduced_data.TM_local(1:MM));
161 
162  reduced_data_subset.TM_global = reduced_data.TM_global(1:MM);
163  reduced_data_subset.grid_local_ext = nmd.grid_local_ext;
164  [this.gEI, this.gn_inner_edges, this.gn_boundary_edges] ...
165  = compute_edge_indices(reduced_data_subset.grid_local_ext);
166  this.gn_edges = this.gn_inner_edges + this.gn_boundary_edges;
167 
168  glob2loc = zeros(grid.nelements,1);
169  glob2loc(eind) = 1:length(eind);
170  this.TM_global_args = cell(1, length(nmd.TM_global_args));
171  for i = 1:length(nmd.TM_global_args)
172  oldTM_global = reduced_data.TM_global_args{i};
173  this.TM_global_args{i} = oldTM_global(nmd.TM_global_args{i});
174  this.TM_reduction_args{i} = nmd.TM_global_args{i};
175  end
176  this.TM_local = glob2loc(reduced_data.TM_local(1:MM));
177  this.BM = reduced_data.BM(1:MM,1:MM);
178  this.Mmass = reduced_data.Mmass(1:MM,1:MM);
179 
180  % get Q^t W Q for M to M+M'
181  if rmodel.Mstrich > 0
182  QWQ = this.Mmass(rmodel.M+1:end,MM);
183 % this.factor = norm(QWQ);
184  else
185 % this.factor = NaN;
186  end
187  end
188  end
189 end