FreeFOAM The Cross-Platform CFD Toolkit
cellToPoint.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 "cellToPoint.H"
27 #include <OpenFOAM/polyMesh.H>
28 #include <meshTools/cellSet.H>
29 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 defineTypeNameAndDebug(cellToPoint, 0);
38 
39 addToRunTimeSelectionTable(topoSetSource, cellToPoint, word);
40 
41 addToRunTimeSelectionTable(topoSetSource, cellToPoint, istream);
42 
43 }
44 
45 
46 Foam::topoSetSource::addToUsageTable Foam::cellToPoint::usage_
47 (
48  cellToPoint::typeName,
49  "\n Usage: cellToPoint <cellSet> all\n\n"
50  " Select all points of cells in the cellSet\n\n"
51 );
52 
53 template<>
55 {
56  "all"
57 };
58 
60  Foam::cellToPoint::cellActionNames_;
61 
62 
63 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
64 
65 void Foam::cellToPoint::combine(topoSet& set, const bool add) const
66 {
67  // Load the set
68  cellSet loadedSet(mesh_, setName_);
69 
70  // Add all point from cells in loadedSet
71  for
72  (
73  cellSet::const_iterator iter = loadedSet.begin();
74  iter != loadedSet.end();
75  ++iter
76  )
77  {
78  label cellI = iter.key();
79 
80  const labelList& cFaces = mesh_.cells()[cellI];
81 
82  forAll(cFaces, cFaceI)
83  {
84  const face& f = mesh_.faces()[cFaces[cFaceI]];
85 
86  forAll(f, fp)
87  {
88  addOrDelete(set, f[fp], add);
89  }
90  }
91  }
92 }
93 
94 
95 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96 
97 // Construct from components
99 (
100  const polyMesh& mesh,
101  const word& setName,
102  const cellAction option
103 )
104 :
105  topoSetSource(mesh),
106  setName_(setName),
107  option_(option)
108 {}
109 
110 
111 // Construct from dictionary
113 (
114  const polyMesh& mesh,
115  const dictionary& dict
116 )
117 :
118  topoSetSource(mesh),
119  setName_(dict.lookup("set")),
120  option_(cellActionNames_.read(dict.lookup("option")))
121 {}
122 
123 
124 // Construct from Istream
126 (
127  const polyMesh& mesh,
128  Istream& is
129 )
130 :
131  topoSetSource(mesh),
132  setName_(checkIs(is)),
133  option_(cellActionNames_.read(checkIs(is)))
134 {}
135 
136 
137 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
138 
140 {}
141 
142 
143 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
144 
146 (
147  const topoSetSource::setAction action,
148  topoSet& set
149 ) const
150 {
151  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
152  {
153  Info<< " Adding from " << setName_ << " ..." << endl;
154 
155  combine(set, true);
156  }
157  else if (action == topoSetSource::DELETE)
158  {
159  Info<< " Removing from " << setName_ << " ..." << endl;
160 
161  combine(set, false);
162  }
163 }
164 
165 
166 // ************************ vim: set sw=4 sts=4 et: ************************ //