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-2024 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  if (isZone_)
72  {
73  const auto& faceLabels = mesh_.faceZones()[setName].addressing();
74 
75  // Add all points from given faces
76  for (const label facei : faceLabels)
77  {
78  const face& f = mesh_.faces()[facei];
79 
80  addOrDelete(set, f, add);
81  }
82  }
83  else
84  {
85  // Load the set
86  faceSet loadedSet(mesh_, setName, IOobject::NO_REGISTER);
87  const labelHashSet& faceLabels = loadedSet;
88 
89  // Add all points from given faces
90  for (const label facei : faceLabels)
91  {
92  const face& f = mesh_.faces()[facei];
93 
94  addOrDelete(set, f, add);
95  }
96  }
97 }
98 
99 
100 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101 
103 (
104  const polyMesh& mesh,
105  const word& setName,
106  const faceAction option
107 )
108 :
109  topoSetPointSource(mesh),
110  names_(Foam::one{}, setName),
111  isZone_(false),
112  option_(option)
113 {}
114 
115 
117 (
118  const polyMesh& mesh,
119  const dictionary& dict
120 )
121 :
122  topoSetPointSource(mesh, dict),
123  names_(),
124  isZone_(topoSetSource::readNames(dict, names_)),
125  option_(faceActionNames_.get("option", dict))
126 {}
127 
128 
130 (
131  const polyMesh& mesh,
132  Istream& is
133 )
134 :
136  names_(Foam::one{}, word(checkIs(is))),
137  isZone_(false),
138  option_(faceActionNames_.read(checkIs(is)))
139 {}
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
145 (
146  const topoSetSource::setAction action,
147  topoSet& set
148 ) const
149 {
150  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
151  {
152  if (verbose_)
153  {
154  Info<< " Adding face points in face "
155  << (isZone_ ? "zones: " : "sets: ")
156  << flatOutput(names_) << nl;
157  }
158 
159  for (const word& setName : names_)
160  {
161  combine(set, true, setName);
162  }
163  }
164  else if (action == topoSetSource::SUBTRACT)
165  {
166  if (verbose_)
167  {
168  Info<< " Removing face points in face "
169  << (isZone_ ? "zones: " : "sets: ")
170  << flatOutput(names_) << nl;
171  }
172 
173  for (const word& setName : names_)
174  {
175  combine(set, false, setName);
176  }
177  }
178 }
179 
180 
181 // ************************************************************************* //
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:96
Create a new set and ADD elements to it.
Add elements to current set.
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
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.
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
faceAction
Enumeration defining the valid options.
Definition: faceToPoint.H:177
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:138
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)
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition: polyMesh.H:671
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
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