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
27 \*---------------------------------------------------------------------------*/
29 #include "shapeToCell.H"
31 #include "mathematicalConstants.H"
32 #include "hexMatcher.H"
33 #include "cellFeatures.H"
35 #include "addToRunTimeSelectionTable.H"
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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")
71 for (label cellI = 0; cellI < mesh_.nCells(); cellI++)
73 cellFeatures superCell(mesh_, featureCos, cellI);
75 if (hexMatcher().isA(superCell.faces()))
77 addOrDelete(set, cellI, add);
83 const cellModel& wantedModel = *(cellModeller::lookup(type_));
85 const cellShapeList& cellShapes = mesh_.cellShapes();
87 forAll(cellShapes, cellI)
89 if (cellShapes[cellI].model() == wantedModel)
91 addOrDelete(set, cellI, add);
98 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100 // Construct from components
101 Foam::shapeToCell::shapeToCell
103 const polyMesh& mesh,
110 if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
114 "shapeToCell::shapeToCell(const polyMesh&, const word&)"
115 ) << "Illegal cell type " << type_ << exit(FatalError);
120 // Construct from dictionary
121 Foam::shapeToCell::shapeToCell
123 const polyMesh& mesh,
124 const dictionary& dict
128 type_(dict.lookup("type"))
130 if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
134 "shapeToCell::shapeToCell(const polyMesh&, const dictionary&)"
135 ) << "Illegal cell type " << type_ << exit(FatalError);
140 // Construct from Istream
141 Foam::shapeToCell::shapeToCell
143 const polyMesh& mesh,
150 if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
154 "shapeToCell::shapeToCell(const polyMesh&, Istream&)"
155 ) << "Illegal cell type " << type_ << exit(FatalError);
159 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
161 Foam::shapeToCell::~shapeToCell()
165 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
167 void Foam::shapeToCell::applyToSet
169 const topoSetSource::setAction action,
173 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
175 Info<< " Adding all cells of type " << type_ << " ..." << endl;
179 else if (action == topoSetSource::DELETE)
181 Info<< " Removing all cells of type " << type_ << " ..." << endl;
188 // ************************************************************************* //