FreeFOAM The Cross-Platform CFD Toolkit
pointToCell.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 "pointToCell.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(pointToCell, 0);
38 
39 addToRunTimeSelectionTable(topoSetSource, pointToCell, word);
40 
41 addToRunTimeSelectionTable(topoSetSource, pointToCell, istream);
42 
43 }
44 
45 
46 Foam::topoSetSource::addToUsageTable Foam::pointToCell::usage_
47 (
48  pointToCell::typeName,
49  "\n Usage: pointToCell <pointSet> any\n\n"
50  " Select all cells with any point in the pointSet\n\n"
51 );
52 
53 template<>
55 {
56  "any"
57 };
58 
59 
61  Foam::pointToCell::pointActionNames_;
62 
63 
64 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
65 
66 void Foam::pointToCell::combine(topoSet& set, const bool add) const
67 {
68  // Load the set
69  pointSet loadedSet(mesh_, setName_);
70 
71 
72  // Handle any selection
73  if (option_ == ANY)
74  {
75  for
76  (
77  pointSet::const_iterator iter = loadedSet.begin();
78  iter != loadedSet.end();
79  ++iter
80  )
81  {
82  label pointI = iter.key();
83 
84  const labelList& pCells = mesh_.pointCells()[pointI];
85 
86  forAll(pCells, pCellI)
87  {
88  addOrDelete(set, pCells[pCellI], 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 pointAction 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_(pointActionNames_.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_(pointActionNames_.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 cells according to pointSet " << setName_
154  << " ..." << endl;
155 
156  combine(set, true);
157  }
158  else if (action == topoSetSource::DELETE)
159  {
160  Info<< " Removing cells according to pointSet " << setName_
161  << " ..." << endl;
162 
163  combine(set, false);
164  }
165 }
166 
167 
168 // ************************ vim: set sw=4 sts=4 et: ************************ //