searchableSurfaceToFaceZone.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 
27 #include "polyMesh.H"
28 #include "faceZoneSet.H"
29 #include "searchableSurface.H"
30 #include "syncTools.H"
31 #include "Time.H"
32 
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(searchableSurfaceToFaceZone, 0);
41  (
42  topoSetSource,
43  searchableSurfaceToFaceZone,
44  word
45  );
46 }
47 
48 
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 
51 void Foam::searchableSurfaceToFaceZone::combine
52 (
53  faceZoneSet& fzSet,
54  const bool add
55 ) const
56 {
57  // Get a list of "interior" faces; i.e., either internal or coupled
58  labelList interiorFaceFaces(mesh_.nFaces());
59  {
60  forAll(mesh_.faceNeighbour(), facei)
61  {
62  interiorFaceFaces[facei] = facei;
63  }
64  label nInteriorFaces = mesh_.nInternalFaces();
65  forAll(mesh_.boundaryMesh(), patchi)
66  {
67  const polyPatch& patch = mesh_.boundaryMesh()[patchi];
68  if (patch.coupled())
69  {
70  forAll(patch, patchFacei)
71  {
72  const label facei = patch.start() + patchFacei;
73  interiorFaceFaces[nInteriorFaces] = facei;
74  ++ nInteriorFaces;
75  }
76  }
77  }
78  interiorFaceFaces.resize(nInteriorFaces);
79  }
80 
81  // Create owner and neighbour cell centre lists for all interior faces
82  pointField ownCc(interiorFaceFaces.size());
83  pointField nbrCc(interiorFaceFaces.size());
84  {
85  const pointField& cc = mesh_.cellCentres();
86 
87  vectorField boundaryNbrCc;
88  syncTools::swapBoundaryCellPositions(mesh_, cc, boundaryNbrCc);
89 
90  forAll(ownCc, interiorFacei)
91  {
92  const label facei = interiorFaceFaces[interiorFacei];
93 
94  ownCc[interiorFacei] = cc[mesh_.faceOwner()[facei]];
95  nbrCc[interiorFacei] =
96  mesh_.isInternalFace(facei)
97  ? cc[mesh_.faceNeighbour()[facei]]
98  : boundaryNbrCc[facei - mesh_.nInternalFaces()];
99  }
100  }
101 
102  // Do intersection tests on the vectors between the owner and neighbour
103  // cell centres, extended by the tolerance
104  List<pointIndexHit> hits;
105  pointField normals;
106  surfacePtr_().findLine
107  (
108  ownCc + tol_*(ownCc - nbrCc),
109  nbrCc - tol_*(ownCc - nbrCc),
110  hits
111  );
112  surfacePtr_().getNormal(hits, normals);
113 
114  // Create a list of labels indicating what side of the surface a cell
115  // is on; -1 is below, +1 is above, and 0 is too far from the surface
116  // for the sidedness to be calculable
117  labelList side(mesh_.nCells(), 0);
118  forAll(hits, interiorFacei)
119  {
120  if (hits[interiorFacei].hit())
121  {
122  const label facei = interiorFaceFaces[interiorFacei];
123 
124  const vector d = nbrCc[interiorFacei] - ownCc[interiorFacei];
125  const bool sign = (normals[interiorFacei] & d) < 0;
126 
127  side[mesh_.faceOwner()[facei]] = sign ? -1 : +1;
128 
129  if (mesh_.isInternalFace(facei))
130  {
131  side[mesh_.faceNeighbour()[facei]] = sign ? +1 : -1;
132  }
133  }
134  }
135  labelList boundaryNbrSide;
136  syncTools::swapBoundaryCellList(mesh_, side, boundaryNbrSide);
137 
138  // Create a face direction list indicating which direction a given face
139  // intersects the surface; -1 is backward, +1 is forward, and 0
140  // indicates that the face does not intersect the surface
141  labelList direction(mesh_.nFaces(), 0);
142  forAll(interiorFaceFaces, interiorFacei)
143  {
144  const label facei = interiorFaceFaces[interiorFacei];
145 
146  const label ownSide = side[mesh_.faceOwner()[facei]];
147  const label nbrSide =
148  mesh_.isInternalFace(facei)
149  ? side[mesh_.faceNeighbour()[facei]]
150  : boundaryNbrSide[facei - mesh_.nInternalFaces()];
151 
152  direction[facei] = ownSide*nbrSide < 0 ? ownSide - nbrSide : 0;
153  }
154 
155  // Select intersected faces
156  DynamicList<label> newAddressing;
157  DynamicList<bool> newFlipMap;
158  if (add)
159  {
160  // Start from copy
161  newAddressing = DynamicList<label>(fzSet.addressing());
162  newFlipMap = DynamicList<bool>(fzSet.flipMap());
163 
164  // Add everything with a direction that is not already in the set
165  forAll(direction, facei)
166  {
167  if (direction[facei] != 0 && !fzSet.found(facei))
168  {
169  newAddressing.append(facei);
170  newFlipMap.append(direction[facei] < 0);
171  }
172  }
173  }
174  else
175  {
176  // Start from empty
177  newAddressing = DynamicList<label>(fzSet.addressing().size());
178  newFlipMap = DynamicList<bool>(fzSet.flipMap().size());
179 
180  // Add everything from the zone set that does not have a direction
181  forAll(fzSet.addressing(), i)
182  {
183  if (direction[fzSet.addressing()[i]] == 0)
184  {
185  newAddressing.append(fzSet.addressing()[i]);
186  newFlipMap.append(fzSet.flipMap()[i]);
187  }
188  }
189  }
190  fzSet.addressing().transfer(newAddressing);
191  fzSet.flipMap().transfer(newFlipMap);
192  fzSet.updateSet();
193 }
194 
195 
196 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
197 
199 (
200  const polyMesh& mesh,
201  const dictionary& dict
202 )
203 :
204  topoSetSource(mesh),
205  surfacePtr_
206  (
208  (
209  word(dict.lookup("surface")),
210  IOobject
211  (
212  dict.lookupOrDefault
213  (
214  "file",
215  mesh.objectRegistry::db().name()
216  ),
217  mesh.time().constant(),
219  mesh.objectRegistry::db(),
222  ),
223  dict
224  )
225  ),
226  tol_(dict.lookupOrDefault<scalar>("tol", rootSmall))
227 {}
228 
229 
230 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
231 
233 {}
234 
235 
236 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
237 
239 (
240  const topoSetSource::setAction action,
241  topoSet& set
242 ) const
243 {
244  if (!isA<faceZoneSet>(set))
245  {
247  << "Operation only allowed on a faceZoneSet." << endl;
248  }
249  else
250  {
251  faceZoneSet& fzSet = refCast<faceZoneSet>(set);
252 
253  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
254  {
255  Info<< " Adding all faces from surface "
256  << surfacePtr_().name() << " ..." << endl;
257 
258  combine(fzSet, true);
259  }
260  else if (action == topoSetSource::DELETE)
261  {
262  Info<< " Removing all faces from surface "
263  << surfacePtr_().name() << " ..." << endl;
264 
265  combine(fzSet, false);
266  }
267  }
268 }
269 
270 
271 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const word & name() const
Return name.
Definition: IOobject.H:315
searchableSurfaceToFaceZone(const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
uint8_t direction
Definition: direction.H:45
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
static void swapBoundaryCellPositions(const polyMesh &mesh, const UList< point > &cellData, List< point > &neighbourCellData)
Swap to obtain neighbour cell positions for all boundary faces.
Definition: syncTools.C:31
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
static const word & geometryDir()
Return the geometry directory name.
A class for handling words, derived from string.
Definition: word.H:59
const word & constant() const
Return constant name.
Definition: TimePaths.H:123
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
List< label > labelList
A List of labels.
Definition: labelList.H:56
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
const Time & time() const
Return time.
defineTypeNameAndDebug(combustionModel, 0)
Like faceSet but -reads data from faceZone -updates faceZone when writing.
Definition: faceZoneSet.H:49
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
static void swapBoundaryCellList(const polyMesh &mesh, const UList< T > &cellData, List< T > &neighbourCellData)
Swap to obtain neighbour cell values for all boundary faces.
label patchi
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
#define WarningInFunction
Report a warning using Foam::Warning.
static autoPtr< searchableSurface > New(const word &surfaceType, const IOobject &io, const dictionary &dict)
Return a reference to the selected searchableSurface.
messageStream Info
Field< vector > vectorField
Specialisation of Field<T> for vector.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
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