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 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 const Foam::Enum
71 <
73 >
74 Foam::pointToFace::pointActionNames_
75 ({
76  { pointAction::ANY, "any" },
77  { pointAction::ALL, "all" },
78  { pointAction::EDGE, "edge" },
79 });
80 
81 
82 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
83 
84 void Foam::pointToFace::combine
85 (
86  topoSet& set,
87  const bool add,
88  const word& setName
89 ) const
90 {
91  // Load the set
92  pointSet loadedSet(mesh_, setName);
93 
94  const labelHashSet& pointLabels = loadedSet;
95 
96  if (option_ == ANY)
97  {
98  // Add faces with any point in loadedSet
99  for (const label pointi : pointLabels)
100  {
101  const labelList& pFaces = mesh_.pointFaces()[pointi];
102 
103  addOrDelete(set, pFaces, add);
104  }
105  }
106  else if (option_ == ALL)
107  {
108  // Add all faces whose points are all in set.
109 
110  // Count number of points using face.
111  Map<label> numPoints(pointLabels.size());
112 
113  for (const label pointi : pointLabels)
114  {
115  const labelList& pFaces = mesh_.pointFaces()[pointi];
116 
117  for (const label facei : pFaces)
118  {
119  ++(numPoints(facei, 0));
120  }
121  }
122 
123 
124  // Include faces that are referenced as many times as there are points
125  // in face -> all points of face
126  forAllConstIters(numPoints, iter)
127  {
128  const label facei = iter.key();
129  const label count = iter.val();
130 
131  if (count == mesh_.faces()[facei].size())
132  {
133  addOrDelete(set, facei, add);
134  }
135  }
136  }
137  else if (option_ == EDGE)
138  {
139  const faceList& faces = mesh_.faces();
140 
141  forAll(faces, facei)
142  {
143  const face& f = faces[facei];
144 
145  forAll(f, fp)
146  {
147  if
148  (
149  pointLabels.found(f[fp])
150  && pointLabels.found(f.nextLabel(fp))
151  )
152  {
153  addOrDelete(set, facei, add);
154  break;
155  }
156  }
157  }
158  }
159 }
160 
161 
162 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
163 
165 (
166  const polyMesh& mesh,
167  const word& setName,
168  const pointAction option
169 )
170 :
172  names_(one(), setName),
173  option_(option)
174 {}
175 
176 
178 (
179  const polyMesh& mesh,
180  const dictionary& dict
181 )
182 :
184  names_(),
185  option_(pointActionNames_.get("option", dict))
186 {
187  // Look for 'sets' or 'set'
188  if (!dict.readIfPresent("sets", names_))
189  {
190  names_.resize(1);
191  dict.readEntry("set", names_.first());
192  }
193 }
194 
195 
197 (
198  const polyMesh& mesh,
199  Istream& is
200 )
201 :
203  names_(one(), word(checkIs(is))),
204  option_(pointActionNames_.read(checkIs(is)))
205 {}
206 
207 
208 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
209 
211 (
212  const topoSetSource::setAction action,
213  topoSet& set
214 ) const
215 {
216  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
217  {
218  if (verbose_)
219  {
220  Info<< " Adding faces according to pointSet "
221  << flatOutput(names_) << nl;
222  }
223 
224  for (const word& setName : names_)
225  {
226  combine(set, true, setName);
227  }
228  }
229  else if (action == topoSetSource::SUBTRACT)
230  {
231  if (verbose_)
232  {
233  Info<< " Removing faces according to pointSet "
234  << flatOutput(names_) << nl;
235  }
236 
237  for (const word& setName : names_)
238  {
239  combine(set, false, setName);
240  }
241  }
242 }
243 
244 
245 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::topoSetSource::ADD
Add elements to the set.
Definition: topoSetSource.H:101
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:51
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::primitiveMesh::pointFaces
const labelListList & pointFaces() const
Definition: primitiveMeshPointFaces.C:34
Foam::one
A class representing the concept of 1 (one), which can be used to avoid manipulating objects that are...
Definition: one.H:60
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
Foam::topoSetFaceSource
Base class of a topoSet source for selecting faces.
Definition: topoSetFaceSource.H:50
Foam::pointToFace::pointAction
pointAction
Enumeration defining the valid options.
Definition: pointToFace.H:91
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:106
polyMesh.H
pointToFace.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::pointToFace::pointToFace
pointToFace(const polyMesh &mesh, const word &setName, const pointAction option)
Construct from components.
Definition: pointToFace.C:165
Foam::pointToFace::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: pointToFace.C:211
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
pFaces
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]=cellShape(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
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
Foam::pointToFace::EDGE
Definition: pointToFace.H:95
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:66
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::topoSetSource::SUBTRACT
Subtract elements from the set.
Definition: topoSetSource.H:102
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1063
Foam::nl
constexpr char nl
Definition: Ostream.H:372
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
f
labelList f(nPoints)
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:74
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::pointToFace::ALL
Definition: pointToFace.H:94
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
Definition: topoSetSource.C:170
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::labelHashSet
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys and label hasher.
Definition: HashSet.H:415
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:151
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
pointLabels
labelList pointLabels(nPoints, -1)
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:417
Foam::pointToFace::ANY
Definition: pointToFace.H:93
pointSet.H