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-2020 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 <
56 >
57 Foam::cellToPoint::cellActionNames_
58 ({
59  { cellAction::ALL, "all" },
60 });
61 
62 
63 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
64 
65 template<class Selector>
66 void Foam::cellToPoint::combineImpl
67 (
68  topoSet& set,
69  const bool add,
70  const Selector& cellLabels
71 ) const
72 {
73  // Add all points from given cells
74  for (const label celli : cellLabels)
75  {
76  const labelList& cFaces = mesh_.cells()[celli];
77 
78  for (const label facei : cFaces)
79  {
80  const face& f = mesh_.faces()[facei];
81 
82  addOrDelete(set, f, add);
83  }
84  }
85 }
86 
87 
88 void Foam::cellToPoint::combine
89 (
90  topoSet& set,
91  const bool add,
92  const word& setName
93 ) const
94 {
95  if (isZone_)
96  {
97  const labelList& cellLabels = mesh_.cellZones()[setName];
98 
99  combineImpl(set, add, cellLabels);
100  }
101  else
102  {
103  // Load the set
104  cellSet loadedSet(mesh_, setName, IOobject::NO_REGISTER);
105  const labelHashSet& cellLabels = loadedSet;
106 
107  combineImpl(set, add, cellLabels);
108  }
109 }
110 
111 
112 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
113 
115 (
116  const polyMesh& mesh,
117  const word& setName,
118  const cellAction option
119 )
120 :
121  topoSetPointSource(mesh),
122  names_(Foam::one{}, setName),
123  isZone_(false),
124  option_(option)
125 {}
126 
127 
129 (
130  const polyMesh& mesh,
131  const dictionary& dict
132 )
133 :
134  topoSetPointSource(mesh, dict),
135  names_(),
136  isZone_(topoSetSource::readNames(dict, names_)),
137  option_(cellActionNames_.get("option", dict))
138 {}
139 
140 
142 (
143  const polyMesh& mesh,
144  Istream& is
145 )
146 :
148  names_(Foam::one{}, word(checkIs(is))),
149  isZone_(false),
150  option_(cellActionNames_.read(checkIs(is)))
151 {}
152 
153 
154 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
155 
157 (
158  const topoSetSource::setAction action,
159  topoSet& set
160 ) const
161 {
162  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
163  {
164  if (verbose_)
165  {
166  Info<< " Adding points in cell "
167  << (isZone_ ? "zones: " : "sets: ")
168  << flatOutput(names_) << nl;
169  }
170 
171  for (const word& setName : names_)
172  {
173  combine(set, true, setName);
174  }
175  }
176  else if (action == topoSetSource::SUBTRACT)
177  {
178  if (verbose_)
179  {
180  Info<< " Removing points in cell "
181  << (isZone_ ? "zones: " : "sets: ")
182  << flatOutput(names_) << nl;
183  }
184 
185  for (const word& setName : names_)
186  {
187  combine(set, false, setName);
188  }
189  }
190 }
191 
192 
193 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
The topoSetPointSource is a intermediate class for handling topoSet sources for selecting points...
Create a new set and ADD elements to it.
Add elements to current set.
cellAction
Enumeration defining the valid options.
Definition: cellToPoint.H:187
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
const cellList & cells() const
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when &#39;add&#39; is true.
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:62
dynamicFvMesh & mesh
setAction
Enumeration defining various actions.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: cellToPoint.C:150
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1103
const polyMesh & mesh_
Reference to the mesh.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
Subtract elements from current set.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
Class with constructor to add usage string to table.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
List< label > labelList
A List of labels.
Definition: List.H:62
cellToPoint(const polyMesh &mesh, const word &setName, const cellAction option)
Construct from components.
Definition: cellToPoint.C:108
Do not request registration (bool: false)
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:56
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225