rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
stokes_sobolev_embedding_constant.m
1 function rho_sqr = stokes_sobolev_embedding_constant(model, model_data, tol, maxiter)
2 %function rho_sqr = stokes_sobolev_embedding_constant(model, model_data, tol, maxiter)
3 %
4 
5 % IM 02.12.2014
6 
7 if model.verbose > 1
8  disp('start sobolev embedding constant algorithm');
9 end
10 start_iteration = tic;
11 
12 if nargin < 4
13  maxiter = [];
14 end
15 if nargin < 3
16  tol = [];
17 end
18 
19 if isempty(tol)
20  tol = 1e-9;
21 end
22 if isempty(maxiter)
23  maxiter = 20;
24 end
25 
26 vel_index = get_index(model_data.df_info, 'velocity');
27 df_info = get(model_data.df_info, vel_index);
28 v = Fem.DiscFunc([], df_info);
29 
30 B = get(model.get_inner_product_matrix(model_data), vel_index) ...
31  + eps*speye(df_info.ndofs);
32 
33 dirichlet_gids = [];
34 if model.has_dirichlet_values
35  dirichlet_gids = model_data.bc_info.dirichlet_gids;
36  B(dirichlet_gids, :) = [];
37  B(:, dirichlet_gids) = [];
38 end
39 B = 0.5*(B+B');
40 
41 int_dofs = setdiff(1:df_info.ndofs, dirichlet_gids);
42 
43 tmodel = [];
44 tmodel.reaction = @(grid, eindices, loc, params) ones(length(eindices), 1);
45 tmodel.qdeg = 2*model.pdeg;
46 
47 rho_sqr = 0;
48 rho_old = -1;
49 niter = 0;
50 
51 while abs(rho_old - rho_sqr) > tol
52 
53  rho_old = rho_sqr;
54 
55  A = Fem.Assembly.matrix_part(@Fem.IntegralKernels.matrix_reaction, ...
56  tmodel, df_info) + eps*speye(df_info.ndofs);
57  if ~isempty(dirichlet_gids)
58  A(dirichlet_gids, :) = [];
59  A(:, dirichlet_gids) = [];
60  end
61 
62  [v_int_dofs, rho_sqr] = eigs(A, B, 1, 'LM');
63  niter = niter+1;
64  if model.verbose > 1
65  disp(['deviation to previous step: ', num2str(abs(rho_old - rho_sqr))]);
66  end
67 
68  % compute factor
69  v.dofs(int_dofs) = v_int_dofs;
70  v1 = get_component(v, 1);
71  v2 = get_component(v, 2);
72  v1.dofs = v1.dofs.^2 + v2.dofs.^2;
73  factor = 1/l2_norm(v1);
74 
75  tmodel.reaction = @(grid, eindices, loc, params) ...
76  factor * sum(evaluate(v, eindices, loc, params).^2, 2);
77 
78  if niter >= maxiter
79  warning('stokes:sobolev_embedding_constant', ...
80  ['iteration maximum reached, norm(defect): ', num2str(abs(rho_old - rho_sqr))])
81  break
82  end
83 end
84 if model.verbose > 1
85  disp(['terminate sobolev embedding constant algorithm after ', ...
86  num2str(toc(start_iteration)), ' seconds']);
87 end
88 
89 end
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
Definition: verbose.m:17