rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
OperatorsDefault.m
1 classdef OperatorsDefault < handle
2  %classdef OperatorsDefault < handle
3  % Fem operators can be obtained from stored components.
4  %
5  % This class helps storing Fem system components for accelerating the
6  % operator evaluation, if it is done multiple times. Since the
7  % compontents are accessible, it is also useful for the reduced data
8  % generation. Note that this is compatible with the function
9  % Fem.Assembly.operator.
10  %
11  % The components can be assembled with the method
12  % assemble_components(). If "operators" is a Fem.OperatorsDefault
13  % object, the components are stored in operators.A_comp and
14  % operators.f_comp. To obtain the Fem system simply call [A, f] =
15  % operators(model, model_data).
16  %
17  % In stokes problems, it can only be used for linear terms.
18 
19  properties (SetAccess=private)
20 
21  A_comp = {};
22  f_comp = {};
23  componentsAssembled = 0;
24  end
25 
26  methods
27 
28  function this = OperatorsDefault()
29  %function this = OperatorsDefault()
30  % Only initializing new object.
31  end
32 
33  function varargout = evaluate(this, model, model_data)
34  %function varargout = evaluate(this, model, model_data)
35  % Operator evaluation. Returns a full Fem system.
36  %
37  % If the components are stored, the system is computed via
38  % linear combinations of the components, else the assembly
39  % routine of model is called.
40  %
41  % Return values:
42  % varargout: The first output represents the system matrix,
43  % the second output (only if requested) the right-hand side
44  % vector. The field model.decomp_mode has no influence.
45 
46  if this.componentsAssembled
47  model.decomp_mode = 2;
48  [A_coeff, f_coeff] = model.operators(model, model_data);
49  % the following is needed because dirichlet dofs are
50  % ignored in assembly of components for reduced data
51  if model.has_nonlinearity
52  Qr_dir = length(model_data.bc_info.dirichlet_dof_vector_components);
53  QA_nonlin = length(model.matrix_nonlin_indices);
54  A_coeff(1:Qr_dir*QA_nonlin) = 0;
55  end
56  varargout{1} = lincomb_sequence(this.A_comp, A_coeff);
57  dirichlet_gids = model_data.bc_info.dirichlet_gids;
58  varargout{1} = varargout{1} + sparse(dirichlet_gids, dirichlet_gids, ...
59  ones(size(dirichlet_gids)), model_data.df_info.ndofs, ...
60  model_data.df_info.ndofs) + eps*speye(model_data.df_info.ndofs);
61  if nargout > 1
62  r_dir_coeff = model.dirichlet_values([], [], [], [], model);
63  r_dir = lincomb_sequence(...
64  model_data.bc_info.dirichlet_dof_vector_components, ...
65  r_dir_coeff);
66  f_coeff(end+1-(1:length(r_dir_coeff)*length(A_coeff))) = 0;
67  varargout{2} = lincomb_sequence(this.f_comp, f_coeff) + r_dir;
68  end
69  else
70  model.decomp_mode = 0;
71  [varargout{1:nargout}] = model.operators(model, model_data);
72  end
73  end
74 
75  function this = assemble_components(this, model, model_data)
76  %function this = assemble_components(this, model, model_data)
77  % Calls the assembly routine of model and stores all
78  % components.
79  model.decomp_mode = 1;
80  [this.A_comp, this.f_comp] = model.operators(model, model_data);
81  this.componentsAssembled = 1;
82  end
83 
84  function this = clear_components(this)
85  %function this = clear_components(this)
86  % Deletes all components.
87  this.A_comp = {};
88  this.f_comp = {};
89  this.componentsAssembled = 0;
90  end
91 
92  function varargout = subsref(this, S)
93  %function varargout = subsref(this, S)
94  % Overloads subsref.
95  %
96  % This enables an operator evaluation via operators(model,
97  % model_data), if "operators" is a Fem.OperatorsDefault object.
98  if strcmp(S(1).type, '()')
99  [varargout{1:nargout}] = evaluate(this, S(1).subs{:});
100  else
101  [varargout{1:nargout}] = builtin('subsref', this, S);
102  end
103  end
104 
105  end %methods
106 
107 end %classdef
Fem operators can be obtained from stored components.