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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018 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 "cellToFace.H"
30 #include "polyMesh.H"
31 #include "cellSet.H"
32 #include "Time.H"
33 #include "syncTools.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(cellToFace, 0);
41  addToRunTimeSelectionTable(topoSetSource, cellToFace, word);
42  addToRunTimeSelectionTable(topoSetSource, cellToFace, istream);
43  addToRunTimeSelectionTable(topoSetFaceSource, cellToFace, word);
44  addToRunTimeSelectionTable(topoSetFaceSource, cellToFace, istream);
45 }
46 
47 
48 Foam::topoSetSource::addToUsageTable Foam::cellToFace::usage_
49 (
50  cellToFace::typeName,
51  "\n Usage: cellToFace <cellSet> all|both\n\n"
52  " Select -all : all faces of cells in the cellSet\n"
53  " -both: faces where both neighbours are in the cellSet\n\n"
54 );
55 
56 const Foam::Enum
57 <
59 >
60 Foam::cellToFace::cellActionNames_
61 ({
62  { cellAction::ALL, "all" },
63  { cellAction::BOTH, "both" },
64 });
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
69 void Foam::cellToFace::combine
70 (
71  topoSet& set,
72  const bool add,
73  const word& setName
74 ) const
75 {
76  // Load the set
77  if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName)))
78  {
79  SeriousError<< "Cannot load set "
80  << setName << endl;
81  }
82 
83  cellSet loadedSet(mesh_, setName);
84  const labelHashSet& cellLabels = loadedSet;
85 
86  if (option_ == ALL)
87  {
88  // Add all faces from cell
89  for (const label celli : cellLabels)
90  {
91  const labelList& cFaces = mesh_.cells()[celli];
92 
93  addOrDelete(set, cFaces, add);
94  }
95  }
96  else if (option_ == BOTH)
97  {
98  // Add all faces whose both neighbours are in set.
99 
100  const label nInt = mesh_.nInternalFaces();
101  const labelList& own = mesh_.faceOwner();
102  const labelList& nei = mesh_.faceNeighbour();
103  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
104 
105 
106  // Check all internal faces
107  for (label facei = 0; facei < nInt; ++facei)
108  {
109  if (cellLabels.found(own[facei]) && cellLabels.found(nei[facei]))
110  {
111  addOrDelete(set, facei, add);
112  }
113  }
114 
115 
116  // Get coupled cell status
117  boolList neiInSet(mesh_.nFaces()-nInt, false);
118 
119  for (const polyPatch& pp : patches)
120  {
121  if (pp.coupled())
122  {
123  label facei = pp.start();
124  forAll(pp, i)
125  {
126  neiInSet[facei-nInt] = cellLabels.found(own[facei]);
127  ++facei;
128  }
129  }
130  }
132 
133 
134  // Check all boundary faces
135  for (const polyPatch& pp : patches)
136  {
137  if (pp.coupled())
138  {
139  label facei = pp.start();
140  forAll(pp, i)
141  {
142  if (cellLabels.found(own[facei]) && neiInSet[facei-nInt])
143  {
144  addOrDelete(set, facei, add);
145  }
146  ++facei;
147  }
148  }
149  }
150  }
151 }
152 
153 
154 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
155 
157 (
158  const polyMesh& mesh,
159  const word& setName,
160  const cellAction option
161 )
162 :
164  names_(one(), setName),
165  option_(option)
166 {}
167 
168 
170 (
171  const polyMesh& mesh,
172  const dictionary& dict
173 )
174 :
176  names_(),
177  option_(cellActionNames_.get("option", dict))
178 {
179  // Look for 'sets' or 'set'
180  if (!dict.readIfPresent("sets", names_))
181  {
182  names_.resize(1);
183  dict.readEntry("set", names_.first());
184  }
185 }
186 
187 
189 (
190  const polyMesh& mesh,
191  Istream& is
192 )
193 :
195  names_(one(), word(checkIs(is))),
196  option_(cellActionNames_.read(checkIs(is)))
197 {}
198 
199 
200 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
201 
203 (
204  const topoSetSource::setAction action,
205  topoSet& set
206 ) const
207 {
208  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
209  {
210  if (verbose_)
211  {
212  Info<< " Adding faces according to cellSet "
213  << flatOutput(names_) << nl;
214  }
215 
216  for (const word& setName : names_)
217  {
218  combine(set, true, setName);
219  }
220  }
221  else if (action == topoSetSource::SUBTRACT)
222  {
223  if (verbose_)
224  {
225  Info<< " Removing faces according to cellSet "
226  << flatOutput(names_) << nl;
227  }
228 
229  for (const word& setName : names_)
230  {
231  combine(set, false, setName);
232  }
233  }
234 }
235 
236 
237 // ************************************************************************* //
Foam::topoSet::localPath
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
Definition: topoSet.C:131
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::cellToFace::cellAction
cellAction
Enumeration defining the valid options.
Definition: cellToFace.H:93
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::topoSetSource::ADD
Add elements to the set.
Definition: topoSetSource.H:101
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:51
Foam::exists
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: MSwindows.C:625
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Number of internal faces.
Definition: primitiveMeshI.H:78
Foam::primitiveMesh::nFaces
label nFaces() const
Number of mesh faces.
Definition: primitiveMeshI.H:90
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:186
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
Foam::one
A class representing the concept of 1 (one), which can be used to avoid manipulating objects that are...
Definition: one.H:60
Foam::syncTools::swapBoundaryFaceList
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues)
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:439
Foam::boolList
List< bool > boolList
A List of bools.
Definition: List.H:72
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
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
Foam::topoSetFaceSource
Base class of a topoSet source for selecting faces.
Definition: topoSetFaceSource.H:50
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:106
polyMesh.H
syncTools.H
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
cellToFace.H
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::cellToFace::BOTH
Definition: cellToFace.H:96
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::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
Foam::cellToFace::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: cellToFace.C:203
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1076
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
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
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:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::topoSetSource::SUBTRACT
Subtract elements from the set.
Definition: topoSetSource.H:102
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Time.H
Foam::SeriousError
messageStream SeriousError
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:303
Foam::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
Foam::cellToFace::cellToFace
cellToFace(const polyMesh &mesh, const word &setName, const cellAction option)
Construct from components.
Definition: cellToFace.C:157
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
Definition: topoSetSource.C:170
Foam::cellToFace::ALL
Definition: cellToFace.H:95
cellSet.H
Foam::labelHashSet
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys and label hasher.
Definition: HashSet.H:415
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:151
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::polyMesh::faceNeighbour
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1082
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:417