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-2020 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_ = tmp<volVectorField>
45  (
46  new volVectorField
47  (
48  IOobject
49  (
50  "n" & patchTypeName_,
51  mesh().time().timeName(),
52  mesh()
53  ),
54  mesh(),
56  patchDistMethod::patchTypes<vector>(mesh(), patchIDs_)
57  )
58  );
59 
60  const fvPatchList& patches = mesh().boundary();
61 
62  volVectorField::Boundary& nbf = n_.ref().boundaryFieldRef();
63 
64  for (const label patchi : patchIDs_)
65  {
66  nbf[patchi] == patches[patchi].nf();
67  }
68 }
69 
70 
71 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
72 
73 Foam::wallDist::wallDist
74 (
75  const fvMesh& mesh,
76  const labelHashSet& patchIDs,
77  const word& patchTypeName
78 )
79 :
81  patchIDs_(patchIDs),
82  patchTypeName_(patchTypeName),
83  dict_
84  (
85  static_cast<const fvSchemes&>(mesh).subOrEmptyDict
86  (
87  patchTypeName_ & "Dist"
88  )
89  ),
90  pdm_
91  (
93  (
94  dict_,
95  mesh,
96  patchIDs_
97  )
98  ),
99  y_
100  (
101  IOobject
102  (
103  "y" & patchTypeName_,
104  mesh.time().timeName(),
105  mesh
106  ),
107  mesh,
108  dimensionedScalar("y" & patchTypeName_, dimLength, SMALL),
109  patchDistMethod::patchTypes<scalar>(mesh, patchIDs_)
110  ),
111  nRequired_(dict_.getOrDefault("nRequired", false)),
112  n_(volVectorField::null()),
113  updateInterval_(dict_.getOrDefault<label>("updateInterval", 1)),
114  requireUpdate_(true)
115 {
116  if (nRequired_)
117  {
118  constructn();
119  }
120 
121  movePoints();
122 }
123 
124 
125 Foam::wallDist::wallDist
126 (
127  const fvMesh& mesh,
128  const word& defaultPatchDistMethod,
129  const labelHashSet& patchIDs,
130  const word& patchTypeName
131 )
132 :
134  patchIDs_(patchIDs),
135  patchTypeName_(patchTypeName),
136  dict_
137  (
138  static_cast<const fvSchemes&>(mesh).subOrEmptyDict
139  (
140  patchTypeName_ & "Dist"
141  )
142  ),
143  pdm_
144  (
146  (
147  dict_,
148  mesh,
149  patchIDs_,
150  defaultPatchDistMethod
151  )
152  ),
153  y_
154  (
155  IOobject
156  (
157  "y" & patchTypeName_,
158  mesh.time().timeName(),
159  mesh
160  ),
161  mesh,
162  dimensionedScalar("y" & patchTypeName_, dimLength, SMALL),
163  patchDistMethod::patchTypes<scalar>(mesh, patchIDs_)
164  ),
165  nRequired_(dict_.getOrDefault("nRequired", false)),
166  n_(volVectorField::null()),
167  updateInterval_(dict_.getOrDefault<label>("updateInterval", 1)),
168  requireUpdate_(true)
169 {
170  if (nRequired_)
171  {
172  constructn();
173  }
174 
175  movePoints();
176 }
177 
178 
179 Foam::wallDist::wallDist(const fvMesh& mesh, const word& patchTypeName)
180 :
181  wallDist
182  (
183  mesh,
184  mesh.boundaryMesh().findPatchIDs<wallPolyPatch>(),
185  patchTypeName
186  )
187 {}
188 
189 
190 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
191 
193 {}
194 
195 
196 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
197 
199 {
200  if (isNull(n_()))
201  {
203  << "n requested but 'nRequired' not specified in the "
204  << (patchTypeName_ & "Dist") << " dictionary" << nl
205  << " Recalculating y and n fields." << endl;
206 
207  nRequired_ = true;
208  constructn();
209  pdm_->correct(y_, n_.ref());
210  }
211 
212  return n_();
213 }
214 
215 
217 {
218  if
219  (
220  (updateInterval_ != 0)
221  && ((mesh_.time().timeIndex() % updateInterval_) == 0)
222  )
223  {
224  requireUpdate_ = true;
225  }
226 
227  if (requireUpdate_ && pdm_->movePoints())
228  {
229  DebugInfo<< "Updating wall distance" << endl;
230 
231  requireUpdate_ = false;
232 
233  if (nRequired_)
234  {
235  return pdm_->correct(y_, n_.ref());
236  }
237  else
238  {
239  return pdm_->correct(y_);
240  }
241  }
242 
243  return false;
244 }
245 
246 
248 {
249  pdm_->updateMesh(mpm);
250 
251  // Force update if performing topology change
252  // Note: needed?
253  // - field would have been mapped, so if using updateInterval option (!= 1)
254  // live with error associated of not updating and use mapped values?
255  requireUpdate_ = true;
256  movePoints();
257 }
258 
259 
260 // ************************************************************************* //
wallDist.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::wallDist::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update the y-field when the mesh changes.
Definition: wallDist.C:247
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:53
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::fvSchemes
Selector class for finite volume differencing schemes. fvMesh is derived from fvShemes so that all fi...
Definition: fvSchemes.H:53
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
wallPolyPatch.H
Foam::IOobject::IOobject
IOobject(const IOobject &)=default
Copy construct.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::HashSet< label, Hash< label > >
Foam::IOobject::time
const Time & time() const
Return time.
Definition: IOobject.C:463
Foam::patchDistMethod::New
static autoPtr< patchDistMethod > New(const dictionary &dict, const fvMesh &mesh, const labelHashSet &patchIDs)
Definition: patchDistMethod.C:56
Foam::dimensionedVector
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Definition: dimensionedVector.H:50
Foam::fvPatchList
PtrList< fvPatch > fvPatchList
container classes for fvPatch
Definition: fvPatchList.H:47
Foam::wallDist
Interface to run-time selectable methods to calculate the distance-to-wall and normal-to-wall fields.
Definition: wallDist.H:75
Foam::MeshObject< fvMesh, UpdateableMeshObject, wallDist >::mesh
const fvMesh & mesh() const
Definition: MeshObject.H:122
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
Foam::wallDist::movePoints
virtual bool movePoints()
Update the y-field when the mesh moves.
Definition: wallDist.C:216
timeName
word timeName
Definition: getTimeIndex.H:3
Foam::wallDist::n
const volVectorField & n() const
Return reference to cached normal-to-wall field.
Definition: wallDist.C:198
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::wallPolyPatch
Foam::wallPolyPatch.
Definition: wallPolyPatch.H:50
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::volVectorField
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:62
Foam::fvMesh::boundary
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:679
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:359
Foam::nl
constexpr char nl
Definition: Ostream.H:385
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:275
Foam::boundaryMesh
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:62
Foam::MeshObject
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:88
Foam::isNull
bool isNull(const T *ptr)
True if ptr is a pointer (of type T) to the nullObject.
Definition: nullObject.H:192
Foam::GeometricField< vector, fvPatchField, volMesh >::null
static const GeometricField< vector, fvPatchField, volMesh > & null()
Return a null geometric field.
Definition: GeometricFieldI.H:32
Foam::GeometricField< vector, fvPatchField, volMesh >
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303
Foam::wallDist::~wallDist
virtual ~wallDist()
Destructor.
Definition: wallDist.C:192