Loading...
Searching...
No Matches
cellToFace.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) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2018-2024 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
29#include "cellToFace.H"
30#include "polyMesh.H"
31#include "cellSet.H"
32#include "Time.H"
33#include "syncTools.H"
36// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38namespace Foam
39{
45}
46
47
48Foam::topoSetSource::addToUsageTable Foam::cellToFace::usage_
49(
50 cellToFace::typeName,
51 "\n Usage: cellToFace <cellSet> all|both|outside\n\n"
52 " Select -all : all faces of cells in the cellSet\n"
53 " -both: faces where both neighbours are in the cellSet\n\n"
54);
55
56
57const Foam::Enum
58<
60>
61Foam::cellToFace::cellActionNames_
62({
63 { cellAction::ALL, "all" },
64 { cellAction::BOTH, "both" },
65 { cellAction::OUTSIDE, "outside" }
66});
67
68
69// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
70
71template<class Selector>
72void Foam::cellToFace::combineImpl
73(
74 topoSet& set,
75 const bool add,
76 const Selector& cellLabels
77) const
78{
79 if (option_ == ALL)
80 {
81 // Add all faces from cell
82 for (const label celli : cellLabels)
83 {
84 const labelList& cFaces = mesh_.cells()[celli];
85
86 addOrDelete(set, cFaces, add);
87 }
88 }
89 else if (option_ == BOTH)
90 {
91 // Add all faces whose both neighbours are in set.
92
93 const label nInt = mesh_.nInternalFaces();
94 const labelList& own = mesh_.faceOwner();
95 const labelList& nei = mesh_.faceNeighbour();
96 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
97
98
99 // Check all internal faces
100 for (label facei = 0; facei < nInt; ++facei)
101 {
102 if (cellLabels.found(own[facei]) && cellLabels.found(nei[facei]))
103 {
104 addOrDelete(set, facei, add);
105 }
106 }
107
108
109 // Get coupled cell status
110 boolList neiInSet(mesh_.nBoundaryFaces(), false);
111
112 for (const polyPatch& pp : patches)
113 {
114 if (pp.coupled())
115 {
116 label facei = pp.start();
117 forAll(pp, i)
118 {
119 neiInSet[facei-nInt] = cellLabels.found(own[facei]);
120 ++facei;
121 }
122 }
123 }
125
126
127 // Check all boundary faces
128 for (const polyPatch& pp : patches)
129 {
130 if (pp.coupled())
131 {
132 label facei = pp.start();
133 forAll(pp, i)
134 {
135 if (cellLabels.found(own[facei]) && neiInSet[facei-nInt])
136 {
137 addOrDelete(set, facei, add);
138 }
139 ++facei;
140 }
141 }
142 }
143 }
144 else if (option_ == OUTSIDE)
145 {
146 // Add all faces where only one neighbour is in set.
147
148 const label nInt = mesh_.nInternalFaces();
149 const labelList& own = mesh_.faceOwner();
150 const labelList& nei = mesh_.faceNeighbour();
151 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
152
153
154 // Check all internal faces
155 for (label facei = 0; facei < nInt; ++facei)
156 {
157 if (cellLabels.found(own[facei]) != cellLabels.found(nei[facei]))
158 {
159 addOrDelete(set, facei, add);
160 }
161 }
162
163
164 // Get coupled cell status
165 boolList neiInSet(mesh_.nBoundaryFaces(), false);
166
167 for (const polyPatch& pp : patches)
168 {
169 if (pp.coupled())
170 {
171 label facei = pp.start();
172 forAll(pp, i)
173 {
174 neiInSet[facei-nInt] = cellLabels.found(own[facei]);
175 ++facei;
176 }
177 }
178 }
180
181
182 // Check all boundary faces
183 for (const polyPatch& pp : patches)
184 {
185 label facei = pp.start();
186 forAll(pp, i)
187 {
188 if (cellLabels.found(own[facei]) != neiInSet[facei-nInt])
189 {
190 addOrDelete(set, facei, add);
191 }
192 ++facei;
193 }
194 }
195 }
196 else
197 {
199 << "Selected option is not available"
200 << ", option: " << cellActionNames_[option_]
201 << exit(FatalError);
202 }
203}
204
205
206void Foam::cellToFace::combine
207(
208 topoSet& set,
209 const bool add,
210 const word& setName
211) const
212{
213 if (isZone_)
214 {
215 const labelList& cellLabels = mesh_.cellZones()[setName];
216
217 combineImpl(set, add, cellLabels);
218 }
219 else
220 {
221 // Load the set
222 if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName)))
223 {
225 << "Cannot load set " << setName << endl;
226 }
227
228 cellSet loadedSet(mesh_, setName, IOobject::NO_REGISTER);
229 const labelHashSet& cellLabels = loadedSet;
230
231 combineImpl(set, add, cellLabels);
232 }
233}
234
235
236// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
237
239(
240 const polyMesh& mesh,
241 const word& setName,
242 const cellAction option
243)
244:
246 names_(Foam::one{}, setName),
247 isZone_(false),
248 option_(option)
249{}
250
251
253(
254 const polyMesh& mesh,
255 const dictionary& dict
256)
257:
259 names_(),
260 isZone_(topoSetSource::readNames(dict, names_)),
261 option_(cellActionNames_.get("option", dict))
262{}
263
264
266(
267 const polyMesh& mesh,
268 Istream& is
269)
270:
272 names_(Foam::one{}, word(checkIs(is))),
273 isZone_(false),
274 option_(cellActionNames_.read(checkIs(is)))
275{}
276
277
278// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
279
281(
282 const topoSetSource::setAction action,
283 topoSet& set
284) const
285{
286 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
287 {
288 if (verbose_)
289 {
290 Info<< " Adding faces according to cell "
291 << (isZone_ ? "zones: " : "sets: ")
292 << flatOutput(names_) << nl;
293 }
294
295 for (const word& setName : names_)
296 {
297 combine(set, true, setName);
298 }
299 }
300 else if (action == topoSetSource::SUBTRACT)
301 {
302 if (verbose_)
303 {
304 Info<< " Removing faces according to cell "
305 << (isZone_ ? "zones: " : "sets: ")
306 << flatOutput(names_) << nl;
307 }
308
309 for (const word& setName : names_)
310 {
311 combine(set, false, setName);
312 }
313 }
314}
315
316
317// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
@ NO_REGISTER
Do not request registration (bool: false).
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A collection of cell labels.
Definition cellSet.H:50
A topoSetFaceSource to select all the faces from given cellSet(s).
Definition cellToFace.H:186
cellToFace(const polyMesh &mesh, const word &setName, const cellAction option)
Construct from components.
Definition cellToFace.C:232
cellAction
Enumeration defining the valid options.
Definition cellToFace.H:192
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition cellToFace.C:274
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition one.H:57
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues, const bool parRun=UPstream::parRun())
Swap coupled boundary face values. Uses eqOp.
Definition syncTools.H:524
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
topoSetFaceSource(const polyMesh &mesh)
Construct from mesh.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
static bool readNames(const dictionary &dict, wordList &names)
Helper: extract wordList of patches/zones from dictionary. Returns.
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
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.
bool verbose_
Output verbosity (default: true).
const polyMesh & mesh() const noexcept
Reference to the mesh.
const polyMesh & mesh_
Reference to the mesh.
static Istream & checkIs(Istream &is)
Check state of stream.
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
Definition topoSet.C:127
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
Namespace for OpenFOAM.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition POSIX.C:837
List< label > labelList
A List of labels.
Definition List.H:62
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition HashSet.H:85
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
messageStream SeriousError
Error stream (stdout output on all processes), with additional 'FOAM Serious Error' header text.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
List< bool > boolList
A List of bools.
Definition List.H:60
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dict add("bounds", meshBb)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299