Forward compatibility: flex
[foam-extend-3.2.git] / src / meshTools / sets / cellSources / faceZoneToCell / faceZoneToCell.C
blob8e882485fb835e1dc459c9da8acfc1831fa0ab8c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "faceZoneToCell.H"
27 #include "polyMesh.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
36 defineTypeNameAndDebug(faceZoneToCell, 0);
38 addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, word);
40 addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, istream);
45 Foam::topoSetSource::addToUsageTable Foam::faceZoneToCell::usage_
47     faceZoneToCell::typeName,
48     "\n    Usage: faceZoneToCell zone master|slave\n\n"
49     "    Select master or slave side of the faceZone."
50     " Note:accepts wildcards for zone.\n\n"
54 template<>
55 const char* Foam::NamedEnum<Foam::faceZoneToCell::faceAction, 2>::names[] =
57     "master",
58     "slave"
62 const Foam::NamedEnum<Foam::faceZoneToCell::faceAction, 2>
63     Foam::faceZoneToCell::faceActionNames_;
66 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
68 void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
70     bool hasMatched = false;
72     forAll(mesh_.faceZones(), i)
73     {
74         const faceZone& zone = mesh_.faceZones()[i];
76         if (zoneName_.match(zone.name()))
77         {
78             const labelList& cellLabels =
79             (
80                 option_ == MASTER
81               ? zone.masterCells()
82               : zone.slaveCells()
83             );
85             Info<< "    Found matching zone " << zone.name()
86                 << " with " << cellLabels.size() << " cells on selected side."
87                 << endl;
89             hasMatched = true;
91             forAll(cellLabels, i)
92             {
93                 // Only do active cells
94                 if (cellLabels[i] < mesh_.nCells())
95                 {
96                     addOrDelete(set, cellLabels[i], add);
97                 }
98             }
99         }
100     }
102     if (!hasMatched)
103     {
104         WarningIn("faceZoneToCell::combine(topoSet&, const bool)")
105             << "Cannot find any faceZone named " << zoneName_ << endl
106             << "Valid names are " << mesh_.faceZones().names() << endl;
107     }
111 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
113 // Construct from components
114 Foam::faceZoneToCell::faceZoneToCell
116     const polyMesh& mesh,
117     const word& zoneName,
118     const faceAction option
121     topoSetSource(mesh),
122     zoneName_(zoneName),
123     option_(option)
127 // Construct from dictionary
128 Foam::faceZoneToCell::faceZoneToCell
130     const polyMesh& mesh,
131     const dictionary& dict
134     topoSetSource(mesh),
135     zoneName_(dict.lookup("name")),
136     option_(faceActionNames_.read(dict.lookup("option")))
140 // Construct from Istream
141 Foam::faceZoneToCell::faceZoneToCell
143     const polyMesh& mesh,
144     Istream& is
147     topoSetSource(mesh),
148     zoneName_(checkIs(is)),
149     option_(faceActionNames_.read(checkIs(is)))
153 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
155 Foam::faceZoneToCell::~faceZoneToCell()
159 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
161 void Foam::faceZoneToCell::applyToSet
163     const topoSetSource::setAction action,
164     topoSet& set
165 ) const
167     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
168     {
169         Info<< "    Adding all " << faceActionNames_[option_]
170             << " cells of faceZone " << zoneName_ << " ..." << endl;
172         combine(set, true);
173     }
174     else if (action == topoSetSource::DELETE)
175     {
176         Info<< "    Removing all " << faceActionNames_[option_]
177             << " cells of faceZone " << zoneName_ << " ..." << endl;
179         combine(set, false);
180     }
184 // ************************************************************************* //