searchableSurfaceToFaceZone.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 | Copyright (C) 2012-2016 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 Foam::topoSetSource::addToUsageTable Foam::searchableSurfaceToFaceZone::usage_
50 (
51  searchableSurfaceToFaceZone::typeName,
52  "\n Usage: searchableSurfaceToFaceZone surface\n\n"
53  " Select all faces whose cell-cell centre vector intersects the surface "
54  "\n"
55 );
56 
57 
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 
60 // Construct from dictionary
62 (
63  const polyMesh& mesh,
64  const dictionary& dict
65 )
66 :
67  topoSetSource(mesh),
68  surfacePtr_
69  (
71  (
72  word(dict.lookup("surface")),
73  IOobject
74  (
75  dict.lookupOrDefault("name", mesh.objectRegistry::db().name()),
76  mesh.time().constant(),
77  "triSurface",
78  mesh.objectRegistry::db(),
81  ),
82  dict
83  )
84  )
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
89 
91 {}
92 
93 
94 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
95 
97 (
98  const topoSetSource::setAction action,
99  topoSet& set
100 ) const
101 {
102  if (!isA<faceZoneSet>(set))
103  {
105  << "Operation only allowed on a faceZoneSet." << endl;
106  }
107  else
108  {
109  faceZoneSet& fzSet = refCast<faceZoneSet>(set);
110 
111  // Get cell-cell centre vectors
112  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113 
114  pointField start(mesh_.nFaces());
115  pointField end(mesh_.nFaces());
116 
117  const pointField& cc = mesh_.cellCentres();
118 
119  // Internal faces
120  for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
121  {
122  start[facei] = cc[mesh_.faceOwner()[facei]];
123  end[facei] = cc[mesh_.faceNeighbour()[facei]];
124  }
125 
126  // Boundary faces
127  vectorField nbrCellCentres;
128  syncTools::swapBoundaryCellPositions(mesh_, cc, nbrCellCentres);
129 
130  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
131 
132  forAll(pbm, patchi)
133  {
134  const polyPatch& pp = pbm[patchi];
135 
136  if (pp.coupled())
137  {
138  forAll(pp, i)
139  {
140  label facei = pp.start()+i;
141  start[facei] = cc[mesh_.faceOwner()[facei]];
142  end[facei] = nbrCellCentres[facei-mesh_.nInternalFaces()];
143  }
144  }
145  else
146  {
147  forAll(pp, i)
148  {
149  label facei = pp.start()+i;
150  start[facei] = cc[mesh_.faceOwner()[facei]];
151  end[facei] = mesh_.faceCentres()[facei];
152  }
153  }
154  }
155 
156 
157  // Do all intersection tests
158  // ~~~~~~~~~~~~~~~~~~~~~~~~~
159 
160  List<pointIndexHit> hits;
161  surfacePtr_().findLine(start, end, hits);
162  pointField normals;
163  surfacePtr_().getNormal(hits, normals);
164 
165 
166  // Select intersected faces
167  // ~~~~~~~~~~~~~~~~~~~~~~~~
168 
169  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
170  {
171  Info<< " Adding all faces from surface "
172  << surfacePtr_().name() << " ..." << endl;
173 
174  DynamicList<label> newAddressing(fzSet.addressing());
175  DynamicList<bool> newFlipMap(fzSet.flipMap());
176 
177  forAll(hits, facei)
178  {
179  if (hits[facei].hit() && !fzSet.found(facei))
180  {
181  newAddressing.append(facei);
182  vector d = end[facei]-start[facei];
183  newFlipMap.append((normals[facei] & d) < 0);
184  }
185  }
186 
187  fzSet.addressing().transfer(newAddressing);
188  fzSet.flipMap().transfer(newFlipMap);
189  fzSet.updateSet();
190  }
191  else if (action == topoSetSource::DELETE)
192  {
193  Info<< " Removing all faces from surface "
194  << surfacePtr_().name() << " ..." << endl;
195 
196  // Start off empty
197  DynamicList<label> newAddressing(fzSet.addressing().size());
198  DynamicList<bool> newFlipMap(fzSet.flipMap().size());
199 
200  forAll(fzSet.addressing(), i)
201  {
202  if (!hits[fzSet.addressing()[i]].hit())
203  {
204  newAddressing.append(fzSet.addressing()[i]);
205  newFlipMap.append(fzSet.flipMap()[i]);
206  }
207  }
208  fzSet.addressing().transfer(newAddressing);
209  fzSet.flipMap().transfer(newFlipMap);
210  fzSet.updateSet();
211  }
212  }
213 }
214 
215 
216 // ************************************************************************* //
const Time & time() const
Return time.
const labelList & addressing() const
Definition: faceZoneSet.H:107
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
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:137
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
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
const boolList & flipMap() const
Definition: faceZoneSet.H:118
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:300
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:310
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
Foam::polyBoundaryMesh.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
void updateSet()
Sort addressing and make faceSet part consistent with addressing.
Definition: faceZoneSet.C:48
Like faceSet but updates faceZone when writing.
Definition: faceZoneSet.H:49
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
Class with constructor to add usage string to table.
static autoPtr< searchableSurface > New(const word &surfaceType, const IOobject &io, const dictionary &dict)
Return a reference to the selected searchableSurface.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:365
const word & name() const
Return name.
Definition: IOobject.H:260
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451