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 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() << " : adding constraints to keep owner of faces"
64  << " in patches " << patches_
65  << " on same processor. This only makes sense for cyclics." << endl;
66  }
67 }
68 
69 
71 (
72  const UList<wordRe>& patches
73 )
74 :
76  patches_(patches)
77 {
79  {
80  Info<< type() << " : adding constraints to keep owner of faces"
81  << " in patches " << patches_
82  << " on same processor. This only makes sense for cyclics." << endl;
83  }
84 }
85 
86 
87 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
88 
90 (
91  const polyMesh& mesh,
92  boolList& blockedFace,
93  PtrList<labelList>& specifiedProcessorFaces,
94  labelList& specifiedProcessor,
95  List<labelPair>& explicitConnections
96 ) const
97 {
98  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
99 
100  blockedFace.resize(mesh.nFaces(), true);
101 
102  const labelList patchIDs(pbm.patchSet(patches_).sortedToc());
103 
104  label nUnblocked = 0;
105 
106  for (const label patchi : patchIDs)
107  {
108  const polyPatch& pp = pbm[patchi];
109 
110  forAll(pp, i)
111  {
112  const label meshFacei = pp.start() + i;
113 
114  if (blockedFace[meshFacei])
115  {
116  blockedFace[meshFacei] = false;
117  ++nUnblocked;
118  }
119  }
120  }
121 
123  {
124  reduce(nUnblocked, sumOp<label>());
125  Info<< type() << " : unblocked " << nUnblocked << " faces" << endl;
126  }
127 
128  syncTools::syncFaceList(mesh, blockedFace, andEqOp<bool>());
129 }
130 
131 
133 (
134  const polyMesh& mesh,
135  const boolList& blockedFace,
136  const PtrList<labelList>& specifiedProcessorFaces,
137  const labelList& specifiedProcessor,
138  const List<labelPair>& explicitConnections,
139  labelList& decomposition
140 ) const
141 {
142  // If the decomposition has not enforced the constraint, do it over here.
143 
144  // Synchronise decomposition on patchIDs
145  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146 
147  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
148 
149  labelList destProc(mesh.nBoundaryFaces(), labelMax);
150 
151  for (const polyPatch& pp : pbm)
152  {
153  const labelUList& faceCells = pp.faceCells();
154 
155  forAll(faceCells, i)
156  {
157  label bFaceI = pp.start()+i-mesh.nInternalFaces();
158  destProc[bFaceI] = decomposition[faceCells[i]];
159  }
160  }
161 
162  syncTools::syncBoundaryFaceList(mesh, destProc, minEqOp<label>());
163 
164 
165  // Override if differing
166  // ~~~~~~~~~~~~~~~~~~~~~
167 
168  const labelList patchIDs(pbm.patchSet(patches_).sortedToc());
169 
170  label nChanged = 0;
171 
172  for (const label patchi : patchIDs)
173  {
174  const polyPatch& pp = pbm[patchi];
175 
176  const labelUList& faceCells = pp.faceCells();
177 
178  forAll(faceCells, i)
179  {
180  const label bFaceI = pp.start()+i-mesh.nInternalFaces();
181 
182  if (decomposition[faceCells[i]] != destProc[bFaceI])
183  {
184  decomposition[faceCells[i]] = destProc[bFaceI];
185  ++nChanged;
186  }
187  }
188  }
189 
191  {
192  reduce(nChanged, sumOp<label>());
193  Info<< type() << " : changed decomposition on " << nChanged
194  << " cells" << endl;
195  }
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:133
Foam::decompositionConstraint
Abstract class for handling decomposition constraints.
Definition: decompositionConstraint.H:58
Foam::decompositionConstraints::defineTypeName
defineTypeName(geometric)
Foam::labelMax
constexpr label labelMax
Definition: label.H:61
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::andEqOp
Definition: ops.H:85
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:90
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
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::minEqOp
Definition: ops.H:81
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
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:62
preservePatchesConstraint.H
Foam::List::resize
void resize(const label newSize)
Adjust allocated size of list.
Definition: ListI.H:139
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:121
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:363
Foam::HashTable::sortedToc
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:136
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:313
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:862
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