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-2020 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().setHit();
174  ni.first().setPoint(fc);
175  ni.first().setIndex(i);
176  }
177  }
178 
179  // Globally reduce
180  combineReduce(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 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::topoSetSource::ADD
Add elements to current set.
Definition: topoSetSource.H:103
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
PatchTools.H
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:129
Foam::combineReduce
void combineReduce(const List< UPstream::commsStruct > &comms, T &Value, const CombineOp &cop, const int tag, const label comm)
Definition: PstreamCombineReduceOps.H:54
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
Foam::regionToFace::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Apply specified action to the topoSet.
Definition: regionToFace.C:252
Foam::topoSetFaceSource
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
Definition: topoSetFaceSource.H:54
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:104
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::regionToFace::regionToFace
regionToFace(const polyMesh &mesh, const word &setName, const point &nearPoint)
Construct from components.
Definition: regionToFace.C:213
PatchEdgeFaceWave.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
faceSet.H
Foam::mappedPatchBase::nearInfo
Tuple2< pointIndexHit, Tuple2< scalar, label > > nearInfo
Helper class for finding nearest.
Definition: mappedPatchBase.H:147
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
indirectPrimitivePatch.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::topoSetSource::SUBTRACT
Subtract elements from current set.
Definition: topoSetSource.H:105
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
edgeTopoDistanceData.H
Foam::indirectPrimitivePatch
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field.
Definition: indirectPrimitivePatch.H:49
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::pointIndexHit
PointIndexHit< point > pointIndexHit
A PointIndexHit for 3D points.
Definition: pointIndexHit.H:46
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:463
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::Vector< scalar >
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::point
vector point
Point is a vector.
Definition: point.H:43
regionToFace.H
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:156
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
mappedPatchBase.H