OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

kShellIntegration.C

Go 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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "kShellIntegration.H"
00028 #include "mathematicalConstants.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 graph kShellIntegration
00038 (
00039     const complexVectorField& Ek,
00040     const Kmesh& K
00041 )
00042 {
00043     // evaluate the radial component of the spectra as an average
00044     // over the shells of thickness dk
00045 
00046     graph kShellMeanEk = kShellMean(Ek, K);
00047     const scalarField& x = kShellMeanEk.x();
00048     scalarField& y = *kShellMeanEk.begin()();
00049 
00050     // now multiply by 4pi k^2 (the volume of each shell) to get the
00051     // spectra E(k). int E(k) dk is now the total energy in a box
00052     // of side 2pi
00053 
00054     y *= sqr(x)*4.0*mathematicalConstant::pi;
00055 
00056     // now scale this to get the energy in a box of side l0
00057 
00058     scalar l0(K.sizeOfBox()[0]*(scalar(K.nn()[0])/(scalar(K.nn()[0])-1.0)));
00059     scalar factor = pow((l0/(2.0*mathematicalConstant::pi)),3.0);
00060 
00061     y *= factor;
00062 
00063     // and divide by the number of points in the box, to give the
00064     // energy density.
00065 
00066     y /= scalar(K.size());
00067 
00068     return kShellMeanEk;
00069 }
00070 
00071 
00072 // kShellMean : average over the points in a k-shell to evaluate the
00073 // radial part of the energy spectrum.
00074 
00075 graph kShellMean
00076 (
00077     const complexVectorField& Ek,
00078     const Kmesh& K
00079 )
00080 {
00081     const label tnp = Ek.size();
00082     const label NoSubintervals = label
00083     (
00084         pow(scalar(tnp), 1.0/vector::dim)*pow(1.0/vector::dim, 0.5) - 0.5
00085     );
00086 
00087     scalarField k1D(NoSubintervals);
00088     scalarField Ek1D(NoSubintervals);
00089     scalarField EWeight(NoSubintervals);
00090 
00091     scalar kmax = K.max()*pow(1.0/vector::dim,0.5);
00092     scalar delta_k = kmax/(NoSubintervals);
00093 
00094     forAll(Ek1D, a)
00095     {
00096         k1D[a] = (a + 1)*delta_k;
00097         Ek1D[a] = 0.0;
00098         EWeight[a] = 0;
00099     }
00100 
00101     forAll(K, l)
00102     {
00103         scalar kmag = mag(K[l]);
00104 
00105         for (label a=0; a<NoSubintervals; a++)
00106         {
00107             if
00108             (
00109                 kmag <= ((a + 1)*delta_k + delta_k/2.0)
00110              && kmag > ((a + 1)*delta_k - delta_k/2.0)
00111             )
00112             {
00113                 scalar dist = delta_k/2.0 - mag((a + 1)*delta_k - kmag);
00114 
00115                 Ek1D[a] += dist*
00116                 magSqr
00117                 (
00118                     vector
00119                     (
00120                         mag(Ek[l].x()),
00121                         mag(Ek[l].y()),
00122                         mag(Ek[l].z())
00123                     )
00124                  );
00125 
00126                 EWeight[a] += dist;
00127             }
00128         }
00129     }
00130 
00131     for (label a=0; a<NoSubintervals; a++)
00132     {
00133         if (EWeight[a] > 0)
00134         {
00135             Ek1D[a] /= EWeight[a];
00136         }
00137     }
00138 
00139     return graph("E(k)", "k", "E(k)", Ek1D, k1D);
00140 }
00141 
00142 
00143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00144 
00145 } // End namespace Foam
00146 
00147 // ************************************************************************* //
00148 
Copyright © 2000-2009 OpenCFD Ltd