regionToFace.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) 2012-2017 OpenFOAM Foundation
9 Copyright (C) 2018-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
29#include "regionToFace.H"
30#include "polyMesh.H"
31#include "faceSet.H"
32#include "mappedPatchBase.H"
34#include "PatchTools.H"
36#include "PatchEdgeFaceWave.H"
38
39// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40
41namespace Foam
42{
49 (
52 word,
53 region
54 );
56 (
59 istream,
60 region
61 );
62}
63
64
65Foam::topoSetSource::addToUsageTable Foam::regionToFace::usage_
66(
67 regionToFace::typeName,
68 "\n Usage: regionToFace <faceSet> (x y z)\n\n"
69 " Select all faces in the connected region of the faceSet"
70 " starting from the point.\n"
71);
72
73
74// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
75
76void Foam::regionToFace::markZone
77(
78 const indirectPrimitivePatch& patch,
79 const label proci,
80 const label facei,
81 const label zonei,
82 labelList& faceZone
83) const
84{
85 // Data on all edges and faces
86 List<edgeTopoDistanceData<label>> allEdgeInfo(patch.nEdges());
87 List<edgeTopoDistanceData<label>> allFaceInfo(patch.size());
88
89 DynamicList<label> changedEdges;
90 DynamicList<edgeTopoDistanceData<label>> changedInfo;
91
92 if (Pstream::myProcNo() == proci)
93 {
94 const labelList& fEdges = patch.faceEdges()[facei];
95 for (const label edgei : fEdges)
96 {
97 changedEdges.append(edgei);
98 changedInfo.append
99 (
100 edgeTopoDistanceData<label>
101 (
102 0, // distance
103 zonei
104 )
105 );
106 }
107 }
108
109 // Walk
110 PatchEdgeFaceWave
111 <
113 edgeTopoDistanceData<label>
114 > calc
115 (
116 mesh_,
117 patch,
118 changedEdges,
119 changedInfo,
120 allEdgeInfo,
121 allFaceInfo,
122 returnReduce(patch.nEdges(), sumOp<label>())
123 );
124
125 forAll(allFaceInfo, facei)
126 {
127 if
128 (
129 allFaceInfo[facei].valid(calc.data())
130 && allFaceInfo[facei].data() == zonei
131 )
132 {
133 faceZone[facei] = zonei;
134 }
135 }
136}
137
138
139void Foam::regionToFace::combine(topoSet& set, const bool add) const
140{
141 if (verbose_)
142 {
143 Info<< " Loading subset " << setName_
144 << " to delimit search region." << endl;
145 }
146
147 faceSet subSet(mesh_, setName_);
148
150 (
151 IndirectList<face>(mesh_.faces(), subSet.toc()),
152 mesh_.points()
153 );
154
156 (
157 pointIndexHit(false, Zero, -1),
158 Tuple2<scalar, label>
159 (
160 sqr(GREAT),
162 )
163 );
164
165 forAll(patch, i)
166 {
167 const point& fc = patch.faceCentres()[i];
168 scalar d2 = magSqr(fc-nearPoint_);
169
170 if (!ni.first().hit() || d2 < ni.second().first())
171 {
172 ni.second().first() = d2;
173 ni.first().setHit();
174 ni.first().setPoint(fc);
175 ni.first().setIndex(i);
176 }
177 }
178
179 // Globally reduce
180 Pstream::combineAllGather(ni, mappedPatchBase::nearestEqOp());
181
182 if (verbose_)
183 {
184 Info<< " Found nearest face at " << ni.first().rawPoint()
185 << " on processor " << ni.second().second()
186 << " face " << ni.first().index()
187 << " distance " << Foam::sqrt(ni.second().first()) << endl;
188 }
189
190 labelList faceRegion(patch.size(), -1);
191 markZone
192 (
193 patch,
194 ni.second().second(), // proci
195 ni.first().index(), // start face
196 0, // currentZone
197 faceRegion
198 );
199
200 forAll(faceRegion, facei)
201 {
202 if (faceRegion[facei] == 0)
203 {
204 addOrDelete(set, patch.addressing()[facei], add);
205 }
206 }
207}
208
209
210// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
211
213(
214 const polyMesh& mesh,
215 const word& setName,
216 const point& nearPoint
217)
218:
220 setName_(setName),
221 nearPoint_(nearPoint)
222{}
223
224
226(
227 const polyMesh& mesh,
228 const dictionary& dict
229)
230:
232 setName_(dict.get<word>("set")),
233 nearPoint_(dict.get<point>("nearPoint"))
234{}
235
236
238(
239 const polyMesh& mesh,
240 Istream& is
241)
242:
244 setName_(checkIs(is)),
245 nearPoint_(checkIs(is))
246{}
247
248
249// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
250
252(
253 const topoSetSource::setAction action,
254 topoSet& set
255) const
256{
257 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
258 {
259 if (verbose_)
260 {
261 Info<< " Adding all faces of connected region of set "
262 << setName_ << " starting from point " << nearPoint_
263 << " ..." << endl;
264 }
265
266 combine(set, true);
267 }
268 else if (action == topoSetSource::SUBTRACT)
269 {
270 if (verbose_)
271 {
272 Info<< " Removing all cells of connected region of set "
273 << setName_ << " starting from point " << nearPoint_
274 << " ..." << endl;
275 }
276
277 combine(set, false);
278 }
279}
280
281
282// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
static void combineAllGather(const List< commsStruct > &comms, T &value, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Tuple2< pointIndexHit, Tuple2< scalar, label > > nearInfo
Helper class for finding nearest.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
int myProcNo() const noexcept
Return processor number.
A topoSetFaceSource to select cells belonging to a topologically connected region (that contains give...
Definition: regionToFace.H:155
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Apply specified action to the topoSet.
Definition: regionToFace.C:252
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
Definition: topoSetSource.H:68
setAction
Enumeration defining various actions.
@ SUBTRACT
Subtract elements from current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
const polyMesh & mesh_
Reference to the mesh.
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:67
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
const std::string patch
OpenFOAM patch number as a std::string.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
dimensionedSymmTensor sqr(const dimensionedVector &dv)
PointIndexHit< point > pointIndexHit
A PointIndexHit for 3D points.
Definition: pointIndexHit.H:46
messageStream Info
Information stream (stdout output on master, null elsewhere)
vector point
Point is a vector.
Definition: point.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensionedScalar sqrt(const dimensionedScalar &ds)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333