OUprocess.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-2024 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 "OUprocess.H"
27 #include "Kmesh.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 
36 complexVector OUprocess::WeinerProcess(const scalar deltaT) const
37 {
38  return sqrt(deltaT)*complexVector
39  (
40  complex(stdNormal_.sample(), stdNormal_.sample()),
41  complex(stdNormal_.sample(), stdNormal_.sample()),
42  complex(stdNormal_.sample(), stdNormal_.sample())
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 (
51  const Kmesh& kmesh,
52  const scalar deltaT,
53  const dictionary& OUdict
54 )
55 :
56  stdNormal_(0),
57  Kmesh_(kmesh),
58  OUfield_(Kmesh_.size()),
59 
60  alpha_(OUdict.lookup<scalar>("alpha")),
61  sigma_(OUdict.lookup<scalar>("sigma")),
62  kUpper_(OUdict.lookup<scalar>("kUpper")),
63  kLower_(OUdict.lookup<scalar>("kLower")),
64  scale_((kUpper_ - kLower_)*pow(scalar(Kmesh_.size()), 1.0/vector::dim))
65 {
66  const vectorField& K = Kmesh_;
67 
68  scalar sqrkUpper_ = sqr(kUpper_);
69  scalar sqrkLower_ = sqr(kLower_) + small;
70  scalar sqrK;
71 
72  forAll(OUfield_, i)
73  {
74  if ((sqrK = magSqr(K[i])) < sqrkUpper_ && sqrK > sqrkLower_)
75  {
76  OUfield_[i] = scale_*sigma_*WeinerProcess(deltaT);
77  }
78  else
79  {
80  OUfield_[i] = complexVector
81  (
82  complex(0, 0),
83  complex(0, 0),
84  complex(0, 0)
85  );
86  }
87  }
88 }
89 
90 
91 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92 
93 const complexVectorField& OUprocess::newField(const scalar deltaT) const
94 {
95  const vectorField& K = Kmesh_;
96 
97  scalar sqrkUpper_ = sqr(kUpper_);
98  scalar sqrkLower_ = sqr(kLower_) + small;
99  scalar sqrK;
100 
101  forAll(OUfield_, i)
102  {
103  if ((sqrK = magSqr(K[i])) < sqrkUpper_ && sqrK > sqrkLower_)
104  {
105  OUfield_[i] =
106  (1.0 - alpha_*deltaT)*OUfield_[i]
107  + scale_*sigma_*WeinerProcess(deltaT);
108  }
109  }
110 
111  return OUfield_;
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 
117 } // End namespace Foam
118 
119 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Calculate the wavenumber vector field corresponding to the space vector field of a finite volume mesh...
Definition: Kmesh.H:52
OUprocess(const Kmesh &kmesh, const scalar deltaT, const dictionary &)
Construct from wavenumber mesh, timestep and coefficients dict.
Definition: OUprocess.C:50
const complexVectorField & newField(const scalar deltaT) const
Return the current random Ornstein-Uhlenbeck process field.
Definition: OUprocess.C:93
Extension to the c++ complex library type.
Definition: complex.H:77
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
virtual scalar sample() const
Sample the distribution.
K
Definition: pEqn.H:75
Namespace for OpenFOAM.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensionedScalar sqrt(const dimensionedScalar &ds)
Vector< complex > complexVector
complexVector obtained from generic Vector.
Definition: complexVector.H:46
dimensioned< scalar > magSqr(const dimensioned< Type > &)