FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/polyMesh.H>
28 #include <meshTools/pointSet.H>
29 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 defineTypeNameAndDebug(pointToFace, 0);
38 
39 addToRunTimeSelectionTable(topoSetSource, pointToFace, word);
40 
41 addToRunTimeSelectionTable(topoSetSource, pointToFace, istream);
42 
43 }
44 
45 
46 Foam::topoSetSource::addToUsageTable Foam::pointToFace::usage_
47 (
48  pointToFace::typeName,
49  "\n Usage: pointToFace <pointSet> any|all\n\n"
50  " Select faces with\n"
51  " -any point in the pointSet\n"
52  " -all points in the pointSet\n\n"
53 );
54 
55 template<>
57 {
58  "any",
59  "all"
60 };
61 
63  Foam::pointToFace::pointActionNames_;
64 
65 
66 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
67 
68 void Foam::pointToFace::combine(topoSet& set, const bool add) const
69 {
70  // Load the set
71  pointSet loadedSet(mesh_, setName_);
72 
73  if (option_ == ANY)
74  {
75  // Add faces with any point in loadedSet
76  for
77  (
78  pointSet::const_iterator iter = loadedSet.begin();
79  iter != loadedSet.end();
80  ++iter
81  )
82  {
83  label pointI = iter.key();
84 
85  const labelList& pFaces = mesh_.pointFaces()[pointI];
86 
87  forAll(pFaces, pFaceI)
88  {
89  addOrDelete(set, pFaces[pFaceI], add);
90  }
91  }
92  }
93  else if (option_ == ALL)
94  {
95  // Add all faces whose points are all in set.
96 
97  // Count number of points using face.
98  Map<label> numPoints(loadedSet.size());
99 
100  forAllConstIter(pointSet, loadedSet, iter)
101  {
102  label pointI = iter.key();
103 
104  const labelList& pFaces = mesh_.pointFaces()[pointI];
105 
106  forAll(pFaces, pFaceI)
107  {
108  label faceI = pFaces[pFaceI];
109 
110  Map<label>::iterator fndFace = numPoints.find(faceI);
111 
112  if (fndFace == numPoints.end())
113  {
114  numPoints.insert(faceI, 1);
115  }
116  else
117  {
118  fndFace()++;
119  }
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  for
127  (
128  Map<label>::const_iterator iter = numPoints.begin();
129  iter != numPoints.end();
130  ++iter
131  )
132  {
133  label faceI = iter.key();
134 
135  if (iter() == mesh_.faces()[faceI].size())
136  {
137  addOrDelete(set, faceI, add);
138  }
139  }
140  }
141 }
142 
143 
144 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
145 
146 // Construct from components
148 (
149  const polyMesh& mesh,
150  const word& setName,
151  const pointAction option
152 )
153 :
154  topoSetSource(mesh),
155  setName_(setName),
156  option_(option)
157 {}
158 
159 
160 // Construct from dictionary
162 (
163  const polyMesh& mesh,
164  const dictionary& dict
165 )
166 :
167  topoSetSource(mesh),
168  setName_(dict.lookup("set")),
169  option_(pointActionNames_.read(dict.lookup("option")))
170 {}
171 
172 
173 // Construct from Istream
175 (
176  const polyMesh& mesh,
177  Istream& is
178 )
179 :
180  topoSetSource(mesh),
181  setName_(checkIs(is)),
182  option_(pointActionNames_.read(checkIs(is)))
183 {}
184 
185 
186 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
187 
189 {}
190 
191 
192 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
193 
195 (
196  const topoSetSource::setAction action,
197  topoSet& set
198 ) const
199 {
200  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
201  {
202  Info<< " Adding faces according to pointSet " << setName_
203  << " ..." << endl;
204 
205  combine(set, true);
206  }
207  else if (action == topoSetSource::DELETE)
208  {
209  Info<< " Removing faces according to pointSet " << setName_
210  << " ..." << endl;
211 
212  combine(set, false);
213  }
214 }
215 
216 
217 // ************************ vim: set sw=4 sts=4 et: ************************ //