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-2018 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 
61 (
62  const polyMesh& mesh,
63  const dictionary& dict
64 )
65 :
66  topoSetSource(mesh),
67  surfacePtr_
68  (
70  (
71  word(dict.lookup("surface")),
72  IOobject
73  (
74  dict.lookupOrDefault("name", mesh.objectRegistry::db().name()),
75  mesh.time().constant(),
76  "triSurface",
77  mesh.objectRegistry::db(),
80  ),
81  dict
82  )
83  )
84 {}
85 
86 
87 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
88 
90 {}
91 
92 
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 
96 (
97  const topoSetSource::setAction action,
98  topoSet& set
99 ) const
100 {
101  if (!isA<faceZoneSet>(set))
102  {
104  << "Operation only allowed on a faceZoneSet." << endl;
105  }
106  else
107  {
108  faceZoneSet& fzSet = refCast<faceZoneSet>(set);
109 
110  // Get cell-cell centre vectors
111  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112 
113  pointField start(mesh_.nFaces());
114  pointField end(mesh_.nFaces());
115 
116  const pointField& cc = mesh_.cellCentres();
117 
118  // Internal faces
119  for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
120  {
121  start[facei] = cc[mesh_.faceOwner()[facei]];
122  end[facei] = cc[mesh_.faceNeighbour()[facei]];
123  }
124 
125  // Boundary faces
126  vectorField nbrCellCentres;
127  syncTools::swapBoundaryCellPositions(mesh_, cc, nbrCellCentres);
128 
129  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
130 
131  forAll(pbm, patchi)
132  {
133  const polyPatch& pp = pbm[patchi];
134 
135  if (pp.coupled())
136  {
137  forAll(pp, i)
138  {
139  label facei = pp.start()+i;
140  start[facei] = cc[mesh_.faceOwner()[facei]];
141  end[facei] = nbrCellCentres[facei-mesh_.nInternalFaces()];
142  }
143  }
144  else
145  {
146  forAll(pp, i)
147  {
148  label facei = pp.start()+i;
149  start[facei] = cc[mesh_.faceOwner()[facei]];
150  end[facei] = mesh_.faceCentres()[facei];
151  }
152  }
153  }
154 
155 
156  // Do all intersection tests
157  // ~~~~~~~~~~~~~~~~~~~~~~~~~
158 
159  List<pointIndexHit> hits;
160  surfacePtr_().findLine(start, end, hits);
161  pointField normals;
162  surfacePtr_().getNormal(hits, normals);
163 
164 
165  // Select intersected faces
166  // ~~~~~~~~~~~~~~~~~~~~~~~~
167 
168  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
169  {
170  Info<< " Adding all faces from surface "
171  << surfacePtr_().name() << " ..." << endl;
172 
173  DynamicList<label> newAddressing(fzSet.addressing());
174  DynamicList<bool> newFlipMap(fzSet.flipMap());
175 
176  forAll(hits, facei)
177  {
178  if (hits[facei].hit() && !fzSet.found(facei))
179  {
180  newAddressing.append(facei);
181  vector d = end[facei]-start[facei];
182  newFlipMap.append((normals[facei] & d) < 0);
183  }
184  }
185 
186  fzSet.addressing().transfer(newAddressing);
187  fzSet.flipMap().transfer(newFlipMap);
188  fzSet.updateSet();
189  }
190  else if (action == topoSetSource::DELETE)
191  {
192  Info<< " Removing all faces from surface "
193  << surfacePtr_().name() << " ..." << endl;
194 
195  // Start off empty
196  DynamicList<label> newAddressing(fzSet.addressing().size());
197  DynamicList<bool> newFlipMap(fzSet.flipMap().size());
198 
199  forAll(fzSet.addressing(), i)
200  {
201  if (!hits[fzSet.addressing()[i]].hit())
202  {
203  newAddressing.append(fzSet.addressing()[i]);
204  newFlipMap.append(fzSet.flipMap()[i]);
205  }
206  }
207  fzSet.addressing().transfer(newAddressing);
208  fzSet.flipMap().transfer(newFlipMap);
209  fzSet.updateSet();
210  }
211  }
212 }
213 
214 
215 // ************************************************************************* //
const boolList & flipMap() const
Definition: faceZoneSet.H:118
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
const word & name() const
Return name.
Definition: IOobject.H:295
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:158
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:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
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
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:313
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:113
A class for handling words, derived from string.
Definition: word.H:59
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Foam::polyBoundaryMesh.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
const Time & time() const
Return time.
defineTypeNameAndDebug(combustionModel, 0)
void updateSet()
Sort addressing and make faceSet part consistent with addressing.
Definition: faceZoneSet.C:51
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
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.
Class with constructor to add usage string to table.
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:303
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
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:92
const labelList & addressing() const
Definition: faceZoneSet.H:107
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:583