cellToPoint.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 "cellToPoint.H"
27 #include "polyMesh.H"
28 #include "cellSet.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(cellToPoint, 0);
36  addToRunTimeSelectionTable(topoSetSource, cellToPoint, word);
37 }
38 
41 {
42  "all"
43 };
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
48 void Foam::cellToPoint::combine(topoSet& set, const bool add) const
49 {
50  // Load the set
51  cellSet loadedSet(mesh_, setName_);
52 
53  // Add all point from cells in loadedSet
54  forAllConstIter(cellSet, loadedSet, iter)
55  {
56  const label celli = iter.key();
57  const labelList& cFaces = mesh_.cells()[celli];
58 
59  forAll(cFaces, cFacei)
60  {
61  const face& f = mesh_.faces()[cFaces[cFacei]];
62 
63  forAll(f, fp)
64  {
65  addOrDelete(set, f[fp], add);
66  }
67  }
68  }
69 }
70 
71 
72 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
73 
75 (
76  const polyMesh& mesh,
77  const word& setName,
78  const cellAction option
79 )
80 :
81  topoSetSource(mesh),
82  setName_(setName),
83  option_(option)
84 {}
85 
86 
88 (
89  const polyMesh& mesh,
90  const dictionary& dict
91 )
92 :
93  topoSetSource(mesh),
94  setName_(dict.lookup("set")),
95  option_(cellActionNames_.read(dict.lookup("option")))
96 {}
97 
98 
99 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
100 
102 {}
103 
104 
105 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106 
108 (
109  const topoSetSource::setAction action,
110  topoSet& set
111 ) const
112 {
113  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
114  {
115  Info<< " Adding from " << setName_ << " ..." << endl;
116 
117  combine(set, true);
118  }
119  else if (action == topoSetSource::DELETE)
120  {
121  Info<< " Removing from " << setName_ << " ..." << endl;
122 
123  combine(set, false);
124  }
125 }
126 
127 
128 // ************************************************************************* //
#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
static const NamedEnum< cellAction, 1 > cellActionNames_
Names of the valid options.
Definition: cellToPoint.H:64
cellToPoint(const polyMesh &mesh, const word &setName, const cellAction option)
Construct from components.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
virtual ~cellToPoint()
Destructor.
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1308
const cellList & cells() const
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
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
labelList f(nPoints)
dictionary dict