]> Creatis software - CreaPhase.git/blob - octave_packages/fpl-1.2.0/pdemesh.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / fpl-1.2.0 / pdemesh.m
1 ##  Copyright (C) 2010  Carlo de Falco
2 ##
3 ##  This file is part of:
4 ##         FPL - Fem PLotting package for octave
5 ##
6 ##  FPL is free software; you can redistribute it and/or modify
7 ##  it under the terms of the GNU General Public License as published by
8 ##  the Free Software Foundation; either version 2 of the License, or
9 ##  (at your option) any later version.
10 ##
11 ##  FPL is distributed in the hope that it will be useful,
12 ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ##  GNU General Public License for more details.
15 ##
16 ##  You should have received a copy of the GNU General Public License
17 ##  along with FPL; If not, see <http://www.gnu.org/licenses/>.
18 ##
19 ##  author: Carlo de Falco     <cdf _AT_ users.sourceforge.net>
20
21 ## -*- texinfo -*-
22 ## @deftypefn {Function File} {@var{h} =} pdemesh (@var{p}, @var{e}, @var{t}, @var{u})
23 ##
24 ## Plot a triangular mesh in 3D given a mesh structure and node data.
25 ## @var{p}, @var{t} are the mesh vertices and connectivity, @var{u} node data.
26 ## @var{e} is ignored and is accepted only for compatibiity.
27 ##
28 ## @seealso{fpl_dx_write_field, fpl_vtk_write_field} 
29 ##
30 ## @end deftypefn
31
32 function h = pdemesh (p, e, t, u)
33
34   ## Check input
35   if (nargin < 3)
36     error("pdemesh: wrong number of input parameters");
37   elseif (nargin == 3)
38     u = zeros (1, columns (p));
39   endif
40
41   nel = columns (t);
42   npt = columns (p);
43   if (numel (u) != npt)
44     error("pdemesh: wrong data size");
45   endif
46
47   hs = ishold ();
48   
49 ### node data
50   H = trimesh (t(1:3, :).', p(1,:).', p(2,:).', u(:));
51   
52   if (nargout == 1)
53     h = H;
54   endif
55
56   if (hs)
57     hold on;
58   else
59     hold off;
60   endif
61
62 endfunction
63
64 %!demo
65 %! msh = msh2m_structured_mesh ([0:.05:1], [0:.1:1], 1, 1:4, 'random');
66 %! x = msh.p(1,:)'; xm = sum(x(msh.t(1:3,:)),1)/3;
67 %! y = msh.p(2,:)'; ym = sum(y(msh.t(1:3,:)),1)/3;
68 %! pdemesh (msh.p, msh.t, msh.t, x.*(1-x).*y.*(1-y))
69 %! view(3)