Loading...
Searching...
No Matches
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"
36// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38namespace Foam
39{
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 {
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
224 syncTools::syncFaceList(mesh, blockedFace, andEqOp<bool>());
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.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition List.C:347
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition bitSetI.H:502
A cell is defined as a list of faces with extra functionality.
Definition cell.H:56
Abstract class for handling decomposition constraints.
dictionary coeffDict_
Constraint coefficients dictionary.
decompositionConstraint(const decompositionConstraint &)=delete
No copy construct.
Keep faces together based on geometric considerations from a list of topoSetFaceSource....
geometric(const dictionary &dict)
Construct with constraint dictionary.
virtual void add(const polyMesh &mesh, boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add this constraint to list of constraints.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
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:560
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
A special purpose topoSet with the face labels stored as a boolList. It does not correspond to a face...
Definition faceBoolSet.H:50
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
static void syncFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop, const bool parRun=UPstream::parRun())
Synchronize values on all mesh faces.
Definition syncTools.H:465
const boolList & addressing() const noexcept
Return the boolList.
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
static autoPtr< topoSetFaceSource > New(const word &sourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected source type.
@ SUBTRACT
Subtract elements from current set.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeName(Type)
Define the typeName.
Definition className.H:113
dynamicFvMesh & mesh
#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:73
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
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 POSIX.C:801
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
List< bool > boolList
A List of bools.
Definition List.H:60
dictionary dict