setAndNormalToFaceZone.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2013-2016 OpenFOAM Foundation
9  Copyright (C) 2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "setAndNormalToFaceZone.H"
30 #include "polyMesh.H"
31 #include "faceZoneSet.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(setAndNormalToFaceZone, 0);
39  addToRunTimeSelectionTable(topoSetSource, setAndNormalToFaceZone, word);
40  addToRunTimeSelectionTable(topoSetSource, setAndNormalToFaceZone, istream);
41 }
42 
43 
44 Foam::topoSetSource::addToUsageTable Foam::setAndNormalToFaceZone::usage_
45 (
46  setAndNormalToFaceZone::typeName,
47  "\n Usage: setAndNormalToFaceZone <faceSet> <normal>\n\n"
48  " Select all faces in the faceSet and orient using normal.\n\n"
49 );
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 (
56  const polyMesh& mesh,
57  const word& setName,
58  const vector& normal
59 )
60 :
62  setName_(setName),
63  normal_(normal)
64 {}
65 
66 
68 (
69  const polyMesh& mesh,
70  const dictionary& dict
71 )
72 :
74  setName_(dict.get<word>("faceSet")),
75  normal_(dict.get<vector>("normal"))
76 {}
77 
78 
80 (
81  const polyMesh& mesh,
82  Istream& is
83 )
84 :
86  setName_(checkIs(is)),
87  normal_(checkIs(is))
88 {}
89 
90 
91 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92 
94 (
95  const topoSetSource::setAction action,
96  topoSet& set
97 ) const
98 {
99  if (!isA<faceZoneSet>(set))
100  {
102  << "Operation only allowed on a faceZoneSet." << endl;
103  }
104  else
105  {
106  faceZoneSet& zoneSet = refCast<faceZoneSet>(set);
107 
108  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
109  {
110  if (verbose_)
111  {
112  Info<< " Adding all faces from faceSet " << setName_
113  << " ..." << endl;
114  }
115 
116  // Load the sets
117  faceSet loadedSet(mesh_, setName_);
118  labelHashSet& faceIds = loadedSet;
119 
120  // Start off from copy
121  DynamicList<label> newAddressing(zoneSet.addressing());
122  DynamicList<bool> newFlipMap(zoneSet.flipMap());
123 
124  const faceList& faces = mesh_.faces();
125  const pointField& points = mesh_.points();
126 
127  for (const label facei : faceIds)
128  {
129  if (!zoneSet.found(facei))
130  {
131  newAddressing.append(facei);
132 
133  const vector n = faces[facei].areaNormal(points);
134  if ((n & normal_) > 0)
135  {
136  newFlipMap.append(false);
137  }
138  else
139  {
140  newFlipMap.append(true);
141  }
142  }
143  }
144 
145  zoneSet.addressing().transfer(newAddressing);
146  zoneSet.flipMap().transfer(newFlipMap);
147  zoneSet.updateSet();
148  }
149  else if (action == topoSetSource::SUBTRACT)
150  {
151  if (verbose_)
152  {
153  Info<< " Removing all faces from faceSet " << setName_
154  << " ..." << endl;
155  }
156 
157  // Load the set
158  faceSet loadedSet(mesh_, setName_);
159 
160  // Start off empty
161  DynamicList<label> newAddressing(zoneSet.addressing().size());
162  DynamicList<bool> newFlipMap(zoneSet.flipMap().size());
163 
164  forAll(zoneSet.addressing(), i)
165  {
166  if (!loadedSet.found(zoneSet.addressing()[i]))
167  {
168  newAddressing.append(zoneSet.addressing()[i]);
169  newFlipMap.append(zoneSet.flipMap()[i]);
170  }
171  }
172  zoneSet.addressing().transfer(newAddressing);
173  zoneSet.flipMap().transfer(newFlipMap);
174  zoneSet.updateSet();
175  }
176  }
177 }
178 
179 
180 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::faceZoneSet::addressing
const labelList & addressing() const
Definition: faceZoneSet.H:107
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::DynamicList< label >
faceZoneSet.H
Foam::faceZoneSet::updateSet
void updateSet()
Sort addressing and make faceSet part consistent with addressing.
Definition: faceZoneSet.C:51
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::faceSet
A list of face labels.
Definition: faceSet.H:51
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
polyMesh.H
Foam::HashSet< label, Hash< label > >
Foam::faceZoneSet::flipMap
const boolList & flipMap() const
Definition: faceZoneSet.H:118
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::topoSet::found
virtual bool found(const label id) const
Has the given index?
Definition: topoSet.C:511
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:62
Foam::Field< vector >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:472
setAndNormalToFaceZone.H
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:436
Foam::faceZoneSet
Like faceSet but -reads data from faceZone -updates faceZone when writing.
Definition: faceZoneSet.H:52
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:66
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:66
Foam::setAndNormalToFaceZone::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: setAndNormalToFaceZone.C:94
Foam::setAndNormalToFaceZone::setAndNormalToFaceZone
setAndNormalToFaceZone(const polyMesh &mesh, const word &setName, const vector &normal)
Construct from components.
Definition: setAndNormalToFaceZone.C:55
Foam::Vector< scalar >
Foam::List< face >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294