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 (allFaceInfo[facei].data() == zoneI)
128  {
129  faceZone[facei] = zoneI;
130  }
131  }
132 }
133 
134 
135 void Foam::regionToFace::combine(topoSet& set, const bool add) const
136 {
137  if (verbose_)
138  {
139  Info<< " Loading subset " << setName_
140  << " to delimit search region." << endl;
141  }
142 
143  faceSet subSet(mesh_, setName_);
144 
146  (
147  IndirectList<face>(mesh_.faces(), subSet.toc()),
148  mesh_.points()
149  );
150 
152  (
153  pointIndexHit(false, Zero, -1),
154  Tuple2<scalar, label>
155  (
156  sqr(GREAT),
158  )
159  );
160 
161  forAll(patch, i)
162  {
163  const point& fc = patch.faceCentres()[i];
164  scalar d2 = magSqr(fc-nearPoint_);
165 
166  if (!ni.first().hit() || d2 < ni.second().first())
167  {
168  ni.second().first() = d2;
169  ni.first().setHit();
170  ni.first().setPoint(fc);
171  ni.first().setIndex(i);
172  }
173  }
174 
175  // Globally reduce
176  combineReduce(ni, mappedPatchBase::nearestEqOp());
177 
178  if (verbose_)
179  {
180  Info<< " Found nearest face at " << ni.first().rawPoint()
181  << " on processor " << ni.second().second()
182  << " face " << ni.first().index()
183  << " distance " << Foam::sqrt(ni.second().first()) << endl;
184  }
185 
186  labelList faceRegion(patch.size(), -1);
187  markZone
188  (
189  patch,
190  ni.second().second(), // proci
191  ni.first().index(), // start face
192  0, // currentZone
193  faceRegion
194  );
195 
196  forAll(faceRegion, facei)
197  {
198  if (faceRegion[facei] == 0)
199  {
200  addOrDelete(set, patch.addressing()[facei], add);
201  }
202  }
203 }
204 
205 
206 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
207 
209 (
210  const polyMesh& mesh,
211  const word& setName,
212  const point& nearPoint
213 )
214 :
216  setName_(setName),
217  nearPoint_(nearPoint)
218 {}
219 
220 
222 (
223  const polyMesh& mesh,
224  const dictionary& dict
225 )
226 :
228  setName_(dict.get<word>("set")),
229  nearPoint_(dict.get<point>("nearPoint"))
230 {}
231 
232 
234 (
235  const polyMesh& mesh,
236  Istream& is
237 )
238 :
240  setName_(checkIs(is)),
241  nearPoint_(checkIs(is))
242 {}
243 
244 
245 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
246 
248 (
249  const topoSetSource::setAction action,
250  topoSet& set
251 ) const
252 {
253  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
254  {
255  if (verbose_)
256  {
257  Info<< " Adding all faces of connected region of set "
258  << setName_ << " starting from point " << nearPoint_
259  << " ..." << endl;
260  }
261 
262  combine(set, true);
263  }
264  else if (action == topoSetSource::SUBTRACT)
265  {
266  if (verbose_)
267  {
268  Info<< " Removing all cells of connected region of set "
269  << setName_ << " starting from point " << nearPoint_
270  << " ..." << endl;
271  }
272 
273  combine(set, false);
274  }
275 }
276 
277 
278 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::topoSetSource::ADD
Add elements to the set.
Definition: topoSetSource.H:101
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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:124
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:350
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
Foam::regionToFace::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Apply specified action to the topoSet.
Definition: regionToFace.C:248
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:81
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:106
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:209
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 (uses stdout - output is on the master only)
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:141
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:121
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 the set.
Definition: topoSetSource.H:102
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
edgeTopoDistanceData.H
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:445
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
Definition: pointIndexHit.H:45
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:151
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
mappedPatchBase.H