cellToFace.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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"
31 #include "OSspecific.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(cellToFace, 0);
39  addToRunTimeSelectionTable(topoSetSource, cellToFace, word);
40  addToRunTimeSelectionTable(topoSetSource, cellToFace, istream);
41 
42  template<>
43  const char* Foam::NamedEnum
44  <
46  2
47  >::names[] =
48  {
49  "all",
50  "both"
51  };
52 }
53 
54 
55 Foam::topoSetSource::addToUsageTable Foam::cellToFace::usage_
56 (
57  cellToFace::typeName,
58  "\n Usage: cellToFace <cellSet> all|both\n\n"
59  " Select -all : all faces of cells in the cellSet\n"
60  " -both: faces where both neighbours are in the cellSet\n\n"
61 );
62 
64  Foam::cellToFace::cellActionNames_;
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
69 void Foam::cellToFace::combine(topoSet& set, const bool add) const
70 {
71  // Load the set
72  if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName_)))
73  {
74  SeriousError<< "Cannot load set "
75  << setName_ << endl;
76  }
77 
78  cellSet loadedSet(mesh_, setName_);
79 
80  if (option_ == ALL)
81  {
82  // Add all faces from cell
83  forAllConstIter(cellSet, loadedSet, iter)
84  {
85  const label celli = iter.key();
86  const labelList& cFaces = mesh_.cells()[celli];
87 
88  forAll(cFaces, cFacei)
89  {
90  addOrDelete(set, cFaces[cFacei], add);
91  }
92  }
93  }
94  else if (option_ == BOTH)
95  {
96  // Add all faces whose both neighbours are in set.
97 
98  const label nInt = mesh_.nInternalFaces();
99  const labelList& own = mesh_.faceOwner();
100  const labelList& nei = mesh_.faceNeighbour();
101  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
102 
103 
104  // Check all internal faces
105  for (label facei = 0; facei < nInt; facei++)
106  {
107  if (loadedSet.found(own[facei]) && loadedSet.found(nei[facei]))
108  {
109  addOrDelete(set, facei, add);
110  }
111  }
112 
113 
114  // Get coupled cell status
115  boolList neiInSet(mesh_.nFaces()-nInt, false);
116 
117  forAll(patches, patchi)
118  {
119  const polyPatch& pp = patches[patchi];
120 
121  if (pp.coupled())
122  {
123  label facei = pp.start();
124  forAll(pp, i)
125  {
126  neiInSet[facei-nInt] = loadedSet.found(own[facei]);
127  facei++;
128  }
129  }
130  }
131  syncTools::swapBoundaryFaceList(mesh_, neiInSet);
132 
133 
134  // Check all boundary faces
135  forAll(patches, patchi)
136  {
137  const polyPatch& pp = patches[patchi];
138 
139  if (pp.coupled())
140  {
141  label facei = pp.start();
142  forAll(pp, i)
143  {
144  if (loadedSet.found(own[facei]) && neiInSet[facei-nInt])
145  {
146  addOrDelete(set, facei, add);
147  }
148  facei++;
149  }
150  }
151  }
152  }
153 }
154 
155 
156 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
157 
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 
172 (
173  const polyMesh& mesh,
174  const dictionary& dict
175 )
176 :
177  topoSetSource(mesh),
178  setName_(dict.lookup("set")),
179  option_(cellActionNames_.read(dict.lookup("option")))
180 {}
181 
182 
184 (
185  const polyMesh& mesh,
186  Istream& is
187 )
188 :
189  topoSetSource(mesh),
190  setName_(checkIs(is)),
191  option_(cellActionNames_.read(checkIs(is)))
192 {}
193 
194 
195 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
196 
198 {}
199 
200 
201 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
202 
204 (
205  const topoSetSource::setAction action,
206  topoSet& set
207 ) const
208 {
209  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
210  {
211  Info<< " Adding faces according to cellSet " << setName_
212  << " ..." << endl;
213 
214  combine(set, true);
215  }
216  else if (action == topoSetSource::DELETE)
217  {
218  Info<< " Removing faces according to cellSet " << setName_
219  << " ..." << endl;
220 
221  combine(set, false);
222  }
223 }
224 
225 
226 // ************************************************************************* //
bool exists(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist (as directory or file) in the file system?
Definition: POSIX.C:520
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:156
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:251
patches[0]
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
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
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:319
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:197
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:309
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: cellToFace.C:204
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
fileName localPath() const
Return the path relative to the case.
Definition: IOobject.C:372
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844