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 "normalToFace.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(normalToFace, 0);
42 addToRunTimeSelectionTable(topoSetSource, normalToFace, word);
44 addToRunTimeSelectionTable(topoSetSource, normalToFace, istream);
49 Foam::topoSetSource::addToUsageTable Foam::normalToFace::usage_
51 normalToFace::typeName,
52 "\n Usage: normalToFace (nx ny nz) <tol>\n\n"
53 " Select faces with normal aligned to unit vector (nx ny nz)\n"
58 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
60 void Foam::normalToFace::setNormal()
62 normal_ /= mag(normal_) + VSMALL;
64 Info<< " normalToFace : Normalized vector to " << normal_ << endl;
66 if (tol_ < -1 || tol_ > 1)
70 "normalToFace::normalToFace(const polyMesh&, const vector&"
72 ) << "tolerance not within range -1..1 : " << tol_
78 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
80 // Construct from components
81 Foam::normalToFace::normalToFace
96 // Construct from dictionary
97 Foam::normalToFace::normalToFace(const polyMesh& mesh, const dictionary& dict)
100 normal_(dict.lookup("normal")),
101 tol_(readScalar(dict.lookup("cos")))
107 // Construct from Istream
108 Foam::normalToFace::normalToFace(const polyMesh& mesh, Istream& is)
111 normal_(checkIs(is)),
112 tol_(readScalar(checkIs(is)))
118 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
120 Foam::normalToFace::~normalToFace()
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 void Foam::normalToFace::applyToSet
128 const topoSetSource::setAction action,
132 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
134 Info<< " Adding faces according to normal being aligned with "
135 << normal_ << " (to within " << tol_ << ") ..." << endl;
137 forAll(mesh_.faceAreas(), faceI)
139 vector n = mesh_.faceAreas()[faceI];
140 n /= mag(n) + VSMALL;
142 if (mag(1 - (n & normal_)) < tol_)
148 else if (action == topoSetSource::DELETE)
150 Info<< " Removing faces according to normal being aligned with "
151 << normal_ << " (to within " << tol_ << ") ..." << endl;
154 DynamicList<label> toBeRemoved(set.size()/10);
156 forAllIter(topoSet, set, iter)
158 label faceI = iter.key();
160 vector n = mesh_.faceAreas()[faceI];
161 n /= mag(n) + VSMALL;
163 if (mag(1 - (n & normal_)) < tol_)
165 toBeRemoved.append(faceI);
169 forAll(toBeRemoved, i)
171 set.erase(toBeRemoved[i]);
177 // ************************************************************************* //