FreeFOAM The Cross-Platform CFD Toolkit
atmBoundaryLayerInletVelocityFvPatchVectorField.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 | Copyright (C) 2010-2010 OpenCFD Ltd.
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 the
13  Free Software Foundation; either version 3 of the License, or (at your
14  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, write to the Free Software Foundation,
23  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 
25 \*---------------------------------------------------------------------------*/
26 
30 #include <finiteVolume/volFields.H>
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace incompressible
38 {
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
42 atmBoundaryLayerInletVelocityFvPatchVectorField::
43 atmBoundaryLayerInletVelocityFvPatchVectorField
44 (
45  const fvPatch& p,
47 )
48 :
49  fixedValueFvPatchVectorField(p, iF),
50  Ustar_(0),
53  z0_(0),
54  kappa_(0.41),
55  Uref_(0),
56  Href_(0),
57  zGround_(0)
58 {}
59 
60 
61 atmBoundaryLayerInletVelocityFvPatchVectorField::
62 atmBoundaryLayerInletVelocityFvPatchVectorField
63 (
65  const fvPatch& p,
67  const fvPatchFieldMapper& mapper
68 )
69 :
70  fixedValueFvPatchVectorField(ptf, p, iF, mapper),
71  Ustar_(ptf.Ustar_),
72  n_(ptf.n_),
73  z_(ptf.z_),
74  z0_(ptf.z0_),
75  kappa_(ptf.kappa_),
76  Uref_(ptf.Uref_),
77  Href_(ptf.Href_),
78  zGround_(ptf.zGround_)
79 {}
80 
81 
82 atmBoundaryLayerInletVelocityFvPatchVectorField::
83 atmBoundaryLayerInletVelocityFvPatchVectorField
84 (
85  const fvPatch& p,
87  const dictionary& dict
88 )
89 :
90  fixedValueFvPatchVectorField(p, iF),
91  Ustar_(0),
92  n_(dict.lookup("n")),
93  z_(dict.lookup("z")),
94  z0_(readScalar(dict.lookup("z0"))),
95  kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
96  Uref_(readScalar(dict.lookup("Uref"))),
97  Href_(readScalar(dict.lookup("Href"))),
98  zGround_(readScalar(dict.lookup("zGround")))
99 {
100  if (mag(n_) < SMALL || mag(z_) < SMALL || mag(z0_) < SMALL)
101  {
103  (
104  "atmBoundaryLayerInletVelocityFvPatchVectorField"
105  "("
106  "const fvPatch&, "
107  "const DimensionedField<vector, volMesh>&, "
108  "onst dictionary&"
109  ")"
110  )
111  << "magnitude of n, z and z0 vectors must be greater than zero"
112  << abort(FatalError);
113  }
114 
115  n_ /= mag(n_);
116  z_ /= mag(z_);
117 
118  Ustar_ = kappa_*Uref_/(log((Href_ + z0_)/max(z0_ , 0.001)));
119 
120  evaluate();
121 }
122 
123 
124 atmBoundaryLayerInletVelocityFvPatchVectorField::
125 atmBoundaryLayerInletVelocityFvPatchVectorField
126 (
129 )
130 :
131  fixedValueFvPatchVectorField(blpvf, iF),
132  Ustar_(blpvf.Ustar_),
133  n_(blpvf.n_),
134  z_(blpvf.z_),
135  z0_(blpvf.z0_),
136  kappa_(blpvf.kappa_),
137  Uref_(blpvf.Uref_),
138  Href_(blpvf.Href_),
139  zGround_(blpvf.zGround_)
140 {}
141 
142 
143 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
144 
145 void atmBoundaryLayerInletVelocityFvPatchVectorField::updateCoeffs()
146 {
147  const vectorField& c = patch().Cf();
148  scalarField coord = (c & z_);
149  scalarField Un(coord.size());
150 
151  forAll(coord, i)
152  {
153  if((coord[i] - zGround_) < Href_)
154  {
155  Un[i] = (Ustar_/kappa_)*log((coord[i] - zGround_ + z0_)/max(z0_ , 0.001));
156  }
157  else
158  {
159  Un[i] = (Uref_);
160  }
161  }
162 
163  vectorField::operator=(n_*Un);
164 
165  fixedValueFvPatchVectorField::updateCoeffs();
166 }
167 
168 
169 void atmBoundaryLayerInletVelocityFvPatchVectorField::write(Ostream& os) const
170 {
172  os.writeKeyword("z0")
173  << z0_ << token::END_STATEMENT << nl;
174  os.writeKeyword("n")
175  << n_ << token::END_STATEMENT << nl;
176  os.writeKeyword("z")
177  << z_ << token::END_STATEMENT << nl;
178  os.writeKeyword("kappa")
179  << kappa_ << token::END_STATEMENT << nl;
180  os.writeKeyword("Uref")
181  << Uref_ << token::END_STATEMENT << nl;
182  os.writeKeyword("Href")
183  << Href_ << token::END_STATEMENT << nl;
184  os.writeKeyword("zGround")
185  << zGround_ << token::END_STATEMENT << nl;
186  writeEntry("value", os);
187 }
188 
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
193 (
196 );
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 } // End namespace incompressible
201 } // End namespace Foam
202 
203 // ************************************************************************* //