pointToFace.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "pointToFace.H"
27 #include "polyMesh.H"
28 #include "pointSet.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(pointToFace, 0);
36  addToRunTimeSelectionTable(topoSetSource, pointToFace, word);
37  addToRunTimeSelectionTable(topoSetSource, pointToFace, istream);
38 
39  template<>
40  const char* Foam::NamedEnum
41  <
43  3
44  >::names[] =
45  {
46  "any",
47  "all",
48  "edge"
49  };
50 }
51 
52 
53 Foam::topoSetSource::addToUsageTable Foam::pointToFace::usage_
54 (
55  pointToFace::typeName,
56  "\n Usage: pointToFace <pointSet> any|all|edge\n\n"
57  " Select faces with\n"
58  " -any point in the pointSet\n"
59  " -all points in the pointSet\n\n"
60  " -two consecutive points (an edge) in the pointSet\n\n"
61 );
62 
64  Foam::pointToFace::pointActionNames_;
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
69 void Foam::pointToFace::combine(topoSet& set, const bool add) const
70 {
71  // Load the set
72  pointSet loadedSet(mesh_, setName_);
73 
74  if (option_ == ANY)
75  {
76  // Add faces with any point in loadedSet
77  forAllConstIter(pointSet, loadedSet, iter)
78  {
79  const label pointi = iter.key();
80  const labelList& pFaces = mesh_.pointFaces()[pointi];
81 
82  forAll(pFaces, pFacei)
83  {
84  addOrDelete(set, pFaces[pFacei], add);
85  }
86  }
87  }
88  else if (option_ == ALL)
89  {
90  // Add all faces whose points are all in set.
91 
92  // Count number of points using face.
93  Map<label> numPoints(loadedSet.size());
94 
95  forAllConstIter(pointSet, loadedSet, iter)
96  {
97  const label pointi = iter.key();
98  const labelList& pFaces = mesh_.pointFaces()[pointi];
99 
100  forAll(pFaces, pFacei)
101  {
102  const label facei = pFaces[pFacei];
103 
104  Map<label>::iterator fndFace = numPoints.find(facei);
105 
106  if (fndFace == numPoints.end())
107  {
108  numPoints.insert(facei, 1);
109  }
110  else
111  {
112  fndFace()++;
113  }
114  }
115  }
116 
117 
118  // Include faces that are referenced as many times as there are points
119  // in face -> all points of face
120  forAllConstIter(Map<label>, numPoints, iter)
121  {
122  const label facei = iter.key();
123 
124  if (iter() == mesh_.faces()[facei].size())
125  {
126  addOrDelete(set, facei, add);
127  }
128  }
129  }
130  else if (option_ == EDGE)
131  {
132  const faceList& faces = mesh_.faces();
133  forAll(faces, facei)
134  {
135  const face& f = faces[facei];
136 
137  forAll(f, fp)
138  {
139  if (loadedSet.found(f[fp]) && loadedSet.found(f.nextLabel(fp)))
140  {
141  addOrDelete(set, facei, add);
142  break;
143  }
144  }
145  }
146  }
147 }
148 
149 
150 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
151 
153 (
154  const polyMesh& mesh,
155  const word& setName,
156  const pointAction option
157 )
158 :
159  topoSetSource(mesh),
160  setName_(setName),
161  option_(option)
162 {}
163 
164 
166 (
167  const polyMesh& mesh,
168  const dictionary& dict
169 )
170 :
171  topoSetSource(mesh),
172  setName_(dict.lookup("set")),
173  option_(pointActionNames_.read(dict.lookup("option")))
174 {}
175 
176 
178 (
179  const polyMesh& mesh,
180  Istream& is
181 )
182 :
183  topoSetSource(mesh),
184  setName_(checkIs(is)),
185  option_(pointActionNames_.read(checkIs(is)))
186 {}
187 
188 
189 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
190 
192 {}
193 
194 
195 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
196 
198 (
199  const topoSetSource::setAction action,
200  topoSet& set
201 ) const
202 {
203  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
204  {
205  Info<< " Adding faces according to pointSet " << setName_
206  << " ..." << endl;
207 
208  combine(set, true);
209  }
210  else if (action == topoSetSource::DELETE)
211  {
212  Info<< " Removing faces according to pointSet " << setName_
213  << " ..." << endl;
214 
215  combine(set, false);
216  }
217 }
218 
219 
220 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:59
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112
A set of point labels.
Definition: pointSet.H:48
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
label nextLabel(const label i) const
Next vertex on face.
Definition: faceI.H:100
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
pointToFace(const polyMesh &mesh, const word &setName, const pointAction option)
Construct from components.
Definition: pointToFace.C:153
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
pointAction
Enumeration defining the valid options.
Definition: pointToFace.H:57
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:142
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:113
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
virtual ~pointToFace()
Destructor.
Definition: pointToFace.C:191
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=*(cellModeller::lookup("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, &mergedCyclicPolyPatch::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
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Class with constructor to add usage string to table.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: pointToFace.C:198
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844