initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / sets / cellSources / zoneToCell / zoneToCell.C
blob14b6deb7f37771b062c29e8d635f7feae33448aa
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 "zoneToCell.H"
28 #include "polyMesh.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
37 defineTypeNameAndDebug(zoneToCell, 0);
39 addToRunTimeSelectionTable(topoSetSource, zoneToCell, word);
41 addToRunTimeSelectionTable(topoSetSource, zoneToCell, istream);
46 Foam::topoSetSource::addToUsageTable Foam::zoneToCell::usage_
48     zoneToCell::typeName,
49     "\n    Usage: zoneToCell zone\n\n"
50     "    Select all cells in the cellZone."
51     " Note:accepts wildcards for zone.\n\n"
55 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
57 void Foam::zoneToCell::combine(topoSet& set, const bool add) const
59     bool hasMatched = false;
61     forAll(mesh_.cellZones(), i)
62     {
63         const cellZone& zone = mesh_.cellZones()[i];
65         if (zoneName_.match(zone.name()))
66         {
67             const labelList& cellLabels = mesh_.cellZones()[i];
69             Info<< "    Found matching zone " << zone.name()
70                 << " with " << cellLabels.size() << " cells." << endl;
72             hasMatched = true;
74             forAll(cellLabels, i)
75             {
76                 // Only do active cells
77                 if (cellLabels[i] < mesh_.nCells())
78                 {
79                     addOrDelete(set, cellLabels[i], add);
80                 }
81             }
82         }
83     }
85     if (!hasMatched)
86     {
87         WarningIn("zoneToCell::combine(topoSet&, const bool)")
88             << "Cannot find any cellZone named " << zoneName_ << endl
89             << "Valid names are " << mesh_.cellZones().names() << endl;
90     }
94 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
96 // Construct from components
97 Foam::zoneToCell::zoneToCell
99     const polyMesh& mesh,
100     const word& zoneName
103     topoSetSource(mesh),
104     zoneName_(zoneName)
108 // Construct from dictionary
109 Foam::zoneToCell::zoneToCell
111     const polyMesh& mesh,
112     const dictionary& dict
115     topoSetSource(mesh),
116     zoneName_(dict.lookup("name"))
120 // Construct from Istream
121 Foam::zoneToCell::zoneToCell
123     const polyMesh& mesh,
124     Istream& is
127     topoSetSource(mesh),
128     zoneName_(checkIs(is))
132 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
134 Foam::zoneToCell::~zoneToCell()
138 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
140 void Foam::zoneToCell::applyToSet
142     const topoSetSource::setAction action,
143     topoSet& set
144 ) const
146     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
147     {
148         Info<< "    Adding all cells of cellZone " << zoneName_ << " ..."
149             << endl;
151         combine(set, true);
152     }
153     else if (action == topoSetSource::DELETE)
154     {
155         Info<< "    Removing all cells of cellZone " << zoneName_ << " ..."
156             << endl;
158         combine(set, false);
159     }
163 // ************************************************************************* //