|
|
|
fftRenumber.CGo to the documentation of this file.00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software; you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM; if not, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 Description 00026 Multi-dimensional renumbering used in the Numerical Recipes 00027 fft routine. This version is recursive, so works in n-d : 00028 determined by the length of array nn 00029 00030 \*---------------------------------------------------------------------------*/ 00031 00032 #include "fftRenumber.H" 00033 00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00035 00036 namespace Foam 00037 { 00038 00039 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00040 00041 // recursively evaluate the indexing necessary to do the folding of 00042 // the fft data. We recurse until we have the indexing ncessary for 00043 // the folding in all directions. 00044 00045 void fftRenumberRecurse 00046 ( 00047 List<complex>& data, 00048 List<complex>& renumData, 00049 const labelList& nn, 00050 label nnprod, 00051 label ii, 00052 label l1, 00053 label l2 00054 ) 00055 { 00056 if (ii == nn.size()) 00057 { 00058 // we've worked out the renumbering scheme. Now copy 00059 // the components across 00060 00061 data[l1] = complex(renumData[l2].Re(),renumData[l2].Im()); 00062 } 00063 else 00064 { 00065 // do another level of folding. First work out the 00066 // multiplicative value of the index 00067 00068 nnprod /= nn[ii]; 00069 label i_1(0); 00070 00071 for (label i=0; i<nn[ii]; i++) 00072 { 00073 // now evaluate the indices (both from array 1 and to 00074 // array 2). These get multiplied by nnprod to (cumulatively) 00075 // find the real position in the list corresponding to 00076 // this set of indices. 00077 00078 if (i<nn[ii]/2) 00079 { 00080 i_1 = i + nn[ii]/2; 00081 } 00082 else 00083 { 00084 i_1 = i - nn[ii]/2; 00085 } 00086 00087 00088 // go to the next level of recursion. 00089 00090 fftRenumberRecurse 00091 ( 00092 data, 00093 renumData, 00094 nn, 00095 nnprod, 00096 ii+1, 00097 l1+i*nnprod, 00098 l2+i_1*nnprod 00099 ); 00100 } 00101 } 00102 } 00103 00104 00105 // fftRenumber : fold the n-d data array to get the fft components in 00106 // the right places. 00107 00108 #include "fftRenumber.H" 00109 00110 void fftRenumber 00111 ( 00112 List<complex>& data, 00113 const labelList& nn 00114 ) 00115 { 00116 List<complex> renumData(data); 00117 00118 label nnprod(1); 00119 for (label i=0; i<nn.size(); i++) 00120 { 00121 nnprod *= nn[i]; 00122 } 00123 00124 label ii(0), l1(0), l2(0); 00125 00126 fftRenumberRecurse 00127 ( 00128 data, 00129 renumData, 00130 nn, 00131 nnprod, 00132 ii, 00133 l1, 00134 l2 00135 ); 00136 } 00137 00138 00139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00140 00141 } // End namespace Foam 00142 00143 // ************************************************************************* // |