faMeshDistributor.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 
28 #include "faMeshDistributor.H"
29 #include "BitOps.H"
30 #include "fileOperation.H"
31 #include "areaFields.H"
32 #include "edgeFields.H"
33 #include "faMeshTools.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 void Foam::faMeshDistributor::createPatchMaps() const
43 {
44  const faBoundaryMesh& oldPatches = srcMesh_.boundary();
45  const faBoundaryMesh& newPatches = tgtMesh_.boundary();
46 
47  patchEdgeMaps_.clear();
48  patchEdgeMaps_.resize(oldPatches.size());
49 
50  // area: edgeMap (volume: faceMap)
51  const auto& faEdgeMap = distMap_.faceMap();
52 
53  // The logical edge ranges per patch [target mesh]
54  List<labelRange> ranges = newPatches.patchRanges();
55 
56  forAll(oldPatches, patchi)
57  {
58  if (!isA<processorFaPatch>(oldPatches[patchi]))
59  {
60  // Map non-processor only
61 
62  // Copy full map
63  patchEdgeMaps_.set
64  (
65  patchi,
66  new mapDistributeBase(faEdgeMap)
67  );
68 
69  // Retain patch elements
70  patchEdgeMaps_[patchi].compactRemoteData
71  (
72  bitSet(ranges[patchi]),
74  true // Also renumber/resize the compact maps
75  );
76  }
77  }
78 }
79 
80 
81 void Foam::faMeshDistributor::createInternalEdgeMap() const
82 {
83  // area: edgeMap (volume: faceMap)
84  const auto& faEdgeMap = distMap_.faceMap();
85 
86  // Copy full map
87  internalEdgeMap_.reset(new mapDistributeBase(faEdgeMap));
88 
89  // Retain internal edges
90  internalEdgeMap_->compactRemoteData
91  (
92  bitSet(tgtMesh_.nInternalEdges(), true),
94  true // Also renumber/resize the compact maps
95  );
96 }
97 
98 
99 void Foam::faMeshDistributor::checkAddressing() const
100 {
101  #ifdef FULLDEBUG
102  {
103  Pout<< "Create from nFaces:" << srcMesh_.faceLabels().size()
104  << " to:" << tgtMesh_.faceLabels().size() << endl;
105 
106  // Check face centres
107  {
108  vectorField oldFaceCentres(srcMesh_.areaCentres());
109  vectorField newFaceCentres(tgtMesh_.areaCentres());
110 
111  // volume: cells, area: faces
112  distMap_.distributeCellData(oldFaceCentres);
113 
114  vectorField diff(newFaceCentres - oldFaceCentres);
115 
116  if (!diff.empty() && !diff.uniform())
117  {
118  forAll(oldFaceCentres, facei)
119  {
120  if (oldFaceCentres[facei] != newFaceCentres[facei])
121  {
122  Pout<< "face: " << facei
123  << ' ' << oldFaceCentres[facei]
124  << " vs " << newFaceCentres[facei]
125  << endl;
126  }
127  }
128  }
129  }
130 
131  // Check edge centres
132  {
133  vectorField oldEdgeCentres
134  (
135  faMeshTools::flattenEdgeField(srcMesh_.edgeCentres())
136  );
137  vectorField newEdgeCentres
138  (
139  faMeshTools::flattenEdgeField(tgtMesh_.edgeCentres())
140  );
141 
142  Pout<< "distributed edges: " << oldEdgeCentres.size() << " from "
143  << srcMesh_.nEdges() << " to " << tgtMesh_.nEdges() << endl;
144 
145  // volume: faces, area: edges
146  distMap_.distributeFaceData(oldEdgeCentres);
147 
148  vectorField diff(newEdgeCentres - oldEdgeCentres);
149 
150  if (!diff.empty() && !diff.uniform())
151  {
152  forAll(oldEdgeCentres, edgei)
153  {
154  if (oldEdgeCentres[edgei] != newEdgeCentres[edgei])
155  {
156  Pout<< "edge: " << edgei
157  << ' ' << oldEdgeCentres[edgei]
158  << " vs " << newEdgeCentres[edgei]
159  << endl;
160  }
161  }
162  }
163 
164  Info<< "Patch edge maps" << endl;
165  forAll(patchEdgeMaps_, patchi)
166  {
167  if (patchEdgeMaps_.set(patchi))
168  {
169  Pout<< "patch " << patchi << " : "
170  << patchEdgeMaps_[patchi].info() << endl;
171  }
172  }
173 
174  Info<< nl << "Detailed patch maps" << endl;
175 
176  forAll(patchEdgeMaps_, patchi)
177  {
178  if (patchEdgeMaps_.set(patchi))
179  {
180  Info<< "patch " << patchi << " : "
181  << patchEdgeMaps_[patchi] << endl;
182  }
183  }
184  }
185  }
186  #endif
187 }
188 
189 
190 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
191 
193 (
194  const faMesh& srcMesh,
195  const faMesh& tgtMesh,
196  const mapDistributePolyMesh& distMap,
197  const bool isWriteProc
198 )
199 :
200  srcMesh_(srcMesh),
201  tgtMesh_(tgtMesh),
202  distMap_(distMap),
203  internalEdgeMap_(),
204  patchEdgeMaps_(),
205  dummyHandler_(fileOperation::null()),
206  writeHandler_(dummyHandler_),
207  isWriteProc_(isWriteProc)
208 {
209  checkAddressing();
210 }
211 
212 
214 (
215  const faMesh& srcMesh,
216  const faMesh& tgtMesh,
217  const mapDistributePolyMesh& distMap,
218  refPtr<fileOperation>& writeHandler
219 )
220 :
221  srcMesh_(srcMesh),
222  tgtMesh_(tgtMesh),
223  distMap_(distMap),
224  internalEdgeMap_(),
225  patchEdgeMaps_(),
226  dummyHandler_(nullptr),
227  writeHandler_(writeHandler),
228  isWriteProc_(Switch::INVALID)
229 {
230  checkAddressing();
231 }
232 
233 
234 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
235 
237 (
238  const IOobjectList& objects,
239  const wordRes& selected
240 ) const
241 {
242  label nTotal = 0;
243 
244  nTotal += distributeAreaFields<scalar>(objects, selected);
245  nTotal += distributeAreaFields<vector>(objects, selected);
246  nTotal += distributeAreaFields<symmTensor>(objects, selected);
247  nTotal += distributeAreaFields<sphericalTensor>(objects, selected);
248  nTotal += distributeAreaFields<tensor>(objects, selected);
249 
250  nTotal += distributeEdgeFields<scalar>(objects, selected);
251  nTotal += distributeEdgeFields<vector>(objects, selected);
252  nTotal += distributeEdgeFields<symmTensor>(objects, selected);
253  nTotal += distributeEdgeFields<sphericalTensor>(objects, selected);
254  nTotal += distributeEdgeFields<tensor>(objects, selected);
255 
256  return nTotal;
257 }
258 
259 
260 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:87
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition: triad.C:373
faMeshDistributor(const faMeshDistributor &)=delete
No copy construct.
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, any/none. Also accepts 0/1 as a string and shortcuts t/f, y/n.
Definition: Switch.H:77
InfoProxy< IOstream > info() const noexcept
Return info proxy, used to print IOstream information to a stream.
Definition: IOstream.H:517
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1229
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
An encapsulation of filesystem-related operations.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
static int verbose_
Output verbosity when writing.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
label distributeAllFields(const IOobjectList &objects, const wordRes &selectedFields=wordRes()) const
Read, distribute and write all/selected point field types (scalar, vector, ... types) ...
const faBoundaryMesh & boundary() const noexcept
Return constant reference to boundary mesh.
Definition: faMeshI.H:31
messageStream Info
Information stream (stdout output on master, null elsewhere)
Field< vector > vectorField
Specialisation of Field<T> for vector.
static tmp< Field< Type > > flattenEdgeField(const GeometricField< Type, faePatchField, edgeMesh > &fld, const bool primitiveOrdering=false)
Flatten an edge field into linear addressing.
const mapDistribute & faceMap() const noexcept
Face distribute map.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.