FreeFOAM The Cross-Platform CFD Toolkit
Kmesh.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "Kmesh.H"
27 #include <OpenFOAM/polyMesh.H>
28 #include <finiteVolume/volFields.H>
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
36  inline label rep
37  (
38  const label i,
39  const label j,
40  const label k,
41  const labelList& nn
42  )
43  {
44  return (k + j*nn[2] + i*nn[1]*nn[2]);
45  }
47 
48 } // End namespace Foam
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
53 // from fvMesh
55 :
56  vectorField(mesh.V().size()),
57  NN(vector::dim)
58 {
59  const scalar pi = mathematicalConstant::pi;
60  const scalar twoPi = 2.0*pi;
61 
62  boundBox box = mesh.bounds();
63  L = box.span();
64 
65  vector cornerCellCentre = ::Foam::max(mesh.C().internalField());
66  vector cellL = 2 * (box.max() - cornerCellCentre);
67 
68  vector rdeltaByL;
69  label nTot = 1;
70 
71  label i;
72  forAll(NN, i)
73  {
74  NN[i] = label(L[i]/cellL[i] + 0.5);
75  nTot *= NN[i];
76 
77  if (NN[i] > 1)
78  {
79  L[i] -= cellL[i];
80  }
81 
82  rdeltaByL[i] = NN[i]/(L[i]*L[i]);
83  }
84 
85  if (nTot != mesh.nCells())
86  {
87  FatalErrorIn("Kmesh::Kmesh(const fvMesh& mesh)")
88  << "calculated number of cells is incorrect"
89  << abort(FatalError);
90  }
91 
92  for (i=0; i<NN[0]; i++)
93  {
94  scalar k1 = (i - NN[0]/2)*twoPi/L[0];
95 
96  for (label j=0; j<NN[1]; j++)
97  {
98  scalar k2 = (j - NN[1]/2)*twoPi/L[1];
99 
100  for (label k=0; k<NN[2]; k++)
101  {
102  scalar k3 = (k - NN[2]/2)*twoPi/L[2];
103 
104  (*this)[rep(i, j, k, NN)] = vector(k1, k2, k3);
105  }
106  }
107  }
108 
109  Kmax = mag((*this)[rep(NN[0]-1, NN[1]-1, NN[2]-1, NN)]);
110 }
111 
112 
113 // ************************ vim: set sw=4 sts=4 et: ************************ //