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 
37 {
38  return sampleWorld_;
39 }
40 
41 
43 {
44  if (sampleRegion_.empty())
45  {
46  if (!coupleGroup_.good())
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_.good())
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 
136 {
137  return offset_;
138 }
139 
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 
169 inline bool Foam::mappedPatchBase::sameWorld() const
170 {
171  return
172  (
173  UPstream::allWorlds().size() == 1
174  || sampleWorld_.empty()
175  || UPstream::myWorld() == sampleWorld_
176  );
177 }
178 
179 
180 inline bool Foam::mappedPatchBase::masterWorld() const
181 {
182  if (sameWorld())
183  {
184  return true;
185  }
187  // Use ordering in allWorlds
188  const label otherWorldId = UPstream::allWorlds().find(sampleWorld_);
189  return (otherWorldId < 0 || (UPstream::myWorldID() < otherWorldId));
190 }
191 
192 
194 {
195  return sameRegion_;
196 }
197 
198 
201 {
202  if (!updateSampleMeshTimePtr_)
203  {
204  const auto& mesh = sampleMesh();
205 
206  updateSampleMeshTimePtr_.reset
207  (
209  (
210  IOobject
211  (
212  "updateSampleMeshTime",
214  mesh.thisDb(),
218  )
219  )
220  );
221  }
222 
223  return updateSampleMeshTimePtr_();
224 }
225 
226 
229 {
230  if (!updateMeshTimePtr_)
231  {
232  const auto& mesh = patch_.boundaryMesh().mesh();
233 
234  updateMeshTimePtr_.reset
235  (
237  (
238  IOobject
239  (
240  "updateMeshTime",
242  mesh.thisDb(),
246  )
247  )
248  );
249  }
250 
251  return updateMeshTimePtr_();
252 }
253 
254 
255 inline bool Foam::mappedPatchBase::upToDate() const
256 {
257  const polyMesh& thisMesh = patch_.boundaryMesh().mesh();
258 
259  if (sameWorld())
260  {
261  return
262  sampleMesh().upToDatePoints(updateSampleMeshTime())
263  && thisMesh.upToDatePoints(updateMeshTime());
264  }
265  else
266  {
267  // If not the same world we do not know what the other side is doing
268  // so only check our local side
269  return thisMesh.upToDatePoints(updateMeshTime());
270  }
271 }
272 
273 
275 {
276  if (!upToDate())
277  {
278  mapPtr_.reset(nullptr);
279 
280  if (AMIPtr_)
281  {
282  AMIPtr_->upToDate(false);
283  }
284  }
285 
286  if (!mapPtr_)
287  {
288  calcMapping();
289  }
290 
291  return *mapPtr_;
292 }
293 
294 
296 (
297  bool forceUpdate
298 ) const
299 {
300  if (!upToDate())
301  {
302  mapPtr_.reset(nullptr);
303  AMIPtr_->upToDate(false);
304  }
305 
306  if (forceUpdate)
307  {
308  AMIPtr_->upToDate(false);
309  }
311  calcAMI();
312 
313  return *AMIPtr_;
314 }
315 
316 
317 inline bool Foam::mappedPatchBase::owner() const
318 {
319  return (patch_.boundaryMesh().mesh().name() < sampleRegion());
320 }
321 
322 
323 // ************************************************************************* //
static const word & myWorld()
My world.
Definition: UPstream.H:1165
const vector & offset() const noexcept
Offset vector (from patch faces to destination mesh objects)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
uniformDimensionedScalarField & updateMeshTime() const
Sample mesh upate time.
Ignore writing from objectRegistry::writeObject()
uniformDimensionedScalarField & updateSampleMeshTime() const
Local mesh update time.
const mapDistribute & map() const
Return reference to the parallel distribution map.
UniformDimensionedField< scalar > uniformDimensionedScalarField
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:376
bool sameWorld() const
Is sample world the local world?
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: polyMesh.C:853
dynamicFvMesh & mesh
const polyMesh & mesh() const noexcept
Return the mesh reference.
bool masterWorld() const
Is my world ordered before the sampleWorld?
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:608
A class for handling words, derived from Foam::string.
Definition: word.H:63
const AMIPatchToPatchInterpolation & AMI(const bool forceUpdate=false) const
Return reference to the AMI interpolator.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
label find(const T &val) const
Find index of the first occurrence of the value.
Definition: UList.C:173
void reset(const label nPoints, const label nInternalFaces, const label nFaces, const label nCells)
Reset this primitiveMesh given the primitive array sizes.
const direction noexcept
Definition: Scalar.H:258
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
label sampleSize() const
Return size of mapped mesh/patch/boundary.
label comm() const
Identical to getCommunicator()
label getCommunicator() const
Get the communicator (worldComm or world-to-world)
sampleMode mode() const noexcept
What to sample.
bool owner() const
Is it owner.
Class containing processor-to-processor mapping information.
bool sameRegion() const noexcept
Cached sampleRegion != mesh.name()
const word & coupleGroup() const
PatchGroup (only if NEARESTPATCHFACE)
sampleMode
Mesh items to sample.
Nothing to be read.
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
const word & sampleWorld() const noexcept
World to sample.
const word & samplePatch() const
Patch (only if NEARESTPATCHFACE)
static const wordList & allWorlds() noexcept
All worlds.
Definition: UPstream.H:1141
const word & sampleRegion() const
Region to sample.
label nBoundaryFaces() const noexcept
Number of boundary faces (== nFaces - nInternalFaces)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Do not request registration (bool: false)
void reset(autoPtr< mapDistribute > &&srcToTgtMap, autoPtr< mapDistribute > &&tgtToSrcMap, labelListList &&srcAddress, scalarListList &&srcWeights, labelListList &&tgtAddress, scalarListList &&tgtWeights, const label singlePatchProc)
Set the maps, addresses and weights from an external source.
const vectorField & offsets() const noexcept
Offset vectors (from patch faces to destination mesh objects)
static label myWorldID()
My worldID.
Definition: UPstream.H:1157
const sampleMode mode_
What to sample.