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 | Copyright (C) 2012-2016 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 
41 defineTypeNameAndDebug(regionToFace, 0);
42 
43 addToRunTimeSelectionTable(topoSetSource, regionToFace, word);
44 
45 addToRunTimeSelectionTable(topoSetSource, regionToFace, istream);
46 
47 }
48 
49 
50 Foam::topoSetSource::addToUsageTable Foam::regionToFace::usage_
51 (
52  regionToFace::typeName,
53  "\n Usage: regionToFace <faceSet> (x y z)\n\n"
54  " Select all faces in the connected region of the faceSet"
55  " starting from the point.\n"
56 );
57 
58 
59 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
60 
61 void Foam::regionToFace::markZone
62 (
63  const indirectPrimitivePatch& patch,
64  const label proci,
65  const label facei,
66  const label zoneI,
67  labelList& faceZone
68 ) const
69 {
70  // Data on all edges and faces
71  List<patchEdgeFaceRegion> allEdgeInfo(patch.nEdges());
72  List<patchEdgeFaceRegion> allFaceInfo(patch.size());
73 
74  DynamicList<label> changedEdges;
75  DynamicList<patchEdgeFaceRegion> changedInfo;
76 
77  if (Pstream::myProcNo() == proci)
78  {
79  const labelList& fEdges = patch.faceEdges()[facei];
80  forAll(fEdges, i)
81  {
82  changedEdges.append(fEdges[i]);
83  changedInfo.append(zoneI);
84  }
85  }
86 
87  // Walk
88  PatchEdgeFaceWave
89  <
91  patchEdgeFaceRegion
92  > calc
93  (
94  mesh_,
95  patch,
96  changedEdges,
97  changedInfo,
98  allEdgeInfo,
99  allFaceInfo,
100  returnReduce(patch.nEdges(), sumOp<label>())
101  );
102 
103  forAll(allFaceInfo, facei)
104  {
105  if (allFaceInfo[facei].region() == zoneI)
106  {
107  faceZone[facei] = zoneI;
108  }
109  }
110 }
111 
112 
113 void Foam::regionToFace::combine(topoSet& set, const bool add) const
114 {
115  Info<< " Loading subset " << setName_ << " to delimit search region."
116  << endl;
117  faceSet subSet(mesh_, setName_);
118 
119  indirectPrimitivePatch patch
120  (
121  IndirectList<face>(mesh_.faces(), subSet.toc()),
122  mesh_.points()
123  );
124 
126  (
127  pointIndexHit(false, Zero, -1),
128  Tuple2<scalar, label>
129  (
130  sqr(GREAT),
132  )
133  );
134 
135  forAll(patch, i)
136  {
137  const point& fc = patch.faceCentres()[i];
138  scalar d2 = magSqr(fc-nearPoint_);
139 
140  if (!ni.first().hit() || d2 < ni.second().first())
141  {
142  ni.second().first() = d2;
143  ni.first().setHit();
144  ni.first().setPoint(fc);
145  ni.first().setIndex(i);
146  }
147  }
148 
149  // Globally reduce
150  combineReduce(ni, mappedPatchBase::nearestEqOp());
151 
152  Info<< " Found nearest face at " << ni.first().rawPoint()
153  << " on processor " << ni.second().second()
154  << " face " << ni.first().index()
155  << " distance " << Foam::sqrt(ni.second().first()) << endl;
156 
157  labelList faceRegion(patch.size(), -1);
158  markZone
159  (
160  patch,
161  ni.second().second(), // proci
162  ni.first().index(), // start face
163  0, // currentZone
164  faceRegion
165  );
166 
167  forAll(faceRegion, facei)
168  {
169  if (faceRegion[facei] == 0)
170  {
171  addOrDelete(set, patch.addressing()[facei], add);
172  }
173  }
174 }
175 
176 
177 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
178 
179 // Construct from components
181 (
182  const polyMesh& mesh,
183  const word& setName,
184  const point& nearPoint
185 )
186 :
187  topoSetSource(mesh),
188  setName_(setName),
189  nearPoint_(nearPoint)
190 {}
191 
192 
193 // Construct from dictionary
195 (
196  const polyMesh& mesh,
197  const dictionary& dict
198 )
199 :
200  topoSetSource(mesh),
201  setName_(dict.lookup("set")),
202  nearPoint_(dict.lookup("nearPoint"))
203 {}
204 
205 
206 // Construct from Istream
208 (
209  const polyMesh& mesh,
210  Istream& is
211 )
212 :
213  topoSetSource(mesh),
214  setName_(checkIs(is)),
215  nearPoint_(checkIs(is))
216 {}
217 
218 
219 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
220 
222 {}
223 
224 
225 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
226 
228 (
229  const topoSetSource::setAction action,
230  topoSet& set
231 ) const
232 {
233  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
234  {
235  Info<< " Adding all faces of connected region of set "
236  << setName_
237  << " starting from point "
238  << nearPoint_ << " ..." << endl;
239 
240  combine(set, true);
241  }
242  else if (action == topoSetSource::DELETE)
243  {
244  Info<< " Removing all cells of connected region of set "
245  << setName_
246  << " starting from point "
247  << nearPoint_ << " ..." << endl;
248 
249  combine(set, false);
250  }
251 }
252 
253 
254 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:137
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: regionToFace.C:228
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:418
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:42
PrimitivePatch< face, IndirectList, 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:91
virtual ~regionToFace()
Destructor.
Definition: regionToFace.C:221
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:181
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:576