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-2016 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  << "tolerance not within range -1..1 : " << tol_
67  << exit(FatalError);
68  }
69 }
70 
71 
72 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
73 
74 // Construct from components
76 (
77  const polyMesh& mesh,
78  const vector& normal,
79  const scalar tol
80 )
81 :
82  topoSetSource(mesh),
83  normal_(normal),
84  tol_(tol)
85 {
86  setNormal();
87 }
88 
89 
90 // Construct from dictionary
92 :
93  topoSetSource(mesh),
94  normal_(dict.lookup("normal")),
95  tol_(readScalar(dict.lookup("cos")))
96 {
97  setNormal();
98 }
99 
100 
101 // Construct from Istream
103 :
104  topoSetSource(mesh),
105  normal_(checkIs(is)),
106  tol_(readScalar(checkIs(is)))
107 {
108  setNormal();
109 }
110 
111 
112 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
113 
115 {}
116 
117 
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
119 
121 (
122  const topoSetSource::setAction action,
123  topoSet& set
124 ) const
125 {
126  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
127  {
128  Info<< " Adding faces according to normal being aligned with "
129  << normal_ << " (to within " << tol_ << ") ..." << endl;
130 
131  forAll(mesh_.faceAreas(), facei)
132  {
133  vector n = mesh_.faceAreas()[facei];
134  n /= mag(n) + VSMALL;
135 
136  if (mag(1 - (n & normal_)) < tol_)
137  {
138  set.insert(facei);
139  }
140  }
141  }
142  else if (action == topoSetSource::DELETE)
143  {
144  Info<< " Removing faces according to normal being aligned with "
145  << normal_ << " (to within " << tol_ << ") ..." << endl;
146 
147 
148  DynamicList<label> toBeRemoved(set.size()/10);
149 
150  forAllConstIter(topoSet, set, iter)
151  {
152  const label facei = iter.key();
153 
154  vector n = mesh_.faceAreas()[facei];
155  n /= mag(n) + VSMALL;
156 
157  if (mag(1 - (n & normal_)) < tol_)
158  {
159  toBeRemoved.append(facei);
160  }
161  }
162 
163  forAll(toBeRemoved, i)
164  {
165  set.erase(toBeRemoved[i]);
166  }
167  }
168 }
169 
170 
171 // ************************************************************************* //
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
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:253
static Istream & checkIs(Istream &is)
Check state of stream.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: normalToFace.C:121
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
stressControl lookup("compactNormalStress") >> compactNormalStress
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:292
virtual ~normalToFace()
Destructor.
Definition: normalToFace.C:114
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
const polyMesh & mesh_
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Class with constructor to add usage string to table.
const vectorField & faceAreas() const
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
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:76
Namespace for OpenFOAM.