zoneToPoint.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "zoneToPoint.H"
27 #include "polyMesh.H"
28 
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 void Foam::zoneToPoint::combine(topoSet& set, const bool add) const
43 {
44  bool hasMatched = false;
45 
46  forAll(mesh_.pointZones(), i)
47  {
48  const pointZone& zone = mesh_.pointZones()[i];
49 
50  if (zoneName_.match(zone.name()))
51  {
52  const labelList& pointLabels = mesh_.pointZones()[i];
53 
54  Info<< " Found matching zone " << zone.name()
55  << " with " << returnReduce(pointLabels.size(), sumOp<label>())
56  << " points." << endl;
57 
58  hasMatched = true;
59 
61  {
62  // Only do active points
63  if (pointLabels[i] < mesh_.nPoints())
64  {
65  addOrDelete(set, pointLabels[i], add);
66  }
67  }
68  }
69  }
70 
71  if (!hasMatched)
72  {
74  << "Cannot find any pointZone named " << zoneName_ << endl
75  << "Valid names are " << mesh_.pointZones().names() << endl;
76  }
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81 
83 (
84  const polyMesh& mesh,
85  const word& zoneName
86 )
87 :
88  topoSetSource(mesh),
89  zoneName_(zoneName)
90 {}
91 
92 
94 (
95  const polyMesh& mesh,
96  const dictionary& dict
97 )
98 :
99  topoSetSource(mesh),
100  zoneName_
101  (
102  dict.dictName() == "sourceInfo"
103  ? dict.lookupBackwardsCompatible({"zone", "name"})
104  : dict.lookup("zone")
105  )
106 {}
107 
108 
109 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
110 
112 {}
113 
114 
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 
118 (
119  const topoSetSource::setAction action,
120  topoSet& set
121 ) const
122 {
123  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
124  {
125  Info<< " Adding all points of pointZone " << zoneName_ << " ..."
126  << endl;
127 
128  combine(set, true);
129  }
130  else if (action == topoSetSource::DELETE)
131  {
132  Info<< " Removing all points of pointZone " << zoneName_ << " ..."
133  << endl;
134 
135  combine(set, false);
136  }
137 }
138 
139 
140 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
wordList names() const
Return a list of zone names.
Definition: MeshZones.C:256
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:860
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const meshPointZones & pointZones() const
Return point zones.
Definition: polyMesh.H:439
label nPoints() const
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
Definition: topoSetSource.C:96
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:65
bool match(const std::string &, bool literalMatch=false) const
Smart match as regular expression or as a string.
Definition: wordReI.H:202
A class for handling words, derived from string.
Definition: word.H:62
A topoSetSource to select points based on pointZone.
Definition: zoneToPoint.H:52
zoneToPoint(const polyMesh &mesh, const word &zoneName)
Construct from components.
Definition: zoneToPoint.C:83
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: zoneToPoint.C:118
virtual ~zoneToPoint()
Destructor.
Definition: zoneToPoint.C:111
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
labelList pointLabels(nPoints, -1)
dictionary dict