UOprocess.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-2017 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 "error.H"
29 
30 #include "UOprocess.H"
31 #include "Kmesh.H"
32 #include "dictionary.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 complexVector UOprocess::WeinerProcess()
42 {
43  return RootDeltaT*complexVector
44  (
45  complex(GaussGen.GaussNormal<scalar>(), GaussGen.GaussNormal<scalar>()),
46  complex(GaussGen.GaussNormal<scalar>(), GaussGen.GaussNormal<scalar>()),
47  complex(GaussGen.GaussNormal<scalar>(), GaussGen.GaussNormal<scalar>())
48  );
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 (
56  const Kmesh& kmesh,
57  const scalar deltaT,
58  const dictionary& UOdict
59 )
60 :
61  GaussGen(),
62  Mesh(kmesh),
63  DeltaT(deltaT),
64  RootDeltaT(sqrt(DeltaT)),
65  UOfield(Mesh.size()),
66 
67  Alpha(UOdict.get<scalar>("UOalpha")),
68  Sigma(UOdict.get<scalar>("UOsigma")),
69  Kupper(UOdict.get<scalar>("UOKupper")),
70  Klower(UOdict.get<scalar>("UOKlower")),
71  Scale((Kupper - Klower)*pow(scalar(Mesh.size()), 1.0/vector::dim))
72 {
73  const vectorField& K = Mesh;
74 
75  scalar sqrKupper = sqr(Kupper);
76  scalar sqrKlower = sqr(Klower) + SMALL;
77  scalar sqrK;
78 
79  forAll(UOfield, i)
80  {
81  if ((sqrK = magSqr(K[i])) < sqrKupper && sqrK > sqrKlower)
82  {
83  UOfield[i] = Scale*Sigma*WeinerProcess();
84  }
85  else
86  {
87  UOfield[i] = complexVector::zero;
88  }
89  }
90 }
91 
92 
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 
96 {
97  const vectorField& K = Mesh;
98 
99  label count = 0;
100  scalar sqrKupper = sqr(Kupper);
101  scalar sqrKlower = sqr(Klower) + SMALL;
102  scalar sqrK;
103 
104  forAll(UOfield, i)
105  {
106  if ((sqrK = magSqr(K[i])) < sqrKupper && sqrK > sqrKlower)
107  {
108  count++;
109  UOfield[i] =
110  (1.0 - Alpha*DeltaT)*UOfield[i]
111  + Scale*Sigma*WeinerProcess();
112  }
113  }
114 
115  Info<< " Number of forced K = " << count << nl;
116 
117  return UOfield;
118 }
119 
120 
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122 
123 } // End namespace Foam
124 
125 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
Field< complexVector > complexVectorField
Specialisation of Field<T> for complexVector.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
dimensionedSymmTensor sqr(const dimensionedVector &dv)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
const complexVectorField & newField()
Definition: UOprocess.C:88
dimensionedScalar sqrt(const dimensionedScalar &ds)
CGAL::Exact_predicates_exact_constructions_kernel K
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
Vector< complex > complexVector
A Vector of complex values with &#39;scalar&#39; precision.
Definition: complexVector.H:45
Calculate the wavenumber vector field corresponding to the space vector field of a finite volume mesh...
Definition: Kmesh.H:47
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Field< vector > vectorField
Specialisation of Field<T> for vector.
Type GaussNormal()
Return a sample whose components are normally distributed with zero mean and unity variance N(0...
UOprocess(const Kmesh &kmesh, const scalar deltaT, const dictionary &)
Construct from wavenumber mesh and timestep.
Definition: UOprocess.C:48
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Namespace for OpenFOAM.