preservePatchesConstraint.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-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace decompositionConstraints
38 {
39  defineTypeName(preservePatches);
40 
42  (
43  decompositionConstraint,
44  preservePatches,
45  dictionary
46  );
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const dictionary& dict
56 )
57 :
58  decompositionConstraint(dict, typeName),
59  patches_(coeffDict_.get<wordRes>("patches"))
60 {
62  {
63  Info<< type()
64  << " : adding constraints to keep owner and (coupled) neighbour"
65  << " of faces in patches " << patches_
66  << " on same processor. This only makes sense for cyclics"
67  << " and cyclicAMI." << endl;
68  }
69 }
70 
71 
73 (
74  const UList<wordRe>& patches
75 )
76 :
78  patches_(patches)
79 {
81  {
82  Info<< type()
83  << " : adding constraints to keep owner and (coupled) neighbour"
84  << " of faces in patches " << patches_
85  << " on same processor. This only makes sense for cyclics"
86  << " and cyclicAMI." << endl;
87  }
88 }
89 
90 
91 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
92 
94 (
95  const polyMesh& mesh,
96  boolList& blockedFace,
97  PtrList<labelList>& specifiedProcessorFaces,
98  labelList& specifiedProcessor,
99  List<labelPair>& explicitConnections
100 ) const
101 {
102  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
103 
104  blockedFace.resize(mesh.nFaces(), true);
105 
106  const labelList patchIDs(pbm.patchSet(patches_).sortedToc());
107 
108  label nUnblocked = 0;
109 
110  for (const label patchi : patchIDs)
111  {
112  const polyPatch& pp = pbm[patchi];
113 
114  forAll(pp, i)
115  {
116  const label meshFacei = pp.start() + i;
117 
118  if (blockedFace[meshFacei])
119  {
120  blockedFace[meshFacei] = false;
121  ++nUnblocked;
122  }
123  }
124  }
125 
127  {
128  Info<< type() << " : unblocked "
129  << returnReduce(nUnblocked, sumOp<label>()) << " faces" << endl;
130  }
131 
132  syncTools::syncFaceList(mesh, blockedFace, andEqOp<bool>());
133 }
134 
135 
137 (
138  const polyMesh& mesh,
139  const boolList& blockedFace,
140  const PtrList<labelList>& specifiedProcessorFaces,
141  const labelList& specifiedProcessor,
142  const List<labelPair>& explicitConnections,
143  labelList& decomposition
144 ) const
145 {
146  // If the decomposition has not enforced the constraint, do it over here.
147 
148  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
149 
150  const labelList patchIDs(pbm.patchSet(patches_).sortedToc());
151 
152  // Synchronise decomposition on patchIDs
153  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154 
155  label nChanged = 0;
156 
157  do
158  {
159  // Extract min coupled boundary data
160  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
161 
162  labelList destProc;
163  getMinBoundaryValue(mesh, decomposition, destProc);
164 
165 
166  // Override (patchIDs only) if differing
167  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168 
169  nChanged = 0;
170  for (const label patchi : patchIDs)
171  {
172  const polyPatch& pp = pbm[patchi];
173 
174  const labelUList& faceCells = pp.faceCells();
175 
176  forAll(faceCells, i)
177  {
178  const label bFacei = pp.offset()+i;
179  if (destProc[bFacei] < decomposition[faceCells[i]])
180  {
181  decomposition[faceCells[i]] = destProc[bFacei];
182  ++nChanged;
183  }
184  }
185  }
186 
188  {
189  Info<< type() << " : changed decomposition on "
190  << returnReduce(nChanged, sumOp<label>()) << " cells" << endl;
191  }
192 
193  } while (returnReduceOr(nChanged));
194 }
195 
196 
197 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
const labelList patchIDs(pbm.indices(polyPatchNames, true))
const polyBoundaryMesh & pbm
Abstract class for handling decomposition constraints.
dictionary dict
virtual void apply(const polyMesh &mesh, const boolList &blockedFace, const PtrList< labelList > &specifiedProcessorFaces, const labelList &specifiedProcessor, const List< labelPair > &explicitConnections, labelList &decomposition) const
Apply any additional post-decomposition constraints.
preservePatches(const dictionary &dict)
Construct with constraint dictionary.
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static void syncFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop)
Synchronize values on all mesh faces.
Definition: syncTools.H:432
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:52
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
dynamicFvMesh & mesh
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
int debug
Static debugging option.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
addToRunTimeSelectionTable(decompositionConstraint, geometric, dictionary)
const polyBoundaryMesh & patches
virtual void add(const polyMesh &mesh, boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add my constraints to list of constraints.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.