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 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
42void 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
81void 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// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100
102(
103 const faMesh& srcMesh,
104 const faMesh& tgtMesh,
105 const mapDistributePolyMesh& distMap,
106 const bool isWriteProc
107)
108:
109 srcMesh_(srcMesh),
110 tgtMesh_(tgtMesh),
111 distMap_(distMap),
112 internalEdgeMap_(),
113 patchEdgeMaps_(),
114 isWriteProc_(isWriteProc)
115{
116 #ifdef FULLDEBUG
117 {
118 Pout<< "Create from nFaces:" << srcMesh.faceLabels().size()
119 << " to:" << tgtMesh.faceLabels().size() << endl;
120
121 // Check face centres
122 {
123 vectorField oldFaceCentres(srcMesh_.areaCentres());
124 vectorField newFaceCentres(tgtMesh_.areaCentres());
125
126 // volume: cells, area: faces
127 distMap_.distributeCellData(oldFaceCentres);
128
129 vectorField diff(newFaceCentres - oldFaceCentres);
130
131 if (!diff.empty() && !diff.uniform())
132 {
133 forAll(oldFaceCentres, facei)
134 {
135 if (oldFaceCentres[facei] != newFaceCentres[facei])
136 {
137 Pout<< "face: " << facei
138 << ' ' << oldFaceCentres[facei]
139 << " vs " << newFaceCentres[facei]
140 << endl;
141 }
142 }
143 }
144 }
145
146 // Check edge centres
147 {
148 vectorField oldEdgeCentres
149 (
151 );
152 vectorField newEdgeCentres
153 (
155 );
156
157 Pout<< "distributed edges: " << oldEdgeCentres.size() << " from "
158 << srcMesh.nEdges() << " to " << tgtMesh.nEdges() << endl;
159
160 // volume: faces, area: edges
161 distMap_.distributeFaceData(oldEdgeCentres);
162
163 vectorField diff(newEdgeCentres - oldEdgeCentres);
164
165 if (!diff.empty() && !diff.uniform())
166 {
167 forAll(oldEdgeCentres, edgei)
168 {
169 if (oldEdgeCentres[edgei] != newEdgeCentres[edgei])
170 {
171 Pout<< "edge: " << edgei
172 << ' ' << oldEdgeCentres[edgei]
173 << " vs " << newEdgeCentres[edgei]
174 << endl;
175 }
176 }
177 }
178
179 Info<< "Patch edge maps" << endl;
180 forAll(patchEdgeMaps_, patchi)
181 {
182 if (patchEdgeMaps_.set(patchi))
183 {
184 Pout<< "patch " << patchi << " : "
185 << patchEdgeMaps_[patchi].info() << endl;
186 }
187 }
188
189 Info<< nl << "Detailed patch maps" << endl;
190
191 forAll(patchEdgeMaps_, patchi)
192 {
193 if (patchEdgeMaps_.set(patchi))
194 {
195 Info<< "patch " << patchi << " : "
196 << patchEdgeMaps_[patchi] << endl;
197 }
198 }
199 }
200 }
201 #endif
202}
203
204
205// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
206
208(
209 const IOobjectList& objects,
210 const wordRes& selected
211) const
212{
213 label nTotal = 0;
214
215 nTotal += distributeAreaFields<scalar>(objects, selected);
216 nTotal += distributeAreaFields<vector>(objects, selected);
217 nTotal += distributeAreaFields<symmTensor>(objects, selected);
218 nTotal += distributeAreaFields<sphericalTensor>(objects, selected);
219 nTotal += distributeAreaFields<tensor>(objects, selected);
220
221 nTotal += distributeEdgeFields<scalar>(objects, selected);
222 nTotal += distributeEdgeFields<vector>(objects, selected);
223 nTotal += distributeEdgeFields<symmTensor>(objects, selected);
224 nTotal += distributeEdgeFields<sphericalTensor>(objects, selected);
225 nTotal += distributeEdgeFields<tensor>(objects, selected);
226
227 return nTotal;
228}
229
230
231// ************************************************************************* //
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:556
Holds a reference to the original mesh (the baseMesh) and optionally to a subset of that mesh (the su...
static int verbose_
Output verbosity when writing.
label distributeAllFields(const IOobjectList &objects, const wordRes &selectedFields=wordRes()) const
static tmp< Field< Type > > flattenEdgeField(const GeometricField< Type, faePatchField, edgeMesh > &fld, const bool primitiveOrdering=false)
Flatten an edge field into linear addressing.
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:100
const faBoundaryMesh & boundary() const noexcept
Return constant reference to boundary mesh.
Definition: faMeshI.H:38
label nEdges() const noexcept
Number of local mesh edges.
Definition: faMeshI.H:62
const edgeVectorField & edgeCentres() const
Return edge centres as edgeVectorField.
Definition: faMesh.C:768
const labelList & faceLabels() const noexcept
Return the underlying polyMesh face labels.
Definition: faMeshI.H:122
const areaVectorField & areaCentres() const
Return face centres as areaVectorField.
Definition: faMesh.C:757
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
void distributeCellData(List< T > &values) const
Distribute list of cell data.
void distributeFaceData(List< T > &values) const
Distribute list of face data.
const mapDistribute & faceMap() const noexcept
Face distribute map.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition: triad.C:378
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333