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-------------------------------------------------------------------------------
10License
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"
32
33// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34
35inline 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 (
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// ************************************************************************* //
label k
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
Calculate the wavenumber vector field corresponding to the space vector field of a finite volume mesh...
Definition: Kmesh.H:54
const List< int > & nn() const
Definition: Kmesh.H:96
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:64
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:97
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:127
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
const volVectorField & C() const
Return cell centres as volVectorField.
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:462
label nCells() const noexcept
Number of mesh cells.
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
constexpr scalar twoPi(2 *M_PI)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
Vector< scalar > vector
Definition: vector.H:61
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333