setsToFaceZone.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2020 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 "setsToFaceZone.H"
30 #include "polyMesh.H"
31 #include "faceZoneSet.H"
32 #include "cellSet.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(setsToFaceZone, 0);
40  addToRunTimeSelectionTable(topoSetSource, setsToFaceZone, word);
41  addToRunTimeSelectionTable(topoSetSource, setsToFaceZone, istream);
42 
43  addToRunTimeSelectionTable(topoSetFaceZoneSource, setsToFaceZone, word);
44  addToRunTimeSelectionTable(topoSetFaceZoneSource, setsToFaceZone, istream);
45 }
46 
47 
48 Foam::topoSetSource::addToUsageTable Foam::setsToFaceZone::usage_
49 (
50  setsToFaceZone::typeName,
51  "\n Usage: setsToFaceZone <faceSet> <slaveCellSet>\n\n"
52  " Select all faces in the faceSet."
53  " Orientated so slave side is in cellSet.\n\n"
54 );
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
60 (
61  const polyMesh& mesh,
62  const word& faceSetName,
63  const word& cellSetName,
64  const bool flip
65 )
66 :
68  faceSetName_(faceSetName),
69  cellSetName_(cellSetName),
70  flip_(flip)
71 {}
72 
73 
75 (
76  const polyMesh& mesh,
77  const dictionary& dict
78 )
79 :
81  faceSetName_(dict.get<word>("faceSet")),
82  cellSetName_(dict.get<word>("cellSet")),
83  flip_(dict.getOrDefault("flip", false))
84 {}
85 
86 
88 (
89  const polyMesh& mesh,
90  Istream& is
91 )
92 :
94  faceSetName_(checkIs(is)),
95  cellSetName_(checkIs(is)),
96  flip_(false)
97 {}
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
103 (
104  const topoSetSource::setAction action,
105  topoSet& set
106 ) const
107 {
108  if (!isA<faceZoneSet>(set))
109  {
111  << "Operation only allowed on a faceZoneSet." << endl;
112  return;
113  }
114  else
115  {
116  faceZoneSet& zoneSet = refCast<faceZoneSet>(set);
117 
118  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
119  {
120  if (verbose_)
121  {
122  if (flip_)
123  {
124  Info<< " Adding all faces from faceSet " << faceSetName_
125  << "; orientation pointing into cellSet "
126  << cellSetName_ << " ..." << endl;
127  }
128  else
129  {
130  Info<< " Adding all faces from faceSet " << faceSetName_
131  << "; orientation pointing away from cellSet "
132  << cellSetName_ << " ..." << endl;
133  }
134  }
135 
136  // Load the sets
137  faceSet fSet(mesh_, faceSetName_);
138  cellSet cSet(mesh_, cellSetName_);
139 
140  // Start off from copy
141  DynamicList<label> newAddressing(zoneSet.addressing());
142  DynamicList<bool> newFlipMap(zoneSet.flipMap());
143 
144  for (const label facei : fSet)
145  {
146  if (!zoneSet.found(facei))
147  {
148  bool flipFace = false;
149 
150  const label own = mesh_.faceOwner()[facei];
151  const bool ownFound = cSet.found(own);
152 
153  if (mesh_.isInternalFace(facei))
154  {
155  label nei = mesh_.faceNeighbour()[facei];
156  bool neiFound = cSet.found(nei);
157 
158  if (ownFound && !neiFound)
159  {
160  flipFace = false;
161  }
162  else if (!ownFound && neiFound)
163  {
164  flipFace = true;
165  }
166  else
167  {
169  << "One of owner or neighbour of internal face "
170  << facei << " should be in cellSet "
171  << cSet.name()
172  << " to be able to determine orientation."
173  << endl
174  << "Face:" << facei << " own:" << own
175  << " OwnInCellSet:" << ownFound
176  << " nei:" << nei
177  << " NeiInCellSet:" << neiFound
178  << endl;
179  }
180  }
181  else
182  {
183  flipFace = !ownFound;
184  }
185 
186 
187  if (flip_)
188  {
189  flipFace = !flipFace;
190  }
191 
192  newAddressing.append(facei);
193  newFlipMap.append(flipFace);
194  }
195  }
196 
197  zoneSet.addressing().transfer(newAddressing);
198  zoneSet.flipMap().transfer(newFlipMap);
199  zoneSet.updateSet();
200  }
201  else if (action == topoSetSource::SUBTRACT)
202  {
203  if (verbose_)
204  {
205  Info<< " Removing all faces from faceSet " << faceSetName_
206  << " ..." << endl;
207  }
208 
209  // Load the set
210  faceZoneSet loadedSet(mesh_, faceSetName_);
211 
212  // Start off empty
213  DynamicList<label> newAddressing(zoneSet.addressing().size());
214  DynamicList<bool> newFlipMap(zoneSet.flipMap().size());
215 
216  forAll(zoneSet.addressing(), i)
217  {
218  if (!loadedSet.found(zoneSet.addressing()[i]))
219  {
220  newAddressing.append(zoneSet.addressing()[i]);
221  newFlipMap.append(zoneSet.flipMap()[i]);
222  }
223  }
224  zoneSet.addressing().transfer(newAddressing);
225  zoneSet.flipMap().transfer(newFlipMap);
226  zoneSet.updateSet();
227  }
228  }
229 }
230 
231 
232 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::faceZoneSet::addressing
const labelList & addressing() const
Definition: faceZoneSet.H:106
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
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:129
Foam::topoSetFaceZoneSource
The topoSetFaceZoneSource is a intermediate class for handling topoSet sources for selecting face zon...
Definition: topoSetFaceZoneSource.H:57
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:369
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
polyMesh.H
Foam::faceZoneSet::flipMap
const boolList & flipMap() const
Definition: faceZoneSet.H:117
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:296
Foam::setsToFaceZone::setsToFaceZone
setsToFaceZone(const polyMesh &mesh, const word &faceSetName, const word &cellSetName, const bool flip)
Construct from components.
Definition: setsToFaceZone.C:60
Foam::setsToFaceZone::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: setsToFaceZone.C:103
Foam::topoSet::found
virtual bool found(const label id) const
Has the given index?
Definition: topoSet.C:508
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 (stdout output on master, null elsewhere)
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:456
Foam::faceZoneSet
Like faceSet but -reads data from faceZone -updates faceZone when writing.
Definition: faceZoneSet.H:51
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
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:123
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::cellSet
A collection of cell labels.
Definition: cellSet.H:51
Foam::IOobject::name
const word & name() const noexcept
Return name.
Definition: IOobjectI.H:65
setsToFaceZone.H
cellSet.H
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328