mappedPatchBaseI.H
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) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2020-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 
31 {
32  return mode_;
33 }
34 
35 
36 inline const Foam::word& Foam::mappedPatchBase::sampleWorld() const noexcept
37 {
38  return sampleWorld_;
39 }
40 
41 
43 {
44  if (sampleRegion_.empty())
45  {
46  if (!coupleGroup_.valid())
47  {
49  << "Supply either a regionName or a coupleGroup"
50  << " for patch " << patch_.name()
51  << " in region " << patch_.boundaryMesh().mesh().name()
52  << exit(FatalError);
53  }
54 
55  // Try and use patchGroup to find samplePatch and sampleRegion
56  label samplePatchID = coupleGroup_.findOtherPatchID
57  (
58  patch_,
59  sampleRegion_
60  );
61 
62  samplePatch_ = sampleMesh().boundaryMesh()[samplePatchID].name();
63  }
64  return sampleRegion_;
65 }
66 
67 
69 {
70  if (samplePatch_.empty())
71  {
72  if (!coupleGroup_.valid())
73  {
75  << "Supply either a patchName or a coupleGroup"
76  << " for patch " << patch_.name()
77  << " in region " << patch_.boundaryMesh().mesh().name() << nl
78  << exit(FatalError);
79  }
80 
81  // Try and use patchGroup to find samplePatch and sampleRegion
82  label samplePatchID = coupleGroup_.findOtherPatchID
83  (
84  patch_,
85  sampleRegion_
86  );
87 
88  samplePatch_ = sampleMesh().boundaryMesh()[samplePatchID].name();
89  }
90  return samplePatch_;
91 }
92 
93 
95 {
96  return coupleGroup_.name();
97 }
98 
99 
100 inline Foam::label Foam::mappedPatchBase::sampleSize() const
101 {
102  switch (mode_)
103  {
104  case NEARESTPATCHFACEAMI:
105  {
106  return samplePolyPatch().size();
107  }
108  case NEARESTCELL:
109  {
110  return sampleMesh().nCells();
111  }
112  case NEARESTPATCHFACE:
113  {
114  return samplePolyPatch().size();
115  }
116  case NEARESTPATCHPOINT:
117  {
118  return samplePolyPatch().nPoints();
119  }
120  case NEARESTFACE:
121  {
122  const polyMesh& mesh = sampleMesh();
123  return mesh.nBoundaryFaces();
124  }
125  default:
126  {
128  << "problem." << abort(FatalError);
129  return -1;
130  }
131  }
132 }
133 
134 
135 inline const Foam::vector& Foam::mappedPatchBase::offset() const noexcept
136 {
137  return offset_;
138 }
139 
140 
141 inline const Foam::vectorField& Foam::mappedPatchBase::offsets() const noexcept
142 {
143  return offsets_;
144 }
145 
146 
147 inline Foam::label Foam::mappedPatchBase::getCommunicator() const
148 {
149  // Cached communicator, or a get a new one
150  if (communicator_ == -1)
151  {
152  const_cast<label&>(communicator_) = getWorldCommunicator();
153  }
154  return communicator_;
155 }
156 
157 
158 inline Foam::label Foam::mappedPatchBase::comm() const
159 {
160  // Cached communicator, or a get a new one
161  if (communicator_ == -1)
162  {
163  const_cast<label&>(communicator_) = getWorldCommunicator();
164  }
165  return communicator_;
166 }
167 
168 
170 {
171  return
172  (
173  UPstream::allWorlds().size() == 1
174  || sampleWorld_.empty()
175  || UPstream::myWorld() == sampleWorld_
176  );
177 }
178 
179 
181 {
182  if (sameWorld())
183  {
184  return true;
185  }
186 
187  // Use ordering in allWorlds
188  const label otherWorldId = UPstream::allWorlds().find(sampleWorld_);
189  return (otherWorldId < 0 || (UPstream::myWorldID() < otherWorldId));
190 }
191 
192 
193 inline bool Foam::mappedPatchBase::sameRegion() const noexcept
194 {
195  return sameRegion_;
196 }
197 
198 
200 {
201  const polyMesh& thisMesh = patch_.boundaryMesh().mesh();
202  bool topoChange =
203  (sameWorld() && sampleMesh().topoChanging())
204  || thisMesh.topoChanging();
205 
206  if (topoChange)
207  {
208  mapPtr_.reset(nullptr);
209  }
210 
211  if (!mapPtr_)
212  {
213  calcMapping();
214  }
215 
216  return *mapPtr_;
217 }
218 
219 
221 (
222  bool forceUpdate
223 ) const
224 {
225  const polyMesh& thisMesh = patch_.boundaryMesh().mesh();
226  bool topoChange =
227  (sameWorld() && sampleMesh().topoChanging())
228  || thisMesh.topoChanging();
229 
230  if (topoChange || forceUpdate)
231  {
232  AMIPtr_->upToDate() = false;
233  }
234 
235  calcAMI();
236 
237  return *AMIPtr_;
238 }
239 
240 
241 inline bool Foam::mappedPatchBase::owner() const
242 {
243  return (patch_.boundaryMesh().mesh().name() < sampleRegion());
244 }
245 
246 
247 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::mappedPatchBase::offsets
const vectorField & offsets() const noexcept
Offset vectors (from patch faces to destination mesh objects)
Definition: mappedPatchBaseI.H:141
Foam::mappedPatchBase::map
const mapDistribute & map() const
Return reference to the parallel distribution map.
Definition: mappedPatchBaseI.H:199
Foam::mappedPatchBase::mode_
const sampleMode mode_
What to sample.
Definition: mappedPatchBase.H:235
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::mappedPatchBase::sameWorld
bool sameWorld() const
Is sample world the local world?
Definition: mappedPatchBaseI.H:169
Foam::polyMesh::topoChanging
bool topoChanging() const noexcept
Is mesh topology changing.
Definition: polyMesh.H:536
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::UPstream::allWorlds
static const wordList & allWorlds() noexcept
All worlds.
Definition: UPstream.H:483
Foam::mappedPatchBase::sampleSize
label sampleSize() const
Return size of mapped mesh/patch/boundary.
Definition: mappedPatchBaseI.H:100
Foam::polyBoundaryMesh::mesh
const polyMesh & mesh() const noexcept
Return the mesh reference.
Definition: polyBoundaryMesh.H:152
Foam::UPstream::myWorldID
static label myWorldID()
My worldID.
Definition: UPstream.H:495
Foam::Field< vector >
Foam::mappedPatchBase::getCommunicator
label getCommunicator() const
Get the communicator (worldComm or world-to-world)
Definition: mappedPatchBaseI.H:147
Foam::mappedPatchBase::comm
label comm() const
Identical to getCommunicator()
Definition: mappedPatchBaseI.H:158
Foam::mapDistribute
Class containing processor-to-processor mapping information.
Definition: mapDistribute.H:163
Foam::mappedPatchBase::mode
sampleMode mode() const noexcept
What to sample.
Definition: mappedPatchBaseI.H:30
Foam::primitiveMesh::nBoundaryFaces
label nBoundaryFaces() const noexcept
Number of boundary faces (== nFaces - nInternalFaces)
Definition: primitiveMeshI.H:84
Foam::mappedPatchBase::sameRegion
bool sameRegion() const noexcept
Cached sampleRegion != mesh.name()
Definition: mappedPatchBaseI.H:193
Foam::UPstream::myWorld
static const word & myWorld()
My world.
Definition: UPstream.H:501
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::mappedPatchBase::masterWorld
bool masterWorld() const
Is my world ordered before the sampleWorld?
Definition: mappedPatchBaseI.H:180
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::mappedPatchBase::coupleGroup
const word & coupleGroup() const
PatchGroup (only if NEARESTPATCHFACE)
Definition: mappedPatchBaseI.H:94
Foam::mappedPatchBase::sampleRegion
const word & sampleRegion() const
Region to sample.
Definition: mappedPatchBaseI.H:42
Foam::mappedPatchBase::sampleWorld
const word & sampleWorld() const noexcept
World to sample.
Definition: mappedPatchBaseI.H:36
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Vector< scalar >
Foam::AMIInterpolation
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
Definition: AMIInterpolation.H:79
Foam::mappedPatchBase::AMI
const AMIPatchToPatchInterpolation & AMI(const bool forceUpdate=false) const
Return reference to the AMI interpolator.
Definition: mappedPatchBaseI.H:221
Foam::mappedPatchBase::owner
bool owner() const
Is it owner.
Definition: mappedPatchBaseI.H:241
Foam::mappedPatchBase::sampleMode
sampleMode
Mesh items to sample.
Definition: mappedPatchBase.H:119
Foam::mappedPatchBase::offset
const vector & offset() const noexcept
Offset vector (from patch faces to destination mesh objects)
Definition: mappedPatchBaseI.H:135
Foam::mappedPatchBase::samplePatch
const word & samplePatch() const
Patch (only if NEARESTPATCHFACE)
Definition: mappedPatchBaseI.H:68