rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
matrix_advection.m
1 function res = matrix_advection(x, model, df_info, i, j)
2 %function res = matrix_advection(x, model, df_info, i, j)
3 
4 % IM 21.07.2016
5 
6 gradient_hat_phi_i = evaluate_basis_function_derivative(df_info, x, i);
7 hat_phi_j = evaluate_basis_function(df_info, x, j);
8 
9 JIT = df_info.grid.JIT;
10 
11 v = cache_function(@(xarg, xmodel)xmodel.velocity(df_info.grid, ...
12  1:df_info.grid.nelements, ...
13  xarg, xmodel), x, model);
14 
15 if ~iscell(v)
16  % the following is vectorial of size nelements!
17  res = - hat_phi_j * ( v(:,1) .* (JIT(:,1,1) * gradient_hat_phi_i(1) ...
18  + JIT(:,1,2)* gradient_hat_phi_i(2)) ...
19  + v(:,2) .* (JIT(:,2,1) * gradient_hat_phi_i(1) ...
20  + JIT(:,2,2)* gradient_hat_phi_i(2)));
21 else
22  res = cell(1,length(v));
23  for q = 1:length(res)
24  res{q} = - hat_phi_j * ( v{q}(:,1) .* (JIT(:,1,1) * gradient_hat_phi_i(1) ...
25  + JIT(:,1,2)* gradient_hat_phi_i(2)) ...
26  + v{q}(:,2) .* (JIT(:,2,1) * gradient_hat_phi_i(1) ...
27  + JIT(:,2,2)* gradient_hat_phi_i(2)));
28 
29  end
30 end
31 
32 end
33 
34 
35 
36 
37 
function varargout = cache_function(func_ptr, varargin)
simple caching of function call inputs are cached too!