faceToPoint.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 "faceToPoint.H"
30 #include "polyMesh.H"
31 #include "faceSet.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(faceToPoint, 0);
39  addToRunTimeSelectionTable(topoSetSource, faceToPoint, word);
40  addToRunTimeSelectionTable(topoSetSource, faceToPoint, istream);
41  addToRunTimeSelectionTable(topoSetPointSource, faceToPoint, word);
42  addToRunTimeSelectionTable(topoSetPointSource, faceToPoint, istream);
43 }
44 
45 Foam::topoSetSource::addToUsageTable Foam::faceToPoint::usage_
46 (
47  faceToPoint::typeName,
48  "\n Usage: faceToPoint <faceSet> all\n\n"
49  " Select all points of faces in the faceSet\n\n"
50 );
51 
52 const Foam::Enum
53 <
55 >
56 Foam::faceToPoint::faceActionNames_
57 ({
58  { faceAction::ALL, "all" },
59 });
60 
61 
62 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
63 
64 void Foam::faceToPoint::combine
65 (
66  topoSet& set,
67  const bool add,
68  const word& setName
69 ) const
70 {
71  // Load the set
72  faceSet loadedSet(mesh_, setName);
73  const labelHashSet& faceLabels = loadedSet;
74 
75  // Add all points from faces in loadedSet
76  for (const label facei : faceLabels)
77  {
78  const face& f = mesh_.faces()[facei];
79 
80  addOrDelete(set, f, add);
81  }
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
88 (
89  const polyMesh& mesh,
90  const word& setName,
91  const faceAction option
92 )
93 :
95  names_(one{}, setName),
96  option_(option)
97 {}
98 
99 
101 (
102  const polyMesh& mesh,
103  const dictionary& dict
104 )
105 :
106  topoSetPointSource(mesh),
107  names_(),
108  option_(faceActionNames_.get("option", dict))
109 {
110  // Look for 'sets' or 'set'
111  if (!dict.readIfPresent("sets", names_))
112  {
113  names_.resize(1);
114  dict.readEntry("set", names_.front());
115  }
116 }
117 
118 
120 (
121  const polyMesh& mesh,
122  Istream& is
123 )
124 :
125  topoSetPointSource(mesh),
126  names_(one{}, word(checkIs(is))),
127  option_(faceActionNames_.read(checkIs(is)))
128 {}
129 
130 
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 
134 (
135  const topoSetSource::setAction action,
136  topoSet& set
137 ) const
138 {
139  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
140  {
141  if (verbose_)
142  {
143  Info<< " Adding points from face in face sets: "
144  << flatOutput(names_) << nl;
145  }
146 
147  for (const word& setName : names_)
148  {
149  combine(set, true, setName);
150  }
151  }
152  else if (action == topoSetSource::SUBTRACT)
153  {
154  if (verbose_)
155  {
156  Info<< " Removing points from face in face sets: "
157  << flatOutput(names_) << nl;
158  }
159 
160  for (const word& setName : names_)
161  {
162  combine(set, false, setName);
163  }
164  }
165 }
166 
167 
168 // ************************************************************************* //
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...
faceToPoint(const polyMesh &mesh, const word &setName, const faceAction option)
Construct from components.
Definition: faceToPoint.C:81
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
Create a new set and ADD elements to it.
Add elements to current set.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
T & front()
Access first element of the list, position [0].
Definition: UListI.H:237
labelList faceLabels(nFaceLabels)
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.
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
faceAction
Enumeration defining the valid options.
Definition: faceToPoint.H:179
dynamicFvMesh & mesh
setAction
Enumeration defining various actions.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: faceToPoint.C:127
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)
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