rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
stokes_matrix_fd_nl.m
Go to the documentation of this file.
1 function res = stokes_matrix_fd_nl(x, model, df_info, i, j)
2 %function res = stokes_matrix_fd_nl(x, model, df_info, i, j)
3 % additional trilinear term in Frechet derivative of global operator
4 
5 % IM 02.12.2104
6 
7 
8 vel_ndofs_per_element = df_info.values{1}.values{1}.ndofs_per_element;
9 
10 % detect velocity indices
11 if all([i j] <= vel_ndofs_per_element*2) && sum([i j] <= vel_ndofs_per_element) ~= 1
12 
13  if isfield(model, 'uh')
14 
15  hat_phi_i = evaluate_basis_function(df_info, x, i);
16  hat_phi_j = evaluate_basis_function(df_info, x, j);
17 
18  grad_uh_vals = cache_function(@ ...
19  (xarg, xmodel)xmodel.uh ...
20  .evaluate_derivative(':', ...
21  xarg), x, model);
22  d = cache_function(@(xarg, xmodel)xmodel.divergence_tensor(df_info.grid, ...
23  1: ...
24  df_info ...
25  .grid.nelements, ...
26  xarg, ...
27  xmodel), x, model);
28 
29  grad_uh1_phi_i = ...
30  grad_uh_vals(:, 1, 1) * hat_phi_i(1) + ...
31  grad_uh_vals(:, 1, 2) * hat_phi_i(2);
32  grad_uh2_phi_i = ...
33  grad_uh_vals(:, 2, 1) * hat_phi_i(1) + ...
34  grad_uh_vals(:, 2, 2) * hat_phi_i(2);
35 
36  if ~iscell(d)
37 
38  res = hat_phi_j(1) * ...
39  (grad_uh1_phi_i .* d(:, 1) + grad_uh2_phi_i .* d(:, 2)) + ...
40  hat_phi_j(2) * ...
41  (grad_uh1_phi_i .* d(:, 3) + grad_uh2_phi_i .* d(:, 4));
42  else
43 
44  res = cell(1,length(d));
45  for q = 1:length(d)
46 
47  res{q} = hat_phi_j(1) * ...
48  (grad_uh1_phi_i .* d{q}(:, 1) + grad_uh2_phi_i .* d{q}(:, 2)) + ...
49  hat_phi_j(2) * ...
50  (grad_uh1_phi_i .* d{q}(:, 3) + grad_uh2_phi_i .* d{q}(:, 4));
51  end
52 
53  end
54  end
55 
56 else
57  res = [];
58 end
59 
60 end
function varargout = cache_function(func_ptr, varargin)
simple caching of function call inputs are cached too!