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-2022 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 Foam::topoSetSource::addToUsageTable Foam::searchableSurfaceToFaceZone::usage_
65 (
66  searchableSurfaceToFaceZone::typeName,
67  "\n Usage: searchableSurfaceToFaceZone surface\n\n"
68  " Select all faces whose cell-cell centre vector intersects the surface "
69  "\n"
70 );
71 
72 
73 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
74 
75 namespace Foam
76 {
77 
78 // Difficult to get a good default name from the dictionary name.
79 // It could be
80 // sourceInfo { .. }
81 // But even with something like
82 // mySurf.stl { .. }
83 // The dictName() method will only return the "stl" ending.
84 
85 static inline word getSurfaceName
86 (
87  const dictionary& dict,
88  const word& defaultName
89 )
90 {
91  return
93  (
94  "surfaceName",
95  {{"name", 1806}},
96  defaultName
97  );
98 }
99 
100 } // End namespace Foam
101 
102 
103 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
104 
106 (
107  const word& surfaceType,
108  const polyMesh& mesh,
109  const dictionary& dict
110 )
111 :
113  surfacePtr_
114  (
116  (
117  surfaceType,
118  IOobject
119  (
121  mesh.time().constant(), // Instance
122  "triSurface", // Local
123  mesh.objectRegistry::db(), // Registry
124  IOobject::MUST_READ,
125  IOobject::NO_WRITE
126  ),
128  )
129  )
130 {}
131 
132 
134 (
135  const polyMesh& mesh,
136  const dictionary& dict
137 )
138 :
140  (
141  dict.getCompat<word>("surfaceType", {{"surface", 0}}),
142  mesh,
143  dict
144  )
145 {}
146 
147 
148 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
149 
151 (
152  const topoSetSource::setAction action,
153  topoSet& set
154 ) const
155 {
156  if (!isA<faceZoneSet>(set))
157  {
159  << "Operation only allowed on a faceZoneSet." << endl;
160  return;
161  }
162  else
163  {
164  faceZoneSet& fzSet = refCast<faceZoneSet>(set);
165 
166  // Get cell-cell centre vectors
167  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168 
169  pointField start(mesh_.nFaces());
170  pointField end(mesh_.nFaces());
171 
172  const pointField& cc = mesh_.cellCentres();
173 
174  // Internal faces
175  for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
176  {
177  start[facei] = cc[mesh_.faceOwner()[facei]];
178  end[facei] = cc[mesh_.faceNeighbour()[facei]];
179  }
180 
181  // Boundary faces
182  vectorField nbrCellCentres;
183  syncTools::swapBoundaryCellPositions(mesh_, cc, nbrCellCentres);
184 
185  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
186 
187  for (const polyPatch& pp : pbm)
188  {
189  if (pp.coupled())
190  {
191  forAll(pp, i)
192  {
193  label facei = pp.start()+i;
194  start[facei] = cc[mesh_.faceOwner()[facei]];
195  end[facei] = nbrCellCentres[facei-mesh_.nInternalFaces()];
196  }
197  }
198  else
199  {
200  forAll(pp, i)
201  {
202  label facei = pp.start()+i;
203  start[facei] = cc[mesh_.faceOwner()[facei]];
204  end[facei] = mesh_.faceCentres()[facei];
205  }
206  }
207  }
208 
209 
210  // Do all intersection tests
211  // ~~~~~~~~~~~~~~~~~~~~~~~~~
212 
213  List<pointIndexHit> hits;
214  surfacePtr_().findLine(start, end, hits);
215  pointField normals;
216  surfacePtr_().getNormal(hits, normals);
217 
218 
219  // Select intersected faces
220  // ~~~~~~~~~~~~~~~~~~~~~~~~
221 
222  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
223  {
224  if (verbose_)
225  {
226  Info<< " Adding all faces from surface "
227  << surfacePtr_().name() << " ..." << endl;
228  }
229 
230  DynamicList<label> newAddressing(fzSet.addressing());
231  DynamicList<bool> newFlipMap(fzSet.flipMap());
232 
233  forAll(hits, facei)
234  {
235  if (hits[facei].hit() && !fzSet.found(facei))
236  {
237  newAddressing.append(facei);
238  vector d = end[facei]-start[facei];
239  newFlipMap.append((normals[facei] & d) < 0);
240  }
241  }
242 
243  fzSet.addressing().transfer(newAddressing);
244  fzSet.flipMap().transfer(newFlipMap);
245  fzSet.updateSet();
246  }
247  else if (action == topoSetSource::SUBTRACT)
248  {
249  if (verbose_)
250  {
251  Info<< " Removing all faces from surface "
252  << surfacePtr_().name() << " ..." << endl;
253  }
254 
255  // Start off empty
256  DynamicList<label> newAddressing(fzSet.addressing().size());
257  DynamicList<bool> newFlipMap(fzSet.flipMap().size());
258 
259  forAll(fzSet.addressing(), i)
260  {
261  if (!hits[fzSet.addressing()[i]].hit())
262  {
263  newAddressing.append(fzSet.addressing()[i]);
264  newFlipMap.append(fzSet.flipMap()[i]);
265  }
266  }
267  fzSet.addressing().transfer(newAddressing);
268  fzSet.flipMap().transfer(newFlipMap);
269  fzSet.updateSet();
270  }
271  }
272 }
273 
274 
275 // ************************************************************************* //
const polyBoundaryMesh & pbm
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Create a new set and ADD elements to it.
Add elements to current set.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
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:27
static word getSurfaceName(const dictionary &dict, const word &defaultName)
searchableSurfaceToFaceZone(const word &surfaceType, const polyMesh &mesh, const dictionary &dict)
Construct surface-type from dictionary.
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A topoSetSource to select all faces whose cell-cell centre vector intersects with a given searchableS...
A class for handling words, derived from Foam::string.
Definition: word.H:63
setAction
Enumeration defining various actions.
Vector< scalar > vector
Definition: vector.H:57
static word getSurfaceName(const dictionary &dict, word surfaceName)
const wordList surface
Standard surface field types (scalar, vector, tensor, etc)
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:201
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
Subtract elements from current set.
#define WarningInFunction
Report a warning using Foam::Warning.
Class with constructor to add usage string to table.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Field< vector > vectorField
Specialisation of Field<T> for vector.
The topoSetFaceZoneSource is a intermediate class for handling topoSet sources for selecting face zon...
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Registry of regIOobjects.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
T getOrDefaultCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value using any compatibility names if needed...