cellToFace.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-2016 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 "cellToFace.H"
27 #include "polyMesh.H"
28 #include "cellSet.H"
29 #include "Time.H"
30 #include "syncTools.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(cellToFace, 0);
38  addToRunTimeSelectionTable(topoSetSource, cellToFace, word);
39  addToRunTimeSelectionTable(topoSetSource, cellToFace, istream);
40 
41  template<>
42  const char* Foam::NamedEnum
43  <
45  2
46  >::names[] =
47  {
48  "all",
49  "both"
50  };
51 }
52 
53 
54 Foam::topoSetSource::addToUsageTable Foam::cellToFace::usage_
55 (
56  cellToFace::typeName,
57  "\n Usage: cellToFace <cellSet> all|both\n\n"
58  " Select -all : all faces of cells in the cellSet\n"
59  " -both: faces where both neighbours are in the cellSet\n\n"
60 );
61 
63  Foam::cellToFace::cellActionNames_;
64 
65 
66 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
67 
68 void Foam::cellToFace::combine(topoSet& set, const bool add) const
69 {
70  // Load the set
71  if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName_)))
72  {
73  SeriousError<< "Cannot load set "
74  << setName_ << endl;
75  }
76 
77  cellSet loadedSet(mesh_, setName_);
78 
79  if (option_ == ALL)
80  {
81  // Add all faces from cell
82  forAllConstIter(cellSet, loadedSet, iter)
83  {
84  const label celli = iter.key();
85  const labelList& cFaces = mesh_.cells()[celli];
86 
87  forAll(cFaces, cFacei)
88  {
89  addOrDelete(set, cFaces[cFacei], add);
90  }
91  }
92  }
93  else if (option_ == BOTH)
94  {
95  // Add all faces whose both neighbours are in set.
96 
97  const label nInt = mesh_.nInternalFaces();
98  const labelList& own = mesh_.faceOwner();
99  const labelList& nei = mesh_.faceNeighbour();
100  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
101 
102 
103  // Check all internal faces
104  for (label facei = 0; facei < nInt; facei++)
105  {
106  if (loadedSet.found(own[facei]) && loadedSet.found(nei[facei]))
107  {
108  addOrDelete(set, facei, add);
109  }
110  }
111 
112 
113  // Get coupled cell status
114  boolList neiInSet(mesh_.nFaces()-nInt, false);
115 
116  forAll(patches, patchi)
117  {
118  const polyPatch& pp = patches[patchi];
119 
120  if (pp.coupled())
121  {
122  label facei = pp.start();
123  forAll(pp, i)
124  {
125  neiInSet[facei-nInt] = loadedSet.found(own[facei]);
126  facei++;
127  }
128  }
129  }
130  syncTools::swapBoundaryFaceList(mesh_, neiInSet);
131 
132 
133  // Check all boundary faces
134  forAll(patches, patchi)
135  {
136  const polyPatch& pp = patches[patchi];
137 
138  if (pp.coupled())
139  {
140  label facei = pp.start();
141  forAll(pp, i)
142  {
143  if (loadedSet.found(own[facei]) && neiInSet[facei-nInt])
144  {
145  addOrDelete(set, facei, add);
146  }
147  facei++;
148  }
149  }
150  }
151  }
152 }
153 
154 
155 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
156 
157 // Construct from componenta
159 (
160  const polyMesh& mesh,
161  const word& setName,
162  const cellAction option
163 )
164 :
165  topoSetSource(mesh),
166  setName_(setName),
167  option_(option)
168 {}
169 
170 
171 // Construct from dictionary
173 (
174  const polyMesh& mesh,
175  const dictionary& dict
176 )
177 :
178  topoSetSource(mesh),
179  setName_(dict.lookup("set")),
180  option_(cellActionNames_.read(dict.lookup("option")))
181 {}
182 
183 
184 // Construct from Istream
186 (
187  const polyMesh& mesh,
188  Istream& is
189 )
190 :
191  topoSetSource(mesh),
192  setName_(checkIs(is)),
193  option_(cellActionNames_.read(checkIs(is)))
194 {}
195 
196 
197 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
198 
200 {}
201 
202 
203 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
204 
206 (
207  const topoSetSource::setAction action,
208  topoSet& set
209 ) const
210 {
211  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
212  {
213  Info<< " Adding faces according to cellSet " << setName_
214  << " ..." << endl;
215 
216  combine(set, true);
217  }
218  else if (action == topoSetSource::DELETE)
219  {
220  Info<< " Removing faces according to cellSet " << setName_
221  << " ..." << endl;
222 
223  combine(set, false);
224  }
225 }
226 
227 
228 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
cellAction
Enumeration defining the valid options.
Definition: cellToFace.H:59
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
patches[0]
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:310
messageStream SeriousError
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:113
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
virtual ~cellToFace()
Destructor.
Definition: cellToFace.C:199
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
Foam::polyBoundaryMesh.
cellToFace(const polyMesh &mesh, const word &setName, const cellAction option)
Construct from components.
Definition: cellToFace.C:159
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
label patchi
Class with constructor to add usage string to table.
A collection of cell labels.
Definition: cellSet.H:48
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:300
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: cellToFace.C:206
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled boundary face values.
Definition: syncTools.H:430
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
Definition: topoSet.C:124
bool exists(const fileName &, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: POSIX.C:517
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576