initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / sets / cellSources / shapeToCell / shapeToCell.C
blobd5ca0772aeb27be17ec1d669de6d2ad414979e93
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 Description
27 \*---------------------------------------------------------------------------*/
29 #include "shapeToCell.H"
30 #include "polyMesh.H"
31 #include "mathematicalConstants.H"
32 #include "hexMatcher.H"
33 #include "cellFeatures.H"
35 #include "addToRunTimeSelectionTable.H"
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 namespace Foam
42 defineTypeNameAndDebug(shapeToCell, 0);
44 addToRunTimeSelectionTable(topoSetSource, shapeToCell, word);
46 addToRunTimeSelectionTable(topoSetSource, shapeToCell, istream);
51 Foam::topoSetSource::addToUsageTable Foam::shapeToCell::usage_
53     shapeToCell::typeName,
54     "\n    Usage: shapeToCell tet|pyr|prism|hex|tetWedge|wedge|splitHex\n\n"
55     "    Select all cells of given cellShape.\n"
56     "    (splitHex hardcoded with internal angle < 10 degrees)\n"
60 // Angle for polys to be considered splitHexes.
61 Foam::scalar Foam::shapeToCell::featureCos =
62     Foam::cos(10.0 * mathematicalConstant::pi/180.0);
65 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
67 void Foam::shapeToCell::combine(topoSet& set, const bool add) const
69     if (type_ == "splitHex")
70     {
71         for (label cellI = 0; cellI < mesh_.nCells(); cellI++)
72         {
73             cellFeatures superCell(mesh_, featureCos, cellI);
75             if (hexMatcher().isA(superCell.faces()))
76             {
77                 addOrDelete(set, cellI, add);
78             }
79         }
80     }
81     else
82     {
83         const cellModel& wantedModel = *(cellModeller::lookup(type_));
85         const cellShapeList& cellShapes = mesh_.cellShapes();
87         forAll(cellShapes, cellI)
88         {
89             if (cellShapes[cellI].model() == wantedModel)
90             {
91                 addOrDelete(set, cellI, add);
92             }
93         }
94     }
98 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
100 // Construct from components
101 Foam::shapeToCell::shapeToCell
103     const polyMesh& mesh,
104     const word& type
107     topoSetSource(mesh),
108     type_(type)
110     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
111     {
112         FatalErrorIn
113         (
114             "shapeToCell::shapeToCell(const polyMesh&, const word&)"
115         )   << "Illegal cell type " << type_ << exit(FatalError);
116     }
120 // Construct from dictionary
121 Foam::shapeToCell::shapeToCell
123     const polyMesh& mesh,
124     const dictionary& dict
127     topoSetSource(mesh),
128     type_(dict.lookup("type"))
130     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
131     {
132         FatalErrorIn
133         (
134             "shapeToCell::shapeToCell(const polyMesh&, const dictionary&)"
135         )   << "Illegal cell type " << type_ << exit(FatalError);
136     }
140 // Construct from Istream
141 Foam::shapeToCell::shapeToCell
143     const polyMesh& mesh,
144     Istream& is
147     topoSetSource(mesh),
148     type_(checkIs(is))
150     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
151     {
152         FatalErrorIn
153         (
154             "shapeToCell::shapeToCell(const polyMesh&, Istream&)"
155         )   << "Illegal cell type " << type_ << exit(FatalError);
156     }
159 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
161 Foam::shapeToCell::~shapeToCell()
165 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
167 void Foam::shapeToCell::applyToSet
169     const topoSetSource::setAction action,
170     topoSet& set
171 ) const
173     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
174     {
175         Info<< "    Adding all cells of type " << type_ << " ..." << endl;
177         combine(set, true);
178     }
179     else if (action == topoSetSource::DELETE)
180     {
181         Info<< "    Removing all cells of type " << type_ << " ..." << endl;
183         combine(set, false);
184     }
188 // ************************************************************************* //