wallDist.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) 2015-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2021 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 "wallDist.H"
30 #include "wallPolyPatch.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(wallDist, 0);
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 void Foam::wallDist::constructn() const
43 {
44  n_.reset
45  (
46  new volVectorField
47  (
48  IOobject
49  (
50  "n" & patchTypeName_,
51  mesh().time().timeName(),
52  mesh().thisDb(),
54  ),
55  mesh(),
57  patchDistMethod::patchTypes<vector>(mesh(), patchIDs_)
58  )
59  );
60 
61  const fvPatchList& patches = mesh().boundary();
62 
63  volVectorField::Boundary& nbf = n_.ref().boundaryFieldRef();
64 
65  for (const label patchi : patchIDs_)
66  {
67  nbf[patchi] == patches[patchi].nf();
68  }
69 }
70 
71 
72 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
73 
74 Foam::wallDist::wallDist
75 (
76  const fvMesh& mesh,
77  const labelHashSet& patchIDs,
78  const word& patchTypeName
79 )
80 :
81  wallDist(mesh, word::null, patchIDs, patchTypeName)
82 {}
83 
84 
85 Foam::wallDist::wallDist
86 (
87  const fvMesh& mesh,
88  const word& defaultPatchDistMethod,
89  const labelHashSet& patchIDs,
90  const word& patchTypeName
91 )
92 :
94  patchIDs_(patchIDs),
95  patchTypeName_(patchTypeName),
96  dict_
97  (
98  static_cast<const fvSchemes&>(mesh).subOrEmptyDict
99  (
100  patchTypeName_ & "Dist"
101  )
102  ),
103  pdm_
104  (
106  (
107  dict_,
108  mesh,
109  patchIDs_,
110  defaultPatchDistMethod
111  )
112  ),
113  y_
114  (
115  IOobject
116  (
117  "y" & patchTypeName_,
118  mesh.time().timeName(),
119  mesh.thisDb(),
120  IOobjectOption::NO_REGISTER
121  ),
122  mesh,
123  dimensionedScalar("y" & patchTypeName_, dimLength, SMALL),
124  patchDistMethod::patchTypes<scalar>(mesh, patchIDs_)
125  ),
126  n_(volVectorField::null()),
127  updateInterval_(dict_.getOrDefault<label>("updateInterval", 1)),
128  nRequired_(dict_.getOrDefault("nRequired", false)),
129  requireUpdate_(true)
130 {
131  if (nRequired_)
132  {
133  constructn();
134  }
135 
136  movePoints();
137 }
138 
139 
140 Foam::wallDist::wallDist(const fvMesh& mesh, const word& patchTypeName)
141 :
142  wallDist
143  (
144  mesh,
145  mesh.boundaryMesh().findPatchIDs<wallPolyPatch>(),
146  patchTypeName
147  )
148 {}
149 
150 
151 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
154 {}
155 
156 
157 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
158 
160 {
161  if (isNull(n_()))
162  {
164  << "n requested but 'nRequired' not specified in the "
165  << (patchTypeName_ & "Dist") << " dictionary" << nl
166  << " Recalculating y and n fields." << endl;
167 
168  nRequired_ = true;
169  constructn();
170  pdm_->correct(y_, n_.ref());
171  }
172 
173  return n_();
174 }
175 
176 
178 {
179  if
180  (
181  (updateInterval_ > 0)
182  && ((mesh_.time().timeIndex() % updateInterval_) == 0)
183  )
184  {
185  requireUpdate_ = true;
186  }
187 
188  if (requireUpdate_ && pdm_->movePoints())
189  {
190  DebugInfo<< "Updating wall distance" << endl;
191 
192  requireUpdate_ = false;
193 
194  if (nRequired_)
195  {
196  return pdm_->correct(y_, n_.ref());
197  }
198  else
199  {
200  return pdm_->correct(y_);
201  }
202  }
203 
204  return false;
205 }
206 
207 
208 void Foam::wallDist::updateMesh(const mapPolyMesh& mpm)
209 {
210  pdm_->updateMesh(mpm);
211 
212  // Force update if performing topology change
213  // Note: needed?
214  // - field would have been mapped, so if using updateInterval option (!= 1)
215  // live with error associated of not updating and use mapped values?
216  requireUpdate_ = true;
217  movePoints();
218 }
219 
220 
221 // ************************************************************************* //
const labelList patchIDs(pbm.indices(polyPatchNames, true))
const volVectorField & n() const
Return reference to cached normal-to-wall field.
Definition: wallDist.C:152
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
wordList patchTypes(nPatches)
virtual ~wallDist()
Destructor.
Definition: wallDist.C:146
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
GeometricBoundaryField< vector, fvPatchField, volMesh > Boundary
Type of boundary fields.
const dimensionSet dimless
Dimensionless.
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:82
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:85
word timeName
Definition: getTimeIndex.H:3
dynamicFvMesh & mesh
const fvMesh & mesh() const noexcept
Reference to the mesh.
Definition: MeshObject.H:157
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void updateMesh(const mapPolyMesh &)
Update the y-field when the mesh changes.
Definition: wallDist.C:201
virtual bool movePoints()
Update the y-field when the mesh moves.
Definition: wallDist.C:170
#define DebugInfo
Report an information message using Foam::Info.
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Definition: IOobject.C:456
bool isNull(const T *ptr)
True if ptr is a pointer (of type T) to the nullObject.
Definition: nullObject.H:227
defineTypeNameAndDebug(combustionModel, 0)
#define WarningInFunction
Report a warning using Foam::Warning.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
Selector class for finite volume differencing schemes. fvMesh is derived from fvSchemes so that all f...
Definition: fvSchemes.H:51
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
const polyBoundaryMesh & patches
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition: fvMesh.H:395
Interface to run-time selectable methods to calculate the distance-to-wall and normal-to-wall fields...
Definition: wallDist.H:71
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Specialisation of patchDist for wall distance calculation.
Do not request registration (bool: false)
Namespace for OpenFOAM.
PtrList< fvPatch > fvPatchList
Store lists of fvPatch as a PtrList.
Definition: fvPatch.H:59
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127