wallDist.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2015-2023 OpenFOAM Foundation
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your 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, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "wallDist.H"
27 #include "wallPolyPatch.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
34 }
35 
36 
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 
39 void Foam::wallDist::constructn() const
40 {
41  n_ = new volVectorField
42  (
43  IOobject
44  (
45  "n" & patchTypeName_,
46  mesh().time().name(),
47  mesh()
48  ),
49  mesh(),
51  patchDistMethod::patchTypes<vector>(mesh(), patchIndices_)
52  );
53 
54  const fvPatchList& patches = mesh().boundary();
55 
56  volVectorField::Boundary& nbf = n_->boundaryFieldRef();
57 
58  forAllConstIter(labelHashSet, patchIndices_, iter)
59  {
60  label patchi = iter.key();
61  nbf[patchi] == patches[patchi].nf();
62  }
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
67 
68 Foam::wallDist::wallDist(const fvMesh& mesh, const word& patchTypeName)
69 :
71  patchIndices_(mesh.boundaryMesh().findIndices<wallPolyPatch>()),
72  patchTypeName_(patchTypeName),
73  pdm_
74  (
76  (
77  static_cast<const fvSchemes&>(mesh)
78  .subDict(patchTypeName_ & "Dist"),
79  mesh,
80  patchIndices_
81  )
82  ),
83  y_
84  (
85  IOobject
86  (
87  "y" & patchTypeName_,
88  mesh.time().name(),
89  mesh
90  ),
91  mesh,
92  dimensionedScalar("y" & patchTypeName_, dimLength, small),
93  patchDistMethod::patchTypes<scalar>(mesh, patchIndices_)
94  ),
95  nRequired_
96  (
97  static_cast<const fvSchemes&>(mesh).subDict(patchTypeName_ & "Dist")
98  .lookupOrDefault<Switch>("nRequired", false)
99  )
100 {
101  if (nRequired_)
102  {
103  constructn();
104  pdm_->correct(y_, n_());
105  }
106  else
107  {
108  pdm_->correct(y_);
109  }
110 }
111 
112 
114 (
115  const fvMesh& mesh,
116  const labelHashSet& patchIDs,
117  const word& patchTypeName
118 )
119 :
121  patchIndices_(patchIDs),
122  patchTypeName_(patchTypeName),
123  pdm_
124  (
126  (
127  static_cast<const fvSchemes&>(mesh)
128  .subDict(patchTypeName_ & "Dist"),
129  mesh,
130  patchIndices_
131  )
132  ),
133  y_
134  (
135  IOobject
136  (
137  "y" & patchTypeName_,
138  mesh.time().name(),
139  mesh
140  ),
141  mesh,
142  dimensionedScalar("y" & patchTypeName_, dimLength, small),
143  patchDistMethod::patchTypes<scalar>(mesh, patchIndices_)
144  ),
145  nRequired_
146  (
147  static_cast<const fvSchemes&>(mesh).subDict(patchTypeName_ & "Dist")
148  .lookupOrDefault<Switch>("nRequired", false)
149  )
150 {
151  if (nRequired_)
152  {
153  constructn();
154  pdm_->correct(y_, n_());
155  }
156  else
157  {
158  pdm_->correct(y_);
159  }
160 }
161 
162 
163 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
164 
166 {}
167 
168 
169 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
170 
172 {
173  if (!n_.valid())
174  {
176  << "n requested but 'nRequired' not specified in the "
177  << (patchTypeName_ & "Dist") << " dictionary" << nl
178  << " Recalculating y and n fields." << endl;
179 
180  nRequired_ = true;
181  constructn();
182  pdm_->correct(y_, n_());
183  }
184 
185  return n_();
186 }
187 
188 
189 // ************************************************************************* //
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
MeshObject types:
Definition: MeshObjects.H:67
Templated abstract base-class for demand-driven mesh objects used to automate their allocation to the...
Generic GeometricField class.
GeometricBoundaryField< Type, PatchField, GeoMesh > Boundary
Type of the boundary field.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
const Time & time() const
Return time.
Definition: IOobject.C:318
IOobject(const word &name, const fileName &instance, const objectRegistry &registry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true)
Construct from name, instance, registry, io options.
Definition: IOobject.C:167
const word & name() const
Return name.
Definition: IOobject.H:310
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:857
Selector class for finite volume differencing schemes. fvMesh is derived from fvSchemes so that all f...
Definition: fvSchemes.H:53
Specialisation of patchDist for wall distance calculation.
Interface to run-time selectable methods to calculate the distance-to-wall and normal-to-wall fields.
Definition: wallDist.H:71
wallDist(const fvMesh &mesh, const word &patchTypeName="wall")
Construct from mesh and optional patch type name.
Definition: wallDist.C:68
virtual ~wallDist()
Destructor.
Definition: wallDist.C:165
const volVectorField & n() const
Return reference to cached normal-to-wall field.
Definition: wallDist.C:171
Foam::wallPolyPatch.
Definition: wallPolyPatch.H:51
A class for handling words, derived from string.
Definition: word.H:62
label patchi
const fvPatchList & patches
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
VolField< vector > volVectorField
Definition: volFieldsFwd.H:65
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
labelList findIndices(const ListType &, typename ListType::const_reference, const label start=0)
Find all occurrences of given element. Linear search.
const dimensionSet dimless
const dimensionSet dimLength
PtrList< fvPatch > fvPatchList
container classes for fvPatch
Definition: fvPatchList.H:45
defineTypeNameAndDebug(combustionModel, 0)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:213
static const char nl
Definition: Ostream.H:266
wordList patchTypes(nPatches)