Added zone handling to sets.
[OpenFOAM-1.6.x.git] / src / meshTools / sets / cellSources / pointToCell / pointToCell.C
blob323809ab5be6f77ae36e6fd44e5ec485c91d2563
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "pointToCell.H"
28 #include "polyMesh.H"
29 #include "pointSet.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace Foam
38 defineTypeNameAndDebug(pointToCell, 0);
40 addToRunTimeSelectionTable(topoSetSource, pointToCell, word);
42 addToRunTimeSelectionTable(topoSetSource, pointToCell, istream);
47 Foam::topoSetSource::addToUsageTable Foam::pointToCell::usage_
49     pointToCell::typeName,
50     "\n    Usage: pointToCell <pointSet> any\n\n"
51     "    Select all cells with any point in the pointSet\n\n"
54 template<>
55 const char* Foam::NamedEnum<Foam::pointToCell::pointAction, 1>::names[] =
57     "any"
61 const Foam::NamedEnum<Foam::pointToCell::pointAction, 1>
62     Foam::pointToCell::pointActionNames_;
65 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
67 void Foam::pointToCell::combine(topoSet& set, const bool add) const
69     // Load the set
70     pointSet loadedSet(mesh_, setName_);
73     // Handle any selection
74     if (option_ == ANY)
75     {
76         for
77         (
78             pointSet::const_iterator iter = loadedSet.begin();
79             iter != loadedSet.end();
80             ++iter
81         )
82         {
83             label pointI = iter.key();
85             const labelList& pCells = mesh_.pointCells()[pointI];
87             forAll(pCells, pCellI)
88             {
89                 addOrDelete(set, pCells[pCellI], add);
90             }
91         }
92     }
96 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
98 // Construct from components
99 Foam::pointToCell::pointToCell
101     const polyMesh& mesh,
102     const word& setName,
103     const pointAction option
106     topoSetSource(mesh),
107     setName_(setName),
108     option_(option)
112 // Construct from dictionary
113 Foam::pointToCell::pointToCell
115     const polyMesh& mesh,
116     const dictionary& dict
119     topoSetSource(mesh),
120     setName_(dict.lookup("set")),
121     option_(pointActionNames_.read(dict.lookup("option")))
125 // Construct from Istream
126 Foam::pointToCell::pointToCell
128     const polyMesh& mesh,
129     Istream& is
132     topoSetSource(mesh),
133     setName_(checkIs(is)),
134     option_(pointActionNames_.read(checkIs(is)))
138 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
140 Foam::pointToCell::~pointToCell()
144 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
146 void Foam::pointToCell::applyToSet
148     const topoSetSource::setAction action,
149     topoSet& set
150 ) const
152     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
153     {
154         Info<< "    Adding cells according to pointSet " << setName_
155             << " ..." << endl;
157         combine(set, true);
158     }
159     else if (action == topoSetSource::DELETE)
160     {
161         Info<< "    Removing cells according to pointSet " << setName_
162             << " ..." << endl;
164         combine(set, false);
165     }
169 // ************************************************************************* //