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-2019 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 
44 
45 Foam::topoSetSource::addToUsageTable Foam::setsToFaceZone::usage_
46 (
47  setsToFaceZone::typeName,
48  "\n Usage: setsToFaceZone <faceSet> <slaveCellSet>\n\n"
49  " Select all faces in the faceSet."
50  " Orientated so slave side is in cellSet.\n\n"
51 );
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
57 (
58  const polyMesh& mesh,
59  const word& faceSetName,
60  const word& cellSetName,
61  const bool flip
62 )
63 :
65  faceSetName_(faceSetName),
66  cellSetName_(cellSetName),
67  flip_(flip)
68 {}
69 
70 
72 (
73  const polyMesh& mesh,
74  const dictionary& dict
75 )
76 :
78  faceSetName_(dict.get<word>("faceSet")),
79  cellSetName_(dict.get<word>("cellSet")),
80  flip_(dict.lookupOrDefault("flip", false))
81 {}
82 
83 
85 (
86  const polyMesh& mesh,
87  Istream& is
88 )
89 :
91  faceSetName_(checkIs(is)),
92  cellSetName_(checkIs(is)),
93  flip_(false)
94 {}
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
100 (
101  const topoSetSource::setAction action,
102  topoSet& set
103 ) const
104 {
105  if (!isA<faceZoneSet>(set))
106  {
108  << "Operation only allowed on a faceZoneSet." << endl;
109  }
110  else
111  {
112  faceZoneSet& zoneSet = refCast<faceZoneSet>(set);
113 
114  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
115  {
116  if (verbose_)
117  {
118  if (flip_)
119  {
120  Info<< " Adding all faces from faceSet " << faceSetName_
121  << "; orientation pointing into cellSet "
122  << cellSetName_ << " ..." << endl;
123  }
124  else
125  {
126  Info<< " Adding all faces from faceSet " << faceSetName_
127  << "; orientation pointing away from cellSet "
128  << cellSetName_ << " ..." << endl;
129  }
130  }
131 
132  // Load the sets
133  faceSet fSet(mesh_, faceSetName_);
134  cellSet cSet(mesh_, cellSetName_);
135 
136  // Start off from copy
137  DynamicList<label> newAddressing(zoneSet.addressing());
138  DynamicList<bool> newFlipMap(zoneSet.flipMap());
139 
140  for (const label facei : fSet)
141  {
142  if (!zoneSet.found(facei))
143  {
144  bool flipFace = false;
145 
146  const label own = mesh_.faceOwner()[facei];
147  const bool ownFound = cSet.found(own);
148 
149  if (mesh_.isInternalFace(facei))
150  {
151  label nei = mesh_.faceNeighbour()[facei];
152  bool neiFound = cSet.found(nei);
153 
154  if (ownFound && !neiFound)
155  {
156  flipFace = false;
157  }
158  else if (!ownFound && neiFound)
159  {
160  flipFace = true;
161  }
162  else
163  {
165  << "One of owner or neighbour of internal face "
166  << facei << " should be in cellSet "
167  << cSet.name()
168  << " to be able to determine orientation."
169  << endl
170  << "Face:" << facei << " own:" << own
171  << " OwnInCellSet:" << ownFound
172  << " nei:" << nei
173  << " NeiInCellSet:" << neiFound
174  << endl;
175  }
176  }
177  else
178  {
179  flipFace = !ownFound;
180  }
181 
182 
183  if (flip_)
184  {
185  flipFace = !flipFace;
186  }
187 
188  newAddressing.append(facei);
189  newFlipMap.append(flipFace);
190  }
191  }
192 
193  zoneSet.addressing().transfer(newAddressing);
194  zoneSet.flipMap().transfer(newFlipMap);
195  zoneSet.updateSet();
196  }
197  else if (action == topoSetSource::SUBTRACT)
198  {
199  if (verbose_)
200  {
201  Info<< " Removing all faces from faceSet " << faceSetName_
202  << " ..." << endl;
203  }
204 
205  // Load the set
206  faceZoneSet loadedSet(mesh_, faceSetName_);
207 
208  // Start off empty
209  DynamicList<label> newAddressing(zoneSet.addressing().size());
210  DynamicList<bool> newFlipMap(zoneSet.flipMap().size());
211 
212  forAll(zoneSet.addressing(), i)
213  {
214  if (!loadedSet.found(zoneSet.addressing()[i]))
215  {
216  newAddressing.append(zoneSet.addressing()[i]);
217  newFlipMap.append(zoneSet.flipMap()[i]);
218  }
219  }
220  zoneSet.addressing().transfer(newAddressing);
221  zoneSet.flipMap().transfer(newFlipMap);
222  zoneSet.updateSet();
223  }
224  }
225 }
226 
227 
228 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::faceZoneSet::addressing
const labelList & addressing() const
Definition: faceZoneSet.H:107
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:46
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::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
Foam::setsToFaceZone::setsToFaceZone
setsToFaceZone(const polyMesh &mesh, const word &faceSetName, const word &cellSetName, const bool flip)
Construct from components.
Definition: setsToFaceZone.C:57
Foam::setsToFaceZone::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: setsToFaceZone.C:100
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::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::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::cellSet
A collection of cell labels.
Definition: cellSet.H:51
setsToFaceZone.H
cellSet.H
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294