Kmesh.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
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 "polyMesh.H"
28 #include "volFields.H"
29 #include "mathematicalConstants.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 inline Foam::label Foam::Kmesh::index
34 (
35  const label i,
36  const label j,
37  const label k,
38  const labelList& nn
39 )
40 {
41  return (k + j*nn[2] + i*nn[1]*nn[2]);
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 :
49  vectorField(mesh.V().size()),
50  nn_(vector::dim)
51 {
52  boundBox box = mesh.bounds();
53  l_ = box.span();
54 
55  vector cornerCellCentre = ::Foam::max(mesh.C().primitiveField());
56  vector cellL = 2*(box.max() - cornerCellCentre);
57 
58  vector rdeltaByL;
59  label nTot = 1;
60 
61  forAll(nn_, i)
62  {
63  nn_[i] = label(l_[i]/cellL[i] + 0.5);
64  nTot *= nn_[i];
65 
66  if (nn_[i] > 1)
67  {
68  l_[i] -= cellL[i];
69  }
70 
71  rdeltaByL[i] = nn_[i]/(l_[i]*l_[i]);
72  }
73 
74  if (nTot != mesh.nCells())
75  {
77  << "calculated number of cells is incorrect"
78  << abort(FatalError);
79  }
80 
81  for (label i=0; i<nn_[0]; i++)
82  {
83  scalar k1 = (i - nn_[0]/2)*constant::mathematical::twoPi/l_[0];
84 
85  for (label j=0; j<nn_[1]; j++)
86  {
87  scalar k2 = (j - nn_[1]/2)*constant::mathematical::twoPi/l_[1];
88 
89  for (label k=0; k<nn_[2]; k++)
90  {
91  scalar k3 = (k - nn_[2]/2)*constant::mathematical::twoPi/l_[2];
92 
93  (*this)[index(i, j, k, nn_)] = vector(k1, k2, k3);
94  }
95  }
96  }
97 
98  kmax_ = mag
99  (
100  Foam::max
101  (
102  cmptMag((*this)[index(nn_[0]-1, nn_[1]-1, nn_[2]-1, nn_)]),
103  cmptMag((*this)[index(0, 0, 0, nn_)])
104  )
105  );
106 }
107 
108 
109 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
label nCells() const
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
fvMesh & mesh
Kmesh(const fvMesh &)
Construct from fvMesh.
Definition: Kmesh.C:47
dimensionSet cmptMag(const dimensionSet &)
Definition: dimensionSet.C:275
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const scalar twoPi(2 *pi)
const point & max() const
Maximum point defining the bounding box.
Definition: boundBoxI.H:60
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:459
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:84
dimensioned< scalar > mag(const dimensioned< Type > &)
const volVectorField & C() const
Return cell centres.
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171