Added zone handling to sets.
[OpenFOAM-1.6.x.git] / src / meshTools / sets / faceSources / patchToFace / patchToFace.C
blob0d76a37e4bedfe9616c703ea6d3b056ba641dcc6
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 "patchToFace.H"
28 #include "polyMesh.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
37 defineTypeNameAndDebug(patchToFace, 0);
39 addToRunTimeSelectionTable(topoSetSource, patchToFace, word);
41 addToRunTimeSelectionTable(topoSetSource, patchToFace, istream);
46 Foam::topoSetSource::addToUsageTable Foam::patchToFace::usage_
48     patchToFace::typeName,
49     "\n    Usage: patchToFace patch\n\n"
50     "    Select all faces in the patch. Note:accepts wildcards for patch.\n\n"
54 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
56 void Foam::patchToFace::combine(topoSet& set, const bool add) const
58     bool hasMatched = false;
60     forAll(mesh_.boundaryMesh(), patchI)
61     {
62         const polyPatch& pp = mesh_.boundaryMesh()[patchI];
64         if (patchName_.match(pp.name()))
65         {
66             Info<< "    Found matching patch " << pp.name()
67                 << " with " << pp.size() << " faces." << endl;
69             hasMatched = true;
72             for
73             (
74                 label faceI = pp.start();
75                 faceI < pp.start() + pp.size();
76                 faceI++
77             )
78             {
79                 addOrDelete(set, faceI, add);
80             }
81         }
82     }
84     if (!hasMatched)
85     {
86         WarningIn("patchToFace::combine(topoSet&, const bool)")
87             << "Cannot find any patch named " << patchName_ << endl
88             << "Valid names are " << mesh_.boundaryMesh().names() << endl;
89     }
93 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
95 // Construct from components
96 Foam::patchToFace::patchToFace
98     const polyMesh& mesh,
99     const word& patchName
102     topoSetSource(mesh),
103     patchName_(patchName)
107 // Construct from dictionary
108 Foam::patchToFace::patchToFace
110     const polyMesh& mesh,
111     const dictionary& dict
114     topoSetSource(mesh),
115     patchName_(dict.lookup("name"))
119 // Construct from Istream
120 Foam::patchToFace::patchToFace
122     const polyMesh& mesh,
123     Istream& is
126     topoSetSource(mesh),
127     patchName_(checkIs(is))
131 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
133 Foam::patchToFace::~patchToFace()
137 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
139 void Foam::patchToFace::applyToSet
141     const topoSetSource::setAction action,
142     topoSet& set
143 ) const
145     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
146     {
147         Info<< "    Adding all faces of patch " << patchName_ << " ..." << endl;
149         combine(set, true);
150     }
151     else if (action == topoSetSource::DELETE)
152     {
153         Info<< "    Removing all faces of patch " << patchName_ << " ..."
154             << endl;
156         combine(set, false);
157     }
161 // ************************************************************************* //