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 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 {
38 (
39  decompositionConstraint,
41  dictionary
42 );
43 }
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
51 (
52  const dictionary& constraintsDict,
53  const word& modelType
54 )
55 :
56  decompositionConstraint(constraintsDict, typeName),
57  patches_(coeffDict_.lookup("patches"))
58 {
59  if (decompositionConstraint::debug)
60  {
61  Info<< type() << " : adding constraints to keep owner of faces"
62  << " in patches " << patches_
63  << " on same processor. This only makes sense for cyclics." << endl;
64  }
65 }
66 
67 
70 (
71  const wordReList& patches
72 )
73 :
75  patches_(patches)
76 {
77  if (decompositionConstraint::debug)
78  {
79  Info<< type() << " : adding constraints to keep owner of faces"
80  << " in patches " << patches_
81  << " on same processor. This only makes sense for cyclics." << endl;
82  }
83 }
84 
85 
86 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
87 
89 (
90  const polyMesh& mesh,
91  boolList& blockedFace,
92  PtrList<labelList>& specifiedProcessorFaces,
93  labelList& specifiedProcessor,
94  List<labelPair>& explicitConnections
95 ) const
96 {
97  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
98 
99  blockedFace.setSize(mesh.nFaces(), true);
100 
101  const labelList patchIDs(pbm.patchSet(patches_).sortedToc());
102 
103  label nUnblocked = 0;
104 
105  forAll(patchIDs, i)
106  {
107  const polyPatch& pp = pbm[patchIDs[i]];
108 
109  forAll(pp, i)
110  {
111  if (blockedFace[pp.start() + i])
112  {
113  blockedFace[pp.start() + i] = false;
114  nUnblocked++;
115  }
116  }
117  }
118 
119  if (decompositionConstraint::debug & 2)
120  {
121  reduce(nUnblocked, sumOp<label>());
122  Info<< type() << " : unblocked " << nUnblocked << " faces" << endl;
123  }
124 
125  syncTools::syncFaceList(mesh, blockedFace, andEqOp<bool>());
126 }
127 
128 
130 (
131  const polyMesh& mesh,
132  const boolList& blockedFace,
133  const PtrList<labelList>& specifiedProcessorFaces,
134  const labelList& specifiedProcessor,
135  const List<labelPair>& explicitConnections,
136  labelList& decomposition
137 ) const
138 {
139  // If the decomposition has not enforced the constraint do it over
140  // here.
141 
142  // Synchronise decomposition on patchIDs
143  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144 
145  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
146 
147  labelList destProc(mesh.nFaces()-mesh.nInternalFaces(), labelMax);
148 
149  forAll(pbm, patchI)
150  {
151  const polyPatch& pp = pbm[patchI];
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  forAll(patchIDs, i)
173  {
174  const polyPatch& pp = pbm[patchIDs[i]];
175 
176  const labelUList& faceCells = pp.faceCells();
177 
178  forAll(faceCells, i)
179  {
180  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 
190  if (decompositionConstraint::debug & 2)
191  {
192  reduce(nChanged, sumOp<label>());
193  Info<< type() << " : changed decomposition on " << nChanged
194  << " cells" << endl;
195  }
196 }
197 
198 
199 // ************************************************************************* //
Foam::decompositionConstraint
Definition: decompositionConstraint.H:54
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::decompositionConstraints::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionConstraint, preserveBafflesConstraint, dictionary)
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::decompositionConstraints::defineTypeName
defineTypeName(preserveBafflesConstraint)
Foam::labelMax
static const label labelMax
Definition: label.H:62
Foam::decompositionConstraints::preservePatchesConstraint::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:130
Foam::decompositionConstraints::preservePatchesConstraint::preservePatchesConstraint
preservePatchesConstraint(const dictionary &constraintsDict, const word &type)
Construct with generic dictionary with optional entry for type.
Definition: preservePatchesConstraint.C:51
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
syncTools.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
Foam::label
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
Foam::Info
messageStream Info
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::minEqOp
Definition: ops.H:78
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
preservePatchesConstraint.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::polyPatch::faceCells
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:340
Foam::HashTable::sortedToc
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:216
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
Foam::decompositionConstraints::preservePatchesConstraint::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:89
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::sumOp
Definition: ops.H:162
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
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:60
preservePatchesConstraint
Constraint to keep owner and neighbour of (cyclic) patch on same processor.
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::polyBoundaryMesh::patchSet
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.
Definition: polyBoundaryMesh.C:750
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::andEqOp
Definition: ops.H:81