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-2024 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 template<class Selector>
68 void Foam::pointToCell::combineImpl
69 (
70  topoSet& set,
71  const bool add,
72  const Selector& pointLabels
73 ) const
74 {
75  // Handle any selection
76  if (option_ == ANY)
77  {
78  for (const label pointi : pointLabels)
79  {
80  const labelList& pCells = mesh_.pointCells()[pointi];
81 
82  addOrDelete(set, pCells, add);
83  }
84  }
85  else if (option_ == EDGE)
86  {
87  const faceList& faces = mesh_.faces();
88 
89  forAll(faces, facei)
90  {
91  const face& f = faces[facei];
92 
93  forAll(f, fp)
94  {
95  if
96  (
97  pointLabels.found(f[fp])
98  && pointLabels.found(f.nextLabel(fp))
99  )
100  {
101  addOrDelete(set, mesh_.faceOwner()[facei], add);
102  if (mesh_.isInternalFace(facei))
103  {
104  addOrDelete(set, mesh_.faceNeighbour()[facei], add);
105  }
106  }
107  }
108  }
109  }
110 }
111 
112 
113 void Foam::pointToCell::combine
114 (
115  topoSet& set,
116  const bool add,
117  const word& setName
118 ) const
119 {
120  if (isZone_)
121  {
122  const labelList& pointLabels = mesh_.pointZones()[setName];
123 
124  combineImpl(set, add, pointLabels);
125  }
126  else
127  {
128  // Load the set
129  pointSet loadedSet(mesh_, setName, IOobject::NO_REGISTER);
130  const labelHashSet& pointLabels = loadedSet;
131 
132  combineImpl(set, add, pointLabels);
133  }
134 }
135 
136 
137 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
138 
140 (
141  const polyMesh& mesh,
142  const word& setName,
143  const pointAction option
144 )
145 :
146  topoSetCellSource(mesh),
147  names_(Foam::one{}, setName),
148  isZone_(false),
149  option_(option)
150 {}
151 
152 
154 (
155  const polyMesh& mesh,
156  const dictionary& dict
157 )
158 :
159  topoSetCellSource(mesh, dict),
160  names_(),
161  isZone_(topoSetSource::readNames(dict, names_)),
162  option_(pointActionNames_.get("option", dict))
163 {}
164 
165 
167 (
168  const polyMesh& mesh,
169  Istream& is
170 )
171 :
173  names_(Foam::one{}, word(checkIs(is))),
174  isZone_(false),
175  option_(pointActionNames_.read(checkIs(is)))
176 {}
177 
178 
179 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
180 
182 (
183  const topoSetSource::setAction action,
184  topoSet& set
185 ) const
186 {
187  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
188  {
189  if (verbose_)
190  {
191  Info<< " Adding cells according to point "
192  << (isZone_ ? "zones: " : "sets: ")
193  << flatOutput(names_) << nl;
194  }
195 
196  for (const word& setName : names_)
197  {
198  combine(set, true, setName);
199  }
200  }
201  else if (action == topoSetSource::SUBTRACT)
202  {
203  if (verbose_)
204  {
205  Info<< " Removing cells according to point "
206  << (isZone_ ? "zones: " : "sets: ")
207  << flatOutput(names_) << nl;
208  }
209 
210  for (const word& setName : names_)
211  {
212  combine(set, false, setName);
213  }
214  }
215 }
216 
217 
218 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: pointToCell.C:175
dictionary dict
labelList pointLabels(nPoints, -1)
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1122
Create a new set and ADD elements to it.
Add elements to current set.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells...
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when &#39;add&#39; is true.
Macros for easy insertion into run-time selection tables.
bool isInternalFace(const label faceIndex) const noexcept
Return true if given face label is internal to the mesh.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
List< face > faceList
List of faces.
Definition: faceListFwd.H:39
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:62
dynamicFvMesh & mesh
setAction
Enumeration defining various actions.
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1116
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1103
pointAction
Enumeration defining the valid options.
Definition: pointToCell.H:188
const labelListList & pointCells() const
const polyMesh & mesh_
Reference to the mesh.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
Subtract elements from current set.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
Class with constructor to add usage string to table.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
List< label > labelList
A List of labels.
Definition: List.H:62
Do not request registration (bool: false)
pointToCell(const polyMesh &mesh, const word &setName, const pointAction option)
Construct from components.
Definition: pointToCell.C:133
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:56
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225