Added zone handling to sets.
[OpenFOAM-1.6.x.git] / src / meshTools / sets / cellSources / shapeToCell / shapeToCell.C
blobc8f23570d4d9adabdbf22a4f0add95fe7581c730
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 "shapeToCell.H"
28 #include "polyMesh.H"
29 #include "mathematicalConstants.H"
30 #include "hexMatcher.H"
31 #include "cellFeatures.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 namespace Foam
40 defineTypeNameAndDebug(shapeToCell, 0);
42 addToRunTimeSelectionTable(topoSetSource, shapeToCell, word);
44 addToRunTimeSelectionTable(topoSetSource, shapeToCell, istream);
49 Foam::topoSetSource::addToUsageTable Foam::shapeToCell::usage_
51     shapeToCell::typeName,
52     "\n    Usage: shapeToCell tet|pyr|prism|hex|tetWedge|wedge|splitHex\n\n"
53     "    Select all cells of given cellShape.\n"
54     "    (splitHex hardcoded with internal angle < 10 degrees)\n"
58 // Angle for polys to be considered splitHexes.
59 Foam::scalar Foam::shapeToCell::featureCos =
60     Foam::cos(10.0 * mathematicalConstant::pi/180.0);
63 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
65 void Foam::shapeToCell::combine(topoSet& set, const bool add) const
67     if (type_ == "splitHex")
68     {
69         for (label cellI = 0; cellI < mesh_.nCells(); cellI++)
70         {
71             cellFeatures superCell(mesh_, featureCos, cellI);
73             if (hexMatcher().isA(superCell.faces()))
74             {
75                 addOrDelete(set, cellI, add);
76             }
77         }
78     }
79     else
80     {
81         const cellModel& wantedModel = *(cellModeller::lookup(type_));
83         const cellShapeList& cellShapes = mesh_.cellShapes();
85         forAll(cellShapes, cellI)
86         {
87             if (cellShapes[cellI].model() == wantedModel)
88             {
89                 addOrDelete(set, cellI, add);
90             }
91         }
92     }
96 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
98 // Construct from components
99 Foam::shapeToCell::shapeToCell
101     const polyMesh& mesh,
102     const word& type
105     topoSetSource(mesh),
106     type_(type)
108     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
109     {
110         FatalErrorIn
111         (
112             "shapeToCell::shapeToCell(const polyMesh&, const word&)"
113         )   << "Illegal cell type " << type_ << exit(FatalError);
114     }
118 // Construct from dictionary
119 Foam::shapeToCell::shapeToCell
121     const polyMesh& mesh,
122     const dictionary& dict
125     topoSetSource(mesh),
126     type_(dict.lookup("type"))
128     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
129     {
130         FatalErrorIn
131         (
132             "shapeToCell::shapeToCell(const polyMesh&, const dictionary&)"
133         )   << "Illegal cell type " << type_ << exit(FatalError);
134     }
138 // Construct from Istream
139 Foam::shapeToCell::shapeToCell
141     const polyMesh& mesh,
142     Istream& is
145     topoSetSource(mesh),
146     type_(checkIs(is))
148     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
149     {
150         FatalErrorIn
151         (
152             "shapeToCell::shapeToCell(const polyMesh&, Istream&)"
153         )   << "Illegal cell type " << type_ << exit(FatalError);
154     }
157 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
159 Foam::shapeToCell::~shapeToCell()
163 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
165 void Foam::shapeToCell::applyToSet
167     const topoSetSource::setAction action,
168     topoSet& set
169 ) const
171     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
172     {
173         Info<< "    Adding all cells of type " << type_ << " ..." << endl;
175         combine(set, true);
176     }
177     else if (action == topoSetSource::DELETE)
178     {
179         Info<< "    Removing all cells of type " << type_ << " ..." << endl;
181         combine(set, false);
182     }
186 // ************************************************************************* //