singleProcessorFaceSetsConstraint.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-2016 OpenFOAM Foundation
9 Copyright (C) 2018-2019,2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
31#include "syncTools.H"
32#include "faceSet.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
38namespace decompositionConstraints
39{
41
43 (
47 );
48}
49}
50
51// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
52
53void Foam::decompositionConstraints::singleProcessorFaceSets::printInfo() const
54{
55 for (const auto& nameAndProc : setNameAndProcs_)
56 {
57 Info<< " all cells connected to faceSet "
58 << nameAndProc.first()
59 << " on processor " << nameAndProc.second() << endl;
60 }
61}
62
63
64// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
65
66Foam::decompositionConstraints::singleProcessorFaceSets::
67singleProcessorFaceSets
68(
69 const dictionary& dict
70)
71:
73 setNameAndProcs_
74 (
75 coeffDict_.lookupCompat("sets", {{"singleProcessorFaceSets", 1806}})
76 )
77{
78 if (decompositionConstraint::debug)
79 {
80 Info<< type()
81 << " : adding constraints to keep" << endl;
82
83 printInfo();
84 }
85}
86
87
88Foam::decompositionConstraints::singleProcessorFaceSets::
89singleProcessorFaceSets
90(
91 const List<Tuple2<word, label>>& setNameAndProcs
92)
93:
95 setNameAndProcs_(setNameAndProcs)
96{
97 if (decompositionConstraint::debug)
98 {
99 Info<< type()
100 << " : adding constraints to keep" << endl;
101
102 printInfo();
103 }
104}
105
106
107Foam::decompositionConstraints::singleProcessorFaceSets::
108singleProcessorFaceSets
109(
110 Istream& is
111)
112:
114 setNameAndProcs_(is)
115{
116 if (decompositionConstraint::debug)
117 {
118 Info<< type()
119 << " : adding constraints to keep" << endl;
120
121 printInfo();
122 }
123}
124
125
126// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
127
129(
130 const polyMesh& mesh,
131 boolList& blockedFace,
132 PtrList<labelList>& specifiedProcessorFaces,
133 labelList& specifiedProcessor,
134 List<labelPair>& explicitConnections
135) const
136{
137 blockedFace.resize(mesh.nFaces(), true);
138
139 // Mark faces already in set
140 labelList faceToSet(mesh.nFaces(), -1);
141 forAll(specifiedProcessorFaces, setI)
142 {
143 const labelList& faceLabels = specifiedProcessorFaces[setI];
144 for (const label facei : faceLabels)
145 {
146 if (faceToSet[facei] == -1)
147 {
148 faceToSet[facei] = setI;
149 }
150 else if (faceToSet[facei] != setI)
151 {
152 WarningInFunction << "Face " << facei
153 << " at " << mesh.faceCentres()[facei]
154 << " is already in existing constraint "
155 << faceToSet[facei]
156 << endl;
157 }
158 }
159 }
160
161 forAll(setNameAndProcs_, setI)
162 {
163 //Info<< "Keeping all cells connected to faceSet "
164 // << setNameAndProcs_[setI].first()
165 // << " on processor " << setNameAndProcs_[setI].second() << endl;
166
167 const label destProcI = setNameAndProcs_[setI].second();
168
169 // Read faceSet
170 const faceSet fz(mesh, setNameAndProcs_[setI].first());
171
172 // Check that it does not overlap with existing specifiedProcessorFaces
173 labelList nMatch(specifiedProcessorFaces.size(), Zero);
174 for (const label facei : fz)
175 {
176 const label seti = faceToSet[facei];
177 if (seti != -1)
178 {
179 ++nMatch[seti];
180 }
181 }
182
183
184 // Only store if all faces are not yet in specifiedProcessorFaces
185 // (on all processors)
186 bool store = true;
187
188 forAll(nMatch, setI)
189 {
190 if (nMatch[setI] == fz.size())
191 {
192 // Full match
193 store = false;
194 break;
195 }
196 else if (nMatch[setI] > 0)
197 {
198 // Partial match
199 store = false;
200 break;
201 }
202 }
203
204 reduce(store, orOp<bool>());
205
206 if (store)
207 {
208 specifiedProcessorFaces.append(new labelList(fz.sortedToc()));
209 specifiedProcessor.append(destProcI);
210 }
211 }
212
213
214 // Unblock all point connected faces
215 // 1. Mark all points on specifiedProcessorFaces
216 boolList procFacePoint(mesh.nPoints(), false);
217 forAll(specifiedProcessorFaces, setI)
218 {
219 const labelList& faceLabels = specifiedProcessorFaces[setI];
220 for (const label facei : faceLabels)
221 {
222 const face& f = mesh.faces()[facei];
223
224 for (const label pointi : f)
225 {
226 procFacePoint[pointi] = true;
227 }
228 }
229 }
230 syncTools::syncPointList(mesh, procFacePoint, orEqOp<bool>(), false);
231
232 // 2. Unblock all faces on procFacePoint
233
234 label nUnblocked = 0;
235
236 forAll(procFacePoint, pointi)
237 {
238 if (procFacePoint[pointi])
239 {
240 const labelList& pFaces = mesh.pointFaces()[pointi];
241 forAll(pFaces, i)
242 {
243 if (blockedFace[pFaces[i]])
244 {
245 blockedFace[pFaces[i]] = false;
246 ++nUnblocked;
247 }
248 }
249 }
250 }
251
252 if (decompositionConstraint::debug & 2)
253 {
254 reduce(nUnblocked, sumOp<label>());
255 Info<< type() << " : unblocked " << nUnblocked << " faces" << endl;
256 }
257
259}
260
261
263(
264 const polyMesh& mesh,
265 const boolList& blockedFace,
266 const PtrList<labelList>& specifiedProcessorFaces,
267 const labelList& specifiedProcessor,
268 const List<labelPair>& explicitConnections,
269 labelList& decomposition
270) const
271{
272 // For specifiedProcessorFaces rework the cellToProc to enforce
273 // all on one processor since we can't guarantee that the input
274 // to regionSplit was a single region.
275 // E.g. faceSet 'a' with the cells split into two regions
276 // by a notch formed by two walls
277 //
278 // \ /
279 // \ /
280 // ---a----+-----a-----
281 //
282 //
283 // Note that reworking the cellToProc might make the decomposition
284 // unbalanced.
285 label nChanged = 0;
286
287 forAll(specifiedProcessorFaces, setI)
288 {
289 const labelList& set = specifiedProcessorFaces[setI];
290
291 // Get the processor to use for the set
292 label procI = specifiedProcessor[setI];
293 if (procI == -1)
294 {
295 // If no processor specified use the one from the
296 // 0th element
297 if (set.size())
298 {
299 procI = decomposition[mesh.faceOwner()[set[0]]];
300 }
301 reduce(procI, maxOp<label>());
302 }
303
304 // Get all points on the sets
305 boolList procFacePoint(mesh.nPoints(), false);
306 forAll(set, fI)
307 {
308 const face& f = mesh.faces()[set[fI]];
309 forAll(f, fp)
310 {
311 procFacePoint[f[fp]] = true;
312 }
313 }
314 syncTools::syncPointList(mesh, procFacePoint, orEqOp<bool>(), false);
315
316 // 2. Unblock all faces on procFacePoint
317 forAll(procFacePoint, pointi)
318 {
319 if (procFacePoint[pointi])
320 {
321 const labelList& pFaces = mesh.pointFaces()[pointi];
322 for (const label faceI : pFaces)
323 {
324 const label own = mesh.faceOwner()[faceI];
325
326 if (decomposition[own] != procI)
327 {
328 decomposition[own] = procI;
329 ++nChanged;
330 }
331
332 if (mesh.isInternalFace(faceI))
333 {
334 const label nei = mesh.faceNeighbour()[faceI];
335 if (decomposition[nei] != procI)
336 {
337 decomposition[nei] = procI;
338 ++nChanged;
339 }
340 }
341 }
342 }
343 }
344 }
345
346 if (decompositionConstraint::debug & 2)
347 {
348 reduce(nChanged, sumOp<label>());
349 Info<< type() << " : changed decomposition on " << nChanged
350 << " cells" << endl;
351 }
352}
353
354
355// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:137
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
void append(T *ptr)
Append an element to the end of the list.
Definition: PtrListI.H:113
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:58
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
virtual void apply()=0
Apply bins.
Abstract class for handling decomposition constraints.
Constraint to keep all cells connected to face or point of faceSet on a single processor.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A list of face labels.
Definition: faceSet.H:54
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Sums a given list of (at least two or more) fields and outputs the result into a new field,...
Definition: add.H:161
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
static void syncFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop)
Synchronize values on all mesh faces.
Definition: syncTools.H:396
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
#define defineTypeName(Type)
Define the typeName.
Definition: className.H:96
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=cellModel::ref(cellModel::HEX);labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){ pointMap[i]=i;}for(label i=0;i< nPoints;i++){ if(f[i] > 0.0) { hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells].reset(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei) { if(edges[ei].mag(points)< SMALL) { label start=pointMap[edges[ei].start()];while(start !=pointMap[start]) { start=pointMap[start];} label end=pointMap[edges[ei].end()];while(end !=pointMap[end]) { end=pointMap[end];} label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;} } cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){ cellShape &cs=cellShapes[celli];forAll(cs, i) { cs[i]=pointMap[cs[i]];} cs.collapse();}label bcIDs[11]={-1, 0, 2, 4, -1, 5, -1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={ &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &symmetryPolyPatch::typeName, &wedgePolyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &symmetryPolyPatch::typeName, &oldCyclicPolyPatch::typeName};enum patchTypeNames{ PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={ "piston", "valve", "liner", "cylinderHead", "axis", "wedge", "inflow", "outflow", "presin", "presout", "symmetryPlane", "cyclic"};List< SLList< face > > pFaces[nBCs]
Definition: readKivaGrid.H:235
labelList f(nPoints)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333