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-2020 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  );
49  (
50  topoSetFaceZoneSource,
51  searchableSurfaceToFaceZone,
52  word
53  );
55  (
56  topoSetFaceZoneSource,
57  searchableSurfaceToFaceZone,
58  word,
59  surface
60  );
61 
62 }
63 
64 
65 Foam::topoSetSource::addToUsageTable Foam::searchableSurfaceToFaceZone::usage_
66 (
67  searchableSurfaceToFaceZone::typeName,
68  "\n Usage: searchableSurfaceToFaceZone surface\n\n"
69  " Select all faces whose cell-cell centre vector intersects the surface "
70  "\n"
71 );
72 
73 
74 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
75 
77 (
78  const dictionary& dict,
79  const word& defaultName
80 )
81 {
82  // Unfortunately cannot get a good default name from the dictionary name.
83  // It could be
84  // sourceInfo { .. }
85  // But even with something like
86  // mySurf.stl { .. }
87  // The dictName() method will only return the "stl" ending.
88 
89 
90  return
91  dict.getOrDefaultCompat<word>
92  (
93  "surfaceName",
94  {{"name", 1806}},
95  defaultName
96  );
97 }
98 
99 
100 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101 
103 (
104  const word& surfaceType,
105  const polyMesh& mesh,
106  const dictionary& dict
107 )
108 :
110  surfacePtr_
111  (
113  (
114  surfaceType,
115  IOobject
116  (
117  getSurfaceName(dict, mesh.objectRegistry::db().name()),
118  mesh.time().constant(), // Instance
119  "triSurface", // Local
120  mesh.objectRegistry::db(), // Registry
121  IOobject::MUST_READ,
122  IOobject::NO_WRITE
123  ),
124  dict
125  )
126  )
127 {}
128 
129 
131 (
132  const polyMesh& mesh,
133  const dictionary& dict
134 )
135 :
137  (
138  dict.getCompat<word>("surfaceType", {{"surface", 0}}),
139  mesh,
140  dict
141  )
142 {}
143 
144 
145 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146 
148 (
149  const topoSetSource::setAction action,
150  topoSet& set
151 ) const
152 {
153  if (!isA<faceZoneSet>(set))
154  {
156  << "Operation only allowed on a faceZoneSet." << endl;
157  return;
158  }
159  else
160  {
161  faceZoneSet& fzSet = refCast<faceZoneSet>(set);
162 
163  // Get cell-cell centre vectors
164  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165 
166  pointField start(mesh_.nFaces());
167  pointField end(mesh_.nFaces());
168 
169  const pointField& cc = mesh_.cellCentres();
170 
171  // Internal faces
172  for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
173  {
174  start[facei] = cc[mesh_.faceOwner()[facei]];
175  end[facei] = cc[mesh_.faceNeighbour()[facei]];
176  }
177 
178  // Boundary faces
179  vectorField nbrCellCentres;
180  syncTools::swapBoundaryCellPositions(mesh_, cc, nbrCellCentres);
181 
182  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
183 
184  for (const polyPatch& pp : pbm)
185  {
186  if (pp.coupled())
187  {
188  forAll(pp, i)
189  {
190  label facei = pp.start()+i;
191  start[facei] = cc[mesh_.faceOwner()[facei]];
192  end[facei] = nbrCellCentres[facei-mesh_.nInternalFaces()];
193  }
194  }
195  else
196  {
197  forAll(pp, i)
198  {
199  label facei = pp.start()+i;
200  start[facei] = cc[mesh_.faceOwner()[facei]];
201  end[facei] = mesh_.faceCentres()[facei];
202  }
203  }
204  }
205 
206 
207  // Do all intersection tests
208  // ~~~~~~~~~~~~~~~~~~~~~~~~~
209 
210  List<pointIndexHit> hits;
211  surfacePtr_().findLine(start, end, hits);
212  pointField normals;
213  surfacePtr_().getNormal(hits, normals);
214 
215 
216  // Select intersected faces
217  // ~~~~~~~~~~~~~~~~~~~~~~~~
218 
219  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
220  {
221  if (verbose_)
222  {
223  Info<< " Adding all faces from surface "
224  << surfacePtr_().name() << " ..." << endl;
225  }
226 
227  DynamicList<label> newAddressing(fzSet.addressing());
228  DynamicList<bool> newFlipMap(fzSet.flipMap());
229 
230  forAll(hits, facei)
231  {
232  if (hits[facei].hit() && !fzSet.found(facei))
233  {
234  newAddressing.append(facei);
235  vector d = end[facei]-start[facei];
236  newFlipMap.append((normals[facei] & d) < 0);
237  }
238  }
239 
240  fzSet.addressing().transfer(newAddressing);
241  fzSet.flipMap().transfer(newFlipMap);
242  fzSet.updateSet();
243  }
244  else if (action == topoSetSource::SUBTRACT)
245  {
246  if (verbose_)
247  {
248  Info<< " Removing all faces from surface "
249  << surfacePtr_().name() << " ..." << endl;
250  }
251 
252  // Start off empty
253  DynamicList<label> newAddressing(fzSet.addressing().size());
254  DynamicList<bool> newFlipMap(fzSet.flipMap().size());
255 
256  forAll(fzSet.addressing(), i)
257  {
258  if (!hits[fzSet.addressing()[i]].hit())
259  {
260  newAddressing.append(fzSet.addressing()[i]);
261  newFlipMap.append(fzSet.flipMap()[i]);
262  }
263  }
264  fzSet.addressing().transfer(newAddressing);
265  fzSet.flipMap().transfer(newFlipMap);
266  fzSet.updateSet();
267  }
268  }
269 }
270 
271 
272 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::faceZoneSet::addressing
const labelList & addressing() const
Definition: faceZoneSet.H:106
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::searchableSurfaceToFaceZone::searchableSurfaceToFaceZone
searchableSurfaceToFaceZone(const word &surfaceType, const polyMesh &mesh, const dictionary &dict)
Construct surface-type from dictionary.
Definition: searchableSurfaceToFaceZone.C:103
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
searchableSurface.H
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
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:129
Foam::topoSetFaceZoneSource
The topoSetFaceZoneSource is a intermediate class for handling topoSet sources for selecting face zon...
Definition: topoSetFaceZoneSource.H:57
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
polyMesh.H
syncTools.H
Foam::faceZoneSet::flipMap
const boolList & flipMap() const
Definition: faceZoneSet.H:117
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:296
Foam::topoSet::found
virtual bool found(const label id) const
Has the given index?
Definition: topoSet.C:508
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:456
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Foam::searchableSurfaceToFaceZone::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: searchableSurfaceToFaceZone.C:148
Foam::searchableSurfaceToFaceZone::getSurfaceName
static word getSurfaceName(const dictionary &dict, const word &defaultName)
Retrieve surface name from dictionary entry.
Definition: searchableSurfaceToFaceZone.C:77
Foam::faceZoneSet
Like faceSet but -reads data from faceZone -updates faceZone when writing.
Definition: faceZoneSet.H:51
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
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:123
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:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::searchableSurfaceToFaceZone
A topoSetSource to select all faces whose cell-cell centre vector intersects with a given searchableS...
Definition: searchableSurfaceToFaceZone.H:160
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: BitOps.H:63
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328