initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / sets / faceSources / normalToFace / normalToFace.C
blobf0c0925cd7a2ae29c548b2cae79fac5e018b0446
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 Description
27 \*---------------------------------------------------------------------------*/
29 #include "normalToFace.H"
30 #include "polyMesh.H"
31 #include "faceSet.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 namespace Foam
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"
54     "    to within tol\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)
67     {
68         FatalErrorIn
69         (
70             "normalToFace::normalToFace(const polyMesh&, const vector&"
71             ", const scalar)"
72         )   << "tolerance not within range -1..1 : " << tol_
73             << exit(FatalError);
74     }
78 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
80 // Construct from components
81 Foam::normalToFace::normalToFace
83     const polyMesh& mesh,
84     const vector& normal,
85     const scalar tol
88     topoSetSource(mesh),
89     normal_(normal),
90     tol_(tol)
92     setNormal();
96 // Construct from dictionary
97 Foam::normalToFace::normalToFace(const polyMesh& mesh, const dictionary& dict)
99     topoSetSource(mesh),
100     normal_(dict.lookup("normal")),
101     tol_(readScalar(dict.lookup("cos")))
103     setNormal();
107 // Construct from Istream
108 Foam::normalToFace::normalToFace(const polyMesh& mesh, Istream& is)
110     topoSetSource(mesh),
111     normal_(checkIs(is)),
112     tol_(readScalar(checkIs(is)))
114     setNormal();
118 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
120 Foam::normalToFace::~normalToFace()
124 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
126 void Foam::normalToFace::applyToSet
128     const topoSetSource::setAction action,
129     topoSet& set
130 ) const
132     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
133     {
134         Info<< "    Adding faces according to normal being aligned with "
135             << normal_ << " (to within " << tol_ << ") ..." << endl;
137         forAll(mesh_.faceAreas(), faceI)
138         {
139             vector n = mesh_.faceAreas()[faceI];
140             n /= mag(n) + VSMALL;
142             if (mag(1 - (n & normal_)) < tol_)
143             {
144                 set.insert(faceI);
145             }
146         }
147     }
148     else if (action == topoSetSource::DELETE)
149     {
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)
157         {
158             label faceI = iter.key();
160             vector n = mesh_.faceAreas()[faceI];
161             n /= mag(n) + VSMALL;
163             if (mag(1 - (n & normal_)) < tol_)
164             {
165                 toBeRemoved.append(faceI);
166             }
167         }
169         forAll(toBeRemoved, i)
170         {
171             set.erase(toBeRemoved[i]);
172         }
173     }
177 // ************************************************************************* //