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-------------------------------------------------------------------------------
11License
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
39namespace Foam
40{
43 (
46 word
47 );
49 (
52 word
53 );
55 (
58 word,
59 surface
60 );
61}
62
63
64Foam::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
75namespace 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
85static 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,
119 (
121 mesh.time().constant(), // Instance
122 "triSurface", // Local
123 mesh.objectRegistry::db(), // Registry
124 IOobject::MUST_READ,
125 IOobject::NO_WRITE
126 ),
127 dict
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
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void transfer(List< T > &list)
Definition: List.C:447
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T getOrDefaultCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Like faceSet but -reads data from faceZone -updates faceZone when writing.
Definition: faceZoneSet.H:54
const boolList & flipMap() const noexcept
Definition: faceZoneSet.H:117
const labelList & addressing() const noexcept
Definition: faceZoneSet.H:106
void updateSet()
Sort addressing and make faceSet part consistent with addressing.
Definition: faceZoneSet.C:51
Registry of regIOobjects.
constant condensation/saturation model.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
A topoSetSource to select all faces whose cell-cell centre vector intersects with a given searchableS...
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
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:34
The topoSetFaceZoneSource is a intermediate class for handling topoSet sources for selecting face zon...
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
Definition: topoSetSource.H:68
setAction
Enumeration defining various actions.
@ SUBTRACT
Subtract elements from current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:67
virtual bool found(const label id) const
Has the given index?
Definition: topoSet.C:508
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
static word getSurfaceName(const dictionary &dict, const word &defaultName)
static word getSurfaceName(const dictionary &dict, word surfaceName)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333