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-2021 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 {
37 
38  template<>
39  const char* Foam::NamedEnum
40  <
42  3
43  >::names[] =
44  {
45  "any",
46  "all",
47  "edge"
48  };
49 }
50 
51 
53  Foam::pointToFace::pointActionNames_;
54 
55 
56 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
57 
58 void Foam::pointToFace::combine(topoSet& set, const bool add) const
59 {
60  // Load the set
61  pointSet loadedSet(mesh_, setName_);
62 
63  if (option_ == ANY)
64  {
65  // Add faces with any point in loadedSet
66  forAllConstIter(pointSet, loadedSet, iter)
67  {
68  const label pointi = iter.key();
69  const labelList& pFaces = mesh_.pointFaces()[pointi];
70 
71  forAll(pFaces, pFacei)
72  {
73  addOrDelete(set, pFaces[pFacei], add);
74  }
75  }
76  }
77  else if (option_ == ALL)
78  {
79  // Add all faces whose points are all in set.
80 
81  // Count number of points using face.
82  Map<label> numPoints(loadedSet.size());
83 
84  forAllConstIter(pointSet, loadedSet, iter)
85  {
86  const label pointi = iter.key();
87  const labelList& pFaces = mesh_.pointFaces()[pointi];
88 
89  forAll(pFaces, pFacei)
90  {
91  const label facei = pFaces[pFacei];
92 
93  Map<label>::iterator fndFace = numPoints.find(facei);
94 
95  if (fndFace == numPoints.end())
96  {
97  numPoints.insert(facei, 1);
98  }
99  else
100  {
101  fndFace()++;
102  }
103  }
104  }
105 
106 
107  // Include faces that are referenced as many times as there are points
108  // in face -> all points of face
109  forAllConstIter(Map<label>, numPoints, iter)
110  {
111  const label facei = iter.key();
112 
113  if (iter() == mesh_.faces()[facei].size())
114  {
115  addOrDelete(set, facei, add);
116  }
117  }
118  }
119  else if (option_ == EDGE)
120  {
121  const faceList& faces = mesh_.faces();
122  forAll(faces, facei)
123  {
124  const face& f = faces[facei];
125 
126  forAll(f, fp)
127  {
128  if (loadedSet.found(f[fp]) && loadedSet.found(f.nextLabel(fp)))
129  {
130  addOrDelete(set, facei, add);
131  break;
132  }
133  }
134  }
135  }
136 }
137 
138 
139 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
140 
142 (
143  const polyMesh& mesh,
144  const word& setName,
145  const pointAction option
146 )
147 :
148  topoSetSource(mesh),
149  setName_(setName),
150  option_(option)
151 {}
152 
153 
155 (
156  const polyMesh& mesh,
157  const dictionary& dict
158 )
159 :
160  topoSetSource(mesh),
161  setName_(dict.lookup("set")),
162  option_(pointActionNames_.read(dict.lookup("option")))
163 {}
164 
165 
166 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
167 
169 {}
170 
171 
172 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
173 
175 (
176  const topoSetSource::setAction action,
177  topoSet& set
178 ) const
179 {
180  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
181  {
182  Info<< " Adding faces according to pointSet " << setName_
183  << " ..." << endl;
184 
185  combine(set, true);
186  }
187  else if (action == topoSetSource::DELETE)
188  {
189  Info<< " Removing faces according to pointSet " << setName_
190  << " ..." << endl;
191 
192  combine(set, false);
193  }
194 }
195 
196 
197 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Macros for easy insertion into run-time selection tables.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
HashTable< label, label, Hash< label > >::iterator iterator
Definition: Map.H:56
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:54
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A topoSetSource to select faces based on use of points.
Definition: pointToFace.H:52
pointAction
Enumeration defining the valid options.
Definition: pointToFace.H:58
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: pointToFace.C:175
pointToFace(const polyMesh &mesh, const word &setName, const pointAction option)
Construct from components.
Definition: pointToFace.C:142
virtual ~pointToFace()
Destructor.
Definition: pointToFace.C:168
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1374
const labelListList & pointFaces() const
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
Definition: topoSetSource.C:96
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:65
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
List< face > faceList
Definition: faceListFwd.H:43
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
labelList f(nPoints)
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:229
dictionary dict