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,2021 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  reduce(nUnblocked, sumOp<label>());
129  Info<< type() << " : unblocked " << nUnblocked << " 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;
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 
187  reduce(nChanged, sumOp<label>());
188 
190  {
191  Info<< type() << " : changed decomposition on " << nChanged
192  << " cells" << endl;
193  }
194 
195  } while (nChanged > 0);
196 }
197 
198 
199 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::decompositionConstraints::preservePatches::apply
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.
Definition: preservePatchesConstraint.C:137
Foam::decompositionConstraint
Abstract class for handling decomposition constraints.
Definition: decompositionConstraint.H:58
Foam::decompositionConstraints::defineTypeName
defineTypeName(geometric)
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
Foam::andEqOp
Definition: ops.H:85
Foam::polyPatch::offset
label offset() const
The offset where this patch starts in the boundary face list.
Definition: polyPatch.C:309
Foam::decompositionConstraints::preservePatches::add
virtual void add(const polyMesh &mesh, boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add my constraints to list of constraints.
Definition: preservePatchesConstraint.C:94
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
syncTools.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
preservePatchesConstraint.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
reduce
reduce(hasMovingMesh, orOp< bool >())
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::polyPatch::faceCells
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:371
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:361
Foam::decompositionConstraints::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionConstraint, geometric, dictionary)
Foam::decompositionConstraints::preservePatches::preservePatches
preservePatches(const dictionary &dict)
Construct with constraint dictionary.
Definition: preservePatchesConstraint.C:54
Foam::List< bool >
Foam::UList
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:103
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::polyBoundaryMesh::patchSet
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
Definition: polyBoundaryMesh.C:864
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56