patchToPoint.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) 2024 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "patchToPoint.H"
29 #include "pointMesh.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(patchToPoint, 0);
37  addToRunTimeSelectionTable(topoSetSource, patchToPoint, word);
38  addToRunTimeSelectionTable(topoSetSource, patchToPoint, istream);
39  addToRunTimeSelectionTable(topoSetPointSource, patchToPoint, word);
40  addToRunTimeSelectionTable(topoSetPointSource, patchToPoint, istream);
42  (
43  topoSetPointSource,
44  patchToPoint,
45  word,
46  patch
47  );
49  (
50  topoSetPointSource,
51  patchToPoint,
52  istream,
53  patch
54  );
55 }
56 
57 
58 Foam::topoSetSource::addToUsageTable Foam::patchToPoint::usage_
59 (
60  patchToPoint::typeName,
61  "\n Usage: patchToPoint patch\n\n"
62  " Select all points in the pointPatch."
63  " Note:accepts wildcards for patch.\n\n"
64 );
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
69 void Foam::patchToPoint::combine(topoSet& set, const bool add) const
70 {
71  const pointMesh& pMesh = pointMesh::New(mesh_, IOobject::READ_IF_PRESENT);
72  const pointBoundaryMesh& pbm = pMesh.boundary();
73 
74  const labelList patchIDs
75  (
76  pbm.indices(selectedPatches_, true) // useGroups = true
77  );
78 
79  for (const label patchi : patchIDs)
80  {
81  const pointPatch& pp = pbm[patchi];
82 
83  if (verbose_)
84  {
85  Info<< " Found matching patch " << pp.name() << " with "
86  << returnReduce(pp.size(), sumOp<label>()) << " points" << endl;
87  }
88 
89  for (const label pointi : pp.meshPoints())
90  {
91  addOrDelete(set, pointi, add);
92  }
93  }
94 
95  if (patchIDs.empty())
96  {
98  << "Cannot find any patches matching "
99  << flatOutput(selectedPatches_) << nl
100  //<< "Valid names: " << flatOutput(pbm.names())
101  << endl;
102  }
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
107 
109 (
110  const polyMesh& mesh,
111  const wordRe& patchName
112 )
113 :
115  selectedPatches_(one{}, patchName)
116 {}
117 
118 
120 (
121  const polyMesh& mesh,
122  const dictionary& dict
123 )
124 :
125  topoSetPointSource(mesh),
126  selectedPatches_()
127 {
128  // Look for 'patches' and 'patch', but accept 'name' as well
129  if (!dict.readIfPresent("patches", selectedPatches_))
130  {
131  selectedPatches_.resize(1);
132  selectedPatches_.front() =
133  dict.getCompat<wordRe>("patch", {{"name", 1806}});
134  }
135 }
136 
137 
139 (
140  const polyMesh& mesh,
141  Istream& is
142 )
143 :
144  topoSetPointSource(mesh),
145  selectedPatches_(one{}, wordRe(checkIs(is)))
146 {}
147 
148 
149 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
150 
152 (
153  const topoSetSource::setAction action,
154  topoSet& set
155 ) const
156 {
157  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
158  {
159  if (verbose_)
160  {
161  Info<< " Adding all points of patches: "
162  << flatOutput(selectedPatches_) << " ..." << endl;
163  }
164 
165  combine(set, true);
166  }
167  else if (action == topoSetSource::SUBTRACT)
168  {
169  if (verbose_)
170  {
171  Info<< " Removing all points of patches: "
172  << flatOutput(selectedPatches_) << " ..." << endl;
173  }
174 
175  combine(set, false);
176  }
177 }
178 
179 
180 // ************************************************************************* //
const labelList patchIDs(pbm.indices(polyPatchNames, true))
const polyBoundaryMesh & pbm
dictionary dict
The topoSetPointSource is a intermediate class for handling topoSet sources for selecting points...
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:150
bool verbose_
Output verbosity (default: true)
Create a new set and ADD elements to it.
Add elements to current set.
static FOAM_NO_DANGLING_REFERENCE const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create MeshObject registered with typeName.
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:230
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:529
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.
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:62
patchToPoint(const polyMesh &mesh, const wordRe &patchName)
Construct from components.
Definition: patchToPoint.C:102
dynamicFvMesh & mesh
setAction
Enumeration defining various actions.
Reading is optional [identical to LAZY_READ].
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: patchToPoint.C:145
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)
Subtract elements from current set.
#define WarningInFunction
Report a warning using Foam::Warning.
Class with constructor to add usage string to table.
const std::string patch
OpenFOAM patch number as a std::string.
messageStream Info
Information stream (stdout output on master, null elsewhere)
List< label > labelList
A List of labels.
Definition: List.H:61
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
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