1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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
25 \*---------------------------------------------------------------------------*/
27 #include "normalToFace.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(normalToFace, 0);
40 addToRunTimeSelectionTable(topoSetSource, normalToFace, word);
42 addToRunTimeSelectionTable(topoSetSource, normalToFace, istream);
47 Foam::topoSetSource::addToUsageTable Foam::normalToFace::usage_
49 normalToFace::typeName,
50 "\n Usage: normalToFace (nx ny nz) <tol>\n\n"
51 " Select faces with normal aligned to unit vector (nx ny nz)\n"
56 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
58 void Foam::normalToFace::setNormal()
60 normal_ /= mag(normal_) + VSMALL;
62 Info<< " normalToFace : Normalized vector to " << normal_ << endl;
64 if (tol_ < -1 || tol_ > 1)
68 "normalToFace::normalToFace(const polyMesh&, const vector&"
70 ) << "tolerance not within range -1..1 : " << tol_
76 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 // Construct from components
79 Foam::normalToFace::normalToFace
94 // Construct from dictionary
95 Foam::normalToFace::normalToFace(const polyMesh& mesh, const dictionary& dict)
98 normal_(dict.lookup("normal")),
99 tol_(readScalar(dict.lookup("cos")))
105 // Construct from Istream
106 Foam::normalToFace::normalToFace(const polyMesh& mesh, Istream& is)
109 normal_(checkIs(is)),
110 tol_(readScalar(checkIs(is)))
116 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
118 Foam::normalToFace::~normalToFace()
122 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
124 void Foam::normalToFace::applyToSet
126 const topoSetSource::setAction action,
130 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
132 Info<< " Adding faces according to normal being aligned with "
133 << normal_ << " (to within " << tol_ << ") ..." << endl;
135 forAll(mesh_.faceAreas(), faceI)
137 vector n = mesh_.faceAreas()[faceI];
138 n /= mag(n) + VSMALL;
140 if (mag(1 - (n & normal_)) < tol_)
146 else if (action == topoSetSource::DELETE)
148 Info<< " Removing faces according to normal being aligned with "
149 << normal_ << " (to within " << tol_ << ") ..." << endl;
152 DynamicList<label> toBeRemoved(set.size()/10);
154 forAllIter(topoSet, set, iter)
156 label faceI = iter.key();
158 vector n = mesh_.faceAreas()[faceI];
159 n /= mag(n) + VSMALL;
161 if (mag(1 - (n & normal_)) < tol_)
163 toBeRemoved.append(faceI);
167 forAll(toBeRemoved, i)
169 set.erase(toBeRemoved[i]);
175 // ************************************************************************* //