Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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"
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34namespace Foam
35{
42 (
45 word,
46 patch
47 );
49 (
52 istream,
53 patch
54 );
55}
56
57
58Foam::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
69void 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
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())
102 }
103}
104
105
106// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
107
109(
110 const polyMesh& mesh,
111 const wordRe& patchName
113:
115 selectedPatches_(one{}, patchName)
116{}
117
118
120(
121 const polyMesh& mesh,
122 const dictionary& dict
123)
124:
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:
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
labelList patchIDs
const polyBoundaryMesh & pbm
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
static FOAM_NO_DANGLING_REFERENCE const pointMesh & New(const polyMesh &mesh, Args &&... args)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition one.H:57
A topoSetPointSource to select points associated with given patch(es).
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
patchToPoint(const polyMesh &mesh, const wordRe &patchName)
Construct from components.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
The topoSetPointSource is a intermediate class for handling topoSet sources for selecting points.
topoSetPointSource(const polyMesh &mesh)
Construct from mesh.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
setAction
Enumeration defining various actions.
@ SUBTRACT
Subtract elements from current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
bool verbose_
Output verbosity (default: true).
const polyMesh & mesh() const noexcept
Reference to the mesh.
const polyMesh & mesh_
Reference to the mesh.
static Istream & checkIs(Istream &is)
Check state of stream.
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition wordRe.H:81
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
messageStream Info
Information stream (stdout output on master, null elsewhere).
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.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dict add("bounds", meshBb)
dictionary dict