cellToPoint.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "cellToPoint.H"
30 #include "polyMesh.H"
31 #include "cellSet.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(cellToPoint, 0);
39  addToRunTimeSelectionTable(topoSetSource, cellToPoint, word);
40  addToRunTimeSelectionTable(topoSetSource, cellToPoint, istream);
41  addToRunTimeSelectionTable(topoSetPointSource, cellToPoint, word);
42  addToRunTimeSelectionTable(topoSetPointSource, cellToPoint, istream);
43 }
44 
45 
46 Foam::topoSetSource::addToUsageTable Foam::cellToPoint::usage_
47 (
48  cellToPoint::typeName,
49  "\n Usage: cellToPoint <cellSet> all\n\n"
50  " Select all points of cells in the cellSet\n\n"
51 );
52 
53 const Foam::Enum
54 <
55  Foam::cellToPoint::cellAction
56 >
57 Foam::cellToPoint::cellActionNames_
58 ({
59  { cellAction::ALL, "all" },
60 });
61 
62 
63 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
64 
66 (
67  topoSet& set,
68  const bool add,
69  const word& setName
70 ) const
71 {
72  // Load the set
73  cellSet loadedSet(mesh_, setName);
74  const labelHashSet& cellLabels = loadedSet;
75 
76  // Add all point from cells in loadedSet
77  for (const label celli : cellLabels)
78  {
79  const labelList& cFaces = mesh_.cells()[celli];
80 
81  for (const label facei : cFaces)
82  {
83  const face& f = mesh_.faces()[facei];
84 
85  addOrDelete(set, f, add);
86  }
87  }
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
93 Foam::cellToPoint::cellToPoint
94 (
95  const polyMesh& mesh,
96  const word& setName,
97  const cellAction option
98 )
99 :
100  topoSetPointSource(mesh),
101  names_(one(), setName),
102  option_(option)
103 {}
104 
105 
106 Foam::cellToPoint::cellToPoint
107 (
108  const polyMesh& mesh,
109  const dictionary& dict
110 )
111 :
112  topoSetPointSource(mesh),
113  names_(),
114  option_(cellActionNames_.get("option", dict))
115 {
116  // Look for 'sets' or 'set'
117  if (!dict.readIfPresent("sets", names_))
118  {
119  names_.resize(1);
120  dict.readEntry("set", names_.first());
121  }
122 }
123 
124 
125 Foam::cellToPoint::cellToPoint
126 (
127  const polyMesh& mesh,
128  Istream& is
129 )
130 :
131  topoSetPointSource(mesh),
132  names_(one(), word(checkIs(is))),
133  option_(cellActionNames_.read(checkIs(is)))
134 {}
135 
136 
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 
139 void Foam::cellToPoint::applyToSet
140 (
141  const topoSetSource::setAction action,
142  topoSet& set
143 ) const
144 {
145  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
146  {
147  if (verbose_)
148  {
149  Info<< " Adding points in cellSet "
150  << flatOutput(names_) << nl;
151  }
152 
153  for (const word& setName : names_)
154  {
155  combine(set, true, setName);
156  }
157  }
158  else if (action == topoSetSource::SUBTRACT)
159  {
160  if (verbose_)
161  {
162  Info<< " Removing points in cellSet "
163  << flatOutput(names_) << nl;
164  }
165 
166  for (const word& setName : names_)
167  {
168  combine(set, false, setName);
169  }
170  }
171 }
172 
173 
174 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::topoSetSource::ADD
Add elements to the set.
Definition: topoSetSource.H:101
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:107
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:106
polyMesh.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::topoSetSource::SUBTRACT
Subtract elements from the set.
Definition: topoSetSource.H:102
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
f
labelList f(nPoints)
cellToPoint.H
cellSet.H
Foam::labelHashSet
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys and label hasher.
Definition: HashSet.H:410
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)