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-2021 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 {
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 void Foam::normalToFace::setNormal()
43 {
44  normal_ /= mag(normal_) + vSmall;
45 
46  Info<< " normalToFace : Normalised vector to " << normal_ << endl;
47 
48  if (tol_ < -1 || tol_ > 1)
49  {
51  << "tolerance not within range -1..1 : " << tol_
52  << exit(FatalError);
53  }
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
60 (
61  const polyMesh& mesh,
62  const vector& normal,
63  const scalar tol
64 )
65 :
66  topoSetSource(mesh),
67  normal_(normal),
68  tol_(tol)
69 {
70  setNormal();
71 }
72 
73 
75 :
76  topoSetSource(mesh),
77  normal_(dict.lookup("normal")),
78  tol_(dict.lookup<scalar>("cos"))
79 {
80  setNormal();
81 }
82 
83 
84 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
85 
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91 
93 (
94  const topoSetSource::setAction action,
95  topoSet& set
96 ) const
97 {
98  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
99  {
100  Info<< " Adding faces according to normal being aligned with "
101  << normal_ << " (to within " << tol_ << ") ..." << endl;
102 
103  forAll(mesh_.faceAreas(), facei)
104  {
105  vector n = mesh_.faceAreas()[facei];
106  n /= mag(n) + vSmall;
107 
108  if (mag(1 - (n & normal_)) < tol_)
109  {
110  set.insert(facei);
111  }
112  }
113  }
114  else if (action == topoSetSource::DELETE)
115  {
116  Info<< " Removing faces according to normal being aligned with "
117  << normal_ << " (to within " << tol_ << ") ..." << endl;
118 
119 
120  DynamicList<label> toBeRemoved(set.size()/10);
121 
122  forAllConstIter(topoSet, set, iter)
123  {
124  const label facei = iter.key();
125 
126  vector n = mesh_.faceAreas()[facei];
127  n /= mag(n) + vSmall;
128 
129  if (mag(1 - (n & normal_)) < tol_)
130  {
131  toBeRemoved.append(facei);
132  }
133  }
134 
135  forAll(toBeRemoved, i)
136  {
137  set.erase(toBeRemoved[i]);
138  }
139  }
140 }
141 
142 
143 // ************************************************************************* //
label n
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Macros for easy insertion into run-time selection tables.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:111
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
Definition: HashTable.C:371
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A topoSetSource to select faces based on normal.
Definition: normalToFace.H:52
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: normalToFace.C:93
virtual ~normalToFace()
Destructor.
Definition: normalToFace.C:86
normalToFace(const polyMesh &mesh, const vector &normal, const scalar tol)
Construct from components.
Definition: normalToFace.C:60
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:65
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
error FatalError
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
dictionary dict