rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
SpaceOpEvals.m
1 classdef SpaceOpEvals < SnapshotsGenerator.Cached
2 % Implementation of a SnapshotsGenerator.Cached for empirical basis generation. The
3 % generate() method returns the evaluations of an operator or a function on the
4 % solution (trajectory) of a detailed simulation.
5 %
6 % An SpaceOpEvals depends on a SnapshotsGenerator.Cached providing detailed
7 % simulation (trajectories) on which the operator can be applied.
8 
9  properties (Access = protected)
10  % an object of type SnapshotsGenerator.Trajectories providing a generator for detailed_simulations
11  rb_detailed_generator;
12 
13  end
14  properties (SetAccess = protected)
15  % a localized operator of type ILocalizedOperator
16  ophandle;
17  end
18 
19  methods
20  function eidg = SpaceOpEvals(dmodel, id, rbdgen, ophandle, force_delete, enable_caching)
21  % function eidg = SpaceOpEvals(dmodel, id, M, rbdgen, ophandle,[force_delete, enable_caching])
22  % constructor for a snapshot generator of space operator evaluations.
23  %
24  % Parameters:
25  % id: a unique string identifier for this object.
26  % rbdgen: an underlying object of type SnapshotsGenerator.Cached
27  % generating snapshots `\{u_h^k(\mu)\}_{k=1}^K` for which the
28  % space operator evaluations `\{ {\cal L}_h(\mu)[u_h^k(\mu)]
29  % \}_{k=1}^K` shall be computed.
30  % ophandle: an localized operator of type ILocalizedOperator or a
31  % function_handle with synopsis
32  % 'op(descr, model_data, U, NU_ind)' implementing the operator
33  % `{\cal L}_h`.
34  % force_delete: boolean value indicating whether the cached data shall
35  % be automatically deleted if its inconsistent with the given
36  % 'dmodel'. (Default = 'true')
37  % enable_caching: boolean value indicating whether the generated data
38  % shall be stored in a cache. (Default = 'true')
39  if nargin < 5
40  force_delete = [];
41  end
42  if nargin < 6
43  enable_caching = [];
44  end
45  eidg = eidg@SnapshotsGenerator.Cached(dmodel, id, force_delete, enable_caching);
46 
47  eidg.rb_detailed_generator = rbdgen;
48  if isequal(class(ophandle), 'function_handle')
49  ophandle = LocalizedOperatorDefault(ophandle);
50  elseif ~isa(ophandle, 'ILocalizedOperator')
51  error('fourth constructor argument must be of type ''ILocalizedOperator'' or a function handle');
52  end
53  eidg.ophandle = ophandle;
54  end
55 
56  function combination = plus(this, other)
57  % function combination = plus(this, other)
58  % convenience function allowing to merge several
59  % SnapshotsGeneratorSpaceOpEvals instances together by "adding" them
60  % together with a '+' operator.
61  %
62  % Parameters:
63  % other: an "addend" of type SnapshotsGeneratorSpaceOpEvals
64  %
65  % Return values:
66  % combination: the merged object of type SnapshotsGeneratorMergedSpaceOpEvals
67  assert( isa(other, 'SnapshotsGenerator.SpaceOpEvals') );
68  combination = SnapshotsGenerator.MergedSpaceOpEvals(this, other);
69  end
70 
71  end
72 
73  methods (Access = protected)
74  function [LU, opt_fields] = generate_impl(this, dmodel, detailed_data, fields)
75  if nargin <= 3
76  fields = [];
77  end
78  % function LU = generate_impl(this, dmodel, detailed_data)
79  [U, opt_fields] = generate(this.rb_detailed_generator, dmodel, detailed_data, fields);
80  LU = generate_ei_impl(this, dmodel, detailed_data, U);
81  end
82 
83  function LU = generate_ei_impl(this, dmodel, detailed_data, U)
84  % function LU = generate_ei_impl(this, dmodel, detailed_data, U)
85  % generates operator evaluations for snapshots generated by the
86  % underlying #rb_detailed_generator object.
87  %
88  % Parameters:
89  % U: a matrix of size 'ndofs x K' with snapshots generated by the
90  % underlying #rb_detailed_generator.
91  %
92  % Return values:
93  % LU: a matrix of size 'ndofs x K' with the operator evaluations.
94 
95 
96  % LU = this.ophandle.apply(dmodel, detailed_data, U, []);
97  store_bu = [];
98  descr = dmodel.descr;
99  if isstruct(U)
100  fields = fieldnames(U);
101  nsnaps = size(U.(fields{1}), 2);
102  else
103  nsnaps = size(U, 2);
104  end
105 
106  % for evolution problems: If we include intermediate Newton
107  % solutions, the number of snapshots differs from the number of
108  % timesteps.
109  if ~isfield(descr, 'nt') || nsnaps > descr.nt+1
110  LU = zeros(this.ophandle.ret_size(detailed_data), nsnaps);
111  for tn = 1:nsnaps;
112  fprintf('.');
113  if dmodel.debug && ~descr.data_const_in_time
114  error('time dependent data is not yet implemented for newton schemes');
115  end
116  [nu, bu] = this.ophandle.apply(descr, detailed_data, dmodel.get_dofs_at_time(U, tn), []);
117  if ~isempty(bu) && tn==1
118  store_bu = bu;
119  end;
120  LU(:,tn) = nu(:);
121  end
122  else
123  if ~isfield(descr, 'ei_time_indices')
124  if isfield(descr, 'T')
125  descr.ei_time_indices = 1:descr.nt;
126  else
127  descr.ei_time_indices = 1;
128  descr.t = 1;
129  descr.dt = 1;
130  descr.T = 1;
131  descr.nt = 0;
132  end
133  end
134  LU = zeros(this.ophandle.ret_size(detailed_data), length(descr.ei_time_indices));
135  for tn = 1:length(descr.ei_time_indices);
136  fprintf('.');
137  ti = descr.ei_time_indices(tn);
138  % note the time-shift by 1 in the following (ti=1 is initial data)
139  descr.t = (ti-1)*descr.dt;
140  descr.tstep = tn;
141  [nu, bu] = this.ophandle.apply(descr, detailed_data, dmodel.get_dofs_at_time(U,ti), []);
142  if ~isempty(bu) && tn==1
143  store_bu = bu;
144  end;
145  LU(:,tn) = nu(:);
146  end
147  end
148  if ~isempty(store_bu)
149  LU = [LU, store_bu];
150  end
151  fprintf('\n');
152  end
153  end
154 end
155 
Interface for a localized operator that fulfills the so-called -independent DOF dependence.
Interface for the storage and generation of detailed data that can be used to build reduced basis fun...
Definition: Cached.m:18
this class combines two SnapshotsGenerator.SpaceOpEvals and produces the combination of both operator...
Implementation of a SnapshotsGenerator.Cached for empirical basis generation. The generate() method r...
Definition: SpaceOpEvals.m:18
Cacheable generators of detailed data snapshots.
Definition: Cached.m:1