parFvFieldDistributor.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 OpenFOAM Foundation
9  Copyright (C) 2022-2023 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 
29 #include "parFvFieldDistributor.H"
30 #include "bitSet.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
35 
36 
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 
39 void Foam::parFvFieldDistributor::createPatchFaceMaps()
40 {
41  const fvBoundaryMesh& fvb = srcMesh_.boundary();
42 
43  patchFaceMaps_.resize(fvb.size());
44 
45  forAll(fvb, patchi)
46  {
47  if (!isA<processorFvPatch>(fvb[patchi]))
48  {
49  // Create compact map for patch faces only
50  // - compact for used faces only (destination patch faces)
51  labelList oldToNewSub;
52  labelList oldToNewConstruct;
53 
54  // Copy face map
55  patchFaceMaps_.set
56  (
57  patchi,
58  new mapDistributeBase(distMap_.faceMap())
59  );
60 
61  patchFaceMaps_[patchi].compactRemoteData
62  (
63  bitSet(tgtMesh_.boundaryMesh()[patchi].range()),
64  oldToNewSub,
65  oldToNewConstruct,
66  srcMesh_.nFaces(), // max index of subMap
68  );
69  //Pout<< "patchMap:" << patchFaceMaps_[patchi] << endl;
70  }
71  }
72 }
73 
74 
75 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
76 
78 (
79  const fvMesh& srcMesh,
80  fvMesh& tgtMesh,
81  const mapDistributePolyMesh& distMap,
82  const bool isWriteProc
83 )
84 :
85  srcMesh_(srcMesh),
86  tgtMesh_(tgtMesh),
87  distMap_(distMap),
88  dummyHandler_(fileOperation::null()),
89  writeHandler_(dummyHandler_),
90  isWriteProc_(isWriteProc)
91 {
92  createPatchFaceMaps();
93 }
94 
95 
97 (
98  const fvMesh& srcMesh,
99  fvMesh& tgtMesh,
100  const mapDistributePolyMesh& distMap,
101  refPtr<fileOperation>& writeHandler
102 )
103 :
104  srcMesh_(srcMesh),
105  tgtMesh_(tgtMesh),
106  distMap_(distMap),
107  dummyHandler_(nullptr),
108  writeHandler_(writeHandler),
109  isWriteProc_(Switch::INVALID)
110 {
111  createPatchFaceMaps();
112 }
113 
114 
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 
118 {
119  // Reconstruct the points for moving mesh cases and write them out
121  (
123  distMap_.pointMap()
124  );
125 
126  pointField newPoints(srcMesh_.points(), mapper);
127  tgtMesh_.movePoints(newPoints);
128 
129  if (isWriteProc_.good())
130  {
131  if (UPstream::master())
132  {
133  tgtMesh_.write();
134  }
135  }
136  else if (writeHandler_ && writeHandler_->good())
137  {
138  auto oldHandler = fileOperation::fileHandler(writeHandler_);
139  const label oldComm = UPstream::commWorld(fileHandler().comm());
140 
141  tgtMesh_.write();
142 
143  writeHandler_ = fileOperation::fileHandler(oldHandler);
144  UPstream::commWorld(oldComm);
145  }
146 }
147 
148 
149 // ************************************************************************* //
bool good() const noexcept
True if the Switch represents a valid enumeration.
Definition: Switch.C:296
static int verbose_
Output verbosity when writing.
virtual void movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: fvMesh.C:885
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1184
labelRange range() const noexcept
The face range for all boundary faces.
label nFaces() const noexcept
Number of mesh faces.
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1073
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:414
Invalid/unknown/error type.
const mapDistribute & pointMap() const noexcept
Point distribute map.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:584
virtual bool write(const bool writeOnProc=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1069
DistributedFieldMapper< directFieldMapper > distributedFieldMapper
A directFieldMapper with distributed (with local or remote) quantities.
static const UList< label > & null()
Return a UList reference to a nullObject.
Definition: UListI.H:45
static label commWorld() noexcept
Communicator for all ranks (respecting any local worlds)
Definition: UPstream.H:431
void reconstructPoints()
Helper: reconstruct and write mesh points.
parFvFieldDistributor(const parFvFieldDistributor &)=delete
No copy construct.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1037
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition: fvMesh.H:397
static const fileOperation & fileHandler()
Return the current file handler. Will create the default file handler if necessary.
List< label > labelList
A List of labels.
Definition: List.H:62
const mapDistribute & faceMap() const noexcept
Face distribute map.