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.
6 % An SpaceOpEvals depends on a SnapshotsGenerator.Cached providing detailed
7 % simulation (trajectories) on which the operator can be applied.
9 properties (Access = protected)
10 % an
object of type SnapshotsGenerator.Trajectories providing a generator for detailed_simulations
11 rb_detailed_generator;
14 properties (SetAccess = protected)
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.
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.
31 % function_handle with synopsis
32 %
'op(descr, model_data, U, NU_ind)' implementing the
operator
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')
45 eidg = eidg@SnapshotsGenerator.Cached(dmodel,
id, force_delete, enable_caching);
47 eidg.rb_detailed_generator = rbdgen;
48 if isequal(
class(ophandle),
'function_handle')
51 error('fourth constructor argument must be of type ''
ILocalizedOperator'' or a function handle');
53 eidg.ophandle = ophandle;
56 function combination = plus(this, other)
57 % function combination = plus(this, other)
58 % convenience function allowing to merge several
59 % SnapshotsGenerator::
SpaceOpEvals instances together by "adding" them
60 % together with a '+' operator.
63 % other: an "addend" of type SnapshotsGenerator::
SpaceOpEvals
73 methods (Access = protected)
74 function [LU, opt_fields] = generate_impl(this, dmodel, detailed_data, fields)
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);
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.
89 % U: a matrix of size
'ndofs x K' with snapshots generated by the
90 % underlying #rb_detailed_generator.
93 % LU: a matrix of size
'ndofs x K' with the
operator evaluations.
96 % LU = this.ophandle.apply(dmodel, detailed_data, U, []);
100 fields = fieldnames(U);
101 nsnaps = size(U.(fields{1}), 2);
106 %
for evolution problems: If we include intermediate Newton
107 % solutions, the number of snapshots differs from the number of
109 if ~isfield(descr,
'nt') || nsnaps > descr.nt+1
110 LU = zeros(this.ophandle.ret_size(detailed_data), nsnaps);
113 if dmodel.debug && ~descr.data_const_in_time
114 error(
'time dependent data is not yet implemented for newton schemes');
116 [nu, bu] = this.ophandle.apply(descr, detailed_data, dmodel.get_dofs_at_time(U, tn), []);
117 if ~isempty(bu) && tn==1
123 if ~isfield(descr,
'ei_time_indices')
124 if isfield(descr, 'T')
125 descr.ei_time_indices = 1:descr.nt;
127 descr.ei_time_indices = 1;
134 LU = zeros(this.ophandle.ret_size(detailed_data), length(descr.ei_time_indices));
135 for tn = 1:length(descr.ei_time_indices);
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;
141 [nu, bu] = this.ophandle.apply(descr, detailed_data, dmodel.get_dofs_at_time(U,ti), []);
142 if ~isempty(bu) && tn==1
148 if ~isempty(store_bu)