1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 \*---------------------------------------------------------------------------*/
27 #include "kShellIntegration.H"
28 #include "mathematicalConstants.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 graph kShellIntegration
39 const complexVectorField& Ek,
43 // evaluate the radial component of the spectra as an average
44 // over the shells of thickness dk
46 graph kShellMeanEk = kShellMean(Ek, K);
47 const scalarField& x = kShellMeanEk.x();
48 scalarField& y = *kShellMeanEk.begin()();
50 // now multiply by 4pi k^2 (the volume of each shell) to get the
51 // spectra E(k). int E(k) dk is now the total energy in a box
54 y *= sqr(x)*4.0*mathematicalConstant::pi;
56 // now scale this to get the energy in a box of side l0
58 scalar l0(K.sizeOfBox()[0]*(scalar(K.nn()[0])/(scalar(K.nn()[0])-1.0)));
59 scalar factor = pow((l0/(2.0*mathematicalConstant::pi)),3.0);
63 // and divide by the number of points in the box, to give the
66 y /= scalar(K.size());
72 // kShellMean : average over the points in a k-shell to evaluate the
73 // radial part of the energy spectrum.
77 const complexVectorField& Ek,
81 const label tnp = Ek.size();
82 const label NoSubintervals = label
84 pow(scalar(tnp), 1.0/vector::dim)*pow(1.0/vector::dim, 0.5) - 0.5
87 scalarField k1D(NoSubintervals);
88 scalarField Ek1D(NoSubintervals);
89 scalarField EWeight(NoSubintervals);
91 scalar kmax = K.max()*pow(1.0/vector::dim,0.5);
92 scalar delta_k = kmax/(NoSubintervals);
96 k1D[a] = (a + 1)*delta_k;
103 scalar kmag = mag(K[l]);
105 for (label a=0; a<NoSubintervals; a++)
109 kmag <= ((a + 1)*delta_k + delta_k/2.0)
110 && kmag > ((a + 1)*delta_k - delta_k/2.0)
113 scalar dist = delta_k/2.0 - mag((a + 1)*delta_k - kmag);
131 for (label a=0; a<NoSubintervals; a++)
135 Ek1D[a] /= EWeight[a];
139 return graph("E(k)", "k", "E(k)", Ek1D, k1D);
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 } // End namespace Foam
147 // ************************************************************************* //