Add the OpenFOAM source tree
This commit is contained in:
109
src/randomProcesses/Kmesh/Kmesh.C
Normal file
109
src/randomProcesses/Kmesh/Kmesh.C
Normal file
@ -0,0 +1,109 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Kmesh.H"
|
||||
#include "polyMesh.H"
|
||||
#include "volFields.H"
|
||||
#include "mathematicalConstants.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::label Foam::Kmesh::index
|
||||
(
|
||||
const label i,
|
||||
const label j,
|
||||
const label k,
|
||||
const labelList& nn
|
||||
)
|
||||
{
|
||||
return (k + j*nn[2] + i*nn[1]*nn[2]);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Kmesh::Kmesh(const fvMesh& mesh)
|
||||
:
|
||||
vectorField(mesh.V().size()),
|
||||
nn_(vector::dim)
|
||||
{
|
||||
boundBox box = mesh.bounds();
|
||||
l_ = box.span();
|
||||
|
||||
vector cornerCellCentre = ::Foam::max(mesh.C().internalField());
|
||||
vector cellL = 2*(box.max() - cornerCellCentre);
|
||||
|
||||
vector rdeltaByL;
|
||||
label nTot = 1;
|
||||
|
||||
forAll(nn_, i)
|
||||
{
|
||||
nn_[i] = label(l_[i]/cellL[i] + 0.5);
|
||||
nTot *= nn_[i];
|
||||
|
||||
if (nn_[i] > 1)
|
||||
{
|
||||
l_[i] -= cellL[i];
|
||||
}
|
||||
|
||||
rdeltaByL[i] = nn_[i]/(l_[i]*l_[i]);
|
||||
}
|
||||
|
||||
if (nTot != mesh.nCells())
|
||||
{
|
||||
FatalErrorIn("Kmesh::Kmesh(const fvMesh& mesh)")
|
||||
<< "calculated number of cells is incorrect"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
for (label i=0; i<nn_[0]; i++)
|
||||
{
|
||||
scalar k1 = (i - nn_[0]/2)*constant::mathematical::twoPi/l_[0];
|
||||
|
||||
for (label j=0; j<nn_[1]; j++)
|
||||
{
|
||||
scalar k2 = (j - nn_[1]/2)*constant::mathematical::twoPi/l_[1];
|
||||
|
||||
for (label k=0; k<nn_[2]; k++)
|
||||
{
|
||||
scalar k3 = (k - nn_[2]/2)*constant::mathematical::twoPi/l_[2];
|
||||
|
||||
(*this)[index(i, j, k, nn_)] = vector(k1, k2, k3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kmax_ = mag
|
||||
(
|
||||
Foam::max
|
||||
(
|
||||
cmptMag((*this)[index(nn_[0]-1, nn_[1]-1, nn_[2]-1, nn_)]),
|
||||
cmptMag((*this)[index(0, 0, 0, nn_)])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
115
src/randomProcesses/Kmesh/Kmesh.H
Normal file
115
src/randomProcesses/Kmesh/Kmesh.H
Normal file
@ -0,0 +1,115 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::Kmesh
|
||||
|
||||
Description
|
||||
Calculate the wavenumber vector field corresponding to the
|
||||
space vector field of a finite volume mesh;
|
||||
|
||||
SourceFiles
|
||||
Kmesh.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Kmesh_H
|
||||
#define Kmesh_H
|
||||
|
||||
#include "fvMesh.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class Kmesh Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class Kmesh
|
||||
:
|
||||
public vectorField
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Dimensions of box
|
||||
vector l_;
|
||||
|
||||
//- Multi-dimensional addressing array
|
||||
labelList nn_;
|
||||
|
||||
//- Maximum wavenumber
|
||||
scalar kmax_;
|
||||
|
||||
|
||||
// Private functions
|
||||
|
||||
//- Return the linear index from the i-j-k indices
|
||||
static inline label index
|
||||
(
|
||||
const label i,
|
||||
const label j,
|
||||
const label k,
|
||||
const labelList& nn
|
||||
);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from fvMesh
|
||||
Kmesh(const fvMesh&);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
const vector& sizeOfBox() const
|
||||
{
|
||||
return l_;
|
||||
}
|
||||
|
||||
const labelList& nn() const
|
||||
{
|
||||
return nn_;
|
||||
}
|
||||
|
||||
scalar max() const
|
||||
{
|
||||
return kmax_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
25
src/randomProcesses/Make/files
Normal file
25
src/randomProcesses/Make/files
Normal file
@ -0,0 +1,25 @@
|
||||
Kmesh = Kmesh
|
||||
|
||||
fft = fft
|
||||
|
||||
processes = processes
|
||||
UOprocess = $(processes)/UOprocess
|
||||
|
||||
turbulence = turbulence
|
||||
|
||||
noise = noise
|
||||
|
||||
$(Kmesh)/Kmesh.C
|
||||
|
||||
$(fft)/fft.C
|
||||
$(fft)/fftRenumber.C
|
||||
$(fft)/calcEk.C
|
||||
$(fft)/kShellIntegration.C
|
||||
|
||||
$(UOprocess)/UOprocess.C
|
||||
|
||||
$(turbulence)/turbGen.C
|
||||
|
||||
$(noise)/noiseFFT.C
|
||||
|
||||
LIB = $(FOAM_LIBBIN)/librandomProcesses
|
||||
5
src/randomProcesses/Make/options
Normal file
5
src/randomProcesses/Make/options
Normal file
@ -0,0 +1,5 @@
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/finiteVolume/lnInclude
|
||||
|
||||
LIB_LIBS = \
|
||||
-lfiniteVolume
|
||||
48
src/randomProcesses/fft/calcEk.C
Normal file
48
src/randomProcesses/fft/calcEk.C
Normal file
@ -0,0 +1,48 @@
|
||||
/*======================================================================*/
|
||||
|
||||
// This routine evaluates q(k) (McComb, p61) by summing all wavevectors
|
||||
// in a k-shell. Then we divide through by the volume of the box
|
||||
// - to be accurate, by the volume of the ellipsoid enclosing the
|
||||
// box (assume cells even in each direction). Finally, multiply the
|
||||
// q(k) values by k^2 to give the full power spectrum E(k). Integrating
|
||||
// this over the whole range gives the energy in turbulence.
|
||||
|
||||
/*======================================================================*/
|
||||
|
||||
#include "calcEk.H"
|
||||
#include "fft.H"
|
||||
#include "Kmesh.H"
|
||||
#include "kShellIntegration.H"
|
||||
#include "volFields.H"
|
||||
#include "graph.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
graph calcEk
|
||||
(
|
||||
const volVectorField& U,
|
||||
const Kmesh& K
|
||||
)
|
||||
{
|
||||
return kShellIntegration
|
||||
(
|
||||
fft::forwardTransform
|
||||
(
|
||||
ReComplexField(U.internalField()),
|
||||
K.nn()
|
||||
),
|
||||
K
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
25
src/randomProcesses/fft/calcEk.H
Normal file
25
src/randomProcesses/fft/calcEk.H
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef calcEk_H
|
||||
#define calcEk_H
|
||||
|
||||
#include "volFieldsFwd.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class graph;
|
||||
class Kmesh;
|
||||
|
||||
graph calcEk
|
||||
(
|
||||
const volVectorField& U,
|
||||
const Kmesh& K
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
#endif
|
||||
283
src/randomProcesses/fft/fft.C
Normal file
283
src/randomProcesses/fft/fft.C
Normal file
@ -0,0 +1,283 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fft.H"
|
||||
#include "fftRenumber.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#define SWAP(a,b) tempr=(a); (a)=(b); (b)=tempr
|
||||
#define TWOPI 6.28318530717959
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
void fft::transform
|
||||
(
|
||||
complexField& field,
|
||||
const labelList& nn,
|
||||
transformDirection isign
|
||||
)
|
||||
{
|
||||
forAll(nn, idim)
|
||||
{
|
||||
// Check for power of two
|
||||
unsigned int dimCount = nn[idim];
|
||||
if (!dimCount || (dimCount & (dimCount - 1)))
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fft::transform(complexField&, const labelList&, "
|
||||
"transformDirection)"
|
||||
) << "number of elements in direction " << idim
|
||||
<< " is not a power of 2" << endl
|
||||
<< " Number of elements in each direction = " << nn
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
const label ndim = nn.size();
|
||||
|
||||
label i1, i2, i3, i2rev, i3rev, ip1, ip2, ip3, ifp1, ifp2;
|
||||
label ibit, k1, k2, n, nprev, nrem, idim;
|
||||
scalar tempi, tempr;
|
||||
scalar theta, wi, wpi, wpr, wr, wtemp;
|
||||
scalar* data = reinterpret_cast<scalar*>(field.begin()) - 1;
|
||||
|
||||
|
||||
// if inverse transform : renumber before transform
|
||||
|
||||
if (isign == REVERSE_TRANSFORM)
|
||||
{
|
||||
fftRenumber(field, nn);
|
||||
}
|
||||
|
||||
|
||||
label ntot = 1;
|
||||
forAll(nn, idim)
|
||||
{
|
||||
ntot *= nn[idim];
|
||||
}
|
||||
|
||||
|
||||
nprev = 1;
|
||||
|
||||
for (idim=ndim; idim>=1; idim--)
|
||||
{
|
||||
n = nn[idim-1];
|
||||
nrem = ntot/(n*nprev);
|
||||
ip1 = nprev << 1;
|
||||
ip2 = ip1*n;
|
||||
ip3 = ip2*nrem;
|
||||
i2rev = 1;
|
||||
|
||||
for (i2=1; i2<=ip2; i2+=ip1)
|
||||
{
|
||||
if (i2 < i2rev)
|
||||
{
|
||||
for (i1=i2; i1<=i2 + ip1 - 2; i1+=2)
|
||||
{
|
||||
for (i3=i1; i3<=ip3; i3+=ip2)
|
||||
{
|
||||
i3rev = i2rev + i3 - i2;
|
||||
SWAP(data[i3], data[i3rev]);
|
||||
SWAP(data[i3 + 1], data[i3rev + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ibit = ip2 >> 1;
|
||||
while (ibit >= ip1 && i2rev > ibit)
|
||||
{
|
||||
i2rev -= ibit;
|
||||
ibit >>= 1;
|
||||
}
|
||||
|
||||
i2rev += ibit;
|
||||
}
|
||||
|
||||
ifp1 = ip1;
|
||||
|
||||
while (ifp1 < ip2)
|
||||
{
|
||||
ifp2 = ifp1 << 1;
|
||||
theta = isign*TWOPI/(ifp2/ip1);
|
||||
wtemp = sin(0.5*theta);
|
||||
wpr = -2.0*wtemp*wtemp;
|
||||
wpi = sin(theta);
|
||||
wr = 1.0;
|
||||
wi = 0.0;
|
||||
|
||||
for (i3 = 1; i3 <= ifp1; i3 += ip1)
|
||||
{
|
||||
for (i1 = i3; i1 <= i3 + ip1 - 2; i1 += 2)
|
||||
{
|
||||
for (i2 = i1; i2 <= ip3; i2 += ifp2)
|
||||
{
|
||||
k1 = i2;
|
||||
k2 = k1 + ifp1;
|
||||
tempr = scalar(wr*data[k2]) - scalar(wi*data[k2 + 1]);
|
||||
tempi = scalar(wr*data[k2 + 1]) + scalar(wi*data[k2]);
|
||||
data[k2] = data[k1] - tempr;
|
||||
data[k2 + 1] = data[k1 + 1] - tempi;
|
||||
data[k1] += tempr;
|
||||
data[k1 + 1] += tempi;
|
||||
}
|
||||
}
|
||||
|
||||
wr = (wtemp = wr)*wpr - wi*wpi + wr;
|
||||
wi = wi*wpr + wtemp*wpi + wi;
|
||||
}
|
||||
ifp1 = ifp2;
|
||||
}
|
||||
nprev *= n;
|
||||
}
|
||||
|
||||
|
||||
// if forward transform : renumber after transform
|
||||
|
||||
if (isign == FORWARD_TRANSFORM)
|
||||
{
|
||||
fftRenumber(field, nn);
|
||||
}
|
||||
|
||||
|
||||
// scale result (symmetric scale both forward and inverse transform)
|
||||
|
||||
scalar recRootN = 1.0/sqrt(scalar(ntot));
|
||||
|
||||
forAll(field, i)
|
||||
{
|
||||
field[i] *= recRootN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#undef SWAP
|
||||
#undef TWOPI
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
tmp<complexField> fft::forwardTransform
|
||||
(
|
||||
const tmp<complexField>& tfield,
|
||||
const labelList& nn
|
||||
)
|
||||
{
|
||||
tmp<complexField> tfftField(new complexField(tfield));
|
||||
|
||||
transform(tfftField(), nn, FORWARD_TRANSFORM);
|
||||
|
||||
tfield.clear();
|
||||
|
||||
return tfftField;
|
||||
}
|
||||
|
||||
|
||||
tmp<complexField> fft::reverseTransform
|
||||
(
|
||||
const tmp<complexField>& tfield,
|
||||
const labelList& nn
|
||||
)
|
||||
{
|
||||
tmp<complexField> tifftField(new complexField(tfield));
|
||||
|
||||
transform(tifftField(), nn, REVERSE_TRANSFORM);
|
||||
|
||||
tfield.clear();
|
||||
|
||||
return tifftField;
|
||||
}
|
||||
|
||||
|
||||
tmp<complexVectorField> fft::forwardTransform
|
||||
(
|
||||
const tmp<complexVectorField>& tfield,
|
||||
const labelList& nn
|
||||
)
|
||||
{
|
||||
tmp<complexVectorField> tfftVectorField
|
||||
(
|
||||
new complexVectorField
|
||||
(
|
||||
tfield().size()
|
||||
)
|
||||
);
|
||||
|
||||
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
|
||||
{
|
||||
tfftVectorField().replace
|
||||
(
|
||||
cmpt,
|
||||
forwardTransform(tfield().component(cmpt), nn)
|
||||
);
|
||||
}
|
||||
|
||||
tfield.clear();
|
||||
|
||||
return tfftVectorField;
|
||||
}
|
||||
|
||||
|
||||
tmp<complexVectorField> fft::reverseTransform
|
||||
(
|
||||
const tmp<complexVectorField>& tfield,
|
||||
const labelList& nn
|
||||
)
|
||||
{
|
||||
tmp<complexVectorField> tifftVectorField
|
||||
(
|
||||
new complexVectorField
|
||||
(
|
||||
tfield().size()
|
||||
)
|
||||
);
|
||||
|
||||
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
|
||||
{
|
||||
tifftVectorField().replace
|
||||
(
|
||||
cmpt,
|
||||
reverseTransform(tfield().component(cmpt), nn)
|
||||
);
|
||||
}
|
||||
|
||||
tfield.clear();
|
||||
|
||||
return tifftVectorField;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
109
src/randomProcesses/fft/fft.H
Normal file
109
src/randomProcesses/fft/fft.H
Normal file
@ -0,0 +1,109 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::fft
|
||||
|
||||
Description
|
||||
Fast fourier transform derived from the Numerical
|
||||
Recipes in C routine.
|
||||
|
||||
The complex transform field is returned in the field supplied. The
|
||||
direction of transform is supplied as an argument (1 = forward, -1 =
|
||||
reverse). The dimensionality and organisation of the array of values
|
||||
in space is supplied in the nn indexing array.
|
||||
|
||||
SourceFiles
|
||||
fft.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef fft_H
|
||||
#define fft_H
|
||||
|
||||
#include "complexFields.H"
|
||||
#include "labelList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class fft
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
enum transformDirection
|
||||
{
|
||||
FORWARD_TRANSFORM = 1,
|
||||
REVERSE_TRANSFORM = -1
|
||||
};
|
||||
|
||||
|
||||
static void transform
|
||||
(
|
||||
complexField& field,
|
||||
const labelList& nn,
|
||||
transformDirection fftDirection
|
||||
);
|
||||
|
||||
|
||||
static tmp<complexField> forwardTransform
|
||||
(
|
||||
const tmp<complexField>& field,
|
||||
const labelList& nn
|
||||
);
|
||||
|
||||
|
||||
static tmp<complexField> reverseTransform
|
||||
(
|
||||
const tmp<complexField>& field,
|
||||
const labelList& nn
|
||||
);
|
||||
|
||||
|
||||
static tmp<complexVectorField> forwardTransform
|
||||
(
|
||||
const tmp<complexVectorField>& field,
|
||||
const labelList& nn
|
||||
);
|
||||
|
||||
|
||||
static tmp<complexVectorField> reverseTransform
|
||||
(
|
||||
const tmp<complexVectorField>& field,
|
||||
const labelList& nn
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
142
src/randomProcesses/fft/fftRenumber.C
Normal file
142
src/randomProcesses/fft/fftRenumber.C
Normal file
@ -0,0 +1,142 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
Multi-dimensional renumbering used in the Numerical Recipes
|
||||
fft routine. This version is recursive, so works in n-d :
|
||||
determined by the length of array nn
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fftRenumber.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// recursively evaluate the indexing necessary to do the folding of
|
||||
// the fft data. We recurse until we have the indexing ncessary for
|
||||
// the folding in all directions.
|
||||
|
||||
void fftRenumberRecurse
|
||||
(
|
||||
List<complex>& data,
|
||||
List<complex>& renumData,
|
||||
const labelList& nn,
|
||||
label nnprod,
|
||||
label ii,
|
||||
label l1,
|
||||
label l2
|
||||
)
|
||||
{
|
||||
if (ii == nn.size())
|
||||
{
|
||||
// we've worked out the renumbering scheme. Now copy
|
||||
// the components across
|
||||
|
||||
data[l1] = complex(renumData[l2].Re(),renumData[l2].Im());
|
||||
}
|
||||
else
|
||||
{
|
||||
// do another level of folding. First work out the
|
||||
// multiplicative value of the index
|
||||
|
||||
nnprod /= nn[ii];
|
||||
label i_1(0);
|
||||
|
||||
for (label i=0; i<nn[ii]; i++)
|
||||
{
|
||||
// now evaluate the indices (both from array 1 and to
|
||||
// array 2). These get multiplied by nnprod to (cumulatively)
|
||||
// find the real position in the list corresponding to
|
||||
// this set of indices.
|
||||
|
||||
if (i<nn[ii]/2)
|
||||
{
|
||||
i_1 = i + nn[ii]/2;
|
||||
}
|
||||
else
|
||||
{
|
||||
i_1 = i - nn[ii]/2;
|
||||
}
|
||||
|
||||
|
||||
// go to the next level of recursion.
|
||||
|
||||
fftRenumberRecurse
|
||||
(
|
||||
data,
|
||||
renumData,
|
||||
nn,
|
||||
nnprod,
|
||||
ii+1,
|
||||
l1+i*nnprod,
|
||||
l2+i_1*nnprod
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// fftRenumber : fold the n-d data array to get the fft components in
|
||||
// the right places.
|
||||
|
||||
#include "fftRenumber.H"
|
||||
|
||||
void fftRenumber
|
||||
(
|
||||
List<complex>& data,
|
||||
const labelList& nn
|
||||
)
|
||||
{
|
||||
List<complex> renumData(data);
|
||||
|
||||
label nnprod(1);
|
||||
forAll(nn, i)
|
||||
{
|
||||
nnprod *= nn[i];
|
||||
}
|
||||
|
||||
label ii(0), l1(0), l2(0);
|
||||
|
||||
fftRenumberRecurse
|
||||
(
|
||||
data,
|
||||
renumData,
|
||||
nn,
|
||||
nnprod,
|
||||
ii,
|
||||
l1,
|
||||
l2
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
65
src/randomProcesses/fft/fftRenumber.H
Normal file
65
src/randomProcesses/fft/fftRenumber.H
Normal file
@ -0,0 +1,65 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Global
|
||||
fftRenumber
|
||||
|
||||
Description
|
||||
Multi-dimensional renumbering used in the Numerical Recipes
|
||||
fft routine.
|
||||
|
||||
SourceFiles
|
||||
fftRenumber.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef fftRenumber_H
|
||||
#define fftRenumber_H
|
||||
|
||||
#include "complex.H"
|
||||
#include "List.H"
|
||||
#include "labelList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
void fftRenumber
|
||||
(
|
||||
List<complex>& data,
|
||||
const labelList& nn
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
137
src/randomProcesses/fft/kShellIntegration.C
Normal file
137
src/randomProcesses/fft/kShellIntegration.C
Normal file
@ -0,0 +1,137 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "kShellIntegration.H"
|
||||
#include "mathematicalConstants.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::graph Foam::kShellIntegration
|
||||
(
|
||||
const complexVectorField& Ek,
|
||||
const Kmesh& K
|
||||
)
|
||||
{
|
||||
// evaluate the radial component of the spectra as an average
|
||||
// over the shells of thickness dk
|
||||
|
||||
graph kShellMeanEk = kShellMean(Ek, K);
|
||||
const scalarField& x = kShellMeanEk.x();
|
||||
scalarField& y = *kShellMeanEk.begin()();
|
||||
|
||||
// now multiply by 4pi k^2 (the volume of each shell) to get the
|
||||
// spectra E(k). int E(k) dk is now the total energy in a box
|
||||
// of side 2pi
|
||||
|
||||
y *= sqr(x)*4.0*constant::mathematical::pi;
|
||||
|
||||
// now scale this to get the energy in a box of side l0
|
||||
|
||||
scalar l0(K.sizeOfBox()[0]*(scalar(K.nn()[0])/(scalar(K.nn()[0])-1.0)));
|
||||
scalar factor = pow((l0/(2.0*constant::mathematical::pi)),3.0);
|
||||
|
||||
y *= factor;
|
||||
|
||||
// and divide by the number of points in the box, to give the
|
||||
// energy density.
|
||||
|
||||
y /= scalar(K.size());
|
||||
|
||||
return kShellMeanEk;
|
||||
}
|
||||
|
||||
|
||||
// kShellMean : average over the points in a k-shell to evaluate the
|
||||
// radial part of the energy spectrum.
|
||||
|
||||
Foam::graph Foam::kShellMean
|
||||
(
|
||||
const complexVectorField& Ek,
|
||||
const Kmesh& K
|
||||
)
|
||||
{
|
||||
const label tnp = Ek.size();
|
||||
const label NoSubintervals = label
|
||||
(
|
||||
pow(scalar(tnp), 1.0/vector::dim)*pow(1.0/vector::dim, 0.5) - 0.5
|
||||
);
|
||||
|
||||
scalarField k1D(NoSubintervals);
|
||||
scalarField Ek1D(NoSubintervals);
|
||||
scalarField EWeight(NoSubintervals);
|
||||
|
||||
scalar kmax = K.max()*pow(1.0/vector::dim,0.5);
|
||||
scalar delta_k = kmax/(NoSubintervals);
|
||||
|
||||
forAll(Ek1D, a)
|
||||
{
|
||||
k1D[a] = (a + 1)*delta_k;
|
||||
Ek1D[a] = 0.0;
|
||||
EWeight[a] = 0;
|
||||
}
|
||||
|
||||
forAll(K, l)
|
||||
{
|
||||
scalar kmag = mag(K[l]);
|
||||
|
||||
for (label a=0; a<NoSubintervals; a++)
|
||||
{
|
||||
if
|
||||
(
|
||||
kmag <= ((a + 1)*delta_k + delta_k/2.0)
|
||||
&& kmag > ((a + 1)*delta_k - delta_k/2.0)
|
||||
)
|
||||
{
|
||||
scalar dist = delta_k/2.0 - mag((a + 1)*delta_k - kmag);
|
||||
|
||||
Ek1D[a] += dist*
|
||||
magSqr
|
||||
(
|
||||
vector
|
||||
(
|
||||
mag(Ek[l].x()),
|
||||
mag(Ek[l].y()),
|
||||
mag(Ek[l].z())
|
||||
)
|
||||
);
|
||||
|
||||
EWeight[a] += dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (label a=0; a<NoSubintervals; a++)
|
||||
{
|
||||
if (EWeight[a] > 0)
|
||||
{
|
||||
Ek1D[a] /= EWeight[a];
|
||||
}
|
||||
}
|
||||
|
||||
return graph("E(k)", "k", "E(k)", k1D, Ek1D);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
72
src/randomProcesses/fft/kShellIntegration.H
Normal file
72
src/randomProcesses/fft/kShellIntegration.H
Normal file
@ -0,0 +1,72 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Global
|
||||
kShellIntegration
|
||||
|
||||
Description
|
||||
Integrate a multi-dimensional complexVectorField in k-shells
|
||||
to create the 1D
|
||||
|
||||
SourceFiles
|
||||
kShellIntegration.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef kShellIntegration_H
|
||||
#define kShellIntegration_H
|
||||
|
||||
#include "complexFields.H"
|
||||
#include "Kmesh.H"
|
||||
#include "graph.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
graph kShellIntegration
|
||||
(
|
||||
const complexVectorField& Ek,
|
||||
const Kmesh& K
|
||||
);
|
||||
|
||||
|
||||
graph kShellMean
|
||||
(
|
||||
const complexVectorField& Ek,
|
||||
const Kmesh& K
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
457
src/randomProcesses/noise/noiseFFT.C
Normal file
457
src/randomProcesses/noise/noiseFFT.C
Normal file
@ -0,0 +1,457 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "noiseFFT.H"
|
||||
#include "IFstream.H"
|
||||
#include "DynamicList.H"
|
||||
#include "fft.H"
|
||||
#include "SubField.H"
|
||||
#include "mathematicalConstants.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * //
|
||||
|
||||
Foam::scalar Foam::noiseFFT::p0 = 2e-5;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::noiseFFT::noiseFFT
|
||||
(
|
||||
const scalar deltat,
|
||||
const scalarField& pressure
|
||||
)
|
||||
:
|
||||
scalarField(pressure),
|
||||
deltat_(deltat)
|
||||
{}
|
||||
|
||||
|
||||
Foam::noiseFFT::noiseFFT(const fileName& pFileName, const label skip)
|
||||
:
|
||||
scalarField(),
|
||||
deltat_(0.0)
|
||||
{
|
||||
// Construct pressure data file
|
||||
IFstream pFile(pFileName);
|
||||
|
||||
// Check pFile stream is OK
|
||||
if (!pFile.good())
|
||||
{
|
||||
FatalErrorIn("noiseFFT::noiseFFT(const scalar, const scalarField&)")
|
||||
<< "Cannot read file " << pFileName
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if (skip)
|
||||
{
|
||||
scalar dummyt, dummyp;
|
||||
|
||||
for (label i=0; i<skip; i++)
|
||||
{
|
||||
pFile >> dummyt;
|
||||
|
||||
if (!pFile.good() || pFile.eof())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"noiseFFT::noiseFFT(const scalar, const scalarField&)"
|
||||
)
|
||||
<< "Number of points in file " << pFileName
|
||||
<< " is less than the number to be skipped = " << skip
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
pFile >> dummyp;
|
||||
}
|
||||
}
|
||||
|
||||
scalar t = 0, T = 0;
|
||||
DynamicList<scalar> pData(100000);
|
||||
label i = 0;
|
||||
|
||||
while (!(pFile >> t).eof())
|
||||
{
|
||||
T = t;
|
||||
pFile >> pData(i++);
|
||||
}
|
||||
|
||||
deltat_ = T/pData.size();
|
||||
|
||||
this->transfer(pData);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::graph Foam::noiseFFT::pt() const
|
||||
{
|
||||
scalarField t(size());
|
||||
forAll(t, i)
|
||||
{
|
||||
t[i] = i*deltat_;
|
||||
}
|
||||
|
||||
return graph
|
||||
(
|
||||
"p(t)",
|
||||
"t [s]",
|
||||
"p(t) [Pa]",
|
||||
t,
|
||||
*this
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::scalarField> Foam::noiseFFT::window
|
||||
(
|
||||
const label N,
|
||||
const label ni
|
||||
) const
|
||||
{
|
||||
label windowOffset = N;
|
||||
|
||||
if ((N + ni*windowOffset) > size())
|
||||
{
|
||||
FatalErrorIn("noiseFFT::window(const label, const label) const")
|
||||
<< "Requested window is outside set of data" << endl
|
||||
<< "number of data = " << size() << endl
|
||||
<< "size of window = " << N << endl
|
||||
<< "window = " << ni
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
tmp<scalarField> tpw(new scalarField(N));
|
||||
scalarField& pw = tpw();
|
||||
|
||||
label offset = ni*windowOffset;
|
||||
|
||||
forAll(pw, i)
|
||||
{
|
||||
pw[i] = operator[](i + offset);
|
||||
}
|
||||
|
||||
return tpw;
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::scalarField> Foam::noiseFFT::Hanning(const label N) const
|
||||
{
|
||||
scalarField t(N);
|
||||
forAll(t, i)
|
||||
{
|
||||
t[i] = i*deltat_;
|
||||
}
|
||||
|
||||
scalar T = N*deltat_;
|
||||
|
||||
return 2*(0.5 - 0.5*cos(constant::mathematical::twoPi*t/T));
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::scalarField> Foam::noiseFFT::Pf
|
||||
(
|
||||
const tmp<scalarField>& tpn
|
||||
) const
|
||||
{
|
||||
tmp<scalarField> tPn2
|
||||
(
|
||||
mag
|
||||
(
|
||||
fft::reverseTransform
|
||||
(
|
||||
ReComplexField(tpn),
|
||||
labelList(1, tpn().size())
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
tpn.clear();
|
||||
|
||||
tmp<scalarField> tPn
|
||||
(
|
||||
new scalarField
|
||||
(
|
||||
scalarField::subField(tPn2(), tPn2().size()/2)
|
||||
)
|
||||
);
|
||||
scalarField& Pn = tPn();
|
||||
|
||||
Pn *= 2.0/sqrt(scalar(tPn2().size()));
|
||||
Pn[0] /= 2.0;
|
||||
|
||||
return tPn;
|
||||
}
|
||||
|
||||
|
||||
Foam::graph Foam::noiseFFT::meanPf
|
||||
(
|
||||
const label N,
|
||||
const label nw
|
||||
) const
|
||||
{
|
||||
if (N > size())
|
||||
{
|
||||
FatalErrorIn("noiseFFT::meanPf(const label, const label) const")
|
||||
<< "Requested window is outside set of data" << nl
|
||||
<< "number of data = " << size() << nl
|
||||
<< "size of window = " << N << nl
|
||||
<< "window = " << nw
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
scalarField MeanPf(N/2, 0.0);
|
||||
|
||||
scalarField Hwf(Hanning(N));
|
||||
|
||||
for (label wi=0; wi<nw; ++wi)
|
||||
{
|
||||
MeanPf += Pf(Hwf*window(N, wi));
|
||||
}
|
||||
|
||||
MeanPf /= nw;
|
||||
|
||||
scalarField f(MeanPf.size());
|
||||
scalar deltaf = 1.0/(N*deltat_);
|
||||
|
||||
forAll(f, i)
|
||||
{
|
||||
f[i] = i*deltaf;
|
||||
}
|
||||
|
||||
return graph
|
||||
(
|
||||
"P(f)",
|
||||
"f [Hz]",
|
||||
"P(f) [Pa]",
|
||||
f,
|
||||
MeanPf
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Foam::graph Foam::noiseFFT::RMSmeanPf
|
||||
(
|
||||
const label N,
|
||||
const label nw
|
||||
) const
|
||||
{
|
||||
if (N > size())
|
||||
{
|
||||
FatalErrorIn("noiseFFT::RMSmeanPf(const label, const label) const")
|
||||
<< "Requested window is outside set of data" << endl
|
||||
<< "number of data = " << size() << endl
|
||||
<< "size of window = " << N << endl
|
||||
<< "window = " << nw
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
scalarField RMSMeanPf(N/2, 0.0);
|
||||
|
||||
scalarField Hwf(Hanning(N));
|
||||
|
||||
for (label wi=0; wi<nw; ++wi)
|
||||
{
|
||||
RMSMeanPf += sqr(Pf(Hwf*window(N, wi)));
|
||||
}
|
||||
|
||||
RMSMeanPf = sqrt(RMSMeanPf/nw);
|
||||
|
||||
scalarField f(RMSMeanPf.size());
|
||||
scalar deltaf = 1.0/(N*deltat_);
|
||||
|
||||
forAll(f, i)
|
||||
{
|
||||
f[i] = i*deltaf;
|
||||
}
|
||||
|
||||
return graph
|
||||
(
|
||||
"P(f)",
|
||||
"f [Hz]",
|
||||
"P(f) [Pa]",
|
||||
f,
|
||||
RMSMeanPf
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Foam::graph Foam::noiseFFT::Lf(const graph& gPf) const
|
||||
{
|
||||
return graph
|
||||
(
|
||||
"L(f)",
|
||||
"f [Hz]",
|
||||
"L(f) [dB]",
|
||||
gPf.x(),
|
||||
20*log10(gPf.y()/p0)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Foam::graph Foam::noiseFFT::Ldelta
|
||||
(
|
||||
const graph& gLf,
|
||||
const scalar f1,
|
||||
const scalar fU
|
||||
) const
|
||||
{
|
||||
const scalarField& f = gLf.x();
|
||||
const scalarField& Lf = gLf.y();
|
||||
|
||||
scalarField ldelta(Lf.size(), 0.0);
|
||||
scalarField fm(ldelta.size());
|
||||
|
||||
scalar fratio = cbrt(2.0);
|
||||
scalar deltaf = 1.0/(2*Lf.size()*deltat_);
|
||||
|
||||
scalar fl = f1/sqrt(fratio);
|
||||
scalar fu = fratio*fl;
|
||||
|
||||
label istart = label(fl/deltaf);
|
||||
label j = 0;
|
||||
|
||||
for (label i = istart; i<Lf.size(); i++)
|
||||
{
|
||||
scalar fmi = sqrt(fu*fl);
|
||||
|
||||
if (fmi > fU + 1) break;
|
||||
|
||||
if (f[i] >= fu)
|
||||
{
|
||||
fm[j] = fmi;
|
||||
ldelta[j] = 10*log10(ldelta[j]);
|
||||
|
||||
j++;
|
||||
|
||||
fl = fu;
|
||||
fu *= fratio;
|
||||
}
|
||||
|
||||
ldelta[j] += pow(10, Lf[i]/10.0);
|
||||
}
|
||||
|
||||
fm.setSize(j);
|
||||
ldelta.setSize(j);
|
||||
|
||||
return graph
|
||||
(
|
||||
"Ldelta",
|
||||
"fm [Hz]",
|
||||
"Ldelta [dB]",
|
||||
fm,
|
||||
ldelta
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Foam::graph Foam::noiseFFT::Pdelta
|
||||
(
|
||||
const graph& gPf,
|
||||
const scalar f1,
|
||||
const scalar fU
|
||||
) const
|
||||
{
|
||||
const scalarField& f = gPf.x();
|
||||
const scalarField& Pf = gPf.y();
|
||||
|
||||
scalarField pdelta(Pf.size(), 0.0);
|
||||
scalarField fm(pdelta.size());
|
||||
|
||||
scalar fratio = cbrt(2.0);
|
||||
scalar deltaf = 1.0/(2*Pf.size()*deltat_);
|
||||
|
||||
scalar fl = f1/sqrt(fratio);
|
||||
scalar fu = fratio*fl;
|
||||
|
||||
label istart = label(fl/deltaf + 1.0 - SMALL);
|
||||
label j = 0;
|
||||
|
||||
for (label i = istart; i<Pf.size(); i++)
|
||||
{
|
||||
scalar fmi = sqrt(fu*fl);
|
||||
|
||||
if (fmi > fU + 1) break;
|
||||
|
||||
if (f[i] >= fu)
|
||||
{
|
||||
fm[j] = fmi;
|
||||
pdelta[j] = sqrt((2.0/3.0)*pdelta[j]);
|
||||
|
||||
j++;
|
||||
|
||||
fl = fu;
|
||||
fu *= fratio;
|
||||
}
|
||||
|
||||
pdelta[j] += sqr(Pf[i]);
|
||||
}
|
||||
|
||||
fm.setSize(j);
|
||||
pdelta.setSize(j);
|
||||
|
||||
return graph
|
||||
(
|
||||
"Pdelta",
|
||||
"fm [Hz]",
|
||||
"Pdelta [dB]",
|
||||
fm,
|
||||
pdelta
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::noiseFFT::Lsum(const graph& gLf) const
|
||||
{
|
||||
const scalarField& Lf = gLf.y();
|
||||
|
||||
scalar lsum = 0.0;
|
||||
|
||||
forAll(Lf, i)
|
||||
{
|
||||
lsum += pow(10, Lf[i]/10.0);
|
||||
}
|
||||
|
||||
lsum = 10*log10(lsum);
|
||||
|
||||
return lsum;
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::noiseFFT::dbToPa(const scalar db) const
|
||||
{
|
||||
return p0*pow(10.0, db/20.0);
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::scalarField> Foam::noiseFFT::dbToPa
|
||||
(
|
||||
const tmp<scalarField>& db
|
||||
) const
|
||||
{
|
||||
return p0*pow(10.0, db/20.0);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
132
src/randomProcesses/noise/noiseFFT.H
Normal file
132
src/randomProcesses/noise/noiseFFT.H
Normal file
@ -0,0 +1,132 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::noiseFFT
|
||||
|
||||
Description
|
||||
FFT of the pressure field
|
||||
|
||||
SourceFiles
|
||||
noiseFFT.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef noiseFFT_H
|
||||
#define noiseFFT_H
|
||||
|
||||
#include "scalarField.H"
|
||||
#include "graph.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class noiseFFT Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class noiseFFT
|
||||
:
|
||||
public scalarField
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Time spacing of the raw data
|
||||
scalar deltat_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Reference pressure
|
||||
static scalar p0;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from pressure field
|
||||
noiseFFT
|
||||
(
|
||||
const scalar deltat,
|
||||
const scalarField& pressure
|
||||
);
|
||||
|
||||
//- Construct from Istream
|
||||
noiseFFT(Istream&);
|
||||
|
||||
//- Construct from pressure field file name
|
||||
noiseFFT(const fileName& pFileName, const label skip = 0);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return the graph of p(t)
|
||||
graph pt() const;
|
||||
|
||||
//- Return the nth window
|
||||
tmp<scalarField> window(const label N, const label n) const;
|
||||
|
||||
//- Return the Hanning window function
|
||||
tmp<scalarField> Hanning(const label N) const;
|
||||
|
||||
//- Return the fft of the given pressure data
|
||||
tmp<scalarField> Pf(const tmp<scalarField>& pn) const;
|
||||
|
||||
//- Return the multi-window mean fft of the complete pressure data
|
||||
graph meanPf(const label N, const label nw) const;
|
||||
|
||||
//- Return the multi-window RMS mean fft of the complete pressure data
|
||||
graph RMSmeanPf(const label N, const label nw) const;
|
||||
|
||||
//- Return the narrow-band PFL (pressure-fluctuation level) spectrum
|
||||
graph Lf(const graph& gPf) const;
|
||||
|
||||
//- Return the one-third-octave-band PFL spectrum
|
||||
// starting at octave with mean frequency f1
|
||||
graph Ldelta(const graph& gLf, const scalar f1, const scalar fU) const;
|
||||
|
||||
//- Return the one-third-octave-band pressure spectrum
|
||||
// starting at octave with mean frequency f1
|
||||
graph Pdelta(const graph& gLf, const scalar f1, const scalar fU) const;
|
||||
|
||||
//- Return the total PFL as the sum of Lf over all frequencies
|
||||
scalar Lsum(const graph& gLf) const;
|
||||
|
||||
//- Convert the db into Pa
|
||||
scalar dbToPa(const scalar db) const;
|
||||
|
||||
//- Convert the db-field into Pa
|
||||
tmp<scalarField> dbToPa(const tmp<scalarField>& db) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
130
src/randomProcesses/processes/UOprocess/UOprocess.C
Normal file
130
src/randomProcesses/processes/UOprocess/UOprocess.C
Normal file
@ -0,0 +1,130 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
|
||||
#include "UOprocess.H"
|
||||
#include "Kmesh.H"
|
||||
#include "dictionary.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
complexVector UOprocess::WeinerProcess()
|
||||
{
|
||||
return RootDeltaT*complexVector
|
||||
(
|
||||
complex(GaussGen.GaussNormal(), GaussGen.GaussNormal()),
|
||||
complex(GaussGen.GaussNormal(), GaussGen.GaussNormal()),
|
||||
complex(GaussGen.GaussNormal(), GaussGen.GaussNormal())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
// from components
|
||||
UOprocess::UOprocess
|
||||
(
|
||||
const Kmesh& kmesh,
|
||||
const scalar deltaT,
|
||||
const dictionary& UOdict
|
||||
)
|
||||
:
|
||||
GaussGen(label(0)),
|
||||
Mesh(kmesh),
|
||||
DeltaT(deltaT),
|
||||
RootDeltaT(sqrt(DeltaT)),
|
||||
UOfield(Mesh.size()),
|
||||
|
||||
Alpha(readScalar(UOdict.lookup("UOalpha"))),
|
||||
Sigma(readScalar(UOdict.lookup("UOsigma"))),
|
||||
Kupper(readScalar(UOdict.lookup("UOKupper"))),
|
||||
Klower(readScalar(UOdict.lookup("UOKlower"))),
|
||||
Scale((Kupper - Klower)*pow(scalar(Mesh.size()), 1.0/vector::dim))
|
||||
{
|
||||
const vectorField& K = Mesh;
|
||||
|
||||
scalar sqrKupper = sqr(Kupper);
|
||||
scalar sqrKlower = sqr(Klower) + SMALL;
|
||||
scalar sqrK;
|
||||
|
||||
forAll(UOfield, i)
|
||||
{
|
||||
if ((sqrK = magSqr(K[i])) < sqrKupper && sqrK > sqrKlower)
|
||||
{
|
||||
UOfield[i] = Scale*Sigma*WeinerProcess();
|
||||
}
|
||||
else
|
||||
{
|
||||
UOfield[i] = complexVector
|
||||
(
|
||||
complex(0, 0),
|
||||
complex(0, 0),
|
||||
complex(0, 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
const complexVectorField& UOprocess::newField()
|
||||
{
|
||||
const vectorField& K = Mesh;
|
||||
|
||||
label count = 0;
|
||||
scalar sqrKupper = sqr(Kupper);
|
||||
scalar sqrKlower = sqr(Klower) + SMALL;
|
||||
scalar sqrK;
|
||||
|
||||
forAll(UOfield, i)
|
||||
{
|
||||
if ((sqrK = magSqr(K[i])) < sqrKupper && sqrK > sqrKlower)
|
||||
{
|
||||
count++;
|
||||
UOfield[i] =
|
||||
(1.0 - Alpha*DeltaT)*UOfield[i]
|
||||
+ Scale*Sigma*WeinerProcess();
|
||||
}
|
||||
}
|
||||
|
||||
Info<< " Number of forced K = " << count << nl;
|
||||
|
||||
return UOfield;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
103
src/randomProcesses/processes/UOprocess/UOprocess.H
Normal file
103
src/randomProcesses/processes/UOprocess/UOprocess.H
Normal file
@ -0,0 +1,103 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::UOprocess
|
||||
|
||||
Description
|
||||
Random UO process.
|
||||
|
||||
SourceFiles
|
||||
UOprocess.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef UOprocess_H
|
||||
#define UOprocess_H
|
||||
|
||||
#include "complexFields.H"
|
||||
#include "scalar.H"
|
||||
#include "Random.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class Kmesh;
|
||||
class dictionary;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class UOprocess Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class UOprocess
|
||||
{
|
||||
// Private data
|
||||
|
||||
Random GaussGen;
|
||||
|
||||
const Kmesh& Mesh;
|
||||
const scalar DeltaT, RootDeltaT;
|
||||
complexVectorField UOfield;
|
||||
|
||||
scalar Alpha;
|
||||
scalar Sigma;
|
||||
scalar Kupper;
|
||||
scalar Klower;
|
||||
scalar Scale;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
complexVector WeinerProcess();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from wavenumber mesh and timestep
|
||||
UOprocess
|
||||
(
|
||||
const Kmesh& kmesh,
|
||||
const scalar deltaT,
|
||||
const dictionary&
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
const complexVectorField& newField();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
39
src/randomProcesses/turbulence/Ek.H
Normal file
39
src/randomProcesses/turbulence/Ek.H
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef Ek_H
|
||||
#define Ek_H
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
inline tmp<scalarField> Ek
|
||||
(
|
||||
const scalar Ea,
|
||||
const scalar k0,
|
||||
const scalarField& k
|
||||
)
|
||||
{
|
||||
tmp<scalarField> tEk = Ea*pow(k/k0, 4.0)*exp(-2.0*sqr(k/k0));
|
||||
|
||||
/*
|
||||
scalarField& Ekf = tEk();
|
||||
|
||||
label i;
|
||||
forAll(Ekf, i)
|
||||
{
|
||||
if (k[i] < 2 || k[i] > 10)
|
||||
{
|
||||
Ekf[i] = 0.0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return tEk;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
#endif
|
||||
77
src/randomProcesses/turbulence/turbGen.C
Normal file
77
src/randomProcesses/turbulence/turbGen.C
Normal file
@ -0,0 +1,77 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fft.H"
|
||||
#include "turbGen.H"
|
||||
#include "Kmesh.H"
|
||||
#include "primitiveFields.H"
|
||||
#include "Ek.H"
|
||||
#include "mathematicalConstants.H"
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::turbGen::turbGen(const Kmesh& k, const scalar EA, const scalar K0)
|
||||
:
|
||||
K(k),
|
||||
Ea(EA),
|
||||
k0(K0),
|
||||
RanGen(label(0))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::vectorField Foam::turbGen::U()
|
||||
{
|
||||
vectorField s(K.size());
|
||||
scalarField rndPhases(K.size());
|
||||
|
||||
forAll(K, i)
|
||||
{
|
||||
s[i] = RanGen.vector01();
|
||||
rndPhases[i] = RanGen.scalar01();
|
||||
}
|
||||
|
||||
s = K ^ s;
|
||||
s = s/(mag(s) + 1.0e-20);
|
||||
|
||||
s = Ek(Ea, k0, mag(K))*s;
|
||||
|
||||
complexVectorField up
|
||||
(
|
||||
fft::reverseTransform
|
||||
(
|
||||
ComplexField(cos(constant::mathematical::twoPi*rndPhases)*s,
|
||||
sin(constant::mathematical::twoPi*rndPhases)*s),
|
||||
K.nn()
|
||||
)
|
||||
);
|
||||
|
||||
return ReImSum(up);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
87
src/randomProcesses/turbulence/turbGen.H
Normal file
87
src/randomProcesses/turbulence/turbGen.H
Normal file
@ -0,0 +1,87 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::turbGen
|
||||
|
||||
Description
|
||||
Generate a turbulent velocity field conforming to a given
|
||||
energy spectrum and being divergence free.
|
||||
|
||||
SourceFiles
|
||||
turbGen.C
|
||||
turbGenIO.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef turbGen_H
|
||||
#define turbGen_H
|
||||
|
||||
#include "Random.H"
|
||||
#include "primitiveFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class Kmesh;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class turbGen Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class turbGen
|
||||
{
|
||||
// Private data
|
||||
|
||||
const Kmesh& K;
|
||||
const scalar Ea;
|
||||
const scalar k0;
|
||||
Random RanGen;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
turbGen(const Kmesh& k, const scalar EA, const scalar K0);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Generate and return a velocity field
|
||||
vectorField U();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user