pointToCell.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-2025 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 "pointToCell.H"
27 #include "polyMesh.H"
28 #include "pointSet.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(pointToCell, 0);
36  addToRunTimeSelectionTable(topoSetSource, pointToCell, word);
37 }
38 
41 {
42  "any",
43  "edge"
44 };
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 void Foam::pointToCell::combine(topoSet& set, const bool add) const
50 {
51  // Load the set
52  pointSet loadedSet(mesh_, setName_);
53 
54 
55  // Handle any selection
56  if (option_ == ANY)
57  {
58  forAllConstIter(pointSet, loadedSet, iter)
59  {
60  const label pointi = iter.key();
61  const labelList& pCells = mesh_.pointCells()[pointi];
62 
63  forAll(pCells, pCelli)
64  {
65  addOrDelete(set, pCells[pCelli], add);
66  }
67  }
68  }
69  else if (option_ == EDGE)
70  {
71  const faceList& faces = mesh_.faces();
72  forAll(faces, facei)
73  {
74  const face& f = faces[facei];
75 
76  forAll(f, fp)
77  {
78  if (loadedSet.found(f[fp]) && loadedSet.found(f.nextLabel(fp)))
79  {
80  addOrDelete(set, mesh_.faceOwner()[facei], add);
81  if (mesh_.isInternalFace(facei))
82  {
83  addOrDelete(set, mesh_.faceNeighbour()[facei], add);
84  }
85  }
86  }
87  }
88  }
89 }
90 
91 
92 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
93 
95 (
96  const polyMesh& mesh,
97  const word& setName,
98  const pointAction option
99 )
100 :
101  topoSetSource(mesh),
102  setName_(setName),
103  option_(option)
104 {}
105 
106 
108 (
109  const polyMesh& mesh,
110  const dictionary& dict
111 )
112 :
113  topoSetSource(mesh),
114  setName_(dict.lookup("set")),
115  option_(pointActionNames_.read(dict.lookup("option")))
116 {}
117 
118 
119 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
120 
122 {}
123 
124 
125 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 
128 (
129  const topoSetSource::setAction action,
130  topoSet& set
131 ) const
132 {
133  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
134  {
135  Info<< " Adding cells according to pointSet " << setName_
136  << " ..." << endl;
137 
138  combine(set, true);
139  }
140  else if (action == topoSetSource::DELETE)
141  {
142  Info<< " Removing cells according to pointSet " << setName_
143  << " ..." << endl;
144 
145  combine(set, false);
146  }
147 }
148 
149 
150 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
Macros for easy insertion into run-time selection tables.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:55
pointToCell(const polyMesh &mesh, const word &setName, const pointAction option)
Construct from components.
virtual ~pointToCell()
Destructor.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
static const NamedEnum< pointAction, 2 > pointActionNames_
Names of the valid options.
Definition: pointToCell.H:66
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1308
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1321
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1327
const labelListList & pointCells() const
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
void add(GeometricField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
List< face > faceList
Definition: faceListFwd.H:41
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
labelList f(nPoints)
dictionary dict