pointToCell.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-2020 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 "pointToCell.H"
30 #include "polyMesh.H"
31 #include "pointSet.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(pointToCell, 0);
39  addToRunTimeSelectionTable(topoSetSource, pointToCell, word);
40  addToRunTimeSelectionTable(topoSetSource, pointToCell, istream);
41  addToRunTimeSelectionTable(topoSetCellSource, pointToCell, word);
42  addToRunTimeSelectionTable(topoSetCellSource, pointToCell, istream);
43 }
44 
45 
46 Foam::topoSetSource::addToUsageTable Foam::pointToCell::usage_
47 (
48  pointToCell::typeName,
49  "\n Usage: pointToCell <pointSet> any|edge\n\n"
50  " Select all cells with any point ('any') or any edge ('edge')"
51  " in the pointSet\n\n"
52 );
53 
54 const Foam::Enum
55 <
57 >
58 Foam::pointToCell::pointActionNames_
59 ({
60  { pointAction::ANY, "any" },
61  { pointAction::EDGE, "edge" },
62 });
63 
64 
65 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
66 
67 void Foam::pointToCell::combine
68 (
69  topoSet& set,
70  const bool add,
71  const word& setName
72 ) const
73 {
74  // Load the set
75  pointSet loadedSet(mesh_, setName);
76 
77  const labelHashSet& pointLabels = loadedSet;
78 
79  // Handle any selection
80  if (option_ == ANY)
81  {
82  for (const label pointi : pointLabels)
83  {
84  const labelList& pCells = mesh_.pointCells()[pointi];
85 
86  addOrDelete(set, pCells, add);
87  }
88  }
89  else if (option_ == EDGE)
90  {
91  const faceList& faces = mesh_.faces();
92 
93  forAll(faces, facei)
94  {
95  const face& f = faces[facei];
96 
97  forAll(f, fp)
98  {
99  if
100  (
101  pointLabels.found(f[fp])
102  && pointLabels.found(f.nextLabel(fp))
103  )
104  {
105  addOrDelete(set, mesh_.faceOwner()[facei], add);
106  if (mesh_.isInternalFace(facei))
107  {
108  addOrDelete(set, mesh_.faceNeighbour()[facei], add);
109  }
110  }
111  }
112  }
113  }
114 }
115 
116 
117 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
118 
120 (
121  const polyMesh& mesh,
122  const word& setName,
123  const pointAction option
124 )
125 :
127  names_(one{}, setName),
128  option_(option)
129 {}
130 
131 
133 (
134  const polyMesh& mesh,
135  const dictionary& dict
136 )
137 :
139  names_(),
140  option_(pointActionNames_.get("option", dict))
141 {
142  // Look for 'sets' or 'set'
143  if (!dict.readIfPresent("sets", names_))
144  {
145  names_.resize(1);
146  dict.readEntry("set", names_.first());
147  }
148 }
149 
150 
152 (
153  const polyMesh& mesh,
154  Istream& is
155 )
156 :
158  names_(one{}, word(checkIs(is))),
159  option_(pointActionNames_.read(checkIs(is)))
160 {}
161 
162 
163 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
164 
166 (
167  const topoSetSource::setAction action,
168  topoSet& set
169 ) const
170 {
171  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
172  {
173  if (verbose_)
174  {
175  Info<< " Adding cells according to pointSet "
176  << flatOutput(names_) << nl;
177  }
178 
179  for (const word& setName : names_)
180  {
181  combine(set, true, setName);
182  }
183  }
184  else if (action == topoSetSource::SUBTRACT)
185  {
186  if (verbose_)
187  {
188  Info<< " Removing cells according to pointSet "
189  << flatOutput(names_) << nl;
190  }
191 
192  for (const word& setName : names_)
193  {
194  combine(set, false, setName);
195  }
196  }
197 }
198 
199 
200 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::topoSetSource::ADD
Add elements to current set.
Definition: topoSetSource.H:103
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::pointToCell::EDGE
Definition: pointToCell.H:184
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:129
Foam::one
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:61
Foam::pointToCell::pointAction
pointAction
Enumeration defining the valid options.
Definition: pointToCell.H:181
Foam::pointToCell::ANY
Definition: pointToCell.H:183
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:104
polyMesh.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:296
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 (stdout output on master, null elsewhere)
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::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1107
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:302
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
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:123
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 current set.
Definition: topoSetSource.H:105
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:216
pointToCell.H
Foam::primitiveMesh::isInternalFace
bool isInternalFace(const label faceIndex) const noexcept
Return true if given face label is internal to the mesh.
Definition: primitiveMeshI.H:103
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1094
Foam::nl
constexpr char nl
Definition: Ostream.H:404
f
labelList f(nPoints)
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::topoSetCellSource
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells.
Definition: topoSetCellSource.H:54
Foam::primitiveMesh::pointCells
const labelListList & pointCells() const
Definition: primitiveMeshPointCells.C:110
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:171
Foam::pointToCell::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: pointToCell.C:166
Foam::labelHashSet
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:156
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
pointLabels
labelList pointLabels(nPoints, -1)
Foam::polyMesh::faceNeighbour
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1113
Foam::pointToCell::pointToCell
pointToCell(const polyMesh &mesh, const word &setName, const pointAction option)
Construct from components.
Definition: pointToCell.C:120
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:405
pointSet.H