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 {
41  (
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();
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
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(),
218  searchableSurface::geometryDir(mesh.time()),
219  mesh.objectRegistry::db(),
220  IOobject::MUST_READ,
221  IOobject::NO_WRITE
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
Macros for easy insertion into run-time selection tables.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Like faceSet but -reads data from faceZone -updates faceZone when writing.
Definition: faceZoneSet.H:52
Registry of regIOobjects.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1387
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:403
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1393
label nCells() const
const vectorField & cellCentres() const
label nInternalFaces() const
label nFaces() const
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
A topoSetSource to select faces based on intersection (of cell-cell vector) with a surface.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
searchableSurfaceToFaceZone(const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
static void swapBoundaryCellList(const polyMesh &mesh, const UList< T > &cellData, List< T > &neighbourCellData)
Swap to obtain neighbour cell values for all boundary faces.
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
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
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
dimensionedScalar sign(const dimensionedScalar &ds)
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
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Field< vector > vectorField
Specialisation of Field<T> for vector.
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
uint8_t direction
Definition: direction.H:45
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
dictionary dict