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-2015 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 
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 
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 :
83  normal_(normal),
84  tol_(tol)
85 {
86  setNormal();
87 }
88 
89 
90 // Construct from dictionary
92 :
94  normal_(dict.lookup("normal")),
95  tol_(readScalar(dict.lookup("cos")))
96 {
97  setNormal();
98 }
99 
100 
101 // Construct from Istream
103 :
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 // ************************************************************************* //
Foam::topoSetSource::ADD
@ ADD
Definition: topoSetSource.H:87
Foam::normalToFace::tol_
const scalar tol_
Tolerance (i.e. cos of angle between normal_ and faceNormal)
Definition: normalToFace.H:63
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::normalToFace::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: normalToFace.C:121
Foam::normalToFace::setNormal
void setNormal()
Normalize normal and check tolerance.
Definition: normalToFace.C:57
Foam::DynamicList< label >
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:100
Foam::normalToFace::normalToFace
normalToFace(const polyMesh &mesh, const vector &normal, const scalar tol)
Construct from components.
Definition: normalToFace.C:76
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Foam::topoSetSource::NEW
@ NEW
Definition: topoSetSource.H:85
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::label
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
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Info
messageStream Info
faceSet.H
normalToFace.H
Foam::topoSetSource::DELETE
@ DELETE
Definition: topoSetSource.H:88
Foam::HashTable::erase
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Foam::normalToFace::usage_
static addToUsageTable usage_
Add usage string.
Definition: normalToFace.H:57
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::HashTable::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::normalToFace::~normalToFace
virtual ~normalToFace()
Destructor.
Definition: normalToFace.C:114
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
Foam::Vector< scalar >
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::normalToFace::normal_
vector normal_
(unit)vector to compare to
Definition: normalToFace.H:60
normal
A normal distribution model.
lookup
stressControl lookup("compactNormalStress") >> compactNormalStress