FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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