geometricConstraint.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) 2018-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "geometricConstraint.H"
30 #include "syncTools.H"
31 #include "polyMesh.H"
32 #include "Time.H"
33 #include "BitOps.H"
34 #include "faceBoolSet.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 namespace decompositionConstraints
41 {
43 
45  (
47  geometric,
49  );
50 }
51 }
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
56 (
57  const dictionary& dict
58 )
59 :
60  decompositionConstraint(dict, typeName),
61  sources_(),
62  selection_(coeffDict_.subDict("selection")),
63  grow_(dict.getOrDefault("grow", false))
64 {
65  // Stored as dictionary, since we do not have the mesh at this stage
66 
68  {
69  Info<< type()
70  << " : adding " << selection_.size()
71  << " geometric constraints for faces" << endl;
72  }
73 }
74 
75 
77 (
78  PtrList<topoSetFaceSource>&& selections
79 )
80 :
82  sources_(std::move(selections)),
83  selection_(),
84  grow_(false)
85 {
87  {
88  Info<< type()
89  << " : adding " << sources_.size()
90  << " geometric constraints for faces" << endl;
91  }
92 }
93 
94 
95 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
96 
98 (
99  const polyMesh& mesh,
100  boolList& blockedFace,
101  PtrList<labelList>& specifiedProcessorFaces,
102  labelList& specifiedProcessor,
103  List<labelPair>& explicitConnections
104 ) const
105 {
106  const label nFaces = mesh.nFaces();
107 
108  blockedFace.resize(nFaces, true);
109 
110  label nchanged = 0;
112  {
113  nchanged = BitOps::count(blockedFace, false);
114  }
115 
116  // Modify via topoSetFaceSource
117  faceBoolSet facesToBlock(mesh, std::move(blockedFace));
118 
119  for (const topoSetFaceSource& source : sources_)
120  {
121  // source.verbose(false);
122  source.applyToSet(topoSetSource::SUBTRACT, facesToBlock);
123  }
124 
125  for (const entry& dEntry : selection_)
126  {
127  if (!dEntry.isDict())
128  {
130  << "Ignoring non-dictionary entry "
131  << dEntry << endl;
132  continue;
133  }
134 
135  const dictionary& spec = dEntry.dict();
136 
137  auto source = topoSetFaceSource::New
138  (
139  spec.get<word>("source"),
140  mesh,
141  spec.optionalSubDict("sourceInfo")
142  );
143  // source->verbose(false);
144 
145  source->applyToSet(topoSetSource::SUBTRACT, facesToBlock);
146  }
147 
148 
149  // Finished with topo changes
150  blockedFace.transfer(facesToBlock.addressing());
151 
153  {
154  nchanged = BitOps::count(blockedFace, false) - nchanged;
155  }
156  else
157  {
158  nchanged = 0;
159  }
160 
161  // Grow mode.
162  // Include the faces of cells for which there are already two
163  // or more faces in a constraint.
164  if (grow_)
165  {
166  bitSet moreUnblocking(nFaces, false);
167 
168  label nUnblocked = 0;
169 
170  for (label celli=0; celli < mesh.nCells(); ++celli)
171  {
172  const cell& cFaces = mesh.cells()[celli];
173 
174  nUnblocked = 0;
175  for (const label facei : cFaces)
176  {
177  if (!blockedFace[facei])
178  {
179  ++nUnblocked;
180  if (nUnblocked > 2)
181  {
182  break;
183  }
184  }
185  }
186 
187  if (nUnblocked > 2)
188  {
189  moreUnblocking.set(cFaces);
190  }
191  }
192 
193  nUnblocked = 0;
194 
195  for (label facei : moreUnblocking)
196  {
197  if (blockedFace[facei])
198  {
199  blockedFace[facei] = false;
200  ++nUnblocked;
201  }
202  }
203 
205  {
206  Info<< type()
207  << " : geometric constraint grow added "
208  << returnReduce(nUnblocked, sumOp<label>())
209  <<" faces" << endl;
210  }
211 
212  // Include in the total
213  nchanged += nUnblocked;
214  }
215 
217  {
218  Info<< type()
219  << " : geometric constraint added for "
220  << returnReduce(nchanged, sumOp<label>())
221  <<" faces" << endl;
222  }
223 
224  syncTools::syncFaceList(mesh, blockedFace, andEqOp<bool>());
225 }
226 
227 
228 // ************************************************************************* //
Abstract class for handling decomposition constraints.
dictionary dict
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition: List.C:326
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Keep faces together based on geometric considerations from a list of topoSetFaceSource. The faces selected (inside) of each source are to be kept together during the decomposition.
geometric(const dictionary &dict)
Construct with constraint dictionary.
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.
static autoPtr< topoSetFaceSource > New(const word &sourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected source type.
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
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
dynamicFvMesh & mesh
int debug
Static debugging option.
Subtract elements from current set.
#define WarningInFunction
Report a warning using Foam::Warning.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
addToRunTimeSelectionTable(decompositionConstraint, geometric, dictionary)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual void add(const polyMesh &mesh, boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add this constraint to list of constraints.
Namespace for OpenFOAM.