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 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
BitOps.H
Foam::decompositionConstraint
Abstract class for handling decomposition constraints.
Definition: decompositionConstraint.H:58
Foam::decompositionConstraints::defineTypeName
defineTypeName(geometric)
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::decompositionConstraints::geometric
Keep faces together based on geometric considerations from a searchableSurfaces list....
Definition: geometricConstraint.H:131
Foam::andEqOp
Definition: ops.H:85
Foam::bitSet::set
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:574
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::topoSetFaceSource
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
Definition: topoSetFaceSource.H:54
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::topoBoolSet::addressing
const boolList & addressing() const
Return the boolList.
Definition: topoBoolSet.H:112
polyMesh.H
syncTools.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sumOp
Definition: ops.H:213
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:456
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
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:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::decompositionConstraints::geometric::geometric
geometric(const dictionary &dict)
Construct with constraint dictionary.
Definition: geometricConstraint.C:56
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
geometricConstraint.H
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::decompositionConstraints::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionConstraint, geometric, dictionary)
Time.H
Foam::faceBoolSet
A special purpose topoSet with the face labels stored as a boolList. It does not correspond to a face...
Definition: faceBoolSet.H:51
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::List< bool >
Foam::dictionary::optionalSubDict
const dictionary & optionalSubDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary, otherwise return this dictionary.
Definition: dictionary.C:577
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
faceBoolSet.H
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:54
Foam::decompositionConstraints::geometric::add
virtual void add(const polyMesh &mesh, boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add this constraint to list of constraints.
Definition: geometricConstraint.C:98