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 | 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(preserveFaceZones);
40 
42  (
43  decompositionConstraint,
44  preserveFaceZones,
45  dictionary
46  );
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const dictionary& dict
56 )
57 :
58  decompositionConstraint(dict, typeName),
59  zones_(coeffDict_.get<wordRes>("zones"))
60 {
62  {
63  Info<< type() << " : adding constraints to keep owner and neighbour"
64  << " of faces in zones " << zones_
65  << " on same processor" << endl;
66  }
67 }
68 
69 
71 (
72  const UList<wordRe>& zones
73 )
74 :
76  zones_(zones)
77 {
79  {
80  Info<< type() << " : adding constraints to keep owner and neighbour"
81  << " of faces in zones " << zones_
82  << " on same processor" << 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  blockedFace.setSize(mesh.nFaces(), true);
99 
100  const faceZoneMesh& fZones = mesh.faceZones();
101 
102  const labelList zoneIDs(zones_.matching(fZones.names()));
103 
104  label nUnblocked = 0;
105 
106  for (const label zonei : zoneIDs)
107  {
108  const faceZone& fz = fZones[zonei];
109 
110  for (const label meshFacei : fz)
111  {
112  if (blockedFace[meshFacei])
113  {
114  blockedFace[meshFacei] = false;
115  ++nUnblocked;
116  }
117  }
118  }
119 
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 
144  // Synchronise decomposition on boundary
145  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146 
147  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
148 
149  labelList destProc(mesh.nBoundaryFaces(), labelMax);
150 
151  for (const polyPatch& pp : pbm)
152  {
153  label bFacei = pp.start() - mesh.nInternalFaces();
154 
155  const labelUList& faceCells = pp.faceCells();
156 
157  for (const label celli : faceCells)
158  {
159  destProc[bFacei] = decomposition[celli];
160 
161  ++bFacei;
162  }
163  }
164 
165  syncTools::syncBoundaryFaceList(mesh, destProc, minEqOp<label>());
166 
167 
168  // Override if differing
169  // ~~~~~~~~~~~~~~~~~~~~~
170 
171  const faceZoneMesh& fZones = mesh.faceZones();
172 
173  const labelList zoneIDs(zones_.matching(fZones.names()));
174 
175  label nChanged = 0;
176 
177  for (const label zonei : zoneIDs)
178  {
179  const faceZone& fz = fZones[zonei];
180 
181  for (const label facei : fz)
182  {
183  const label own = mesh.faceOwner()[facei];
184 
185  if (mesh.isInternalFace(facei))
186  {
187  const 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  const label bFaceI = facei-mesh.nInternalFaces();
197  if (decomposition[own] != destProc[bFaceI])
198  {
199  decomposition[own] = destProc[bFaceI];
200  ++nChanged;
201  }
202  }
203  }
204  }
205 
207  {
208  reduce(nChanged, sumOp<label>());
209  Info<< type() << " : changed decomposition on " << nChanged
210  << " cells" << endl;
211  }
212 }
213 
214 
215 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
preserveFaceZonesConstraint.H
Foam::decompositionConstraints::preserveFaceZones::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:131
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::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
syncTools.H
zoneIDs
const labelIOList & zoneIDs
Definition: correctPhi.H:59
Foam::decompositionConstraints::preserveFaceZones::preserveFaceZones
preserveFaceZones(const dictionary &dict)
Construct with constraint dictionary.
Definition: preserveFaceZonesConstraint.C:54
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sumOp
Definition: ops.H:213
Foam::minEqOp
Definition: ops.H:81
Foam::decompositionConstraints::preserveFaceZones::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:90
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:65
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::ZoneMesh< faceZone, polyMesh >
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
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::ZoneMesh::names
wordList names() const
A list of the zone names.
Definition: ZoneMesh.C:340
Foam::decompositionConstraints::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionConstraint, geometric, dictionary)
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::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56