Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
34namespace Foam
35{
37}
38
39
40// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41
42void Foam::wallDist::constructn() const
43{
44 n_.reset
45 (
47 (
48 IOobject
49 (
50 "n" & patchTypeName_,
51 mesh().time().timeName(),
52 mesh().thisDb(),
54 ),
55 mesh(),
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
74Foam::wallDist::wallDist
75(
76 const fvMesh& mesh,
78 const word& patchTypeName
79)
80:
81 wallDist(mesh, word::null, patchIDs, patchTypeName)
82{}
83
84
85Foam::wallDist::wallDist
86(
87 const fvMesh& mesh,
88 const word& defaultPatchDistMethod,
90 const word& patchTypeName
91)
92:
93 MeshObject_type(mesh),
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 (
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
140Foam::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// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
158
160{
161 auto* ptr =
162 mesh.getObjectPtr<UpdateableMeshObject<fvMesh>>("wallDist");
163
164 if (ptr)
165 {
166 return ptr->movePoints();
167 }
169 return false;
170}
171
172
173// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
174
176{
177 if (isNull(n_()))
178 {
180 << "n requested but 'nRequired' not specified in the "
181 << (patchTypeName_ & "Dist") << " dictionary" << nl
182 << " Recalculating y and n fields." << endl;
183
184 nRequired_ = true;
185 constructn();
186 pdm_->correct(y_, n_.ref());
187 }
188
189 return n_();
190}
191
192
194{
195 if
196 (
197 (updateInterval_ > 0)
198 && ((mesh_.time().timeIndex() % updateInterval_) == 0)
199 )
200 {
201 requireUpdate_ = true;
202 }
203
204 if (requireUpdate_ && pdm_->movePoints())
205 {
206 DebugInfo<< "Updating wall distance" << endl;
207
208 requireUpdate_ = false;
209
210 if (nRequired_)
211 {
212 return pdm_->correct(y_, n_.ref());
213 }
214 else
215 {
216 return pdm_->correct(y_);
218 }
219
220 return false;
221}
222
223
225{
226 pdm_->updateMesh(mpm);
227
228 // Force update if performing topology change
229 // Note: needed?
230 // - field would have been mapped, so if using updateInterval option (!= 1)
231 // live with error associated of not updating and use mapped values?
232 requireUpdate_ = true;
233 movePoints();
234}
235
236
237// ************************************************************************* //
labelList patchIDs
GeometricBoundaryField< vector, fvPatchField, volMesh > Boundary
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
@ NO_REGISTER
Do not request registration (bool: false).
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Definition IOobject.C:456
static FOAM_NO_DANGLING_REFERENCE const wallDist & New(const fvMesh &mesh, Args &&... args)
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition fvMesh.H:395
Selector class for finite volume differencing schemes. fvMesh is derived from fvSchemes so that all f...
Definition fvSchemes.H:54
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Specialisation of patchDist for wall distance calculation.
static wordList patchTypes(const fvMesh &mesh, const labelHashSet &patchIDs)
Return the patch types for y and n.
Interface to run-time selectable methods to calculate the distance-to-wall and normal-to-wall fields.
Definition wallDist.H:74
virtual bool movePoints()
Update the y-field when the mesh moves.
Definition wallDist.C:186
static bool try_movePoints(const fvMesh &mesh)
Trigger update of y-field for the "wallDist" MeshObject on the given mesh. A no-op if the wallDist is...
Definition wallDist.C:152
virtual void updateMesh(const mapPolyMesh &)
Update the y-field when the mesh changes.
Definition wallDist.C:217
virtual ~wallDist()
Destructor.
Definition wallDist.C:146
const labelHashSet & patchIDs() const noexcept
Return the patchIDs.
Definition wallDist.H:212
const volVectorField & n() const
Return reference to cached normal-to-wall field.
Definition wallDist.C:168
Foam::wallPolyPatch.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
word timeName
Definition getTimeIndex.H:3
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
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.
GeometricField< vector, fvPatchField, volMesh > volVectorField
const dimensionSet dimless
Dimensionless.
PtrList< fvPatch > fvPatchList
Store lists of fvPatch as a PtrList.
Definition fvPatch.H:64
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition HashSet.H:85
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
bool isNull(const T *ptr) noexcept
True if ptr is a pointer (of type T) to the nullObject.
Definition nullObject.H:248
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
wordList patchTypes(nPatches)