normalToFace.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(normalToFace, 0);
36  addToRunTimeSelectionTable(topoSetSource, normalToFace, word);
37  addToRunTimeSelectionTable(topoSetSource, normalToFace, istream);
38 }
39 
40 
41 Foam::topoSetSource::addToUsageTable Foam::normalToFace::usage_
42 (
43  normalToFace::typeName,
44  "\n Usage: normalToFace (nx ny nz) <tol>\n\n"
45  " Select faces with normal aligned to unit vector (nx ny nz)\n"
46  " to within tol\n"
47 );
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 void Foam::normalToFace::setNormal()
53 {
54  normal_ /= mag(normal_) + vSmall;
55 
56  Info<< " normalToFace : Normalized vector to " << normal_ << endl;
57 
58  if (tol_ < -1 || tol_ > 1)
59  {
61  << "tolerance not within range -1..1 : " << tol_
62  << exit(FatalError);
63  }
64 }
65 
66 
67 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68 
70 (
71  const polyMesh& mesh,
72  const vector& normal,
73  const scalar tol
74 )
75 :
76  topoSetSource(mesh),
77  normal_(normal),
78  tol_(tol)
79 {
80  setNormal();
81 }
82 
83 
85 :
86  topoSetSource(mesh),
87  normal_(dict.lookup("normal")),
88  tol_(readScalar(dict.lookup("cos")))
89 {
90  setNormal();
91 }
92 
93 
95 :
96  topoSetSource(mesh),
97  normal_(checkIs(is)),
98  tol_(readScalar(checkIs(is)))
99 {
100  setNormal();
101 }
102 
103 
104 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
105 
107 {}
108 
109 
110 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
111 
113 (
114  const topoSetSource::setAction action,
115  topoSet& set
116 ) const
117 {
118  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
119  {
120  Info<< " Adding faces according to normal being aligned with "
121  << normal_ << " (to within " << tol_ << ") ..." << endl;
122 
123  forAll(mesh_.faceAreas(), facei)
124  {
125  vector n = mesh_.faceAreas()[facei];
126  n /= mag(n) + vSmall;
127 
128  if (mag(1 - (n & normal_)) < tol_)
129  {
130  set.insert(facei);
131  }
132  }
133  }
134  else if (action == topoSetSource::DELETE)
135  {
136  Info<< " Removing faces according to normal being aligned with "
137  << normal_ << " (to within " << tol_ << ") ..." << endl;
138 
139 
140  DynamicList<label> toBeRemoved(set.size()/10);
141 
142  forAllConstIter(topoSet, set, iter)
143  {
144  const label facei = iter.key();
145 
146  vector n = mesh_.faceAreas()[facei];
147  n /= mag(n) + vSmall;
148 
149  if (mag(1 - (n & normal_)) < tol_)
150  {
151  toBeRemoved.append(facei);
152  }
153  }
154 
155  forAll(toBeRemoved, i)
156  {
157  set.erase(toBeRemoved[i]);
158  }
159  }
160 }
161 
162 
163 // ************************************************************************* //
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:158
#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:256
static Istream & checkIs(Istream &is)
Check state of stream.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: normalToFace.C:113
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:296
virtual ~normalToFace()
Destructor.
Definition: normalToFace.C:106
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:68
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:70
Namespace for OpenFOAM.