meshWaveAddressingPatchDistMethod.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) 2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
29 #include "wallDistAddressing.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace patchDistMethods
39 {
40  defineTypeNameAndDebug(meshWaveAddressing, 0);
41  addToRunTimeSelectionTable(patchDistMethod, meshWaveAddressing, dictionary);
42 }
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 (
50  const dictionary& dict,
51  const fvMesh& mesh,
52  const labelHashSet& patchIDs
53 )
54 :
56  correctWalls_(dict.getOrDefault("correctWalls", true))
57 {}
58 
59 
61 (
62  const fvMesh& mesh,
63  const labelHashSet& patchIDs,
64  const bool correctWalls
65 )
66 :
68  correctWalls_(correctWalls)
69 {}
70 
71 
72 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73 
75 {
76  return correct(y, const_cast<volVectorField&>(volVectorField::null()));
77 }
78 
79 
81 (
84 )
85 {
86  // If not yet constructed, construct with our options.
87  // Note that registration name is still 'wallDistAddressing'
88  // since the supplied options (wall patchIDs and correctWalls)
89  // are not assumed to be different from the defaults of other usage.
90 
91  // Calculate distance and addressing
92  const auto& wDist = wallDistAddressing::New
93  (
94  "wall",
95  mesh_,
96  patchIDs_.sortedToc(),
97  correctWalls_
98  );
99 
100  y = wDist.y();
101 
102  // Note: copying value only so might not be consistent with supplied
103  // patch types (e.g. zeroGradient when called from wallDist). Assume
104  // only affected ones are the supplied patches ...
105  {
106  auto& bfld = y.boundaryFieldRef();
107  const label startOfRequests = UPstream::nRequests();
108  for (const label patchi : patchIDs_)
109  {
110  bfld[patchi].initEvaluate(UPstream::commsTypes::nonBlocking);
111  }
112 
113  // Wait for outstanding requests
114  UPstream::waitRequests(startOfRequests);
115 
116  for (const label patchi : patchIDs_)
117  {
118  bfld[patchi].evaluate(UPstream::commsTypes::nonBlocking);
119  }
120  }
121 
122 
123  // Only calculate n if the field is defined
124  if (notNull(n))
125  {
126  for (const label patchi : patchIDs_)
127  {
128  auto& pnf = n.boundaryFieldRef()[patchi];
129  pnf == pnf.patch().nf();
130  }
131 
132  // No problem with inconsistency as for y (see above) since doing
133  // correctBoundaryConditions on actual n field.
134  wDist.map(n, mapDistribute::transform());
135  }
136 
137  return true;
138 }
139 
140 
141 // ************************************************************************* //
Foam::surfaceFields.
const labelList patchIDs(pbm.indices(polyPatchNames, true))
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
addToRunTimeSelectionTable(patchDistMethod, advectionDiffusion, dictionary)
static const wallDistAddressing & New(const fvMesh &mesh, Args &&... args)
Get existing or create a new MeshObject. Registered with typeName.
Definition: MeshObject.C:53
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests)
static void waitRequests()
Wait for all requests to finish.
Definition: UPstream.H:1538
Macros for easy insertion into run-time selection tables.
virtual bool correct(volScalarField &y)
Correct the given distance-to-patch field.
scalar y
dynamicFvMesh & mesh
static const GeometricField< vector, fvPatchField, volMesh > & null()
Return a null geometric field.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
meshWaveAddressing(const meshWaveAddressing &)=delete
No copy construct.
defineTypeNameAndDebug(advectionDiffusion, 0)
"nonBlocking" : (MPI_Isend, MPI_Irecv)
label n
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
Specialisation of patchDist for wall distance calculation.
bool notNull(const T *ptr)
True if ptr is not a pointer (of type T) to the nullObject.
Definition: nullObject.H:246
Namespace for OpenFOAM.