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

Kmesh.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 "Kmesh.H"
00028 #include "polyMesh.H"
00029 #include "volFields.H"
00030 #include "mathematicalConstants.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00037    inline label rep
00038    (
00039        const label i,
00040        const label j,
00041        const label k,
00042        const labelList& nn
00043    )
00044    {
00045        return (k + j*nn[2] + i*nn[1]*nn[2]);
00046    }
00048 
00049 } // End namespace Foam
00050 
00051 
00052 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00053 
00054 // from fvMesh
00055 Foam::Kmesh::Kmesh(const fvMesh& mesh)
00056 :
00057     vectorField(mesh.V().size()),
00058     NN(vector::dim)
00059 {
00060     const scalar pi = mathematicalConstant::pi;
00061     const scalar twoPi = 2.0*pi;
00062 
00063     boundBox box = mesh.bounds();
00064     L = box.span();
00065 
00066     vector cornerCellCentre = ::Foam::max(mesh.C().internalField());
00067     vector cellL = 2 * (box.max() - cornerCellCentre);
00068 
00069     vector rdeltaByL;
00070     label nTot = 1;
00071 
00072     label i;
00073     forAll(NN, i)
00074     {
00075         NN[i] = label(L[i]/cellL[i] + 0.5);
00076         nTot *= NN[i];
00077 
00078         if (NN[i] > 1)
00079         {
00080             L[i] -= cellL[i];
00081         }
00082 
00083         rdeltaByL[i] = NN[i]/(L[i]*L[i]);
00084     }
00085 
00086     if (nTot != mesh.nCells())
00087     {
00088         FatalErrorIn("Kmesh::Kmesh(const fvMesh& mesh)")
00089             << "calculated number of cells is incorrect"
00090             << abort(FatalError);
00091     }
00092 
00093     for (i=0; i<NN[0]; i++)
00094     {
00095         scalar k1 = (i - NN[0]/2)*twoPi/L[0];
00096 
00097         for (label j=0; j<NN[1]; j++)
00098         {
00099             scalar k2 = (j - NN[1]/2)*twoPi/L[1];
00100 
00101             for (label k=0; k<NN[2]; k++)
00102             {
00103                 scalar k3 = (k - NN[2]/2)*twoPi/L[2];
00104 
00105                 (*this)[rep(i, j, k, NN)] = vector(k1, k2, k3);
00106             }
00107         }
00108     }
00109 
00110     Kmax = mag((*this)[rep(NN[0]-1, NN[1]-1, NN[2]-1, NN)]);
00111 }
00112 
00113 
00114 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd