normalToFace.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2018 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "normalToFace.H"
30#include "polyMesh.H"
31#include "faceSet.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
44 (
47 word,
48 normal
49 );
51 (
54 istream,
55 normal
56 );
57}
58
59
60Foam::topoSetSource::addToUsageTable Foam::normalToFace::usage_
61(
62 normalToFace::typeName,
63 "\n Usage: normalToFace (nx ny nz) <tol>\n\n"
64 " Select faces with normal aligned to unit vector (nx ny nz)\n"
65 " to within tol\n"
66);
67
68
69// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
70
71void Foam::normalToFace::setNormal()
72{
73 normal_.normalise();
74
75 if (tol_ < -1 || tol_ > 1)
76 {
78 << "tolerance not within range -1..1 : " << tol_
79 << exit(FatalError);
80 }
81}
82
83
84// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
85
87(
88 const polyMesh& mesh,
89 const vector& normal,
90 const scalar tol
91)
92:
94 normal_(normal),
95 tol_(tol)
96{
97 setNormal();
98}
99
100
102:
104 (
105 mesh,
106 dict.get<vector>("normal"),
107 dict.get<scalar>("cos")
108 )
109{
110 setNormal();
111}
112
113
115:
117 normal_(checkIs(is)),
118 tol_(readScalar(checkIs(is)))
119{
120 setNormal();
121}
122
123
124// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125
127(
128 const topoSetSource::setAction action,
129 topoSet& set
130) const
131{
132 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
133 {
134 if (verbose_)
135 {
136 Info<< " Adding faces according to normal being aligned with "
137 << normal_ << " (to within " << tol_ << ") ..." << endl;
138 }
139
140 forAll(mesh_.faceAreas(), facei)
141 {
142 const vector n = normalised(mesh_.faceAreas()[facei]);
143
144 if (mag(1 - (n & normal_)) < tol_)
145 {
146 set.set(facei);
147 }
148 }
149 }
150 else if (action == topoSetSource::SUBTRACT)
151 {
152 if (verbose_)
153 {
154 Info<< " Removing faces according to normal being aligned with "
155 << normal_ << " (to within " << tol_ << ") ..." << endl;
156 }
157
158 DynamicList<label> toBeRemoved(set.size()/10);
159
160 for (const label facei : static_cast<const labelHashSet&>(set))
161 {
162 const vector n = normalised(mesh_.faceAreas()[facei]);
163
164 if (mag(1 - (n & normal_)) < tol_)
165 {
166 toBeRemoved.append(facei);
167 }
168 }
169
170 set.unset(toBeRemoved);
171 }
172}
173
174
175// ************************************************************************* //
label n
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A topoSetFaceSource to select faces whose surface normal aligned with a given direction.
Definition: normalToFace.H:152
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: normalToFace.C:127
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
Definition: topoSetSource.H:68
setAction
Enumeration defining various actions.
@ SUBTRACT
Subtract elements from current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:67
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
quaternion normalised(const quaternion &q)
Return the normalised (unit) quaternion of the given quaternion.
Definition: quaternionI.H:680
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333