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 | Copyright (C) 2011-2013 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 "setsToFaceZone.H"
27 #include "polyMesh.H"
28 #include "faceZoneSet.H"
29 #include "cellSet.H"
30 
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(setsToFaceZone, 0);
38  addToRunTimeSelectionTable(topoSetSource, setsToFaceZone, word);
39  addToRunTimeSelectionTable(topoSetSource, setsToFaceZone, istream);
40 }
41 
42 
43 Foam::topoSetSource::addToUsageTable Foam::setsToFaceZone::usage_
44 (
45  setsToFaceZone::typeName,
46  "\n Usage: setsToFaceZone <faceSet> <slaveCellSet>\n\n"
47  " Select all faces in the faceSet."
48  " Orientated so slave side is in cellSet.\n\n"
49 );
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
54 // Construct from components
56 (
57  const polyMesh& mesh,
58  const word& faceSetName,
59  const word& cellSetName,
60  const Switch& flip
61 )
62 :
63  topoSetSource(mesh),
64  faceSetName_(faceSetName),
65  cellSetName_(cellSetName),
66  flip_(flip)
67 {}
68 
69 
70 // Construct from dictionary
72 (
73  const polyMesh& mesh,
74  const dictionary& dict
75 )
76 :
77  topoSetSource(mesh),
78  faceSetName_(dict.lookup("faceSet")),
79  cellSetName_(dict.lookup("cellSet")),
80  flip_(dict.lookupOrDefault("flip", false))
81 {}
82 
83 
84 // Construct from Istream
86 (
87  const polyMesh& mesh,
88  Istream& is
89 )
90 :
91  topoSetSource(mesh),
92  faceSetName_(checkIs(is)),
93  cellSetName_(checkIs(is)),
94  flip_(false)
95 {}
96 
97 
98 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
99 
101 {}
102 
103 
104 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
105 
107 (
108  const topoSetSource::setAction action,
109  topoSet& set
110 ) const
111 {
112  if (!isA<faceZoneSet>(set))
113  {
114  WarningIn
115  (
116  "setsToFaceZone::applyToSet(const topoSetSource::setAction"
117  ", topoSet"
118  ) << "Operation only allowed on a faceZoneSet." << endl;
119  }
120  else
121  {
122  faceZoneSet& fzSet = refCast<faceZoneSet>(set);
123 
124  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
125  {
126  Info<< " Adding all faces from faceSet " << faceSetName_
127  << " ..." << endl;
128 
129  // Load the sets
130  faceSet fSet(mesh_, faceSetName_);
131  cellSet cSet(mesh_, cellSetName_);
132 
133  // Start off from copy
134  DynamicList<label> newAddressing(fzSet.addressing());
135  DynamicList<bool> newFlipMap(fzSet.flipMap());
136 
137  forAllConstIter(faceSet, fSet, iter)
138  {
139  label faceI = iter.key();
140 
141  if (!fzSet.found(faceI))
142  {
143  bool flipFace = false;
144 
145  label own = mesh_.faceOwner()[faceI];
146  bool ownFound = cSet.found(own);
147 
148  if (mesh_.isInternalFace(faceI))
149  {
150  label nei = mesh_.faceNeighbour()[faceI];
151  bool neiFound = cSet.found(nei);
152 
153  if (ownFound && !neiFound)
154  {
155  flipFace = false;
156  }
157  else if (!ownFound && neiFound)
158  {
159  flipFace = true;
160  }
161  else
162  {
163  WarningIn
164  (
165  "setsToFaceZone::applyToSet"
166  "(const topoSetSource::setAction, topoSet)"
167  ) << "One of owner or neighbour of internal face "
168  << faceI << " should be in cellSet "
169  << cSet.name()
170  << " to be able to determine orientation."
171  << endl
172  << "Face:" << faceI << " own:" << own
173  << " OwnInCellSet:" << ownFound
174  << " nei:" << nei
175  << " NeiInCellSet:" << neiFound
176  << endl;
177  }
178  }
179  else
180  {
181  flipFace = !ownFound;
182  }
183 
184 
185  if (flip_)
186  {
187  flipFace = !flipFace;
188  }
189 
190  newAddressing.append(faceI);
191  newFlipMap.append(flipFace);
192  }
193  }
194 
195  fzSet.addressing().transfer(newAddressing);
196  fzSet.flipMap().transfer(newFlipMap);
197  fzSet.updateSet();
198  }
199  else if (action == topoSetSource::DELETE)
200  {
201  Info<< " Removing all faces from faceSet " << faceSetName_
202  << " ..." << endl;
203 
204  // Load the set
205  faceZoneSet loadedSet(mesh_, faceSetName_);
206 
207  // Start off empty
208  DynamicList<label> newAddressing(fzSet.addressing().size());
209  DynamicList<bool> newFlipMap(fzSet.flipMap().size());
210 
211  forAll(fzSet.addressing(), i)
212  {
213  if (!loadedSet.found(fzSet.addressing()[i]))
214  {
215  newAddressing.append(fzSet.addressing()[i]);
216  newFlipMap.append(fzSet.flipMap()[i]);
217  }
218  }
219  fzSet.addressing().transfer(newAddressing);
220  fzSet.flipMap().transfer(newFlipMap);
221  fzSet.updateSet();
222  }
223  }
224 }
225 
226 
227 // ************************************************************************* //
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
A list of face labels.
Definition: faceSet.H:48
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:390
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A collection of cell labels.
Definition: cellSet.H:48
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
Definition: Switch.H:60
messageStream Info
const labelList & addressing() const
Definition: faceZoneSet.H:107
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
setsToFaceZone(const polyMesh &mesh, const word &faceSetName, const word &cellSetName, const Switch &flip)
Construct from components.
Namespace for OpenFOAM.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define WarningIn(functionName)
Report a warning using Foam::Warning.
virtual ~setsToFaceZone()
Destructor.
#define forAll(list, i)
Definition: UList.H:421
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Macros for easy insertion into run-time selection tables.
const word & name() const
Return name.
Definition: IOobject.H:260
Like faceSet but updates faceZone when writing.
Definition: faceZoneSet.H:49
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
const boolList & flipMap() const
Definition: faceZoneSet.H:118
Class with constructor to add usage string to table.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
defineTypeNameAndDebug(combustionModel, 0)
void updateSet()
Sort addressing and make faceSet part consistent with addressing.
Definition: faceZoneSet.C:48