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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "Kmesh.H"
29 #include "polyMesh.H"
30 #include "volFields.H"
31 #include "mathematicalConstants.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 inline Foam::label Foam::Kmesh::index
36 (
37  const label i,
38  const label j,
39  const label k,
40  const UList<int>& nn
41 )
42 {
43  return (k + j*nn[2] + i*nn[1]*nn[2]);
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 :
51  vectorField(mesh.V().size()),
52  nn_(vector::dim)
53 {
54  boundBox box = mesh.bounds();
55  l_ = box.span();
56 
57  vector cornerCellCentre = ::Foam::max(mesh.C().primitiveField());
58  vector cellL = 2*(box.max() - cornerCellCentre);
59 
60  vector rdeltaByL;
61  label nTot = 1;
62 
63  forAll(nn_, i)
64  {
65  nn_[i] = label(l_[i]/cellL[i] + 0.5);
66  nTot *= nn_[i];
67 
68  if (nn_[i] > 1)
69  {
70  l_[i] -= cellL[i];
71  }
72 
73  rdeltaByL[i] = nn_[i]/(l_[i]*l_[i]);
74  }
75 
76  if (nTot != mesh.nCells())
77  {
79  << "calculated number of cells is incorrect"
80  << abort(FatalError);
81  }
82 
83  for (label i=0; i<nn_[0]; i++)
84  {
85  scalar k1 = (i - nn_[0]/2)*constant::mathematical::twoPi/l_[0];
86 
87  for (label j=0; j<nn_[1]; j++)
88  {
89  scalar k2 = (j - nn_[1]/2)*constant::mathematical::twoPi/l_[1];
90 
91  for (label k=0; k<nn_[2]; k++)
92  {
93  scalar k3 = (k - nn_[2]/2)*constant::mathematical::twoPi/l_[2];
94 
95  (*this)[index(i, j, k, nn_)] = vector(k1, k2, k3);
96  }
97  }
98  }
99 
100  kmax_ = mag
101  (
102  Foam::max
103  (
104  cmptMag((*this)[index(nn_[0]-1, nn_[1]-1, nn_[2]-1, nn_)]),
105  cmptMag((*this)[index(0, 0, 0, nn_)])
106  )
107  );
108 }
109 
110 
111 // ************************************************************************* //
volFields.H
Kmesh.H
mathematicalConstants.H
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:97
polyMesh.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::boundBox::span
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:127
Foam::cmptMag
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:400
Foam::Field< vector >
Foam::Kmesh::Kmesh
Kmesh(const fvMesh &)
Construct from fvMesh.
Definition: Kmesh.C:49
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::constant::mathematical::twoPi
constexpr scalar twoPi(2 *M_PI)
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::Kmesh::nn
const List< int > & nn() const
Definition: Kmesh.H:96
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::Vector< scalar >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63