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-2015 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 
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 :
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(),
79  IOobject::MUST_READ,
80  IOobject::NO_WRITE
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 // ************************************************************************* //
Foam::faceZoneSet::addressing
const labelList & addressing() const
Definition: faceZoneSet.H:107
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::topoSetSource::ADD
@ ADD
Definition: topoSetSource.H:87
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
searchableSurface.H
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList< label >
faceZoneSet.H
Foam::faceZoneSet::updateSet
void updateSet()
Sort addressing and make faceSet part consistent with addressing.
Definition: faceZoneSet.C:48
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:100
Foam::polyPatch::coupled
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:322
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Foam::topoSetSource::NEW
@ NEW
Definition: topoSetSource.H:85
polyMesh.H
syncTools.H
Foam::faceZoneSet::flipMap
const boolList & flipMap() const
Definition: faceZoneSet.H:118
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::syncTools::swapBoundaryCellPositions
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
Foam::Info
messageStream Info
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::faceZoneSet
Like faceSet but updates faceZone when writing.
Definition: faceZoneSet.H:49
Foam::topoSetSource::DELETE
@ DELETE
Definition: topoSetSource.H:88
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::HashTable::found
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
Foam::searchableSurfaceToFaceZone::usage_
static addToUsageTable usage_
Add usage string.
Definition: searchableSurfaceToFaceZone.H:58
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
searchableSurfaceToFaceZone.H
Foam::Vector< scalar >
Foam::List
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
Foam::searchableSurfaceToFaceZone::~searchableSurfaceToFaceZone
virtual ~searchableSurfaceToFaceZone()
Destructor.
Definition: searchableSurfaceToFaceZone.C:90
Foam::searchableSurfaceToFaceZone::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: searchableSurfaceToFaceZone.C:97
Foam::searchableSurfaceToFaceZone::searchableSurfaceToFaceZone
searchableSurfaceToFaceZone(const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: searchableSurfaceToFaceZone.C:62
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259