1 /* Copyright (C) 2008  VZLU Prague, a.s., Czech Republic
2  *
3  * Author: Jaroslav Hajek <highegg@gmail.com>
4  *
5  * This file is part of NLWing2.
6  *
7  * NLWing2 is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this software; see the file COPYING.  If not, see
19  * <http://www.gnu.org/licenses/>.  */
20 
21 #include <oct.h>
22 #include <f77-fcn.h>
23 
24 extern "C"
25 {
26   F77_RET_T
27   F77_FUNC(vitens, VITENS) (const octave_idx_type&, const double&,
28                             const double*, const double*, const double*,
29                             const int&, double*, double*,
30                             double*, double*);
31 }
32 
33 DEFUN_DLD(vitensor, args, nargout,
34 "-*- texinfo -*-\n\
35 @deftypefn{Loadable Function} {[@var{vxg}, @var{vyg}, @var{vx0}, @var{vy0}]} = \
36 vitensor (@var{alfa}, @var{xAC}, @var{yAC}, @var{zAC}, @var{sym})\n\
37 Computes the induced velocities tensors on a lifting line approximated by a chain\n\
38 of vortex segments. @var{alfa} is the angle of attack (relative to x-z plane),\n\
39 @var{xAC}, @var{yAC}, @var{zAC} are coordinates of the lifting line points\n\
40 (chordwise, vertical, spanwise). @var{sym} denotes symmetry - only half of the\n\
41 lifting line is given, the other half is obtained by mirroring by the xy plane.\n\
42 On return, @var{vxg} and @var{vyg} are jacobians of induced local x and y\n\
43 velocities - the velocities induced by j-th vortex on i-th collocation point are\n\
44 given by @var{vxg}(i,j), @var{vyg}(i,j). @var{vx0}(i), @var{vy0}(i) denote local\n\
45 velocities induced on the collocation point by freestream. Thus, if @var{gam} is a\n\
46 vector of panel circulations, the corresponding induced velocities can be calculated\n\
47 as @code{@var{vx} = @var{vxg}*@var{gam}+@var{vx0}; @var{vy} = @var{vyg}*@var{gam}+@var{vy0};}\n\
48 @end deftypefn")
49 {
50   int nargin = args.length ();
51   octave_value_list retval;
52 
53   if (nargin < 4 || nargin > 5)
54     {
55       print_usage ();
56       return retval;
57     }
58 
59   octave_value argalfa = args (0);
60   octave_value argxAC = args (1);
61   octave_value argyAC = args (2);
62   octave_value argzAC = args (3);
63 
64   if (argalfa.is_real_scalar ()
65       && argxAC.is_real_matrix ()
66       && argyAC.is_real_matrix ()
67       && argzAC.is_real_matrix ()
68       && (nargin < 5 || args (4).is_bool_scalar ()))
69     {
70       double alfa = argalfa.scalar_value();
71       octave_idx_type np = argxAC.length()-1;
72 
73       int sym = (nargin >= 5) ? args (4).scalar_value () : 0;
74 
75       if (np > 0 && argyAC.length() == np+1 && argzAC.length() == np+1)
76         {
77           Matrix xAC = argxAC.matrix_value ();
78           Matrix yAC = argyAC.matrix_value ();
79           Matrix zAC = argzAC.matrix_value ();
80 
81           Matrix vxg(np,np), vyg(np,np);
82           Matrix vx0(np,1), vy0(np,1);
83 
84           F77_FUNC(vitens, VITENS) (np, alfa,
85                                     xAC.data (), yAC.data (), zAC.data (), sym,
86                                     vx0.fortran_vec (), vxg.fortran_vec (),
87                                     vy0.fortran_vec (), vyg.fortran_vec ());
88           retval (0) = vxg;
89           retval (1) = vyg;
90           retval (2) = vx0;
91           retval (3) = vy0;
92         }
93       else
94         error ("vitensor: dimension mismatch");
95     }
96   else
97     print_usage();
98 
99   return retval;
100 
101 }
102