pointToFace.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-2020 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 "pointToFace.H"
30#include "polyMesh.H"
31#include "pointSet.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
44 (
47 word,
48 point
49 );
51 (
54 istream,
55 point
56 );
57}
58
59
60Foam::topoSetSource::addToUsageTable Foam::pointToFace::usage_
61(
62 pointToFace::typeName,
63 "\n Usage: pointToFace <pointSet> any|all|edge\n\n"
64 " Select faces with\n"
65 " -any point in the pointSet\n"
66 " -all points in the pointSet\n\n"
67 " -two consecutive points (an edge) in the pointSet\n\n"
68);
69
70
71const Foam::Enum
72<
74>
75Foam::pointToFace::pointActionNames_
76({
77 { pointAction::ANY, "any" },
78 { pointAction::ALL, "all" },
79 { pointAction::EDGE, "edge" },
80});
81
82
83// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
84
86(
87 topoSet& set,
88 const bool add,
89 const word& setName
90) const
91{
92 // Load the set
93 pointSet loadedSet(mesh_, setName);
94
95 const labelHashSet& pointLabels = loadedSet;
96
97 if (option_ == ANY)
98 {
99 // Add faces with any point in loadedSet
100 for (const label pointi : pointLabels)
101 {
102 const labelList& pFaces = mesh_.pointFaces()[pointi];
103
104 addOrDelete(set, pFaces, add);
105 }
106 }
107 else if (option_ == ALL)
108 {
109 // Add all faces whose points are all in set.
110
111 // Count number of points using face.
112 Map<label> numPoints(pointLabels.size());
113
114 for (const label pointi : pointLabels)
115 {
116 const labelList& pFaces = mesh_.pointFaces()[pointi];
117
118 for (const label facei : pFaces)
119 {
120 ++(numPoints(facei, 0));
121 }
122 }
123
124
125 // Include faces that are referenced as many times as there are points
126 // in face -> all points of face
127 forAllConstIters(numPoints, iter)
128 {
129 const label facei = iter.key();
130 const label count = iter.val();
131
132 if (count == mesh_.faces()[facei].size())
133 {
134 addOrDelete(set, facei, add);
135 }
136 }
137 }
138 else if (option_ == EDGE)
139 {
140 const faceList& faces = mesh_.faces();
141
142 forAll(faces, facei)
143 {
144 const face& f = faces[facei];
145
146 forAll(f, fp)
147 {
148 if
149 (
150 pointLabels.found(f[fp])
151 && pointLabels.found(f.nextLabel(fp))
152 )
153 {
154 addOrDelete(set, facei, add);
155 break;
156 }
157 }
158 }
159 }
160}
161
162
163// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
164
166(
167 const polyMesh& mesh,
168 const word& setName,
169 const pointAction option
170)
171:
173 names_(one{}, setName),
174 option_(option)
175{}
176
177
179(
180 const polyMesh& mesh,
181 const dictionary& dict
182)
183:
185 names_(),
186 option_(pointActionNames_.get("option", dict))
187{
188 // Look for 'sets' or 'set'
189 if (!dict.readIfPresent("sets", names_))
190 {
191 names_.resize(1);
192 dict.readEntry("set", names_.first());
193 }
194}
195
196
198(
199 const polyMesh& mesh,
200 Istream& is
201)
202:
204 names_(one{}, word(checkIs(is))),
205 option_(pointActionNames_.read(checkIs(is)))
206{}
207
208
209// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
210
212(
213 const topoSetSource::setAction action,
214 topoSet& set
215) const
216{
217 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
218 {
219 if (verbose_)
220 {
221 Info<< " Adding faces according to pointSet "
222 << flatOutput(names_) << nl;
223 }
224
225 for (const word& setName : names_)
226 {
227 combine(set, true, setName);
228 }
229 }
230 else if (action == topoSetSource::SUBTRACT)
231 {
232 if (verbose_)
233 {
234 Info<< " Removing faces according to pointSet "
235 << flatOutput(names_) << nl;
236 }
237
238 for (const word& setName : names_)
239 {
240 combine(set, false, setName);
241 }
242 }
243}
244
245
246// ************************************************************************* //
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.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
T & first()
Return the first element of the list.
Definition: UListI.H:202
bool found(const T &val, label pos=0) const
True if the value if found in the list.
Definition: UListI.H:265
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
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:62
A topoSetFaceSource to select faces with any point or any edge within a given pointSet(s).
Definition: pointToFace.H:179
pointAction
Enumeration defining the valid options.
Definition: pointToFace.H:185
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: pointToFace.C:212
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1108
const labelListList & pointFaces() const
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
Definition: topoSetSource.H:68
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.
const polyMesh & mesh_
Reference to the mesh.
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:67
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
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:78
Namespace for OpenFOAM.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
List< label > labelList
A List of labels.
Definition: List.H:66
messageStream Info
Information stream (stdout output on master, null elsewhere)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=cellModel::ref(cellModel::HEX);labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){ pointMap[i]=i;}for(label i=0;i< nPoints;i++){ if(f[i] > 0.0) { hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells].reset(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei) { if(edges[ei].mag(points)< SMALL) { label start=pointMap[edges[ei].start()];while(start !=pointMap[start]) { start=pointMap[start];} label end=pointMap[edges[ei].end()];while(end !=pointMap[end]) { end=pointMap[end];} label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;} } cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){ cellShape &cs=cellShapes[celli];forAll(cs, i) { cs[i]=pointMap[cs[i]];} cs.collapse();}label bcIDs[11]={-1, 0, 2, 4, -1, 5, -1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={ &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &symmetryPolyPatch::typeName, &wedgePolyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &symmetryPolyPatch::typeName, &oldCyclicPolyPatch::typeName};enum patchTypeNames{ PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={ "piston", "valve", "liner", "cylinderHead", "axis", "wedge", "inflow", "outflow", "presin", "presout", "symmetryPlane", "cyclic"};List< SLList< face > > pFaces[nBCs]
Definition: readKivaGrid.H:235
labelList f(nPoints)
labelList pointLabels(nPoints, -1)
dict add("bounds", meshBb)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278