turbGen.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 OpenFOAM Foundation
9  Copyright (C) 2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "fft.H"
30 #include "turbGen.H"
31 #include "Kmesh.H"
33 #include "Ek.H"
34 #include "mathematicalConstants.H"
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
39 Foam::turbGen::turbGen(const Kmesh& k, const scalar EA, const scalar K0)
40 :
41  K(k),
42  Ea(EA),
43  k0(K0),
44  RanGen(label(0))
45 {}
46 
47 
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49 
51 {
52  vectorField s(K.size());
53  scalarField rndPhases(K.size());
54 
55  forAll(K, i)
56  {
57  s[i] = RanGen.sample01<vector>();
58  rndPhases[i] = RanGen.sample01<scalar>();
59  }
60 
61  s = K ^ s;
62  s = s/(mag(s) + 1.0e-20);
63 
64  s = Ek(Ea, k0, mag(K))*s;
65 
66  label ntot = 1;
67  forAll(K.nn(), idim)
68  {
69  ntot *= K.nn()[idim];
70  }
71  const scalar recRootN = 1.0/sqrt(scalar(ntot));
72 
74  (
76  (
78  (
81  ),
82  K.nn()
83  )*recRootN
84  );
85 
86  return ReImSum(up);
87 }
88 
89 
90 // ************************************************************************* //
Field< complexVector > complexVectorField
Specialisation of Field<T> for complexVector.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static tmp< complexField > reverseTransform(const tmp< complexField > &field, const UList< int > &nn)
Definition: fft.C:252
vectorField U()
Generate and return a velocity field.
Definition: turbGen.C:43
dimensionedScalar sqrt(const dimensionedScalar &ds)
label k
Boltzmann constant.
scalarField ReImSum(const UList< complex > &cmplx)
Sum real and imag components.
Definition: complexField.C:191
tmp< scalarField > Ek(const scalar Ea, const scalar k0, const scalarField &k)
Definition: Ek.H:10
CGAL::Exact_predicates_exact_constructions_kernel K
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Type sample01()
Return a sample whose components lie in the range [0,1].
dimensionedScalar cos(const dimensionedScalar &ds)
constexpr scalar twoPi(2 *M_PI)
complexField ComplexField(const UList< scalar > &realValues, const UList< scalar > &imagValues)
Create complex field by zipping two lists of real/imag values.
Definition: complexField.C:150
Calculate the wavenumber vector field corresponding to the space vector field of a finite volume mesh...
Definition: Kmesh.H:47
dimensionedScalar sin(const dimensionedScalar &ds)
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Specialisations of Field<T> for scalar, vector and tensor.
turbGen(const Kmesh &k, const scalar EA, const scalar K0)
Construct from components.
Definition: turbGen.C:32
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
scalar Ea(const scalar p, const scalar T) const
Definition: HtoEthermo.H:32