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-2024 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 
29 #include "pointToFace.H"
30 #include "polyMesh.H"
31 #include "pointSet.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(pointToFace, 0);
39  addToRunTimeSelectionTable(topoSetSource, pointToFace, word);
40  addToRunTimeSelectionTable(topoSetSource, pointToFace, istream);
41  addToRunTimeSelectionTable(topoSetFaceSource, pointToFace, word);
42  addToRunTimeSelectionTable(topoSetFaceSource, pointToFace, istream);
44  (
45  topoSetFaceSource,
46  pointToFace,
47  word,
48  point
49  );
51  (
52  topoSetFaceSource,
53  pointToFace,
54  istream,
55  point
56  );
57 }
58 
59 
60 Foam::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 
71 const Foam::Enum
72 <
74 >
75 Foam::pointToFace::pointActionNames_
76 ({
77  { pointAction::ANY, "any" },
78  { pointAction::ALL, "all" },
79  { pointAction::EDGE, "edge" },
80 });
81 
82 
83 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
84 
85 template<class Selector>
86 void Foam::pointToFace::combineImpl
87 (
88  topoSet& set,
89  const bool add,
90  const Selector& pointLabels
91 ) const
92 {
93  if (option_ == ANY)
94  {
95  // Add faces with any point in loadedSet
96  for (const label pointi : pointLabels)
97  {
98  const labelList& pFaces = mesh_.pointFaces()[pointi];
99 
100  addOrDelete(set, pFaces, add);
101  }
102  }
103  else if (option_ == ALL)
104  {
105  // Add all faces whose points are all in set.
106 
107  // Count number of points using face.
108  Map<label> numPoints(pointLabels.size());
109 
110  for (const label pointi : pointLabels)
111  {
112  const labelList& pFaces = mesh_.pointFaces()[pointi];
113 
114  for (const label facei : pFaces)
115  {
116  ++(numPoints(facei, 0));
117  }
118  }
119 
120 
121  // Include faces that are referenced as many times as there are points
122  // in face -> all points of face
123  forAllConstIters(numPoints, iter)
124  {
125  const label facei = iter.key();
126  const label count = iter.val();
127 
128  if (count == mesh_.faces()[facei].size())
129  {
130  addOrDelete(set, facei, add);
131  }
132  }
133  }
134  else if (option_ == EDGE)
135  {
136  const faceList& faces = mesh_.faces();
137 
138  forAll(faces, facei)
139  {
140  const face& f = faces[facei];
141 
142  forAll(f, fp)
143  {
144  if
145  (
146  pointLabels.found(f[fp])
147  && pointLabels.found(f.nextLabel(fp))
148  )
149  {
150  addOrDelete(set, facei, add);
151  break;
152  }
153  }
154  }
155  }
156 }
157 
158 
159 void Foam::pointToFace::combine
160 (
161  topoSet& set,
162  const bool add,
163  const word& setName
164 ) const
165 {
166  if (isZone_)
167  {
168  const labelList& pointLabels = mesh_.pointZones()[setName];
169 
170  combineImpl(set, add, pointLabels);
171  }
172  else
173  {
174  // Load the set
175  pointSet loadedSet(mesh_, setName, IOobject::NO_REGISTER);
176  const labelHashSet& pointLabels = loadedSet;
177 
178  combineImpl(set, add, pointLabels);
179  }
180 }
181 
182 
183 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
184 
186 (
187  const polyMesh& mesh,
188  const word& setName,
189  const pointAction option
190 )
191 :
192  topoSetFaceSource(mesh),
193  names_(Foam::one{}, setName),
194  isZone_(false),
195  option_(option)
196 {}
197 
198 
200 (
201  const polyMesh& mesh,
202  const dictionary& dict
203 )
204 :
205  topoSetFaceSource(mesh, dict),
206  names_(),
207  isZone_(topoSetSource::readNames(dict, names_)),
208  option_(pointActionNames_.get("option", dict))
209 {}
210 
211 
213 (
214  const polyMesh& mesh,
215  Istream& is
216 )
217 :
219  names_(Foam::one{}, word(checkIs(is))),
220  isZone_(false),
221  option_(pointActionNames_.read(checkIs(is)))
222 {}
223 
224 
225 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
226 
228 (
229  const topoSetSource::setAction action,
230  topoSet& set
231 ) const
232 {
233  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
234  {
235  if (verbose_)
236  {
237  Info<< " Adding faces according to point "
238  << (isZone_ ? "zones: " : "sets: ")
239  << flatOutput(names_) << nl;
240  }
241 
242  for (const word& setName : names_)
243  {
244  combine(set, true, setName);
245  }
246  }
247  else if (action == topoSetSource::SUBTRACT)
248  {
249  if (verbose_)
250  {
251  Info<< " Removing faces according to point "
252  << (isZone_ ? "zones: " : "sets: ")
253  << flatOutput(names_) << nl;
254  }
255 
256  for (const word& setName : names_)
257  {
258  combine(set, false, setName);
259  }
260  }
261 }
262 
263 
264 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
labelList pointLabels(nPoints, -1)
Create a new set and ADD elements to it.
Add elements to current set.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
pointToFace(const polyMesh &mesh, const word &setName, const pointAction option)
Construct from components.
Definition: pointToFace.C:179
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when &#39;add&#39; is true.
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
pointAction
Enumeration defining the valid options.
Definition: pointToFace.H:191
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
List< face > faceList
List of faces.
Definition: faceListFwd.H:39
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:62
dynamicFvMesh & mesh
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces...
setAction
Enumeration defining various actions.
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1103
const polyMesh & mesh_
Reference to the mesh.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
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
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
Subtract elements from current set.
vector point
Point is a vector.
Definition: point.H:37
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
Class with constructor to add usage string to table.
messageStream Info
Information stream (stdout output on master, null elsewhere)
const labelListList & pointFaces() const
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
List< label > labelList
A List of labels.
Definition: List.H:62
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: pointToFace.C:221
Do not request registration (bool: false)
Namespace for OpenFOAM.
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:56
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225