rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
fixed_point_algorithm.m
1 function [x, defect, niterations] = fixed_point_algorithm(A, f, eval_nonlin, tol, maxiter, damping, verbose)
2 %function [x, defect, niterations] = fixed_point_algorithm(A, f, eval_nonlin, tol, maxiter, damping, verbose)
3 %
4 % used in stokes_detailed_simulation, stokes_rb_simulation,
5 % rbhdd_detailed_simulation
6 % A can be an LUPQ_Handle holding the l-u-p-q-factors if model is linear
7 
8 % IM 28.05.2014
9 
10 has_nonlinearity = ~isempty(eval_nonlin);
11 
12 start_iteration = tic;
13 x = zeros(length(f), 1);
14 defect = f;
15 niterations = 0;
16 
17 if nargin < 7
18  verbose = 0;
19 end
20 if nargin < 6 || isempty(damping)
21  damping = 1;
22 end
23 if nargin < 5 || isempty(maxiter)
24  maxiter = 16;
25 end
26 if nargin < 4 || isempty(tol)
27  tol = 1e-9;
28 end
29 
30 if has_nonlinearity && verbose
31  disp('start fixed point iteration');
32 end
33 
34 if has_nonlinearity
35  A_lin = A;
36 end
37 
38 while norm(defect) > tol
39 
40  x = x + damping * (A \ defect);
41 
42  if has_nonlinearity
43  A = A_lin + eval_nonlin(x);
44  end
45 
46  defect = f - A * x;
47 
48  niterations = niterations + 1;
49 
50  if has_nonlinearity
51  if niterations >= maxiter
52  warning(['iteration maximum in fixed point iteration, norm(defect): ', ...
53  num2str(norm(defect))])
54  break
55  end
56 
57  if norm(defect) > 1e12
58  warning('fixed point iteration diverged!')
59  break
60  end
61 
62  if verbose > 1
63  disp([num2str(niterations), ': norm(defect) = ', num2str(norm(defect))]);
64  elseif verbose
65  fprintf('.');
66  end
67  end
68 end
69 
70 if has_nonlinearity && verbose
71  fprintf('\n');
72  disp(['terminate fixed point iteration after ', num2str(toc(start_iteration)), ...
73  ' seconds.']);
74 end
75 
76 end
function sim_data = stokes_detailed_simulation(model, model_data)
Performs a detailed simulation of a (Navier-)stokes problem.