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

normalToFace.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 "normalToFace.H"
00030 #include "polyMesh.H"
00031 #include "faceSet.H"
00032 
00033 #include "addToRunTimeSelectionTable.H"
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 
00040 defineTypeNameAndDebug(normalToFace, 0);
00041 
00042 addToRunTimeSelectionTable(topoSetSource, normalToFace, word);
00043 
00044 addToRunTimeSelectionTable(topoSetSource, normalToFace, istream);
00045 
00046 }
00047 
00048 
00049 Foam::topoSetSource::addToUsageTable Foam::normalToFace::usage_
00050 (
00051     normalToFace::typeName,
00052     "\n    Usage: normalToFace (nx ny nz) <tol>\n\n"
00053     "    Select faces with normal aligned to unit vector (nx ny nz)\n"
00054     "    to within tol\n"
00055 );
00056 
00057 
00058 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00059 
00060 void Foam::normalToFace::setNormal()
00061 {
00062     normal_ /= mag(normal_) + VSMALL;
00063 
00064     Info<< "    normalToFace : Normalized vector to " << normal_ << endl;
00065 
00066     if (tol_ < -1 || tol_ > 1)
00067     {
00068         FatalErrorIn
00069         (
00070             "normalToFace::normalToFace(const polyMesh&, const vector&"
00071             ", const scalar)"
00072         )   << "tolerance not within range -1..1 : " << tol_
00073             << exit(FatalError);
00074     }
00075 }
00076 
00077 
00078 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00079 
00080 // Construct from components
00081 Foam::normalToFace::normalToFace
00082 (
00083     const polyMesh& mesh,
00084     const vector& normal,
00085     const scalar tol
00086 )
00087 :
00088     topoSetSource(mesh),
00089     normal_(normal),
00090     tol_(tol)
00091 {
00092     setNormal();
00093 }
00094 
00095 
00096 // Construct from dictionary
00097 Foam::normalToFace::normalToFace(const polyMesh& mesh, const dictionary& dict)
00098 :
00099     topoSetSource(mesh),
00100     normal_(dict.lookup("normal")),
00101     tol_(readScalar(dict.lookup("cos")))
00102 {
00103     setNormal();
00104 }
00105 
00106 
00107 // Construct from Istream
00108 Foam::normalToFace::normalToFace(const polyMesh& mesh, Istream& is)
00109 :
00110     topoSetSource(mesh),
00111     normal_(checkIs(is)),
00112     tol_(readScalar(checkIs(is)))
00113 {
00114     setNormal();
00115 }
00116 
00117 
00118 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00119 
00120 Foam::normalToFace::~normalToFace()
00121 {}
00122 
00123 
00124 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00125 
00126 void Foam::normalToFace::applyToSet
00127 (
00128     const topoSetSource::setAction action,
00129     topoSet& set
00130 ) const
00131 {
00132     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00133     {
00134         Info<< "    Adding faces according to normal being aligned with "
00135             << normal_ << " (to within " << tol_ << ") ..." << endl;
00136 
00137         forAll(mesh_.faceAreas(), faceI)
00138         {
00139             vector n = mesh_.faceAreas()[faceI];
00140             n /= mag(n) + VSMALL;
00141 
00142             if (mag(1 - (n & normal_)) < tol_)
00143             {
00144                 set.insert(faceI);
00145             }
00146         }
00147     }
00148     else if (action == topoSetSource::DELETE)
00149     {
00150         Info<< "    Removing faces according to normal being aligned with "
00151             << normal_ << " (to within " << tol_ << ") ..." << endl;
00152 
00153 
00154         DynamicList<label> toBeRemoved(set.size()/10);
00155 
00156         forAllIter(topoSet, set, iter)
00157         {
00158             label faceI = iter.key();
00159 
00160             vector n = mesh_.faceAreas()[faceI];
00161             n /= mag(n) + VSMALL;
00162 
00163             if (mag(1 - (n & normal_)) < tol_)
00164             {
00165                 toBeRemoved.append(faceI);
00166             }
00167         }
00168 
00169         forAll(toBeRemoved, i)
00170         {
00171             set.erase(toBeRemoved[i]);
00172         }
00173     }
00174 }
00175 
00176 
00177 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd