1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
28 #include "volFields.H"
29 #include "mathematicalConstants.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 return (k + j*nn[2] + i*nn[1]*nn[2]);
48 } // End namespace Foam
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 Foam::Kmesh::Kmesh(const fvMesh& mesh)
56 vectorField(mesh.V().size()),
59 boundBox box = mesh.bounds();
62 vector cornerCellCentre = ::Foam::max(mesh.C().internalField());
63 vector cellL = 2*(box.max() - cornerCellCentre);
71 NN[i] = label(L[i]/cellL[i] + 0.5);
79 rdeltaByL[i] = NN[i]/(L[i]*L[i]);
82 if (nTot != mesh.nCells())
84 FatalErrorIn("Kmesh::Kmesh(const fvMesh& mesh)")
85 << "calculated number of cells is incorrect"
89 for (i=0; i<NN[0]; i++)
91 scalar k1 = (i - NN[0]/2)*constant::mathematical::twoPi/L[0];
93 for (label j=0; j<NN[1]; j++)
95 scalar k2 = (j - NN[1]/2)*constant::mathematical::twoPi/L[1];
97 for (label k=0; k<NN[2]; k++)
99 scalar k3 = (k - NN[2]/2)*constant::mathematical::twoPi/L[2];
101 (*this)[rep(i, j, k, NN)] = vector(k1, k2, k3);
106 Kmax = mag((*this)[rep(NN[0]-1, NN[1]-1, NN[2]-1, NN)]);
110 // ************************************************************************* //