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 | Copyright (C) 2015-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 #include "syncTools.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace decompositionConstraints
35 {
36  defineTypeName(preservePatchesConstraint);
37 
39  (
40  decompositionConstraint,
41  preservePatchesConstraint,
42  dictionary
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
52 (
53  const dictionary& constraintsDict,
54  const word& modelType
55 )
56 :
57  decompositionConstraint(constraintsDict, typeName),
58  patches_(coeffDict_.lookup("patches"))
59 {
60  if (decompositionConstraint::debug)
61  {
62  Info<< type() << " : adding constraints to keep owner of faces"
63  << " in patches " << patches_
64  << " on same processor. This only makes sense for cyclics." << endl;
65  }
66 }
67 
68 
71 (
72  const wordReList& patches
73 )
74 :
76  patches_(patches)
77 {
78  if (decompositionConstraint::debug)
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.setSize(mesh.nFaces(), true);
101 
102  const labelList patchIDs(pbm.patchSet(patches_).sortedToc());
103 
104  label nUnblocked = 0;
105 
106  forAll(patchIDs, i)
107  {
108  const polyPatch& pp = pbm[patchIDs[i]];
109 
110  forAll(pp, i)
111  {
112  if (blockedFace[pp.start() + i])
113  {
114  blockedFace[pp.start() + i] = false;
115  nUnblocked++;
116  }
117  }
118  }
119 
120  if (decompositionConstraint::debug & 2)
121  {
122  reduce(nUnblocked, sumOp<label>());
123  Info<< type() << " : unblocked " << nUnblocked << " faces" << endl;
124  }
125 
126  syncTools::syncFaceList(mesh, blockedFace, andEqOp<bool>());
127 }
128 
129 
131 (
132  const polyMesh& mesh,
133  const boolList& blockedFace,
134  const PtrList<labelList>& specifiedProcessorFaces,
135  const labelList& specifiedProcessor,
136  const List<labelPair>& explicitConnections,
137  labelList& decomposition
138 ) const
139 {
140  // If the decomposition has not enforced the constraint do it over
141  // here.
142 
143  // Synchronise decomposition on patchIDs
144  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145 
146  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
147 
148  labelList destProc(mesh.nFaces()-mesh.nInternalFaces(), labelMax);
149 
150  forAll(pbm, patchi)
151  {
152  const polyPatch& pp = pbm[patchi];
153 
154  const labelUList& faceCells = pp.faceCells();
155 
156  forAll(faceCells, i)
157  {
158  label bFaceI = pp.start()+i-mesh.nInternalFaces();
159  destProc[bFaceI] = decomposition[faceCells[i]];
160  }
161  }
162 
164 
165 
166  // Override if differing
167  // ~~~~~~~~~~~~~~~~~~~~~
168 
169  const labelList patchIDs(pbm.patchSet(patches_).sortedToc());
170 
171  label nChanged = 0;
172 
173  forAll(patchIDs, i)
174  {
175  const polyPatch& pp = pbm[patchIDs[i]];
176 
177  const labelUList& faceCells = pp.faceCells();
178 
179  forAll(faceCells, i)
180  {
181  label bFaceI = pp.start()+i-mesh.nInternalFaces();
182 
183  if (decomposition[faceCells[i]] != destProc[bFaceI])
184  {
185  decomposition[faceCells[i]] = destProc[bFaceI];
186  nChanged++;
187  }
188  }
189  }
190 
191  if (decompositionConstraint::debug & 2)
192  {
193  reduce(nChanged, sumOp<label>());
194  Info<< type() << " : changed decomposition on " << nChanged
195  << " cells" << endl;
196  }
197 }
198 
199 
200 // ************************************************************************* //
static void syncBoundaryFaceList(const polyMesh &, UList< T > &, const CombineOp &cop, const TransformOp &top, const bool parRun=Pstream::parRun())
Synchronize values on boundary faces only.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Macros for easy insertion into run-time selection tables.
addToRunTimeSelectionTable(decompositionConstraint, preserveBafflesConstraint, dictionary)
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:300
A class for handling words, derived from string.
Definition: word.H:59
virtual void add(const polyMesh &mesh, boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add my constraints to list of constraints.
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the set of patch IDs corresponding to the given names.
static const label labelMax
Definition: label.H:62
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:60
Foam::polyBoundaryMesh.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
label nFaces() const
static void syncFaceList(const polyMesh &mesh, UList< T > &l, const CombineOp &cop)
Synchronize values on all mesh faces.
Definition: syncTools.H:381
void setSize(const label)
Reset size of List.
Definition: List.C:295
label patchi
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:315
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.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:62
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:213
messageStream Info
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:66
preservePatchesConstraint(const dictionary &constraintsDict, const word &type)
Construct with generic dictionary with optional entry for type.
label nInternalFaces() const
Namespace for OpenFOAM.
defineTypeName(preserveBafflesConstraint)