parPointFieldDistributor.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) 2022-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 "processorPointPatch.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
34 
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
39 (
40  const pointMesh& srcMesh,
41  const bool savePoints,
42  const bool isWriteProc
43 )
44 :
45  srcMesh_(srcMesh),
46  nOldPoints_(srcMesh.size()),
47  patchMeshPoints_(),
48  tgtMeshRef_(nullptr),
49  distMapRef_(nullptr),
50  patchPointMaps_(),
51  dummyHandler_(fileOperation::null()),
52  writeHandler_(dummyHandler_),
53  isWriteProc_(isWriteProc)
54 {
55  if (savePoints)
56  {
57  saveMeshPoints();
58  }
59 }
60 
61 
63 (
64  const pointMesh& srcMesh,
65  const bool savePoints,
66  refPtr<fileOperation>& writeHandler
67 )
68 :
69  srcMesh_(srcMesh),
70  nOldPoints_(srcMesh.size()),
71  patchMeshPoints_(),
72  tgtMeshRef_(nullptr),
73  distMapRef_(nullptr),
74  patchPointMaps_(),
75  dummyHandler_(nullptr),
76  writeHandler_(writeHandler),
77  isWriteProc_(Switch::INVALID)
78 {
79  if (savePoints)
80  {
81  saveMeshPoints();
82  }
83 }
84 
85 
87 (
88  const pointMesh& srcMesh,
89  const pointMesh& tgtMesh,
90  const mapDistributePolyMesh& distMap,
91  const bool savePoints,
92  const bool isWriteProc
93 )
94 :
95  srcMesh_(srcMesh),
96  nOldPoints_(srcMesh.size()),
97  patchMeshPoints_(),
98  tgtMeshRef_(tgtMesh),
99  distMapRef_(distMap),
100  patchPointMaps_(),
101  dummyHandler_(fileOperation::null()),
102  writeHandler_(dummyHandler_),
103  isWriteProc_(isWriteProc)
104 {
105  if (savePoints)
106  {
107  saveMeshPoints();
108  }
109 }
110 
111 
113 (
114  const pointMesh& srcMesh,
115  const pointMesh& tgtMesh,
116  const mapDistributePolyMesh& distMap,
117  const bool savePoints,
118  refPtr<fileOperation>& writeHandler
119 )
120 :
121  srcMesh_(srcMesh),
122  nOldPoints_(srcMesh.size()),
123  patchMeshPoints_(),
124  tgtMeshRef_(tgtMesh),
125  distMapRef_(distMap),
126  patchPointMaps_(),
127  dummyHandler_(nullptr),
128  writeHandler_(writeHandler),
129  isWriteProc_(Switch::INVALID)
130 {
131  if (savePoints)
132  {
133  saveMeshPoints();
134  }
135 }
136 
137 
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 
141 {
142  return !patchMeshPoints_.empty();
143 }
144 
145 
147 {
148  return !patchPointMaps_.empty();
149 }
150 
151 
153 {
154  return (tgtMeshRef_ && distMapRef_);
155 }
156 
157 
159 {
160  patchMeshPoints_.clear();
161 }
162 
164 {
165  patchPointMaps_.clear();
166 }
167 
168 
170 {
171  const pointBoundaryMesh& patches = srcMesh_.boundary();
172 
173  patchMeshPoints_.clear();
174  patchMeshPoints_.resize(patches.size());
175 
176  forAll(patches, patchi)
177  {
178  if (!isA<processorPointPatch>(patches[patchi]))
179  {
180  // Copy meshPoints
181  patchMeshPoints_.set
182  (
183  patchi,
184  new labelList(patches[patchi].meshPoints())
185  );
186  }
187  }
188 }
189 
190 
192 {
193  if (!tgtMeshRef_ || !distMapRef_)
194  {
196  << "Cannot create maps without target mesh and/or distribution!"
197  << abort(FatalError);
198  }
199 
200  const auto& tgtMesh = tgtMeshRef_();
201  const auto& distMap = distMapRef_();
202 
203  const auto& newPatches = tgtMesh.boundary();
204  const auto& oldPatches = srcMesh_.boundary();
205 
206  patchPointMaps_.clear();
207  patchPointMaps_.resize(oldPatches.size());
208 
209  // if (patchPointMaps_.size() != patchMeshPoints_.size())
210  // {
211  // // Warn?
212  // }
213 
214  forAll(oldPatches, patchi)
215  {
216  if (!isA<processorPointPatch>(oldPatches[patchi]))
217  {
218  // Create map for patch points only
219  labelList oldToNewSub;
220  labelList oldToNewConstruct;
221 
222  // Copy point map
223  patchPointMaps_.set
224  (
225  patchi,
226  new mapDistributeBase(distMap.pointMap())
227  );
228 
229  const labelList& oldMeshPoints =
230  (
231  patchMeshPoints_.test(patchi)
232  ? patchMeshPoints_[patchi]
233  : oldPatches[patchi].meshPoints() // <- Questionable!
234  );
235 
236  patchPointMaps_[patchi].compactData
237  (
238  oldMeshPoints,
239  newPatches[patchi].meshPoints(),
240  oldToNewSub,
241  oldToNewConstruct,
242  nOldPoints_,
244  );
245  }
246  }
247 }
248 
249 
251 {
252  tgtMeshRef_.reset(nullptr);
253  distMapRef_.reset(nullptr);
254 
255  // Old maps are now invalid
256  clearPatchPointMaps();
257 }
258 
259 
261 (
262  const pointMesh& tgtMesh,
263  const mapDistributePolyMesh& distMap
264 )
265 {
266  tgtMeshRef_.cref(tgtMesh);
267  distMapRef_.cref(distMap);
268 
269  // Old maps are now invalid
270  clearPatchPointMaps();
271 }
272 
273 
275 (
276  const IOobjectList& objects,
277  const wordRes& selected
278 ) const
279 {
280  label nTotal = 0;
281 
282  nTotal += distributePointFields<scalar>(objects, selected);
283  nTotal += distributePointFields<vector>(objects, selected);
284  nTotal += distributePointFields<symmTensor>(objects, selected);
285  nTotal += distributePointFields<sphericalTensor>(objects, selected);
286  nTotal += distributePointFields<tensor>(objects, selected);
287 
288  return nTotal;
289 }
290 
291 
292 // ************************************************************************* //
void clearMeshPoints()
Clear out meshPoints (per boundary) for the source mesh.
void clearPatchPointMaps()
Clear out patch maps (per boundary)
void saveMeshPoints()
Create/recreate meshPoints (per boundary) for the source mesh.
void createPatchPointMaps()
Construct per-patch addressing.
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
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
Definition: List.H:489
label distributeAllFields(const IOobjectList &objects, const wordRes &selectedFields=wordRes()) const
Read, distribute and write all/selected point field types (scalar, vector, ... types) ...
void resetTarget()
Clear target mesh / distribution map.
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1229
bool hasPatchPointMaps() const
True if patch maps (per boundary) exist.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Invalid/unknown/error type.
static int verbose_
Output verbosity when writing.
bool hasMeshPoints() const
True if meshPoints (per boundary) for the source mesh have been saved.
bool hasTarget() const
True if a target mesh/distribution map has been attached.
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void clear()
Clear the patch list and all demand-driven data.
const polyBoundaryMesh & patches
List< label > labelList
A List of labels.
Definition: List.H:62
parPointFieldDistributor(const parPointFieldDistributor &)=delete
No copy construct.