regionToFace.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "regionToFace.H"
27 #include "polyMesh.H"
28 #include "faceSet.H"
29 #include "mappedPatchBase.H"
30 #include "indirectPrimitivePatch.H"
31 #include "PatchTools.H"
33 #include "PatchEdgeFaceWave.H"
34 #include "patchEdgeFaceRegion.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(regionToFace, 0);
41  addToRunTimeSelectionTable(topoSetSource, regionToFace, word);
42  addToRunTimeSelectionTable(topoSetSource, regionToFace, istream);
43 }
44 
45 
46 Foam::topoSetSource::addToUsageTable Foam::regionToFace::usage_
47 (
48  regionToFace::typeName,
49  "\n Usage: regionToFace <faceSet> (x y z)\n\n"
50  " Select all faces in the connected region of the faceSet"
51  " starting from the point.\n"
52 );
53 
54 
55 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
56 
57 void Foam::regionToFace::markZone
58 (
59  const indirectPrimitivePatch& patch,
60  const label proci,
61  const label facei,
62  const label zoneI,
63  labelList& faceZone
64 ) const
65 {
66  // Data on all edges and faces
67  List<patchEdgeFaceRegion> allEdgeInfo(patch.nEdges());
68  List<patchEdgeFaceRegion> allFaceInfo(patch.size());
69 
70  DynamicList<label> changedEdges;
71  DynamicList<patchEdgeFaceRegion> changedInfo;
72 
73  if (Pstream::myProcNo() == proci)
74  {
75  const labelList& fEdges = patch.faceEdges()[facei];
76  forAll(fEdges, i)
77  {
78  changedEdges.append(fEdges[i]);
79  changedInfo.append(zoneI);
80  }
81  }
82 
83  // Walk
84  PatchEdgeFaceWave
85  <
87  patchEdgeFaceRegion
88  > calc
89  (
90  mesh_,
91  patch,
92  changedEdges,
93  changedInfo,
94  allEdgeInfo,
95  allFaceInfo,
96  returnReduce(patch.nEdges(), sumOp<label>())
97  );
98 
99  forAll(allFaceInfo, facei)
100  {
101  if (allFaceInfo[facei].region() == zoneI)
102  {
103  faceZone[facei] = zoneI;
104  }
105  }
106 }
107 
108 
109 void Foam::regionToFace::combine(topoSet& set, const bool add) const
110 {
111  Info<< " Loading subset " << setName_ << " to delimit search region."
112  << endl;
113  faceSet subSet(mesh_, setName_);
114 
115  indirectPrimitivePatch patch
116  (
117  IndirectList<face>(mesh_.faces(), subSet.toc()),
118  mesh_.points()
119  );
120 
122  (
123  pointIndexHit(false, Zero, -1),
124  Tuple2<scalar, label>
125  (
126  sqr(great),
128  )
129  );
130 
131  forAll(patch, i)
132  {
133  const point& fc = patch.faceCentres()[i];
134  scalar d2 = magSqr(fc-nearPoint_);
135 
136  if (!ni.first().hit() || d2 < ni.second().first())
137  {
138  ni.second().first() = d2;
139  ni.first().setHit();
140  ni.first().setPoint(fc);
141  ni.first().setIndex(i);
142  }
143  }
144 
145  // Globally reduce
146  combineReduce(ni, mappedPatchBase::nearestEqOp());
147 
148  Info<< " Found nearest face at " << ni.first().rawPoint()
149  << " on processor " << ni.second().second()
150  << " face " << ni.first().index()
151  << " distance " << Foam::sqrt(ni.second().first()) << endl;
152 
153  labelList faceRegion(patch.size(), -1);
154  markZone
155  (
156  patch,
157  ni.second().second(), // proci
158  ni.first().index(), // start face
159  0, // currentZone
160  faceRegion
161  );
162 
163  forAll(faceRegion, facei)
164  {
165  if (faceRegion[facei] == 0)
166  {
167  addOrDelete(set, patch.addressing()[facei], add);
168  }
169  }
170 }
171 
172 
173 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
174 
176 (
177  const polyMesh& mesh,
178  const word& setName,
179  const point& nearPoint
180 )
181 :
182  topoSetSource(mesh),
183  setName_(setName),
184  nearPoint_(nearPoint)
185 {}
186 
187 
189 (
190  const polyMesh& mesh,
191  const dictionary& dict
192 )
193 :
194  topoSetSource(mesh),
195  setName_(dict.lookup("set")),
196  nearPoint_(dict.lookup("nearPoint"))
197 {}
198 
199 
201 (
202  const polyMesh& mesh,
203  Istream& is
204 )
205 :
206  topoSetSource(mesh),
207  setName_(checkIs(is)),
208  nearPoint_(checkIs(is))
209 {}
210 
211 
212 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
213 
215 {}
216 
217 
218 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
219 
221 (
222  const topoSetSource::setAction action,
223  topoSet& set
224 ) const
225 {
226  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
227  {
228  Info<< " Adding all faces of connected region of set "
229  << setName_
230  << " starting from point "
231  << nearPoint_ << " ..." << endl;
232 
233  combine(set, true);
234  }
235  else if (action == topoSetSource::DELETE)
236  {
237  Info<< " Removing all cells of connected region of set "
238  << setName_
239  << " starting from point "
240  << nearPoint_ << " ..." << endl;
241 
242  combine(set, false);
243  }
244 }
245 
246 
247 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void combineReduce(const List< UPstream::commsStruct > &comms, T &Value, const CombineOp &cop, const int tag, const label comm)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: regionToFace.C:221
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
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:42
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
Foam::indirectPrimitivePatch.
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
List< label > labelList
A List of labels.
Definition: labelList.H:56
static const zero Zero
Definition: zero.H:97
virtual ~regionToFace()
Destructor.
Definition: regionToFace.C:214
dimensioned< scalar > magSqr(const dimensioned< Type > &)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
regionToFace(const polyMesh &mesh, const word &setName, const point &nearPoint)
Construct from components.
Definition: regionToFace.C:176
Tuple2< pointIndexHit, Tuple2< scalar, label > > nearInfo
Helper class for finding nearest.
vector point
Point is a vector.
Definition: point.H:41
Class with constructor to add usage string to table.
messageStream Info
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812