Loading...
Searching...
No Matches
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-2024 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"
39// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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,
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
140(
141 topoSet& set,
142 const bool add,
143 const labelUList& ids
144) const
145{
146 if (verbose_)
147 {
148 Info<< " Loading subset " << setName_
149 << " to delimit search region." << nl;
150 }
151
153 (
154 IndirectList<face>(mesh_.faces(), ids),
155 mesh_.points()
156 );
157
159 (
160 pointIndexHit(false, Zero, -1),
162 (
163 sqr(GREAT),
165 )
166 );
167
168 forAll(patch, i)
169 {
170 const point& fc = patch.faceCentres()[i];
171 scalar d2 = magSqr(fc-nearPoint_);
172
173 if (!ni.first().hit() || d2 < ni.second().first())
174 {
175 ni.second().first() = d2;
176 ni.first().hitPoint(fc);
177 ni.first().setIndex(i);
178 }
179 }
180
181 // Globally reduce
183
184 if (verbose_)
185 {
186 Info<< " Found nearest face at " << ni.first().point()
187 << " on processor " << ni.second().second()
188 << " face " << ni.first().index()
189 << " distance " << Foam::sqrt(ni.second().first()) << endl;
190 }
191
192 labelList faceRegion(patch.size(), -1);
193 markZone
194 (
195 patch,
196 ni.second().second(), // proci
197 ni.first().index(), // start face
198 0, // currentZone
199 faceRegion
200 );
201
202 forAll(faceRegion, facei)
203 {
204 if (faceRegion[facei] == 0)
205 {
206 addOrDelete(set, patch.addressing()[facei], add);
208 }
209}
210
211
212// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
213
215(
216 const polyMesh& mesh,
217 const word& setName,
218 const point& nearPoint
219)
220:
222 setName_(setName),
223 isZone_(false),
224 nearPoint_(nearPoint)
225{}
226
227
229(
230 const polyMesh& mesh,
231 const dictionary& dict
232)
233:
235 setName_(),
236 isZone_(false),
237 nearPoint_(dict.get<point>("nearPoint"))
238{
239 // A single "set" or "zone" only
240 if (!dict.readIfPresent("set", setName_))
241 {
242 // Mandatory entry
243 dict.readEntry("zone", setName_);
244 isZone_ = true;
245 }
246}
247
248
250(
251 const polyMesh& mesh,
252 Istream& is
253)
254:
256 setName_(checkIs(is)),
257 isZone_(false),
258 nearPoint_(checkIs(is))
259{}
260
261
262// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
263
265(
266 const topoSetSource::setAction action,
267 topoSet& set
268) const
269{
270 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
271 {
272 if (verbose_)
273 {
274 Info<< " Adding all faces of connected region of "
275 << (isZone_ ? "zone " : "set ")
276 << setName_ << " starting from point " << nearPoint_
277 << " ..." << endl;
278 }
279
280 if (isZone_)
281 {
282 combine(set, true, mesh_.faceZones()[setName_].addressing());
283 }
284 else
285 {
286 faceSet subSet(mesh_, setName_, IOobject::NO_REGISTER);
287 combine(set, true, subSet.sortedToc());
288 }
289 }
290 else if (action == topoSetSource::SUBTRACT)
291 {
292 if (verbose_)
293 {
294 Info<< " Removing all cells of connected region of "
295 << (isZone_ ? "zone " : "set ")
296 << setName_ << " starting from point " << nearPoint_
297 << " ..." << endl;
298 }
299
300 if (isZone_)
301 {
302 combine(set, false, mesh_.faceZones()[setName_].addressing());
303 }
304 else
305 {
306 faceSet subSet(mesh_, setName_, IOobject::NO_REGISTER);
307 combine(set, false, subSet.sortedToc());
308 }
309 }
310}
311
312
313// ************************************************************************* //
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.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition HashTable.C:156
@ NO_REGISTER
Do not request registration (bool: false).
A List with indirect addressing.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
static void combineReduce(T &value, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition Tuple2.H:51
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
Definition UPstream.H:1706
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A list of face labels.
Definition faceSet.H:50
Tuple2< pointIndexHit, Tuple2< scalar, label > > nearInfo
Helper class for finding nearest.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A topoSetFaceSource to select cells belonging to a topologically connected region (that contains give...
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Apply specified action to the topoSet.
regionToFace(const polyMesh &mesh, const word &setName, const point &nearPoint)
Construct from components.
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
topoSetFaceSource(const polyMesh &mesh)
Construct from mesh.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
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.
bool verbose_
Output verbosity (default: true).
const polyMesh & mesh() const noexcept
Reference to the mesh.
const polyMesh & mesh_
Reference to the mesh.
static Istream & checkIs(Istream &is)
Check state of stream.
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
List< wallPoints > allFaceInfo(mesh_.nFaces())
const std::string patch
OpenFOAM patch number as a std::string.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
dimensionedSymmTensor sqr(const dimensionedVector &dv)
messageStream Info
Information stream (stdout output on master, null elsewhere).
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.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
dimensionedScalar sqrt(const dimensionedScalar &ds)
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field.
vector point
Point is a vector.
Definition point.H:37
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
UList< label > labelUList
A UList of labels.
Definition UList.H:75
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299