initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / randomProcesses / fft / fftRenumber.C
blob4e663093583025cabdf0a57f5b5be44d86c47454
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
26     Multi-dimensional renumbering used in the Numerical Recipes
27    fft routine. This version is recursive, so works in n-d :
28    determined by the length of array nn
30 \*---------------------------------------------------------------------------*/
32 #include "fftRenumber.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 namespace Foam
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // recursively evaluate the indexing necessary to do the folding of
42 // the fft data. We recurse until we have the indexing ncessary for
43 // the folding in all directions.
45 void fftRenumberRecurse
47     List<complex>& data,
48     List<complex>& renumData,
49     const labelList& nn,
50     label nnprod,
51     label ii,
52     label l1,
53     label l2
56     if (ii == nn.size())
57     {
58         // we've worked out the renumbering scheme. Now copy
59         // the components across
61         data[l1] = complex(renumData[l2].Re(),renumData[l2].Im());
62     }
63     else
64     {
65         // do another level of folding. First work out the
66         // multiplicative value of the index
68         nnprod /= nn[ii];
69         label i_1(0);
71         for (label i=0; i<nn[ii]; i++)
72         {
73             // now evaluate the indices (both from array 1 and to
74             // array 2). These get multiplied by nnprod to (cumulatively)
75             // find the real position in the list corresponding to
76             // this set of indices.
78             if (i<nn[ii]/2)
79             {
80                 i_1 = i + nn[ii]/2;
81             }
82             else
83             {
84                 i_1 = i - nn[ii]/2;
85             }
88             // go to the next level of recursion.
90             fftRenumberRecurse
91             (
92                 data,
93                 renumData,
94                 nn,
95                 nnprod,
96                 ii+1,
97                 l1+i*nnprod,
98                 l2+i_1*nnprod
99             );
100         }
101     }
105 // fftRenumber : fold the n-d data array to get the fft components in
106 // the right places.
108 #include "fftRenumber.H"
110 void fftRenumber
112     List<complex>& data,
113     const labelList& nn
116     List<complex> renumData(data);
118     label nnprod(1);
119     for (label i=0; i<nn.size(); i++)
120     {
121         nnprod *= nn[i];
122     }
124     label ii(0), l1(0), l2(0);
126     fftRenumberRecurse
127     (
128         data,
129         renumData,
130         nn,
131         nnprod,
132         ii,
133         l1,
134         l2
135     );
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 } // End namespace Foam
143 // ************************************************************************* //