1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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"
29 #include "mathematicalConstants.H"
30 #include "hexMatcher.H"
31 #include "cellFeatures.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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")
69 for (label cellI = 0; cellI < mesh_.nCells(); cellI++)
71 cellFeatures superCell(mesh_, featureCos, cellI);
73 if (hexMatcher().isA(superCell.faces()))
75 addOrDelete(set, cellI, add);
81 const cellModel& wantedModel = *(cellModeller::lookup(type_));
83 const cellShapeList& cellShapes = mesh_.cellShapes();
85 forAll(cellShapes, cellI)
87 if (cellShapes[cellI].model() == wantedModel)
89 addOrDelete(set, cellI, add);
96 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
98 // Construct from components
99 Foam::shapeToCell::shapeToCell
101 const polyMesh& mesh,
108 if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
112 "shapeToCell::shapeToCell(const polyMesh&, const word&)"
113 ) << "Illegal cell type " << type_ << exit(FatalError);
118 // Construct from dictionary
119 Foam::shapeToCell::shapeToCell
121 const polyMesh& mesh,
122 const dictionary& dict
126 type_(dict.lookup("type"))
128 if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
132 "shapeToCell::shapeToCell(const polyMesh&, const dictionary&)"
133 ) << "Illegal cell type " << type_ << exit(FatalError);
138 // Construct from Istream
139 Foam::shapeToCell::shapeToCell
141 const polyMesh& mesh,
148 if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
152 "shapeToCell::shapeToCell(const polyMesh&, Istream&)"
153 ) << "Illegal cell type " << type_ << exit(FatalError);
157 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
159 Foam::shapeToCell::~shapeToCell()
163 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
165 void Foam::shapeToCell::applyToSet
167 const topoSetSource::setAction action,
171 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
173 Info<< " Adding all cells of type " << type_ << " ..." << endl;
177 else if (action == topoSetSource::DELETE)
179 Info<< " Removing all cells of type " << type_ << " ..." << endl;
186 // ************************************************************************* //