Loading...
Searching...
No Matches
mergePatchPairs.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) 2009 OpenFOAM Foundation
9 Copyright (C) 2017-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
13
14Description
15 Handle merging of patch pairs
16
17\*---------------------------------------------------------------------------*/
18
19{
20 wordPairList mergePatchPairs;
21
22 // Read in a list of merge patch pairs
23 if
24 (
25 meshDict.readIfPresent("mergePatchPairs", mergePatchPairs)
26 && mergePatchPairs.size()
27 )
28 {
29 Info<< "Merging " << mergePatchPairs.size() << " patch pairs" << nl;
30
31 // Cleanup
32 wordHashSet cleanupPatches(4*mergePatchPairs.size());
33 wordHashSet cleanupPointZones(2*mergePatchPairs.size());
34 wordHashSet cleanupFaceZones(2*mergePatchPairs.size());
35
36 Info<< " Adding point and face zones" << endl;
37 {
38 const auto& pbm = mesh.boundaryMesh();
39
40 auto& pzs = mesh.pointZones(); pzs.clearAddressing();
41 auto& fzs = mesh.faceZones(); fzs.clearAddressing();
42
43 forAll(mergePatchPairs, pairi)
44 {
45 // Patch pairs
46 const polyPatch& patch0 = pbm[mergePatchPairs[pairi].first()];
47 const polyPatch& patch1 = pbm[mergePatchPairs[pairi].second()];
48
49 const word mergeName
50 (
51 mergePatchPairs[pairi].first()
52 + mergePatchPairs[pairi].second()
53 + Foam::name(pairi)
54 );
55
56 // An empty zone for cut points
57 pzs.emplace_back
58 (
59 mergeName + "CutPointZone",
60 pzs.size(), // index
61 pzs
62 );
63 cleanupPointZones.insert(pzs.back().name());
64
65 // Coupling side 0 (master)
66 fzs.emplace_back
67 (
68 mergeName + "Side0Zone",
69 identity(patch0.range()),
70 false, // none are flipped
71 fzs.size(), // index
72 fzs
73 );
74 cleanupFaceZones.insert(fzs.back().name());
75
76 // Coupling side 1 (slave)
77 fzs.emplace_back
78 (
79 mergeName + "Side1Zone",
80 identity(patch1.range()),
81 false, // none are flipped
82 fzs.size(), // index
83 fzs
84 );
85 cleanupFaceZones.insert(fzs.back().name());
86
87 // An empty zone for cut faces
88 fzs.emplace_back
89 (
90 mergeName + "CutFaceZone",
91 fzs.size(), // index
92 fzs
93 );
94 cleanupFaceZones.insert(fzs.back().name());
95 }
96 }
97
98
99 Info<< " Merging with attachPolyTopoChanger" << endl;
100 attachPolyTopoChanger polyMeshAttacher(mesh);
101 polyMeshAttacher.resize(1);
102
103 forAll(mergePatchPairs, pairi)
104 {
105 cleanupPatches.insert(mergePatchPairs[pairi].first());
106 cleanupPatches.insert(mergePatchPairs[pairi].second());
107
108 const word mergeName
109 (
110 mergePatchPairs[pairi].first()
111 + mergePatchPairs[pairi].second()
112 + Foam::name(pairi)
113 );
114
115 // Add the sliding interface mesh modifier
116 polyMeshAttacher.set
117 (
118 0,
119 new slidingInterface
120 (
121 "couple" + Foam::name(pairi),
122 pairi,
123 polyMeshAttacher,
124 mergeName + "Side0Zone",
125 mergeName + "Side1Zone",
126 mergeName + "CutPointZone",
127 mergeName + "CutFaceZone",
128 mergePatchPairs[pairi].first(),
129 mergePatchPairs[pairi].second(),
130 slidingInterface::INTEGRAL, // always integral
131 false,
132 intersection::VISIBLE
133 )
134 );
135
136 polyMeshAttacher.attach(false); // Do not yet remove empty patches
137 }
138
139 // Re-do the boundary patches, removing empty merge patches
140 // but keeping any other empty patches
141 {
142 const polyBoundaryMesh& oldPatches = mesh.boundaryMesh();
143
144 polyPatchList newPatches(oldPatches.size());
145 label nNewPatches = 0;
146
147 wordHashSet removedPatches(cleanupPatches.capacity());
148
149 forAll(oldPatches, patchi)
150 {
151 const word& patchName = oldPatches[patchi].name();
152
153 if
154 (
155 !cleanupPatches.contains(patchName)
156 || returnReduceOr(oldPatches[patchi].size())
157 )
158 {
159 newPatches.set
160 (
161 nNewPatches,
162 oldPatches[patchi].clone
163 (
164 mesh.boundaryMesh(),
165 nNewPatches,
166 oldPatches[patchi].size(),
167 oldPatches[patchi].start()
168 )
169 );
170
171 ++nNewPatches;
172 }
173 else
174 {
175 removedPatches.insert(patchName);
176 }
177 }
178
179 newPatches.resize(nNewPatches);
180
181 mesh.removeBoundary();
182 mesh.addPatches(newPatches);
183
184 Info<< "Removed " << removedPatches.size()
185 << " empty merged patches:" << nl
186 << " " << flatOutput(removedPatches.sortedToc()) << endl;
187 }
188
189 // Cleanup empty merged point zones
190 {
191 auto& zmesh = mesh.pointZones();
192 zmesh.clearAddressing();
193 PtrList<pointZone>& zones = zmesh;
194
195 wordHashSet removedZones(2*zones.size());
196
197 label nZones = 0;
198 forAll(zones, zonei)
199 {
200 if
201 (
202 !cleanupPointZones.contains(zones[zonei].name())
203 || returnReduceOr(zones[zonei].size())
204 )
205 {
206 zones.set(nZones, zones.release(zonei));
207 ++nZones;
208 }
209 else
210 {
211 removedZones.insert(zones[zonei].name());
212 }
213 }
214 zones.resize(nZones);
215 zmesh.reindex();
216
217 if (removedZones.size())
218 {
219 Info<< "Removed " << removedZones.size()
220 << " empty point zones:" << nl
221 << " " << flatOutput(removedZones.sortedToc()) << endl;
222 }
223 }
224
225 // Cleanup empty merged face zones
226 {
227 auto& zmesh = mesh.faceZones();
228 zmesh.clearAddressing();
229 PtrList<faceZone>& zones = zmesh;
230
231 wordHashSet removedZones(2*zones.size());
232
233 label nZones = 0;
234 forAll(zones, zonei)
235 {
236 if
237 (
238 !cleanupFaceZones.contains(zones[zonei].name())
239 || returnReduceOr(zones[zonei].size())
240 )
241 {
242 zones.set(nZones, zones.release(zonei));
243 ++nZones;
244 }
245 else
246 {
247 removedZones.insert(zones[zonei].name());
248 }
249 }
250 zones.resize(nZones);
251 zmesh.reindex();
252
253 if (removedZones.size())
254 {
255 Info<< "Removed " << removedZones.size()
256 << " empty merged face zones:" << nl
257 << " " << flatOutput(removedZones.sortedToc()) << endl;
258 }
259 }
260 }
261 else
262 {
263 Info<< "No patch pairs to merge" << endl;
265}
266
267
268// ************************************************************************* //
const polyBoundaryMesh & pbm
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
dynamicFvMesh & mesh
const IOdictionary & meshDict
auto & name
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< wordPair > wordPairList
List of wordPair.
Definition wordPair.H:33
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299