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 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 
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 
64 
65 
66 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
67 
68 void Foam::cellToFace::combine(topoSet& set, const bool add) const
69 {
70  // Load the set
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();
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  }
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 :
166  setName_(setName),
167  option_(option)
168 {}
169 
170 
171 // Construct from dictionary
173 (
174  const polyMesh& mesh,
175  const dictionary& dict
176 )
177 :
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 :
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 // ************************************************************************* //
Foam::topoSet::localPath
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
Definition: topoSet.C:124
Foam::cellToFace::cellAction
cellAction
Enumeration defining the valid options.
Definition: cellToFace.H:59
Foam::topoSetSource::ADD
@ ADD
Definition: topoSetSource.H:87
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::exists
bool exists(const fileName &, const bool checkGzip=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: POSIX.C:608
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
Foam::cellToFace::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: cellToFace.C:206
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::ListListOps::combine
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:100
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:117
Foam::polyPatch::coupled
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:322
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:136
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Foam::cellToFace::setName_
word setName_
Name of set to use.
Definition: cellToFace.H:74
Foam::cellToFace::cellActionNames_
static const NamedEnum< cellAction, 2 > cellActionNames_
Definition: cellToFace.H:71
Foam::topoSetSource::NEW
@ NEW
Definition: topoSetSource.H:85
polyMesh.H
syncTools.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::cellToFace::usage_
static addToUsageTable usage_
Add usage string.
Definition: cellToFace.H:69
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
cellToFace.H
Foam::cellToFace::~cellToFace
virtual ~cellToFace()
Destructor.
Definition: cellToFace.C:199
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:59
Foam::cellToFace::BOTH
@ BOTH
Definition: cellToFace.H:62
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Info
messageStream Info
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1017
Foam::topoSetSource::DELETE
@ DELETE
Definition: topoSetSource.H:88
Foam::cellToFace::option_
cellAction option_
Option.
Definition: cellToFace.H:77
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Definition: primitiveMeshI.H:52
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:870
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::HashTable::found
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:48
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
Foam::cellToFace::combine
void combine(topoSet &set, const bool add) const
Depending on face to cell option add to or delete from cellSet.
Definition: cellToFace.C:68
Foam::syncTools::swapBoundaryFaceList
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled boundary face values.
Definition: syncTools.H:430
Foam::SeriousError
messageStream SeriousError
Foam::primitiveMesh::nFaces
label nFaces() const
Definition: primitiveMeshI.H:58
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:281
Foam::cellToFace::cellToFace
cellToFace(const polyMesh &mesh, const word &setName, const cellAction option)
Construct from components.
Definition: cellToFace.C:159
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::cellToFace::ALL
@ ALL
Definition: cellToFace.H:61
cellSet.H
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Definition: topoSetSource.H:126
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::polyMesh::faceNeighbour
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1023
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label cellI, const bool) const
Add (if bool) cellI to set or delete cellI from set.
Definition: topoSetSource.C:140
Foam::NamedEnum
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52