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-2021 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 }
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
47 void Foam::regionToFace::markZone
48 (
49  const indirectPrimitivePatch& patch,
50  const label proci,
51  const label facei,
52  const label zoneI,
53  labelList& faceZone
54 ) const
55 {
56  // Data on all edges and faces
57  List<patchEdgeFaceRegion> allEdgeInfo(patch.nEdges());
58  List<patchEdgeFaceRegion> allFaceInfo(patch.size());
59 
60  DynamicList<label> changedEdges;
61  DynamicList<patchEdgeFaceRegion> changedInfo;
62 
63  if (Pstream::myProcNo() == proci)
64  {
65  const labelList& fEdges = patch.faceEdges()[facei];
66  forAll(fEdges, i)
67  {
68  changedEdges.append(fEdges[i]);
69  changedInfo.append(zoneI);
70  }
71  }
72 
73  // Walk
74  PatchEdgeFaceWave
75  <
77  patchEdgeFaceRegion
78  > calc
79  (
80  mesh_,
81  patch,
82  changedEdges,
83  changedInfo,
84  allEdgeInfo,
85  allFaceInfo,
86  returnReduce(patch.nEdges(), sumOp<label>())
87  );
88 
89  forAll(allFaceInfo, facei)
90  {
91  if (allFaceInfo[facei].region() == zoneI)
92  {
93  faceZone[facei] = zoneI;
94  }
95  }
96 }
97 
98 
99 void Foam::regionToFace::combine(topoSet& set, const bool add) const
100 {
101  Info<< " Loading subset " << setName_ << " to delimit search region."
102  << endl;
103  faceSet subSet(mesh_, setName_);
104 
105  indirectPrimitivePatch patch
106  (
107  IndirectList<face>(mesh_.faces(), subSet.toc()),
108  mesh_.points()
109  );
110 
112  (
113  pointIndexHit(false, Zero, -1),
114  Tuple2<scalar, label>
115  (
116  sqr(great),
118  )
119  );
120 
121  forAll(patch, i)
122  {
123  const point& fc = patch.faceCentres()[i];
124  scalar d2 = magSqr(fc-nearPoint_);
125 
126  if (!ni.first().hit() || d2 < ni.second().first())
127  {
128  ni.second().first() = d2;
129  ni.first().setHit();
130  ni.first().setPoint(fc);
131  ni.first().setIndex(i);
132  }
133  }
134 
135  // Globally reduce
136  combineReduce(ni, mappedPatchBase::nearestEqOp());
137 
138  Info<< " Found nearest face at " << ni.first().rawPoint()
139  << " on processor " << ni.second().second()
140  << " face " << ni.first().index()
141  << " distance " << Foam::sqrt(ni.second().first()) << endl;
142 
143  labelList faceRegion(patch.size(), -1);
144  markZone
145  (
146  patch,
147  ni.second().second(), // proci
148  ni.first().index(), // start face
149  0, // currentZone
150  faceRegion
151  );
152 
153  forAll(faceRegion, facei)
154  {
155  if (faceRegion[facei] == 0)
156  {
157  addOrDelete(set, patch.addressing()[facei], add);
158  }
159  }
160 }
161 
162 
163 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
164 
166 (
167  const polyMesh& mesh,
168  const word& setName,
169  const point& nearPoint
170 )
171 :
172  topoSetSource(mesh),
173  setName_(setName),
174  nearPoint_(nearPoint)
175 {}
176 
177 
179 (
180  const polyMesh& mesh,
181  const dictionary& dict
182 )
183 :
184  topoSetSource(mesh),
185  setName_(dict.lookup("set")),
186  nearPoint_(dict.lookup("nearPoint"))
187 {}
188 
189 
190 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
191 
193 {}
194 
195 
196 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
197 
199 (
200  const topoSetSource::setAction action,
201  topoSet& set
202 ) const
203 {
204  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
205  {
206  Info<< " Adding all faces of connected region of set "
207  << setName_
208  << " starting from point "
209  << nearPoint_ << " ..." << endl;
210 
211  combine(set, true);
212  }
213  else if (action == topoSetSource::DELETE)
214  {
215  Info<< " Removing all cells of connected region of set "
216  << setName_
217  << " starting from point "
218  << nearPoint_ << " ..." << endl;
219 
220  combine(set, false);
221  }
222 }
223 
224 
225 // ************************************************************************* //
#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)
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: regionToFace.C:199
dimensionedSymmTensor sqr(const dimensionedVector &dv)
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.
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:192
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:166
Tuple2< pointIndexHit, Tuple2< scalar, label > > nearInfo
Helper class for finding nearest.
vector point
Point is a vector.
Definition: point.H:41
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:76
Namespace for OpenFOAM.
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:77
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864