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 | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "normalToFace.H"
27 #include "polyMesh.H"
28 #include "faceSet.H"
29 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 defineTypeNameAndDebug(normalToFace, 0);
38 
39 addToRunTimeSelectionTable(topoSetSource, normalToFace, word);
40 
41 addToRunTimeSelectionTable(topoSetSource, normalToFace, istream);
42 
43 }
44 
45 
46 Foam::topoSetSource::addToUsageTable Foam::normalToFace::usage_
47 (
48  normalToFace::typeName,
49  "\n Usage: normalToFace (nx ny nz) <tol>\n\n"
50  " Select faces with normal aligned to unit vector (nx ny nz)\n"
51  " to within tol\n"
52 );
53 
54 
55 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
56 
57 void Foam::normalToFace::setNormal()
58 {
59  normal_ /= mag(normal_) + VSMALL;
60 
61  Info<< " normalToFace : Normalized vector to " << normal_ << endl;
62 
63  if (tol_ < -1 || tol_ > 1)
64  {
66  (
67  "normalToFace::normalToFace(const polyMesh&, const vector&"
68  ", const scalar)"
69  ) << "tolerance not within range -1..1 : " << tol_
70  << exit(FatalError);
71  }
72 }
73 
74 
75 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
76 
77 // Construct from components
79 (
80  const polyMesh& mesh,
81  const vector& normal,
82  const scalar tol
83 )
84 :
85  topoSetSource(mesh),
86  normal_(normal),
87  tol_(tol)
88 {
89  setNormal();
90 }
91 
92 
93 // Construct from dictionary
95 :
96  topoSetSource(mesh),
97  normal_(dict.lookup("normal")),
98  tol_(readScalar(dict.lookup("cos")))
99 {
100  setNormal();
101 }
102 
103 
104 // Construct from Istream
106 :
107  topoSetSource(mesh),
108  normal_(checkIs(is)),
109  tol_(readScalar(checkIs(is)))
110 {
111  setNormal();
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
116 
118 {}
119 
120 
121 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122 
124 (
125  const topoSetSource::setAction action,
126  topoSet& set
127 ) const
128 {
129  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
130  {
131  Info<< " Adding faces according to normal being aligned with "
132  << normal_ << " (to within " << tol_ << ") ..." << endl;
133 
134  forAll(mesh_.faceAreas(), faceI)
135  {
136  vector n = mesh_.faceAreas()[faceI];
137  n /= mag(n) + VSMALL;
138 
139  if (mag(1 - (n & normal_)) < tol_)
140  {
141  set.insert(faceI);
142  }
143  }
144  }
145  else if (action == topoSetSource::DELETE)
146  {
147  Info<< " Removing faces according to normal being aligned with "
148  << normal_ << " (to within " << tol_ << ") ..." << endl;
149 
150 
151  DynamicList<label> toBeRemoved(set.size()/10);
152 
153  forAllConstIter(topoSet, set, iter)
154  {
155  const label faceI = iter.key();
156 
157  vector n = mesh_.faceAreas()[faceI];
158  n /= mag(n) + VSMALL;
159 
160  if (mag(1 - (n & normal_)) < tol_)
161  {
162  toBeRemoved.append(faceI);
163  }
164  }
165 
166  forAll(toBeRemoved, i)
167  {
168  set.erase(toBeRemoved[i]);
169  }
170  }
171 }
172 
173 
174 // ************************************************************************* //
const vectorField & faceAreas() const
const polyMesh & mesh_
dimensioned< scalar > mag(const dimensioned< Type > &)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:310
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
messageStream Info
normalToFace(const polyMesh &mesh, const vector &normal, const scalar tol)
Construct from components.
Definition: normalToFace.C:79
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
label n
virtual ~normalToFace()
Destructor.
Definition: normalToFace.C:117
dictionary dict
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
stressControl lookup("compactNormalStress") >> compactNormalStress
#define forAll(list, i)
Definition: UList.H:421
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Macros for easy insertion into run-time selection tables.
static Istream & checkIs(Istream &is)
Check state of stream.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: normalToFace.C:124
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
error FatalError
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
Class with constructor to add usage string to table.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)