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
8 vel_ndofs_per_element = df_info.values{1}.values{1}.ndofs_per_element;
10 % detect velocity indices
11 if all([i j] <= vel_ndofs_per_element*2) && sum([i j] <= vel_ndofs_per_element) ~= 1
13 if isfield(model,
'uh')
15 hat_phi_i = evaluate_basis_function(df_info, x, i);
16 hat_phi_j = evaluate_basis_function(df_info, x, j);
19 (xarg, xmodel)xmodel.uh ...
20 .evaluate_derivative(':', ...
22 d =
cache_function(@(xarg, xmodel)xmodel.divergence_tensor(df_info.grid, ...
30 grad_uh_vals(:, 1, 1) * hat_phi_i(1) + ...
31 grad_uh_vals(:, 1, 2) * hat_phi_i(2);
33 grad_uh_vals(:, 2, 1) * hat_phi_i(1) + ...
34 grad_uh_vals(:, 2, 2) * hat_phi_i(2);
38 res = hat_phi_j(1) * ...
39 (grad_uh1_phi_i .* d(:, 1) + grad_uh2_phi_i .* d(:, 2)) + ...
41 (grad_uh1_phi_i .* d(:, 3) + grad_uh2_phi_i .* d(:, 4));
44 res = cell(1,length(d));
47 res{q} = hat_phi_j(1) * ...
48 (grad_uh1_phi_i .* d{q}(:, 1) + grad_uh2_phi_i .* d{q}(:, 2)) + ...
50 (grad_uh1_phi_i .* d{q}(:, 3) + grad_uh2_phi_i .* d{q}(:, 4));
function varargout = cache_function(func_ptr, varargin)
simple caching of function call inputs are cached too!