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-------------------------------------------------------------------------------
10License
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
38namespace Foam
39{
40namespace decompositionConstraints
41{
43
45 (
49 );
50}
51}
52
53// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54
56(
57 const dictionary& dict
58)
59:
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
67 if (decompositionConstraint::debug)
68 {
69 Info<< type()
70 << " : adding " << selection_.size()
71 << " geometric constraints for faces" << endl;
72 }
73}
74
75
77(
79)
80:
82 sources_(std::move(selections)),
83 selection_(),
84 grow_(false)
85{
86 if (decompositionConstraint::debug)
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;
111 if (decompositionConstraint::debug)
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
152 if (decompositionConstraint::debug)
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
204 if (decompositionConstraint::debug)
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
216 if (decompositionConstraint::debug)
217 {
218 Info<< type()
219 << " : geometric constraint added for "
220 << returnReduce(nchanged, sumOp<label>())
221 <<" faces" << endl;
222 }
223
225}
226
227
228// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
void transfer(List< T > &list)
Definition: List.C:447
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:590
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:57
Abstract class for handling decomposition constraints.
Keep faces together based on geometric considerations from a list of topoSetFaceSource....
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
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
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
A special purpose topoSet with the face labels stored as a boolList. It does not correspond to a face...
Definition: faceBoolSet.H:54
Sums a given list of (at least two or more) fields and outputs the result into a new field,...
Definition: add.H:161
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
static void syncFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop)
Synchronize values on all mesh faces.
Definition: syncTools.H:396
const boolList & addressing() const noexcept
Return the boolList.
Definition: topoBoolSet.H:112
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
@ SUBTRACT
Subtract elements from current set.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeName(Type)
Define the typeName.
Definition: className.H:96
dynamicFvMesh & mesh
const labelList nFaces(UPstream::listGatherValues< label >(aMesh.nFaces()))
#define WarningInFunction
Report a warning using Foam::Warning.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:78
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
dictionary dict