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 -------------------------------------------------------------------------------
11 License
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 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(normalToFace, 0);
39  addToRunTimeSelectionTable(topoSetSource, normalToFace, word);
40  addToRunTimeSelectionTable(topoSetSource, normalToFace, istream);
41  addToRunTimeSelectionTable(topoSetFaceSource, normalToFace, word);
42  addToRunTimeSelectionTable(topoSetFaceSource, normalToFace, istream);
44  (
45  topoSetFaceSource,
46  normalToFace,
47  word,
48  normal
49  );
51  (
52  topoSetFaceSource,
53  normalToFace,
54  istream,
55  normal
56  );
57 }
58 
59 
60 Foam::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 
71 void 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 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::topoSetSource::ADD
Add elements to current set.
Definition: topoSetSource.H:103
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::DynamicList< label >
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:129
Foam::normalToFace::normalToFace
normalToFace(const polyMesh &mesh, const vector &normal, const scalar tol)
Construct from components.
Definition: normalToFace.C:87
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
Foam::topoSetFaceSource
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
Definition: topoSetFaceSource.H:54
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:104
Foam::Vector::normalise
Vector< Cmpt > & normalise()
Normalise the vector by its magnitude.
Definition: VectorI.H:123
polyMesh.H
Foam::HashSet< label, Hash< label > >
Foam::normalToFace::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: normalToFace.C:127
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
faceSet.H
normalToFace.H
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::topoSetSource::SUBTRACT
Subtract elements from current set.
Definition: topoSetSource.H:105
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::normalised
VectorSpace< Form, Cmpt, Ncmpts > normalised(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:487
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::Vector< scalar >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::PtrListOps::get
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
Foam::normalToFace
A topoSetFaceSource to select faces whose surface normal aligned with a given direction.
Definition: normalToFace.H:149
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)