annotate extra/bim/inst/bim2c_intrp.m @ 12628:4cacfa5f9470 octave-forge

push changes made for release
author cdf
date Mon, 08 Jun 2015 08:51:06 +0000
parents 054bd2e703f4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11171
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
1 ## Copyright (C) 2011, 2012 Carlo de Falco
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
2 ##
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
3 ## This program is free software; you can redistribute it and/or modify
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
4 ## it under the terms of the GNU General Public License as published by
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
5 ## the Free Software Foundation; either version 3 of the License, or
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
6 ## (at your option) any later version.
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
7 ##
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
8 ## This program is distributed in the hope that it will be useful,
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
11 ## GNU General Public License for more details.
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
12 ##
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
13 ## You should have received a copy of the GNU General Public License
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
14 ## along with Octave; see the file COPYING. If not, see
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
15 ## <http://www.gnu.org/licenses/>.
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
16
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
17 ## -*- texinfo -*-
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
18 ##
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
19 ## @deftypefn {Function File} {@var{data}} = bim2c_intrp (@var{msh}, @var{n_data}, @var{e_data}, @var{points})
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
20 ##
12628
4cacfa5f9470 push changes made for release
cdf
parents: 11171
diff changeset
21 ## Compute interpolated values of multicomponent node centered field @var{n_data} and/or
4cacfa5f9470 push changes made for release
cdf
parents: 11171
diff changeset
22 ## cell centered field @var{n_data} at an arbitrary set of points whose coordinates are given in the
4cacfa5f9470 push changes made for release
cdf
parents: 11171
diff changeset
23 ## n_by_2 matrix @var{points}.
11171
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
24 ##
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
25 ## @end deftypefn
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
26
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
27
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
28 ## Author: Carlo de Falco <carlo@guglielmo.local>
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
29 ## Created: 2012-10-01
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
30
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
31 function data = bim2c_intrp (msh, n_data, e_data, p)
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
32
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
33 %% for each point, find the enclosing tetrahedron
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
34 [t_list, b_list] = tsearchn (msh.p.', msh.t(1:3, :)', p);
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
35
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
36 %% only keep points within tetrahedra
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
37 invalid = isnan (t_list);
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
38 t_list = t_list (! invalid);
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
39 ntl = numel (t_list);
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
40 b_list = b_list(! invalid, :);
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
41 points(invalid,:) = [];
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
42
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
43 data = [];
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
44 if (! isempty (n_data))
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
45 data = cat (1, data, squeeze (
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
46 sum (reshape (n_data(msh.t(1:3, t_list), :),
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
47 [3, ntl, (columns (n_data))]) .*
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
48 repmat (b_list.', [1, 1, (columns (n_data))]), 1)));
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
49 endif
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
50
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
51 if (! isempty (e_data))
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
52 data = cat (1, data, e_data(t_list, :));
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
53 endif
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
54
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
55 endfunction
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
56
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
57 %!test
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
58 %! msh = bim2c_mesh_properties (msh2m_structured_mesh (linspace (0, 1, 11), linspace (0, 1, 13), 1, 1:4));
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
59 %! x = y = linspace (0, 1, 100).';
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
60 %! u = msh.p(1, :).';
054bd2e703f4 fix bug and add new functions
cdf
parents:
diff changeset
61 %! ui = bim2c_intrp (msh, u, [], [x, y]);
12628
4cacfa5f9470 push changes made for release
cdf
parents: 11171
diff changeset
62 %! assert (ui, linspace (0, 1, 100), 10*eps);