rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
disc_gradient.m
1 function [gradx,grady] = disc_gradient(glob,fdf)
2 %function [gradx,grady] = disc_gradient(glob,fdf)
3 %
4 % compute the gradient of the femdiscfunc fdf
5 %
6 % input:
7 % glob: list of coordinates of points, in which the gradient shall be
8 % calculated. Must not be points in grid vertices or edges, but
9 % inside elements.
10 % fdf: femdiscfunc (FEM solution of a PDE)
11 %
12 % output:
13 % gradx : values of the gradient in x direction
14 % grady : values of the gradient in y direction
15 %
16 % this computation is only exact for pdeg = 1!
17 %
18 % Immanuel Maier, 07.02.2011, Oliver Zeeb, 10.02.11
19 
20 elind = zeros(size(glob,1),1);
21 
22 % loop over all elements:
23 for i = 1:fdf.grid.nelements
24  % compute local coordinates:
25  loc = global2local(fdf.grid,i,glob);
26  % if points lie in element i,
27  % save element-index in elind:
28  iselement = find((loc(:,1) >= 0-5000*eps) & (loc(:,2) >= 0-5000*eps) & ...
29  (loc(:,1)+loc(:,2) <= 1+5000*eps));
30  elind(iselement) = i;
31 end;
32 
33 if ~isempty(find(elind == 0))
34  error('cannot find elements for all points!');
35 end;
36 
37 % compute grad_hat u_hat
38 grad_hatx = fdf.dofs(fdf.grid.VI(elind,2)) - fdf.dofs(fdf.grid.VI(elind,1));
39 grad_haty = fdf.dofs(fdf.grid.VI(elind,3)) - fdf.dofs(fdf.grid.VI(elind,1));
40 
41 % compute grad u with coordinate-transformation-derivative-rule
42 gradx = fdf.grid.JIT(elind,1,1) .* grad_hatx ...
43  + fdf.grid.JIT(elind,1,2) .* grad_haty;
44 grady = fdf.grid.JIT(elind,2,1) .* grad_hatx ...
45  + fdf.grid.JIT(elind,2,2) .* grad_haty;
class representing a continous piecewise polynomial function of arbitrary dimension. DOFS correspond to the values of Lagrange-nodes.
Definition: femdiscfunc.m:17