initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / sets / cellSources / faceZoneToCell / faceZoneToCell.C
blob526620fe14746be56d0e433274be25edb0b5d8cd
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 "faceZoneToCell.H"
28 #include "polyMesh.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
37 defineTypeNameAndDebug(faceZoneToCell, 0);
39 addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, word);
41 addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, istream);
46 Foam::topoSetSource::addToUsageTable Foam::faceZoneToCell::usage_
48     faceZoneToCell::typeName,
49     "\n    Usage: faceZoneToCell zone master|slave\n\n"
50     "    Select master or slave side of the faceZone."
51     " Note:accepts wildcards for zone.\n\n"
55 template<>
56 const char* Foam::NamedEnum<Foam::faceZoneToCell::faceAction, 2>::names[] =
58     "master",
59     "slave"
63 const Foam::NamedEnum<Foam::faceZoneToCell::faceAction, 2>
64     Foam::faceZoneToCell::faceActionNames_;
67 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
69 void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
71     bool hasMatched = false;
73     forAll(mesh_.faceZones(), i)
74     {
75         const faceZone& zone = mesh_.faceZones()[i];
77         if (zoneName_.match(zone.name()))
78         {
79             const labelList& cellLabels =
80             (
81                 option_ == MASTER
82               ? zone.masterCells()
83               : zone.slaveCells()
84             );
86             Info<< "    Found matching zone " << zone.name()
87                 << " with " << cellLabels.size() << " cells on selected side."
88                 << endl;
90             hasMatched = true;
92             forAll(cellLabels, i)
93             {
94                 // Only do active cells
95                 if (cellLabels[i] < mesh_.nCells())
96                 {
97                     addOrDelete(set, cellLabels[i], add);
98                 }
99             }
100         }
101     }
103     if (!hasMatched)
104     {
105         WarningIn("faceZoneToCell::combine(topoSet&, const bool)")
106             << "Cannot find any faceZone named " << zoneName_ << endl
107             << "Valid names are " << mesh_.faceZones().names() << endl;
108     }
112 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
114 // Construct from components
115 Foam::faceZoneToCell::faceZoneToCell
117     const polyMesh& mesh,
118     const word& zoneName,
119     const faceAction option
122     topoSetSource(mesh),
123     zoneName_(zoneName),
124     option_(option)
128 // Construct from dictionary
129 Foam::faceZoneToCell::faceZoneToCell
131     const polyMesh& mesh,
132     const dictionary& dict
135     topoSetSource(mesh),
136     zoneName_(dict.lookup("name")),
137     option_(faceActionNames_.read(dict.lookup("option")))
141 // Construct from Istream
142 Foam::faceZoneToCell::faceZoneToCell
144     const polyMesh& mesh,
145     Istream& is
148     topoSetSource(mesh),
149     zoneName_(checkIs(is)),
150     option_(faceActionNames_.read(checkIs(is)))
154 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
156 Foam::faceZoneToCell::~faceZoneToCell()
160 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
162 void Foam::faceZoneToCell::applyToSet
164     const topoSetSource::setAction action,
165     topoSet& set
166 ) const
168     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
169     {
170         Info<< "    Adding all " << faceActionNames_[option_]
171             << " cells of faceZone " << zoneName_ << " ..." << endl;
173         combine(set, true);
174     }
175     else if (action == topoSetSource::DELETE)
176     {
177         Info<< "    Removing all " << faceActionNames_[option_]
178             << " cells of faceZone " << zoneName_ << " ..." << endl;
180         combine(set, false);
181     }
185 // ************************************************************************* //