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 | Copyright (C) 2011-2016 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"
29 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(pointToFace, 0);
37  addToRunTimeSelectionTable(topoSetSource, pointToFace, word);
38  addToRunTimeSelectionTable(topoSetSource, pointToFace, istream);
39 
40  template<>
41  const char* Foam::NamedEnum
42  <
44  3
45  >::names[] =
46  {
47  "any",
48  "all",
49  "edge"
50  };
51 }
52 
53 
54 Foam::topoSetSource::addToUsageTable Foam::pointToFace::usage_
55 (
56  pointToFace::typeName,
57  "\n Usage: pointToFace <pointSet> any|all|edge\n\n"
58  " Select faces with\n"
59  " -any point in the pointSet\n"
60  " -all points in the pointSet\n\n"
61  " -two consecutive points (an edge) in the pointSet\n\n"
62 );
63 
65  Foam::pointToFace::pointActionNames_;
66 
67 
68 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
69 
70 void Foam::pointToFace::combine(topoSet& set, const bool add) const
71 {
72  // Load the set
73  pointSet loadedSet(mesh_, setName_);
74 
75  if (option_ == ANY)
76  {
77  // Add faces with any point in loadedSet
78  forAllConstIter(pointSet, loadedSet, iter)
79  {
80  const label pointi = iter.key();
81  const labelList& pFaces = mesh_.pointFaces()[pointi];
82 
83  forAll(pFaces, pFacei)
84  {
85  addOrDelete(set, pFaces[pFacei], add);
86  }
87  }
88  }
89  else if (option_ == ALL)
90  {
91  // Add all faces whose points are all in set.
92 
93  // Count number of points using face.
94  Map<label> numPoints(loadedSet.size());
95 
96  forAllConstIter(pointSet, loadedSet, iter)
97  {
98  const label pointi = iter.key();
99  const labelList& pFaces = mesh_.pointFaces()[pointi];
100 
101  forAll(pFaces, pFacei)
102  {
103  const label facei = pFaces[pFacei];
104 
105  Map<label>::iterator fndFace = numPoints.find(facei);
106 
107  if (fndFace == numPoints.end())
108  {
109  numPoints.insert(facei, 1);
110  }
111  else
112  {
113  fndFace()++;
114  }
115  }
116  }
117 
118 
119  // Include faces that are referenced as many times as there are points
120  // in face -> all points of face
121  forAllConstIter(Map<label>, numPoints, iter)
122  {
123  const label facei = iter.key();
124 
125  if (iter() == mesh_.faces()[facei].size())
126  {
127  addOrDelete(set, facei, add);
128  }
129  }
130  }
131  else if (option_ == EDGE)
132  {
133  const faceList& faces = mesh_.faces();
134  forAll(faces, facei)
135  {
136  const face& f = faces[facei];
137 
138  forAll(f, fp)
139  {
140  if (loadedSet.found(f[fp]) && loadedSet.found(f.nextLabel(fp)))
141  {
142  addOrDelete(set, facei, add);
143  break;
144  }
145  }
146  }
147  }
148 }
149 
150 
151 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
152 
153 // Construct from components
155 (
156  const polyMesh& mesh,
157  const word& setName,
158  const pointAction option
159 )
160 :
161  topoSetSource(mesh),
162  setName_(setName),
163  option_(option)
164 {}
165 
166 
167 // Construct from dictionary
169 (
170  const polyMesh& mesh,
171  const dictionary& dict
172 )
173 :
174  topoSetSource(mesh),
175  setName_(dict.lookup("set")),
176  option_(pointActionNames_.read(dict.lookup("option")))
177 {}
178 
179 
180 // Construct from Istream
182 (
183  const polyMesh& mesh,
184  Istream& is
185 )
186 :
187  topoSetSource(mesh),
188  setName_(checkIs(is)),
189  option_(pointActionNames_.read(checkIs(is)))
190 {}
191 
192 
193 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
194 
196 {}
197 
198 
199 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
200 
202 (
203  const topoSetSource::setAction action,
204  topoSet& set
205 ) const
206 {
207  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
208  {
209  Info<< " Adding faces according to pointSet " << setName_
210  << " ..." << endl;
211 
212  combine(set, true);
213  }
214  else if (action == topoSetSource::DELETE)
215  {
216  Info<< " Removing faces according to pointSet " << setName_
217  << " ..." << endl;
218 
219  combine(set, false);
220  }
221 }
222 
223 
224 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:106
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:137
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:253
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
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:155
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:138
A class for handling words, derived from string.
Definition: word.H:59
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,&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
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: pointToFace.C:202
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
virtual ~pointToFace()
Destructor.
Definition: pointToFace.C:195
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
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
label nextLabel(const label i) const
Next vertex on face.
Definition: faceI.H:117
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451