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 -------------------------------------------------------------------------------
11 License
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"
33 #include "indirectPrimitivePatch.H"
34 #include "PatchTools.H"
36 #include "PatchEdgeFaceWave.H"
37 #include "edgeTopoDistanceData.H"
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43  defineTypeNameAndDebug(regionToFace, 0);
44  addToRunTimeSelectionTable(topoSetSource, regionToFace, word);
45  addToRunTimeSelectionTable(topoSetSource, regionToFace, istream);
46  addToRunTimeSelectionTable(topoSetFaceSource, regionToFace, word);
47  addToRunTimeSelectionTable(topoSetFaceSource, regionToFace, istream);
49  (
50  topoSetFaceSource,
51  regionToFace,
52  word,
53  region
54  );
56  (
57  topoSetFaceSource,
58  regionToFace,
59  istream,
60  region
61  );
62 }
63 
64 
65 Foam::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 
76 void Foam::regionToFace::markZone
77 (
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 
139 void 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().hitPoint(fc);
174  ni.first().setIndex(i);
175  }
176  }
177 
178  // Globally reduce
179  Pstream::combineReduce(ni, mappedPatchBase::nearestEqOp());
180 
181  if (verbose_)
182  {
183  Info<< " Found nearest face at " << ni.first().point()
184  << " on processor " << ni.second().second()
185  << " face " << ni.first().index()
186  << " distance " << Foam::sqrt(ni.second().first()) << endl;
187  }
188 
189  labelList faceRegion(patch.size(), -1);
190  markZone
191  (
192  patch,
193  ni.second().second(), // proci
194  ni.first().index(), // start face
195  0, // currentZone
196  faceRegion
197  );
198 
199  forAll(faceRegion, facei)
200  {
201  if (faceRegion[facei] == 0)
202  {
203  addOrDelete(set, patch.addressing()[facei], add);
204  }
205  }
206 }
207 
208 
209 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
210 
212 (
213  const polyMesh& mesh,
214  const word& setName,
215  const point& nearPoint
216 )
217 :
219  setName_(setName),
220  nearPoint_(nearPoint)
221 {}
222 
223 
225 (
226  const polyMesh& mesh,
227  const dictionary& dict
228 )
229 :
231  setName_(dict.get<word>("set")),
232  nearPoint_(dict.get<point>("nearPoint"))
233 {}
234 
235 
237 (
238  const polyMesh& mesh,
239  Istream& is
240 )
241 :
243  setName_(checkIs(is)),
244  nearPoint_(checkIs(is))
245 {}
246 
247 
248 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
249 
251 (
252  const topoSetSource::setAction action,
253  topoSet& set
254 ) const
255 {
256  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
257  {
258  if (verbose_)
259  {
260  Info<< " Adding all faces of connected region of set "
261  << setName_ << " starting from point " << nearPoint_
262  << " ..." << endl;
263  }
264 
265  combine(set, true);
266  }
267  else if (action == topoSetSource::SUBTRACT)
268  {
269  if (verbose_)
270  {
271  Info<< " Removing all cells of connected region of set "
272  << setName_ << " starting from point " << nearPoint_
273  << " ..." << endl;
274  }
275 
276  combine(set, false);
277  }
278 }
279 
280 
281 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Apply specified action to the topoSet.
Definition: regionToFace.C:244
Create a new set and ADD elements to it.
Add elements to current set.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
Definition: pointIndexHit.H:58
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
Definition: UPstream.H:1074
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field...
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:62
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces...
setAction
Enumeration defining various actions.
static void combineReduce(const List< commsStruct > &comms, T &value, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors...
const polyMesh & mesh_
Reference to the mesh.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
Subtract elements from current set.
regionToFace(const polyMesh &mesh, const word &setName, const point &nearPoint)
Construct from components.
Definition: regionToFace.C:205
Tuple2< pointIndexHit, Tuple2< scalar, label > > nearInfo
Helper class for finding nearest.
vector point
Point is a vector.
Definition: point.H:37
Class with constructor to add usage string to table.
const std::string patch
OpenFOAM patch number as a std::string.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< label > labelList
A List of labels.
Definition: List.H:62
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127