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-2021 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  template<>
39  const char* Foam::NamedEnum
40  <
42  2
43  >::names[] =
44  {
45  "any",
46  "edge"
47  };
48 }
49 
50 
52  Foam::pointToCell::pointActionNames_;
53 
54 
55 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
56 
57 void Foam::pointToCell::combine(topoSet& set, const bool add) const
58 {
59  // Load the set
60  pointSet loadedSet(mesh_, setName_);
61 
62 
63  // Handle any selection
64  if (option_ == ANY)
65  {
66  forAllConstIter(pointSet, loadedSet, iter)
67  {
68  const label pointi = iter.key();
69  const labelList& pCells = mesh_.pointCells()[pointi];
70 
71  forAll(pCells, pCelli)
72  {
73  addOrDelete(set, pCells[pCelli], add);
74  }
75  }
76  }
77  else if (option_ == EDGE)
78  {
79  const faceList& faces = mesh_.faces();
80  forAll(faces, facei)
81  {
82  const face& f = faces[facei];
83 
84  forAll(f, fp)
85  {
86  if (loadedSet.found(f[fp]) && loadedSet.found(f.nextLabel(fp)))
87  {
88  addOrDelete(set, mesh_.faceOwner()[facei], add);
89  if (mesh_.isInternalFace(facei))
90  {
91  addOrDelete(set, mesh_.faceNeighbour()[facei], add);
92  }
93  }
94  }
95  }
96  }
97 }
98 
99 
100 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101 
103 (
104  const polyMesh& mesh,
105  const word& setName,
106  const pointAction option
107 )
108 :
109  topoSetSource(mesh),
110  setName_(setName),
111  option_(option)
112 {}
113 
114 
116 (
117  const polyMesh& mesh,
118  const dictionary& dict
119 )
120 :
121  topoSetSource(mesh),
122  setName_(dict.lookup("set")),
123  option_(pointActionNames_.read(dict.lookup("option")))
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
128 
130 {}
131 
132 
133 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
134 
136 (
137  const topoSetSource::setAction action,
138  topoSet& set
139 ) const
140 {
141  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
142  {
143  Info<< " Adding cells according to pointSet " << setName_
144  << " ..." << endl;
145 
146  combine(set, true);
147  }
148  else if (action == topoSetSource::DELETE)
149  {
150  Info<< " Removing cells according to pointSet " << setName_
151  << " ..." << endl;
152 
153  combine(set, false);
154  }
155 }
156 
157 
158 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual ~pointToCell()
Destructor.
Definition: pointToCell.C:129
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
A set of point labels.
Definition: pointSet.H:48
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
label nextLabel(const label i) const
Next vertex on face.
Definition: faceI.H:100
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:113
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
pointAction
Enumeration defining the valid options.
Definition: pointToCell.H:55
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: pointToCell.C:136
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
pointToCell(const polyMesh &mesh, const word &setName, const pointAction option)
Construct from components.
Definition: pointToCell.C:103
Namespace for OpenFOAM.
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:77
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864