FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

shapeToCell.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "shapeToCell.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <OpenFOAM/mathematicalConstants.H>
00029 #include <OpenFOAM/hexMatcher.H>
00030 #include <meshTools/cellFeatures.H>
00031 
00032 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00033 
00034 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038 
00039 defineTypeNameAndDebug(shapeToCell, 0);
00040 
00041 addToRunTimeSelectionTable(topoSetSource, shapeToCell, word);
00042 
00043 addToRunTimeSelectionTable(topoSetSource, shapeToCell, istream);
00044 
00045 }
00046 
00047 
00048 Foam::topoSetSource::addToUsageTable Foam::shapeToCell::usage_
00049 (
00050     shapeToCell::typeName,
00051     "\n    Usage: shapeToCell tet|pyr|prism|hex|tetWedge|wedge|splitHex\n\n"
00052     "    Select all cells of given cellShape.\n"
00053     "    (splitHex hardcoded with internal angle < 10 degrees)\n"
00054 );
00055 
00056 
00057 // Angle for polys to be considered splitHexes.
00058 Foam::scalar Foam::shapeToCell::featureCos =
00059     Foam::cos(10.0 * mathematicalConstant::pi/180.0);
00060 
00061 
00062 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00063 
00064 void Foam::shapeToCell::combine(topoSet& set, const bool add) const
00065 {
00066     if (type_ == "splitHex")
00067     {
00068         for (label cellI = 0; cellI < mesh_.nCells(); cellI++)
00069         {
00070             cellFeatures superCell(mesh_, featureCos, cellI);
00071 
00072             if (hexMatcher().isA(superCell.faces()))
00073             {
00074                 addOrDelete(set, cellI, add);
00075             }
00076         }
00077     }
00078     else
00079     {
00080         const cellModel& wantedModel = *(cellModeller::lookup(type_));
00081 
00082         const cellShapeList& cellShapes = mesh_.cellShapes();
00083 
00084         forAll(cellShapes, cellI)
00085         {
00086             if (cellShapes[cellI].model() == wantedModel)
00087             {
00088                 addOrDelete(set, cellI, add);
00089             }
00090         }
00091     }
00092 }
00093 
00094 
00095 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00096 
00097 // Construct from components
00098 Foam::shapeToCell::shapeToCell
00099 (
00100     const polyMesh& mesh,
00101     const word& type
00102 )
00103 :
00104     topoSetSource(mesh),
00105     type_(type)
00106 {
00107     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
00108     {
00109         FatalErrorIn
00110         (
00111             "shapeToCell::shapeToCell(const polyMesh&, const word&)"
00112         )   << "Illegal cell type " << type_ << exit(FatalError);
00113     }
00114 }
00115 
00116 
00117 // Construct from dictionary
00118 Foam::shapeToCell::shapeToCell
00119 (
00120     const polyMesh& mesh,
00121     const dictionary& dict
00122 )
00123 :
00124     topoSetSource(mesh),
00125     type_(dict.lookup("type"))
00126 {
00127     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
00128     {
00129         FatalErrorIn
00130         (
00131             "shapeToCell::shapeToCell(const polyMesh&, const dictionary&)"
00132         )   << "Illegal cell type " << type_ << exit(FatalError);
00133     }
00134 }
00135 
00136 
00137 // Construct from Istream
00138 Foam::shapeToCell::shapeToCell
00139 (
00140     const polyMesh& mesh,
00141     Istream& is
00142 )
00143 :
00144     topoSetSource(mesh),
00145     type_(checkIs(is))
00146 {
00147     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
00148     {
00149         FatalErrorIn
00150         (
00151             "shapeToCell::shapeToCell(const polyMesh&, Istream&)"
00152         )   << "Illegal cell type " << type_ << exit(FatalError);
00153     }
00154 }
00155 
00156 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00157 
00158 Foam::shapeToCell::~shapeToCell()
00159 {}
00160 
00161 
00162 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00163 
00164 void Foam::shapeToCell::applyToSet
00165 (
00166     const topoSetSource::setAction action,
00167     topoSet& set
00168 ) const
00169 {
00170     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00171     {
00172         Info<< "    Adding all cells of type " << type_ << " ..." << endl;
00173 
00174         combine(set, true);
00175     }
00176     else if (action == topoSetSource::DELETE)
00177     {
00178         Info<< "    Removing all cells of type " << type_ << " ..." << endl;
00179 
00180         combine(set, false);
00181     }
00182 }
00183 
00184 
00185 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines