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-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 "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  addToRunTimeSelectionTable(topoSetSource, cellToPoint, istream);
38 
39  template<>
40  const char* Foam::NamedEnum
41  <
43  1
44  >::names[] =
45  {
46  "all"
47  };
48 }
49 
50 
51 Foam::topoSetSource::addToUsageTable Foam::cellToPoint::usage_
52 (
53  cellToPoint::typeName,
54  "\n Usage: cellToPoint <cellSet> all\n\n"
55  " Select all points of cells in the cellSet\n\n"
56 );
57 
59  Foam::cellToPoint::cellActionNames_;
60 
61 
62 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
63 
64 void Foam::cellToPoint::combine(topoSet& set, const bool add) const
65 {
66  // Load the set
67  cellSet loadedSet(mesh_, setName_);
68 
69  // Add all point from cells in loadedSet
70  forAllConstIter(cellSet, loadedSet, iter)
71  {
72  const label celli = iter.key();
73  const labelList& cFaces = mesh_.cells()[celli];
74 
75  forAll(cFaces, cFacei)
76  {
77  const face& f = mesh_.faces()[cFaces[cFacei]];
78 
79  forAll(f, fp)
80  {
81  addOrDelete(set, f[fp], add);
82  }
83  }
84  }
85 }
86 
87 
88 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
89 
91 (
92  const polyMesh& mesh,
93  const word& setName,
94  const cellAction option
95 )
96 :
97  topoSetSource(mesh),
98  setName_(setName),
99  option_(option)
100 {}
101 
102 
104 (
105  const polyMesh& mesh,
106  const dictionary& dict
107 )
108 :
109  topoSetSource(mesh),
110  setName_(dict.lookup("set")),
111  option_(cellActionNames_.read(dict.lookup("option")))
112 {}
113 
114 
116 (
117  const polyMesh& mesh,
118  Istream& is
119 )
120 :
121  topoSetSource(mesh),
122  setName_(checkIs(is)),
123  option_(cellActionNames_.read(checkIs(is)))
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 from " << setName_ << " ..." << endl;
144 
145  combine(set, true);
146  }
147  else if (action == topoSetSource::DELETE)
148  {
149  Info<< " Removing from " << setName_ << " ..." << endl;
150 
151  combine(set, false);
152  }
153 }
154 
155 
156 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: cellToPoint.C:136
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
cellAction
Enumeration defining the valid options.
Definition: cellToPoint.H:56
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
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
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
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 ~cellToPoint()
Destructor.
Definition: cellToPoint.C:129
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.
A collection of cell labels.
Definition: cellSet.H:48
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
cellToPoint(const polyMesh &mesh, const word &setName, const cellAction option)
Construct from components.
Definition: cellToPoint.C:91
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576