preserveFaceZonesConstraint.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  zones_(coeffDict_.lookup("zones"))
58 {
59  if (decompositionConstraint::debug)
60  {
61  Info<< type() << " : adding constraints to keep owner and neighbour"
62  << " of faces in zones " << zones_
63  << " on same processor" << endl;
64  }
65 }
66 
67 
70 (
71  const wordReList& zones
72 )
73 :
75  zones_(zones)
76 {
77  if (decompositionConstraint::debug)
78  {
79  Info<< type() << " : adding constraints to keep owner and neighbour"
80  << " of faces in zones " << zones_
81  << " on same processor" << 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  blockedFace.setSize(mesh.nFaces(), true);
98 
99  const faceZoneMesh& fZones = mesh.faceZones();
100 
101  const labelList zoneIDs = findStrings(zones_, fZones.names());
102 
103  label nUnblocked = 0;
104 
105  forAll(zoneIDs, i)
106  {
107  const faceZone& fz = fZones[zoneIDs[i]];
108 
109  forAll(fz, i)
110  {
111  if (blockedFace[fz[i]])
112  {
113  blockedFace[fz[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 
143  // Synchronise decomposition on boundary
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 
163  syncTools::syncBoundaryFaceList(mesh, destProc, minEqOp<label>());
164 
165 
166  // Override if differing
167  // ~~~~~~~~~~~~~~~~~~~~~
168 
169  const faceZoneMesh& fZones = mesh.faceZones();
170 
171  const labelList zoneIDs = findStrings(zones_, fZones.names());
172 
173  label nChanged = 0;
174 
175  forAll(zoneIDs, i)
176  {
177  const faceZone& fz = fZones[zoneIDs[i]];
178 
179  forAll(fz, i)
180  {
181  label faceI = fz[i];
182 
183  label own = mesh.faceOwner()[faceI];
184 
185  if (mesh.isInternalFace(faceI))
186  {
187  label nei = mesh.faceNeighbour()[faceI];
188  if (decomposition[own] != decomposition[nei])
189  {
190  decomposition[nei] = decomposition[own];
191  nChanged++;
192  }
193  }
194  else
195  {
196  label bFaceI = faceI-mesh.nInternalFaces();
197  if (decomposition[own] != destProc[bFaceI])
198  {
199  decomposition[own] = destProc[bFaceI];
200  nChanged++;
201  }
202  }
203  }
204  }
205 
206  if (decompositionConstraint::debug & 2)
207  {
208  reduce(nChanged, sumOp<label>());
209  Info<< type() << " : changed decomposition on " << nChanged
210  << " cells" << endl;
211  }
212 }
213 
214 
215 // ************************************************************************* //
preserveFaceZonesConstraint.H
Foam::decompositionConstraint
Definition: decompositionConstraint.H:54
Foam::decompositionConstraints::preserveFaceZonesConstraint::preserveFaceZonesConstraint
preserveFaceZonesConstraint(const dictionary &constraintsDict, const word &type)
Construct with generic dictionary with optional entry for type.
Definition: preserveFaceZonesConstraint.C:51
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::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
preserveFaceZonesConstraint
Constraint to keep/move owner and neighbour of faceZone onto same processor.
syncTools.H
Foam::decompositionConstraints::preserveFaceZonesConstraint::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: preserveFaceZonesConstraint.C:130
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::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
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::ZoneMesh< faceZone, polyMesh >
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
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::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
Foam::ZoneMesh::names
wordList names() const
Return a list of zone names.
Definition: ZoneMesh.C:263
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::findStrings
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
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
Foam::decompositionConstraints::preserveFaceZonesConstraint::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: preserveFaceZonesConstraint.C:89
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::andEqOp
Definition: ops.H:81