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-2022 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 "RemoteData.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 {
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 
106  (
107  IndirectList<face>(mesh_.faces(), subSet.toc()),
108  mesh_.points()
109  );
110 
111  RemoteData<scalar> ni;
112 
113  forAll(patch, i)
114  {
115  const point& fc = patch.faceCentres()[i];
116 
117  const scalar dSqr = magSqr(fc - nearPoint_);
118 
119  if (ni.proci == -1 || dSqr < ni.data)
120  {
121  ni.proci = Pstream::myProcNo();
122  ni.elementi = i;
123  ni.data = dSqr;
124  }
125  }
126 
127  // Globally reduce
128  combineReduce(ni, RemoteData<scalar>::smallestEqOp());
129 
130  Info<< " Found nearest face on processor " << ni.proci
131  << " face " << ni.elementi
132  << " distance " << Foam::sqrt(ni.data) << endl;
133 
134  labelList faceRegion(patch.size(), -1);
135  markZone
136  (
137  patch,
138  ni.proci,
139  ni.elementi,
140  0,
141  faceRegion
142  );
143 
144  forAll(faceRegion, facei)
145  {
146  if (faceRegion[facei] == 0)
147  {
148  addOrDelete(set, patch.addressing()[facei], add);
149  }
150  }
151 }
152 
153 
154 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
155 
157 (
158  const polyMesh& mesh,
159  const word& setName,
160  const point& nearPoint
161 )
162 :
163  topoSetSource(mesh),
164  setName_(setName),
165  nearPoint_(nearPoint)
166 {}
167 
168 
170 (
171  const polyMesh& mesh,
172  const dictionary& dict
173 )
174 :
175  topoSetSource(mesh),
176  setName_(dict.lookup("set")),
177  nearPoint_(dict.lookup("nearPoint"))
178 {}
179 
180 
181 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
182 
184 {}
185 
186 
187 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
188 
190 (
191  const topoSetSource::setAction action,
192  topoSet& set
193 ) const
194 {
195  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
196  {
197  Info<< " Adding all faces of connected region of set "
198  << setName_
199  << " starting from point "
200  << nearPoint_ << " ..." << endl;
201 
202  combine(set, true);
203  }
204  else if (action == topoSetSource::DELETE)
205  {
206  Info<< " Removing all cells of connected region of set "
207  << setName_
208  << " starting from point "
209  << nearPoint_ << " ..." << endl;
210 
211  combine(set, false);
212  }
213 }
214 
215 
216 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
A topoSetSource to select faces belonging to topological connected region (that contains given point)
Definition: regionToFace.H:54
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: regionToFace.C:190
regionToFace(const polyMesh &mesh, const word &setName, const point &nearPoint)
Construct from components.
Definition: regionToFace.C:157
virtual ~regionToFace()
Destructor.
Definition: regionToFace.C:183
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:65
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
vector point
Point is a vector.
Definition: point.H:41
dimensionedScalar sqrt(const dimensionedScalar &ds)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
Foam::indirectPrimitivePatch.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
void combineReduce(const List< UPstream::commsStruct > &comms, T &Value, const CombineOp &cop, const int tag, const label comm)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
dictionary dict