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

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