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 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 "patchEdgeFaceRegion.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<patchEdgeFaceRegion> allEdgeInfo(patch.nEdges());
87  List<patchEdgeFaceRegion> allFaceInfo(patch.size());
88 
89  DynamicList<label> changedEdges;
90  DynamicList<patchEdgeFaceRegion> 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(zoneI);
99  }
100  }
101 
102  // Walk
103  PatchEdgeFaceWave
104  <
106  patchEdgeFaceRegion
107  > calc
108  (
109  mesh_,
110  patch,
111  changedEdges,
112  changedInfo,
113  allEdgeInfo,
114  allFaceInfo,
115  returnReduce(patch.nEdges(), sumOp<label>())
116  );
117 
118  forAll(allFaceInfo, facei)
119  {
120  if (allFaceInfo[facei].region() == zoneI)
121  {
122  faceZone[facei] = zoneI;
123  }
124  }
125 }
126 
127 
128 void Foam::regionToFace::combine(topoSet& set, const bool add) const
129 {
130  if (verbose_)
131  {
132  Info<< " Loading subset " << setName_
133  << " to delimit search region." << endl;
134  }
135 
136  faceSet subSet(mesh_, setName_);
137 
139  (
140  IndirectList<face>(mesh_.faces(), subSet.toc()),
141  mesh_.points()
142  );
143 
145  (
146  pointIndexHit(false, Zero, -1),
147  Tuple2<scalar, label>
148  (
149  sqr(GREAT),
151  )
152  );
153 
154  forAll(patch, i)
155  {
156  const point& fc = patch.faceCentres()[i];
157  scalar d2 = magSqr(fc-nearPoint_);
158 
159  if (!ni.first().hit() || d2 < ni.second().first())
160  {
161  ni.second().first() = d2;
162  ni.first().setHit();
163  ni.first().setPoint(fc);
164  ni.first().setIndex(i);
165  }
166  }
167 
168  // Globally reduce
169  combineReduce(ni, mappedPatchBase::nearestEqOp());
170 
171  if (verbose_)
172  {
173  Info<< " Found nearest face at " << ni.first().rawPoint()
174  << " on processor " << ni.second().second()
175  << " face " << ni.first().index()
176  << " distance " << Foam::sqrt(ni.second().first()) << endl;
177  }
178 
179  labelList faceRegion(patch.size(), -1);
180  markZone
181  (
182  patch,
183  ni.second().second(), // proci
184  ni.first().index(), // start face
185  0, // currentZone
186  faceRegion
187  );
188 
189  forAll(faceRegion, facei)
190  {
191  if (faceRegion[facei] == 0)
192  {
193  addOrDelete(set, patch.addressing()[facei], add);
194  }
195  }
196 }
197 
198 
199 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
200 
202 (
203  const polyMesh& mesh,
204  const word& setName,
205  const point& nearPoint
206 )
207 :
209  setName_(setName),
210  nearPoint_(nearPoint)
211 {}
212 
213 
215 (
216  const polyMesh& mesh,
217  const dictionary& dict
218 )
219 :
221  setName_(dict.get<word>("set")),
222  nearPoint_(dict.get<point>("nearPoint"))
223 {}
224 
225 
227 (
228  const polyMesh& mesh,
229  Istream& is
230 )
231 :
233  setName_(checkIs(is)),
234  nearPoint_(checkIs(is))
235 {}
236 
237 
238 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
239 
241 (
242  const topoSetSource::setAction action,
243  topoSet& set
244 ) const
245 {
246  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
247  {
248  if (verbose_)
249  {
250  Info<< " Adding all faces of connected region of set "
251  << setName_ << " starting from point " << nearPoint_
252  << " ..." << endl;
253  }
254 
255  combine(set, true);
256  }
257  else if (action == topoSetSource::SUBTRACT)
258  {
259  if (verbose_)
260  {
261  Info<< " Removing all cells of connected region of set "
262  << setName_ << " starting from point " << nearPoint_
263  << " ..." << endl;
264  }
265 
266  combine(set, false);
267  }
268 }
269 
270 
271 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
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.
Definition: zero.H:128
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:337
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:241
Foam::topoSetFaceSource
Base class of a topoSet source for selecting faces.
Definition: topoSetFaceSource.H:50
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:290
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:202
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:62
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:66
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
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:444
Foam::indirectPrimitivePatch
PrimitivePatch< face, IndirectList, const pointField & > indirectPrimitivePatch
A PrimitivePatch using an IndirectList for the faces.
Definition: indirectPrimitivePatch.H:47
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)
patchEdgeFaceRegion.H
mappedPatchBase.H