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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2017 OpenFOAM Foundation
9  Copyright (C) 2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "polyMesh.H"
31 #include "faceZoneSet.H"
32 #include "searchableSurface.H"
33 #include "syncTools.H"
34 #include "Time.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41  defineTypeNameAndDebug(searchableSurfaceToFaceZone, 0);
43  (
44  topoSetSource,
45  searchableSurfaceToFaceZone,
46  word
47  );
48 }
49 
50 
51 Foam::topoSetSource::addToUsageTable Foam::searchableSurfaceToFaceZone::usage_
52 (
53  searchableSurfaceToFaceZone::typeName,
54  "\n Usage: searchableSurfaceToFaceZone surface\n\n"
55  " Select all faces whose cell-cell centre vector intersects the surface "
56  "\n"
57 );
58 
59 
60 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
61 
63 (
64  const dictionary& dict,
65  const word& defaultName
66 )
67 {
68  // Unfortunately cannot get a good default name from the dictionary name.
69  // It could be
70  // sourceInfo { .. }
71  // But even with something like
72  // mySurf.stl { .. }
73  // The dictName() method will only return the "stl" ending.
74 
75 
76  return
77  dict.lookupOrDefaultCompat<word>
78  (
79  "surfaceName",
80  {{"name", 1806}},
82  );
83 }
84 
85 
86 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
87 
89 (
90  const word& surfaceType,
91  const polyMesh& mesh,
92  const dictionary& dict
93 )
94 :
96  surfacePtr_
97  (
99  (
100  surfaceType,
101  IOobject
102  (
103  getSurfaceName(dict, mesh.objectRegistry::db().name()),
104  mesh.time().constant(), // Instance
105  "triSurface", // Local
106  mesh.objectRegistry::db(), // Registry
107  IOobject::MUST_READ,
108  IOobject::NO_WRITE
109  ),
110  dict
111  )
112  )
113 {}
114 
115 
117 (
118  const polyMesh& mesh,
119  const dictionary& dict
120 )
121 :
123  (
124  dict.getCompat<word>("surfaceType", {{"surface", 0}}),
125  mesh,
126  dict
127  )
128 {}
129 
130 
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 
134 (
135  const topoSetSource::setAction action,
136  topoSet& set
137 ) const
138 {
139  if (!isA<faceZoneSet>(set))
140  {
142  << "Operation only allowed on a faceZoneSet." << endl;
143  }
144  else
145  {
146  faceZoneSet& fzSet = refCast<faceZoneSet>(set);
147 
148  // Get cell-cell centre vectors
149  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150 
151  pointField start(mesh_.nFaces());
152  pointField end(mesh_.nFaces());
153 
154  const pointField& cc = mesh_.cellCentres();
155 
156  // Internal faces
157  for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
158  {
159  start[facei] = cc[mesh_.faceOwner()[facei]];
160  end[facei] = cc[mesh_.faceNeighbour()[facei]];
161  }
162 
163  // Boundary faces
164  vectorField nbrCellCentres;
165  syncTools::swapBoundaryCellPositions(mesh_, cc, nbrCellCentres);
166 
167  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
168 
169  for (const polyPatch& pp : pbm)
170  {
171  if (pp.coupled())
172  {
173  forAll(pp, i)
174  {
175  label facei = pp.start()+i;
176  start[facei] = cc[mesh_.faceOwner()[facei]];
177  end[facei] = nbrCellCentres[facei-mesh_.nInternalFaces()];
178  }
179  }
180  else
181  {
182  forAll(pp, i)
183  {
184  label facei = pp.start()+i;
185  start[facei] = cc[mesh_.faceOwner()[facei]];
186  end[facei] = mesh_.faceCentres()[facei];
187  }
188  }
189  }
190 
191 
192  // Do all intersection tests
193  // ~~~~~~~~~~~~~~~~~~~~~~~~~
194 
195  List<pointIndexHit> hits;
196  surfacePtr_().findLine(start, end, hits);
197  pointField normals;
198  surfacePtr_().getNormal(hits, normals);
199 
200 
201  // Select intersected faces
202  // ~~~~~~~~~~~~~~~~~~~~~~~~
203 
204  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
205  {
206  if (verbose_)
207  {
208  Info<< " Adding all faces from surface "
209  << surfacePtr_().name() << " ..." << endl;
210  }
211 
212  DynamicList<label> newAddressing(fzSet.addressing());
213  DynamicList<bool> newFlipMap(fzSet.flipMap());
214 
215  forAll(hits, facei)
216  {
217  if (hits[facei].hit() && !fzSet.found(facei))
218  {
219  newAddressing.append(facei);
220  vector d = end[facei]-start[facei];
221  newFlipMap.append((normals[facei] & d) < 0);
222  }
223  }
224 
225  fzSet.addressing().transfer(newAddressing);
226  fzSet.flipMap().transfer(newFlipMap);
227  fzSet.updateSet();
228  }
229  else if (action == topoSetSource::SUBTRACT)
230  {
231  if (verbose_)
232  {
233  Info<< " Removing all faces from surface "
234  << surfacePtr_().name() << " ..." << endl;
235  }
236 
237  // Start off empty
238  DynamicList<label> newAddressing(fzSet.addressing().size());
239  DynamicList<bool> newFlipMap(fzSet.flipMap().size());
240 
241  forAll(fzSet.addressing(), i)
242  {
243  if (!hits[fzSet.addressing()[i]].hit())
244  {
245  newAddressing.append(fzSet.addressing()[i]);
246  newFlipMap.append(fzSet.flipMap()[i]);
247  }
248  }
249  fzSet.addressing().transfer(newAddressing);
250  fzSet.flipMap().transfer(newFlipMap);
251  fzSet.updateSet();
252  }
253  }
254 }
255 
256 
257 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::faceZoneSet::addressing
const labelList & addressing() const
Definition: faceZoneSet.H:107
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::searchableSurfaceToFaceZone::searchableSurfaceToFaceZone
searchableSurfaceToFaceZone(const word &surfaceType, const polyMesh &mesh, const dictionary &dict)
Construct surface-type from dictionary.
Definition: searchableSurfaceToFaceZone.C:89
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
searchableSurface.H
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::DynamicList< label >
faceZoneSet.H
Foam::faceZoneSet::updateSet
void updateSet()
Sort addressing and make faceSet part consistent with addressing.
Definition: faceZoneSet.C:51
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
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:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::topoSet::found
virtual bool found(const label id) const
Has the given index?
Definition: topoSet.C:511
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:62
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:436
Foam::searchableSurfaceToFaceZone::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: searchableSurfaceToFaceZone.C:134
Foam::searchableSurfaceToFaceZone::getSurfaceName
static word getSurfaceName(const dictionary &dict, const word &defaultName)
Retrieve surface name from dictionary entry.
Definition: searchableSurfaceToFaceZone.C:63
Foam::faceZoneSet
Like faceSet but -reads data from faceZone -updates faceZone when writing.
Definition: faceZoneSet.H:52
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:66
Foam::defaultName
static const word defaultName("coeffs")
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:115
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:66
Foam::searchableSurfaceToFaceZone
A topoSetSource to select faces based on intersection (of cell-cell vector) with a surface.
Definition: searchableSurfaceToFaceZone.H:88
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
searchableSurfaceToFaceZone.H
Time.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:102
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294