Loading...
Searching...
No Matches
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"
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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_
80 }
81}
82
83
84// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
85
87(
88 const polyMesh& mesh,
89 const vector& normal,
90 const scalar tol
91)
92:
93 topoSetFaceSource(mesh),
94 normal_(normal),
95 tol_(tol)
96{
97 setNormal();
98}
99
100
102:
104 normal_(dict.get<vector>("normal")),
105 tol_(dict.get<scalar>("cos"))
106{
107 setNormal();
108}
109
110
112:
114 normal_(checkIs(is)),
115 tol_(readScalar(checkIs(is)))
117 setNormal();
118}
119
120
121// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122
124(
125 const topoSetSource::setAction action,
126 topoSet& set
127) const
128{
129 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
130 {
131 if (verbose_)
132 {
133 Info<< " Adding faces according to normal being aligned with "
134 << normal_ << " (to within " << tol_ << ") ..." << endl;
135 }
136
137 forAll(mesh_.faceAreas(), facei)
138 {
139 const vector n = normalised(mesh_.faceAreas()[facei]);
140
141 if (mag(1 - (n & normal_)) < tol_)
142 {
143 set.set(facei);
144 }
145 }
146 }
147 else if (action == topoSetSource::SUBTRACT)
148 {
149 if (verbose_)
150 {
151 Info<< " Removing faces according to normal being aligned with "
152 << normal_ << " (to within " << tol_ << ") ..." << endl;
153 }
154
155 DynamicList<label> toBeRemoved(set.size()/10);
156
157 for (const label facei : static_cast<const labelHashSet&>(set))
158 {
159 const vector n = normalised(mesh_.faceAreas()[facei]);
160
161 if (mag(1 - (n & normal_)) < tol_)
162 {
163 toBeRemoved.append(facei);
164 }
165 }
166
167 set.unset(toBeRemoved);
168 }
169}
170
171
172// ************************************************************************* //
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:68
void append(const T &val)
Copy append an element to the end of this list.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
Vector< Cmpt > & normalise(const scalar tol=ROOTVSMALL)
Inplace normalise the vector by its magnitude.
Definition VectorI.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A topoSetFaceSource to select faces whose surface normal aligned with a given direction.
normalToFace(const polyMesh &mesh, const vector &normal, const scalar tol)
Construct from components.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
topoSetFaceSource(const polyMesh &mesh)
Construct from mesh.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
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.
bool verbose_
Output verbosity (default: true).
const polyMesh & mesh() const noexcept
Reference to the mesh.
const polyMesh & mesh_
Reference to the mesh.
static Istream & checkIs(Istream &is)
Check state of stream.
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
void set(List< bool > &bools, const labelUList &locations)
Set the listed locations (assign 'true').
Definition BitOps.C:35
Namespace for OpenFOAM.
quaternion normalised(const quaternion &q)
Return the normalised (unit) quaternion of the given quaternion.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition HashSet.H:85
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
Vector< scalar > vector
Definition vector.H:57
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299