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-2013 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  {
104  WarningIn
105  (
106  "searchableSurfaceToFaceZone::applyToSet"
107  "(const topoSetSource::setAction"
108  ", topoSet"
109  ) << "Operation only allowed on a faceZoneSet." << endl;
110  }
111  else
112  {
113  faceZoneSet& fzSet = refCast<faceZoneSet>(set);
114 
115  // Get cell-cell centre vectors
116  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117 
118  pointField start(mesh_.nFaces());
119  pointField end(mesh_.nFaces());
120 
121  const pointField& cc = mesh_.cellCentres();
122 
123  // Internal faces
124  for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
125  {
126  start[faceI] = cc[mesh_.faceOwner()[faceI]];
127  end[faceI] = cc[mesh_.faceNeighbour()[faceI]];
128  }
129 
130  // Boundary faces
131  vectorField nbrCellCentres;
132  syncTools::swapBoundaryCellPositions(mesh_, cc, nbrCellCentres);
133 
134  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
135 
136  forAll(pbm, patchI)
137  {
138  const polyPatch& pp = pbm[patchI];
139 
140  if (pp.coupled())
141  {
142  forAll(pp, i)
143  {
144  label faceI = pp.start()+i;
145  start[faceI] = cc[mesh_.faceOwner()[faceI]];
146  end[faceI] = nbrCellCentres[faceI-mesh_.nInternalFaces()];
147  }
148  }
149  else
150  {
151  forAll(pp, i)
152  {
153  label faceI = pp.start()+i;
154  start[faceI] = cc[mesh_.faceOwner()[faceI]];
155  end[faceI] = mesh_.faceCentres()[faceI];
156  }
157  }
158  }
159 
160 
161  // Do all intersection tests
162  // ~~~~~~~~~~~~~~~~~~~~~~~~~
163 
164  List<pointIndexHit> hits;
165  surfacePtr_().findLine(start, end, hits);
166  pointField normals;
167  surfacePtr_().getNormal(hits, normals);
168 
169 
170  // Select intersected faces
171  // ~~~~~~~~~~~~~~~~~~~~~~~~
172 
173  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
174  {
175  Info<< " Adding all faces from surface "
176  << surfacePtr_().name() << " ..." << endl;
177 
178  DynamicList<label> newAddressing(fzSet.addressing());
179  DynamicList<bool> newFlipMap(fzSet.flipMap());
180 
181  forAll(hits, faceI)
182  {
183  if (hits[faceI].hit() && !fzSet.found(faceI))
184  {
185  newAddressing.append(faceI);
186  vector d = end[faceI]-start[faceI];
187  newFlipMap.append((normals[faceI] & d) < 0);
188  }
189  }
190 
191  fzSet.addressing().transfer(newAddressing);
192  fzSet.flipMap().transfer(newFlipMap);
193  fzSet.updateSet();
194  }
195  else if (action == topoSetSource::DELETE)
196  {
197  Info<< " Removing all faces from surface "
198  << surfacePtr_().name() << " ..." << endl;
199 
200  // Start off empty
201  DynamicList<label> newAddressing(fzSet.addressing().size());
202  DynamicList<bool> newFlipMap(fzSet.flipMap().size());
203 
204  forAll(fzSet.addressing(), i)
205  {
206  if (!hits[fzSet.addressing()[i]].hit())
207  {
208  newAddressing.append(fzSet.addressing()[i]);
209  newFlipMap.append(fzSet.flipMap()[i]);
210  }
211  }
212  fzSet.addressing().transfer(newAddressing);
213  fzSet.flipMap().transfer(newFlipMap);
214  fzSet.updateSet();
215  }
216  }
217 }
218 
219 
220 // ************************************************************************* //
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:310
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:390
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
messageStream Info
const labelList & addressing() const
Definition: faceZoneSet.H:107
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
Namespace for OpenFOAM.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
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
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
static autoPtr< searchableSurface > New(const word &surfaceType, const IOobject &io, const dictionary &dict)
Return a reference to the selected searchableSurface.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Foam::polyBoundaryMesh.
#define forAll(list, i)
Definition: UList.H:421
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Macros for easy insertion into run-time selection tables.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
searchableSurfaceToFaceZone(const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
const word & name() const
Return name.
Definition: IOobject.H:260
Like faceSet but updates faceZone when writing.
Definition: faceZoneSet.H:49
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:300
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
const Time & time() const
Return time.
const boolList & flipMap() const
Definition: faceZoneSet.H:118
Class with constructor to add usage string to table.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
defineTypeNameAndDebug(combustionModel, 0)
void updateSet()
Sort addressing and make faceSet part consistent with addressing.
Definition: faceZoneSet.C:48