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-2022 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  Info<< type() << " : unblocked "
123  << returnReduce(nUnblocked, sumOp<label>()) << " 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  label nChanged = 0;
144 
145  do
146  {
147  // Extract min coupled boundary data
148  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149 
150  labelList destProc;
151  getMinBoundaryValue(mesh, decomposition, destProc);
152 
153 
154  // Override if differing
155  // ~~~~~~~~~~~~~~~~~~~~~
156 
157  const faceZoneMesh& fZones = mesh.faceZones();
158 
159  const labelList zoneIDs(zones_.matching(fZones.names()));
160 
161  nChanged = 0;
162  for (const label zonei : zoneIDs)
163  {
164  const faceZone& fz = fZones[zonei];
165 
166  for (const label facei : fz)
167  {
168  const label own = mesh.faceOwner()[facei];
169 
170  if (mesh.isInternalFace(facei))
171  {
172  const label nei = mesh.faceNeighbour()[facei];
173  if (decomposition[nei] < decomposition[own])
174  {
175  decomposition[own] = decomposition[nei];
176  ++nChanged;
177  }
178  }
179  else
180  {
181  const label bFaceI = facei-mesh.nInternalFaces();
182  if (destProc[bFaceI] < decomposition[own])
183  {
184  decomposition[own] = destProc[bFaceI];
185  ++nChanged;
186  }
187  }
188  }
189  }
190 
192  {
193  Info<< type() << " : changed decomposition on "
194  << returnReduce(nChanged, sumOp<label>()) << " cells" << endl;
195  }
196 
197  } while (returnReduceOr(nChanged));
198 }
199 
200 
201 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
Abstract class for handling decomposition constraints.
dictionary dict
const labelIOList & zoneIDs
Definition: correctPhi.H:59
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
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.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static void syncFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop)
Synchronize values on all mesh faces.
Definition: syncTools.H:432
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Macros for easy insertion into run-time selection tables.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
preserveFaceZones(const dictionary &dict)
Construct with constraint dictionary.
void setSize(const label n)
Alias for resize()
Definition: List.H:316
dynamicFvMesh & mesh
virtual void add(const polyMesh &mesh, boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add my constraints to list of constraints.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
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:105
int debug
Static debugging option.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
addToRunTimeSelectionTable(decompositionConstraint, geometric, dictionary)
wordList names() const
A list of the zone names.
Definition: ZoneMesh.C:362
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:60
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
Namespace for OpenFOAM.