annotate scripts/plot/draw/stream3.m @ 28136:23f667483fab stable

Add Matlab compatible "streamtube" function (bug #57471). * streamtube.m: Add new function "streamtube" based on "ostreamtube" that is Matlab compatible. * ostreamtube.m, stream3.m, streamline.m, module.mk, plot.txi, NEWS: Add references.
author Markus Meisinger <chloros2@gmx.de>
date Wed, 19 Feb 2020 07:50:04 +0100
parents 695bb31e565b
children 8a9a041db1dc 0a5b15007766
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
3 ## Copyright (C) 2019-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27810
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
7 ##
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
8 ## This file is part of Octave.
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
9 ##
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
13 ## (at your option) any later version.
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
14 ##
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
18 ## GNU General Public License for more details.
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
19 ##
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
25
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
26 ## -*- texinfo -*-
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
27 ## @deftypefn {} {@var{xyz} =} stream3 (@var{x}, @var{y}, @var{z}, @var{u}, @var{v}, @var{w}, @var{sx}, @var{sy}, @var{sz})
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
28 ## @deftypefnx {} {@var{xyz} =} stream3 (@var{u}, @var{v}, @var{w}, @var{sx}, @var{sy}, @var{sz})
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
29 ## @deftypefnx {} {@var{xyz} =} stream3 (@dots{}, @var{options})
27794
45ad2127582b doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents: 27759
diff changeset
30 ## Compute 3-D streamline data.
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
31 ##
27794
45ad2127582b doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents: 27759
diff changeset
32 ## Calculate streamlines of a vector field given by @code{[@var{u}, @var{v},
45ad2127582b doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents: 27759
diff changeset
33 ## @var{w}]}. The vector field is defined over a rectangular grid given by
45ad2127582b doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents: 27759
diff changeset
34 ## @code{[@var{x}, @var{y}, @var{z}]}. The streamlines start at the seed
45ad2127582b doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents: 27759
diff changeset
35 ## points @code{[@var{sx}, @var{sy}, @var{sz}]}. The returned value @var{xyz}
45ad2127582b doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents: 27759
diff changeset
36 ## contains a cell array of vertex arrays. If the starting point is outside
45ad2127582b doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents: 27759
diff changeset
37 ## the vector field, @code{[]} is returned.
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
38 ##
27794
45ad2127582b doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents: 27759
diff changeset
39 ## The input parameter @var{options} is a 2-D vector of the form
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
40 ## @code{[@var{stepsize}, @var{max_vertices}]}. The first parameter
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
41 ## specifies the step size used for trajectory integration (default 0.1). A
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
42 ## negative value is allowed which will reverse the direction of integration.
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
43 ## The second parameter specifies the maximum number of segments used to
27794
45ad2127582b doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents: 27759
diff changeset
44 ## create a streamline (default 10,000).
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
45 ##
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
46 ## The return value @var{xyz} is a @nospell{nverts x 3} matrix containing the
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
47 ## coordinates of the field line segments.
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
48 ##
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
49 ## Example:
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
50 ##
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
51 ## @example
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
52 ## @group
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
53 ## [x, y, z] = meshgrid (0:3);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
54 ## u = 2 * x;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
55 ## v = y;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
56 ## w = 3 * z;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
57 ## xyz = stream3 (x, y, z, u, v, w, 1.0, 0.5, 0.0);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
58 ## @end group
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
59 ## @end example
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
60 ##
28136
23f667483fab Add Matlab compatible "streamtube" function (bug #57471).
Markus Meisinger <chloros2@gmx.de>
parents: 28135
diff changeset
61 ## @seealso{stream2, streamline, streamtube, ostreamtube}
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
62 ## @end deftypefn
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
63
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
64 ## References:
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
65 ##
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
66 ## @article{
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
67 ## title = {Particle Tracing Algorithms for 3D Curvilinear Grids},
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
68 ## year = {2000},
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
69 ## author = {Nielson, Gregory and Uller, H. and Sadarjoen, I. and Walsum, Theo and Hin, Andrea and Post, Frits}
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
70 ## }
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
71 ##
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
72 ## @article{
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
73 ## title = {Sources of error in the graphical analysis of CFD results},
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
74 ## publisher = {Journal of Scientific Computing},
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
75 ## year = {1988},
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
76 ## volume = {3},
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
77 ## number = {2},
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
78 ## pages = {149--164},
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
79 ## author = {Buning, Pieter G.},
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
80 ## }
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
81
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
82 function xyz = stream3 (varargin)
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
83
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
84 options = [];
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
85 switch (numel (varargin))
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
86 case 0
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
87 print_usage ();
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
88 case {6,7}
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
89 if (numel (varargin) == 6)
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
90 [u, v, w, spx, spy, spz] = varargin{:};
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
91 else
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
92 [u, v, w, spx, spy, spz, options] = varargin{:};
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
93 endif
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
94 [m, n, p] = size (u);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
95 [x, y, z] = meshgrid (1:n, 1:m, 1:p);
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
96 case 9
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
97 [x, y, z, u, v, w, spx, spy, spz] = varargin{:};
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
98 case 10
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
99 [x, y, z, u, v, w, spx, spy, spz, options] = varargin{:};
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
100 otherwise
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
101 error ("stream3: invalid number of inputs");
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
102 endswitch
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
103
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
104 stepsize = 0.1;
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
105 max_vertices = 10_000;
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
106 if (! isempty (options))
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
107 switch (numel (options))
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
108 case 1
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
109 stepsize = options(1);
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
110 case 2
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
111 stepsize = options(1);
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
112 max_vertices = options(2);
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
113 otherwise
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
114 error ("stream3: invalid number of OPTIONS elements");
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
115 endswitch
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
116
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
117 if (! isreal (stepsize) || stepsize == 0)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
118 error ("stream2: STEPSIZE must be a real scalar != 0");
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
119 endif
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
120 if (! isreal (max_vertices) || max_vertices < 1)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
121 error ("stream2: MAX_VERTICES must be an integer > 0");
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
122 endif
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
123 max_vertices = fix (max_vertices);
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
124 endif
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
125
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
126 if (! (size_equal (u, v, w, x, y, z) && size_equal (spx, spy, spz)))
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
127 error ("stream3: matrix dimensions must match");
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
128 endif
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
129 if (iscomplex (u) || iscomplex (v) || iscomplex (w)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
130 || iscomplex (x) || iscomplex (y) || iscomplex (z)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
131 || iscomplex (spx) || iscomplex (spy) || iscomplex (spz))
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
132 error ("stream3: all inputs must be real-valued");
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
133 endif
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
134
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
135 gx = x(1, :, 1);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
136 gy = y(:, 1, 1).';
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
137 tmp = z(1, 1, :);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
138 gz = tmp(:).';
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
139
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
140 ## Jacobian Matrix
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
141 dx = diff (gx);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
142 dy = diff (gy);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
143 dz = diff (gz);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
144 ## "<" used to check if the mesh is ascending
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
145 if (any (dx <= 0) || any (dy <= 0) || any (dz <= 0)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
146 || any (isnan (dx)) || any (isnan (dy)) || any (isnan (dz)))
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
147 error ("stream3: non-monotonically increasing or NaN values found in mesh");
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
148 endif
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
149 tx = 1 ./ dx;
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
150 ty = 1 ./ dy;
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
151 tz = 1 ./ dz;
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
152 ## "Don't cares" used for handling points located on the border
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
153 tx(end + 1) = 0;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
154 ty(end + 1) = 0;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
155 tz(end + 1) = 0;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
156 dx(end + 1) = 0;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
157 dy(end + 1) = 0;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
158 dz(end + 1) = 0;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
159
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
160 px = spx(:);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
161 py = spy(:);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
162 pz = spz(:);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
163
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
164 for nseed = 1 : numel (px)
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
165
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
166 xp = px(nseed);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
167 yp = py(nseed);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
168 zp = pz(nseed);
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
169 idx = find (diff (gx <= xp), 1);
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
170 if (gx(end) == xp)
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
171 idx = numel (gx);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
172 endif
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
173 idy = find (diff (gy <= yp), 1);
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
174 if (gy(end) == yp)
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
175 idy = numel (gy);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
176 endif
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
177 idz = find (diff (gz <= zp), 1);
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
178 if (gz(end) == zp)
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
179 idz = numel (gz);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
180 endif
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
181
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
182 if (isempty (idx) || isempty (idy) || isempty (idz))
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
183 xyz{nseed} = [];
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
184 else
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
185 ## Transform seed from P coordinates to C coordinates
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
186 zeta = (idx - 1) + (xp - gx(idx)) * tx(idx);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
187 xi = (idy - 1) + (yp - gy(idy)) * ty(idy);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
188 rho = (idz - 1) + (zp - gz(idz)) * tz(idz);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
189
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
190 C = __streameuler3d__ (u, v, w, tx, ty, tz, zeta, xi, rho, ...
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
191 stepsize, max_vertices);
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
192
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
193 ## Transform from C coordinates to P coordinates
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
194 idu = floor (C(:, 1));
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
195 idv = floor (C(:, 2));
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
196 idw = floor (C(:, 3));
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
197 xyz{nseed} = [gx(idu + 1).' + (C(:, 1) - idu).*(dx(idu + 1).'), ...
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
198 gy(idv + 1).' + (C(:, 2) - idv).*(dy(idv + 1).'), ...
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
199 gz(idw + 1).' + (C(:, 3) - idw).*(dz(idw + 1).')];
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
200 endif
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
201
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
202 endfor
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
203
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
204 endfunction
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
205
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
206
27759
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
207 %!demo
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
208 %! clf;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
209 %! [x, y, z] = meshgrid (-30:1:30, -30:1:30, 0:1:50);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
210 %! s = 10;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
211 %! b = 8 / 3;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
212 %! r = 28;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
213 %! u = s * (y - x);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
214 %! v = r * x - y - x.*z;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
215 %! w = x.*y - b * z;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
216 %! hold on;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
217 %! sx = 0.1;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
218 %! sy = 0.1;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
219 %! sz = 0.1;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
220 %! plot3 (sx, sy, sz, ".r", "markersize", 15);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
221 %! h = streamline (x, y, z, u, v, w, sx, sy, sz, [0.1, 50000]);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
222 %! set (h, "color", "r");
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
223 %! view (3);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
224 %! title ("Lorenz System");
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
225 %! grid on;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
226 %! axis equal;
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
227
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
228 %!test
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
229 %! [u, v, w] = meshgrid (0:3, 0:3, 0:3);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
230 %! xyz = stream3 (u, v, w, 2, 2, 2, [0.01,5]);
992e702ef0d7 Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff changeset
231 %! assert (numel (xyz{:}), 15);
27810
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
232
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
233 ## Test input validation
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
234 %!error stream3 ()
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
235 %!error <invalid number of inputs> stream3 (1)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
236 %!error <invalid number of inputs> stream3 (1,2)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
237 %!error <invalid number of inputs> stream3 (1,2,3)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
238 %!error <invalid number of inputs> stream3 (1,2,3,4)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
239 %!error <invalid number of inputs> stream3 (1,2,3,4,5)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
240 %!error <invalid number of inputs> stream3 (1,2,3,4,5,6,7,8)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
241 %!error <invalid number of OPTIONS> stream3 (1,2,3,4,5,6, [1,2,3])
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
242 %!error <STEPSIZE must be a real scalar != 0> stream3 (1,2,3,4,5,6, [1i])
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
243 %!error <STEPSIZE must be a real scalar != 0> stream3 (1,2,3,4,5,6, [0])
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
244 %!error <MAX_VERTICES must be an integer> stream3 (1,2,3,4,5,6, [1, 1i])
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
245 %!error <MAX_VERTICES must be an integer> stream3 (1,2,3,4,5,6, [1, 0])
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
246 %!error <matrix dimensions must match> stream3 ([1 1],2,3,4,5,6)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
247 %!error <matrix dimensions must match> stream3 (1,[2 2],3,4,5,6)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
248 %!error <matrix dimensions must match> stream3 (1,2,[3 3],4,5,6)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
249 %!error <matrix dimensions must match> stream3 (1,2,3,[4 4],5,6)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
250 %!error <matrix dimensions must match> stream3 (1,2,3,4,[5 5],6)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
251 %!error <matrix dimensions must match> stream3 (1,2,3,4,5,[6 6])
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
252 %!error <all inputs must be real-valued> stream3 (1i,2,3,4,5,6)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
253 %!error <all inputs must be real-valued> stream3 (1,2i,3,4,5,6)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
254 %!error <all inputs must be real-valued> stream3 (1,2,3i,4,5,6)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
255 %!error <all inputs must be real-valued> stream3 (1,2,3,4i,5,6)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
256 %!error <all inputs must be real-valued> stream3 (1,2,3,4,5i,6)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
257 %!error <all inputs must be real-valued> stream3 (1,2,3,4,5,6i)
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
258 %!error <non-monotonically increasing or NaN values found in mesh>
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
259 %! stream3 ([2 1], [1 2], [3 3], [4 4], [5 5], [6 6], [7 7], [8 8], [9 9]);
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
260 %!error <non-monotonically increasing or NaN values found in mesh>
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
261 %! stream3 ([1 NaN], [1 2], [3 3], [4 4], [5 5], [6 6], [7 7], [8 8], [9 9]);
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
262 ## FIXME: vectors representing x, y, z mesh are not accepted.
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
263 %#!error <non-monotonically increasing or NaN values found in mesh>
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
264 %! stream3 ([1 2], [2 1], [3 3], [4 4], [5 5], [6 6], [7 7], [8 8], [9 9]);
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
265 %#!error <non-monotonically increasing or NaN values found in mesh>
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
266 %! stream3 ([1 2], [1 NaN], [3 3], [4 4], [5 5], [6 6], [7 7], [8 8], [9 9]);
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
267 %#!error <non-monotonically increasing or NaN values found in mesh>
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
268 %! stream3 ([1 2], [1 2], [2 1], [4 4], [5 5], [6 6], [7 7], [8 8], [9 9]);
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
269 %#!error <non-monotonically increasing or NaN values found in mesh>
f2b89a2e20b6 overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents: 27808
diff changeset
270 %! stream3 ([1 2], [1 2], [1 NaN], [4 4], [5 5], [6 6], [7 7], [8 8], [9 9]);