Forward compatibility: flex
[foam-extend-3.2.git] / src / meshTools / sets / cellSources / shapeToCell / shapeToCell.C
blob51d2190db3a94853133d8dce26fb9318fffc82f0
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 "shapeToCell.H"
27 #include "polyMesh.H"
28 #include "mathematicalConstants.H"
29 #include "hexMatcher.H"
30 #include "cellFeatures.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 namespace Foam
39 defineTypeNameAndDebug(shapeToCell, 0);
41 addToRunTimeSelectionTable(topoSetSource, shapeToCell, word);
43 addToRunTimeSelectionTable(topoSetSource, shapeToCell, istream);
48 Foam::topoSetSource::addToUsageTable Foam::shapeToCell::usage_
50     shapeToCell::typeName,
51     "\n    Usage: shapeToCell tet|pyr|prism|hex|tetWedge|wedge|splitHex\n\n"
52     "    Select all cells of given cellShape.\n"
53     "    (splitHex hardcoded with internal angle < 10 degrees)\n"
57 // Angle for polys to be considered splitHexes.
58 Foam::scalar Foam::shapeToCell::featureCos =
59     Foam::cos(10.0 * mathematicalConstant::pi/180.0);
62 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
64 void Foam::shapeToCell::combine(topoSet& set, const bool add) const
66     if (type_ == "splitHex")
67     {
68         for (label cellI = 0; cellI < mesh_.nCells(); cellI++)
69         {
70             cellFeatures superCell(mesh_, featureCos, cellI);
72             if (hexMatcher().isA(superCell.faces()))
73             {
74                 addOrDelete(set, cellI, add);
75             }
76         }
77     }
78     else
79     {
80         const cellModel& wantedModel = *(cellModeller::lookup(type_));
82         const cellShapeList& cellShapes = mesh_.cellShapes();
84         forAll(cellShapes, cellI)
85         {
86             if (cellShapes[cellI].model() == wantedModel)
87             {
88                 addOrDelete(set, cellI, add);
89             }
90         }
91     }
95 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
97 // Construct from components
98 Foam::shapeToCell::shapeToCell
100     const polyMesh& mesh,
101     const word& type
104     topoSetSource(mesh),
105     type_(type)
107     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
108     {
109         FatalErrorIn
110         (
111             "shapeToCell::shapeToCell(const polyMesh&, const word&)"
112         )   << "Illegal cell type " << type_ << exit(FatalError);
113     }
117 // Construct from dictionary
118 Foam::shapeToCell::shapeToCell
120     const polyMesh& mesh,
121     const dictionary& dict
124     topoSetSource(mesh),
125     type_(dict.lookup("type"))
127     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
128     {
129         FatalErrorIn
130         (
131             "shapeToCell::shapeToCell(const polyMesh&, const dictionary&)"
132         )   << "Illegal cell type " << type_ << exit(FatalError);
133     }
137 // Construct from Istream
138 Foam::shapeToCell::shapeToCell
140     const polyMesh& mesh,
141     Istream& is
144     topoSetSource(mesh),
145     type_(checkIs(is))
147     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
148     {
149         FatalErrorIn
150         (
151             "shapeToCell::shapeToCell(const polyMesh&, Istream&)"
152         )   << "Illegal cell type " << type_ << exit(FatalError);
153     }
156 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
158 Foam::shapeToCell::~shapeToCell()
162 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
164 void Foam::shapeToCell::applyToSet
166     const topoSetSource::setAction action,
167     topoSet& set
168 ) const
170     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
171     {
172         Info<< "    Adding all cells of type " << type_ << " ..." << endl;
174         combine(set, true);
175     }
176     else if (action == topoSetSource::DELETE)
177     {
178         Info<< "    Removing all cells of type " << type_ << " ..." << endl;
180         combine(set, false);
181     }
185 // ************************************************************************* //