OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "shapeToCell.H"
00030 #include "polyMesh.H"
00031 #include "mathematicalConstants.H"
00032 #include "hexMatcher.H"
00033 #include "cellFeatures.H"
00034 
00035 #include "addToRunTimeSelectionTable.H"
00036 
00037 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00038 
00039 namespace Foam
00040 {
00041 
00042 defineTypeNameAndDebug(shapeToCell, 0);
00043 
00044 addToRunTimeSelectionTable(topoSetSource, shapeToCell, word);
00045 
00046 addToRunTimeSelectionTable(topoSetSource, shapeToCell, istream);
00047 
00048 }
00049 
00050 
00051 Foam::topoSetSource::addToUsageTable Foam::shapeToCell::usage_
00052 (
00053     shapeToCell::typeName,
00054     "\n    Usage: shapeToCell tet|pyr|prism|hex|tetWedge|wedge|splitHex\n\n"
00055     "    Select all cells of given cellShape.\n"
00056     "    (splitHex hardcoded with internal angle < 10 degrees)\n"
00057 );
00058 
00059 
00060 // Angle for polys to be considered splitHexes.
00061 Foam::scalar Foam::shapeToCell::featureCos =
00062     Foam::cos(10.0 * mathematicalConstant::pi/180.0);
00063 
00064 
00065 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00066 
00067 void Foam::shapeToCell::combine(topoSet& set, const bool add) const
00068 {
00069     if (type_ == "splitHex")
00070     {
00071         for (label cellI = 0; cellI < mesh_.nCells(); cellI++)
00072         {
00073             cellFeatures superCell(mesh_, featureCos, cellI);
00074 
00075             if (hexMatcher().isA(superCell.faces()))
00076             {
00077                 addOrDelete(set, cellI, add);
00078             }
00079         }
00080     }
00081     else
00082     {
00083         const cellModel& wantedModel = *(cellModeller::lookup(type_));
00084 
00085         const cellShapeList& cellShapes = mesh_.cellShapes();
00086 
00087         forAll(cellShapes, cellI)
00088         {
00089             if (cellShapes[cellI].model() == wantedModel)
00090             {
00091                 addOrDelete(set, cellI, add);
00092             }
00093         }
00094     }
00095 }
00096 
00097 
00098 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00099 
00100 // Construct from components
00101 Foam::shapeToCell::shapeToCell
00102 (
00103     const polyMesh& mesh,
00104     const word& type
00105 )
00106 :
00107     topoSetSource(mesh),
00108     type_(type)
00109 {
00110     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
00111     {
00112         FatalErrorIn
00113         (
00114             "shapeToCell::shapeToCell(const polyMesh&, const word&)"
00115         )   << "Illegal cell type " << type_ << exit(FatalError);
00116     }
00117 }
00118 
00119 
00120 // Construct from dictionary
00121 Foam::shapeToCell::shapeToCell
00122 (
00123     const polyMesh& mesh,
00124     const dictionary& dict
00125 )
00126 :
00127     topoSetSource(mesh),
00128     type_(dict.lookup("type"))
00129 {
00130     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
00131     {
00132         FatalErrorIn
00133         (
00134             "shapeToCell::shapeToCell(const polyMesh&, const dictionary&)"
00135         )   << "Illegal cell type " << type_ << exit(FatalError);
00136     }
00137 }
00138 
00139 
00140 // Construct from Istream
00141 Foam::shapeToCell::shapeToCell
00142 (
00143     const polyMesh& mesh,
00144     Istream& is
00145 )
00146 :
00147     topoSetSource(mesh),
00148     type_(checkIs(is))
00149 {
00150     if (!cellModeller::lookup(type_) && (type_ != "splitHex"))
00151     {
00152         FatalErrorIn
00153         (
00154             "shapeToCell::shapeToCell(const polyMesh&, Istream&)"
00155         )   << "Illegal cell type " << type_ << exit(FatalError);
00156     }
00157 }
00158 
00159 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00160 
00161 Foam::shapeToCell::~shapeToCell()
00162 {}
00163 
00164 
00165 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00166 
00167 void Foam::shapeToCell::applyToSet
00168 (
00169     const topoSetSource::setAction action,
00170     topoSet& set
00171 ) const
00172 {
00173     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00174     {
00175         Info<< "    Adding all cells of type " << type_ << " ..." << endl;
00176 
00177         combine(set, true);
00178     }
00179     else if (action == topoSetSource::DELETE)
00180     {
00181         Info<< "    Removing all cells of type " << type_ << " ..." << endl;
00182 
00183         combine(set, false);
00184     }
00185 }
00186 
00187 
00188 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd