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 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 
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 
62 (
63  const indirectPrimitivePatch& patch,
64  const label procI,
65  const label faceI,
66  const label zoneI,
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;
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
89  <
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 
120  (
121  IndirectList<face>(mesh_.faces(), subSet.toc()),
122  mesh_.points()
123  );
124 
126  (
127  pointIndexHit(false, vector::zero, -1),
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
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 :
188  setName_(setName),
189  nearPoint_(nearPoint)
190 {}
191 
192 
193 // Construct from dictionary
195 (
196  const polyMesh& mesh,
197  const dictionary& dict
198 )
199 :
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 :
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 // ************************************************************************* //
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::regionToFace::setName_
word setName_
Name of set to use.
Definition: regionToFace.H:61
Foam::topoSetSource::ADD
@ ADD
Definition: topoSetSource.H:87
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:86
Foam::HashTable::toc
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:201
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList< label >
Foam::Tuple2::second
const Type2 & second() const
Return second.
Definition: Tuple2.H:106
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::ListListOps::combine
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Foam::PatchEdgeFaceWave
Wave propagation of information along patch. Every iteration information goes through one layer of fa...
Definition: PatchEdgeFaceWave.H:69
Foam::PrimitivePatch::nEdges
label nEdges() const
Return number of edges in patch.
Definition: PrimitivePatchTemplate.H:299
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:100
Foam::indirectPrimitivePatch
PrimitivePatch< face, IndirectList, const pointField & > indirectPrimitivePatch
Foam::indirectPrimitivePatch.
Definition: indirectPrimitivePatch.H:45
Foam::calc
void calc(const argList &args, const Time &runTime, const fvMesh &mesh)
Definition: Lambda2.C:38
Foam::Tuple2::first
const Type1 & first() const
Return first.
Definition: Tuple2.H:94
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::combineReduce
void combineReduce(const List< UPstream::commsStruct > &comms, T &Value, const CombineOp &cop, const int tag, const label comm)
Definition: PstreamCombineReduceOps.H:52
Foam::faceSet
A list of face labels.
Definition: faceSet.H:48
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Foam::regionToFace::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: regionToFace.C:228
Foam::PrimitivePatch::faceEdges
const labelListList & faceEdges() const
Return face-edge addressing.
Definition: PrimitivePatchTemplate.C:312
Foam::topoSetSource::NEW
@ NEW
Definition: topoSetSource.H:85
Foam::mappedPatchBase::nearestEqOp
Definition: mappedPatchBase.H:139
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::regionToFace::usage_
static addToUsageTable usage_
Add usage string.
Definition: regionToFace.H:58
Foam::regionToFace::regionToFace
regionToFace(const polyMesh &mesh, const word &setName, const point &nearPoint)
Construct from components.
Definition: regionToFace.C:181
PatchEdgeFaceWave.H
Foam::label
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
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Info
messageStream Info
faceSet.H
Foam::IndirectList
A List with indirect addressing.
Definition: IndirectList.H:102
Foam::topoSetSource::DELETE
@ DELETE
Definition: topoSetSource.H:88
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Foam::regionToFace::markZone
void markZone(const indirectPrimitivePatch &patch, const label procI, const label faceI, const label zoneI, labelList &faceZone) const
Walk edge-face-edge.
Definition: regionToFace.C:62
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
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:870
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:405
Foam::regionToFace::nearPoint_
point nearPoint_
Coordinate that is nearest/on connected region.
Definition: regionToFace.H:64
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::pointIndexHit
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:42
Foam::regionToFace::~regionToFace
virtual ~regionToFace()
Destructor.
Definition: regionToFace.C:221
Foam::sumOp
Definition: ops.H:162
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:142
Foam::patchEdgeFaceRegion
Transport of region for use in PatchEdgeFaceWave.
Definition: patchEdgeFaceRegion.H:59
Foam::PrimitivePatch::faceCentres
const Field< PointType > & faceCentres() const
Return face centres for patch.
Definition: PrimitivePatchTemplate.C:500
Foam::Tuple2
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:47
regionToFace.H
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Definition: topoSetSource.H:126
Foam::regionToFace::combine
void combine(topoSet &set, const bool add) const
Definition: regionToFace.C:113
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
patchEdgeFaceRegion.H
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label cellI, const bool) const
Add (if bool) cellI to set or delete cellI from set.
Definition: topoSetSource.C:140
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88
mappedPatchBase.H