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-2018 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  addToRunTimeSelectionTable(topoSetSource, pointToCell, istream);
38 
39  template<>
40  const char* Foam::NamedEnum
41  <
43  2
44  >::names[] =
45  {
46  "any",
47  "edge"
48  };
49 }
50 
51 
52 Foam::topoSetSource::addToUsageTable Foam::pointToCell::usage_
53 (
54  pointToCell::typeName,
55  "\n Usage: pointToCell <pointSet> any|edge\n\n"
56  " Select all cells with any point ('any') or any edge ('edge')"
57  " in the pointSet\n\n"
58 );
59 
61  Foam::pointToCell::pointActionNames_;
62 
63 
64 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
65 
66 void Foam::pointToCell::combine(topoSet& set, const bool add) const
67 {
68  // Load the set
69  pointSet loadedSet(mesh_, setName_);
70 
71 
72  // Handle any selection
73  if (option_ == ANY)
74  {
75  forAllConstIter(pointSet, loadedSet, iter)
76  {
77  const label pointi = iter.key();
78  const labelList& pCells = mesh_.pointCells()[pointi];
79 
80  forAll(pCells, pCelli)
81  {
82  addOrDelete(set, pCells[pCelli], add);
83  }
84  }
85  }
86  else if (option_ == EDGE)
87  {
88  const faceList& faces = mesh_.faces();
89  forAll(faces, facei)
90  {
91  const face& f = faces[facei];
92 
93  forAll(f, fp)
94  {
95  if (loadedSet.found(f[fp]) && loadedSet.found(f.nextLabel(fp)))
96  {
97  addOrDelete(set, mesh_.faceOwner()[facei], add);
98  if (mesh_.isInternalFace(facei))
99  {
100  addOrDelete(set, mesh_.faceNeighbour()[facei], add);
101  }
102  }
103  }
104  }
105  }
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
110 
112 (
113  const polyMesh& mesh,
114  const word& setName,
115  const pointAction option
116 )
117 :
118  topoSetSource(mesh),
119  setName_(setName),
120  option_(option)
121 {}
122 
123 
125 (
126  const polyMesh& mesh,
127  const dictionary& dict
128 )
129 :
130  topoSetSource(mesh),
131  setName_(dict.lookup("set")),
132  option_(pointActionNames_.read(dict.lookup("option")))
133 {}
134 
135 
137 (
138  const polyMesh& mesh,
139  Istream& is
140 )
141 :
142  topoSetSource(mesh),
143  setName_(checkIs(is)),
144  option_(pointActionNames_.read(checkIs(is)))
145 {}
146 
147 
148 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
149 
151 {}
152 
153 
154 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
155 
157 (
158  const topoSetSource::setAction action,
159  topoSet& set
160 ) const
161 {
162  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
163  {
164  Info<< " Adding cells according to pointSet " << setName_
165  << " ..." << endl;
166 
167  combine(set, true);
168  }
169  else if (action == topoSetSource::DELETE)
170  {
171  Info<< " Removing cells according to pointSet " << setName_
172  << " ..." << endl;
173 
174  combine(set, false);
175  }
176 }
177 
178 
179 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
virtual ~pointToCell()
Destructor.
Definition: pointToCell.C:150
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:158
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
label nextLabel(const label i) const
Next vertex on face.
Definition: faceI.H:117
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
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
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
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:157
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Class with constructor to add usage string to table.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
pointToCell(const polyMesh &mesh, const word &setName, const pointAction option)
Construct from components.
Definition: pointToCell.C:112
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:583