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 :
93  topoSetFaceSource(mesh),
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 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
Create a new set and ADD elements to it.
Add elements to current set.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: normalToFace.C:120
quaternion normalised(const quaternion &q)
Return the normalised (unit) quaternion of the given quaternion.
Definition: quaternionI.H:674
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
dynamicFvMesh & mesh
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces...
A topoSetFaceSource to select faces whose surface normal aligned with a given direction.
Definition: normalToFace.H:145
setAction
Enumeration defining various actions.
Vector< scalar > vector
Definition: vector.H:57
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
Subtract elements from current set.
Class with constructor to add usage string to table.
messageStream Info
Information stream (stdout output on master, null elsewhere)
label n
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
normalToFace(const polyMesh &mesh, const vector &normal, const scalar tol)
Construct from components.
Definition: normalToFace.C:80
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)