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-2019 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 {
35  defineTypeNameAndDebug(zoneToPoint, 0);
36  addToRunTimeSelectionTable(topoSetSource, zoneToPoint, word);
37  addToRunTimeSelectionTable(topoSetSource, zoneToPoint, istream);
38 }
39 
40 
41 Foam::topoSetSource::addToUsageTable Foam::zoneToPoint::usage_
42 (
43  zoneToPoint::typeName,
44  "\n Usage: zoneToPoint zone\n\n"
45  " Select all points in the pointZone."
46  " Note:accepts wildcards for zone.\n\n"
47 );
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 void Foam::zoneToPoint::combine(topoSet& set, const bool add) const
53 {
54  bool hasMatched = false;
55 
56  forAll(mesh_.pointZones(), i)
57  {
58  const pointZone& zone = mesh_.pointZones()[i];
59 
60  if (zoneName_.match(zone.name()))
61  {
62  const labelList& pointLabels = mesh_.pointZones()[i];
63 
64  Info<< " Found matching zone " << zone.name()
65  << " with " << returnReduce(pointLabels.size(), sumOp<label>())
66  << " points." << endl;
67 
68  hasMatched = true;
69 
70  forAll(pointLabels, i)
71  {
72  // Only do active points
73  if (pointLabels[i] < mesh_.nPoints())
74  {
75  addOrDelete(set, pointLabels[i], add);
76  }
77  }
78  }
79  }
80 
81  if (!hasMatched)
82  {
84  << "Cannot find any pointZone named " << zoneName_ << endl
85  << "Valid names are " << mesh_.pointZones().names() << endl;
86  }
87 }
88 
89 
90 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
91 
93 (
94  const polyMesh& mesh,
95  const word& zoneName
96 )
97 :
98  topoSetSource(mesh),
99  zoneName_(zoneName)
100 {}
101 
102 
104 (
105  const polyMesh& mesh,
106  const dictionary& dict
107 )
108 :
109  topoSetSource(mesh),
110  zoneName_(dict.lookup("name"))
111 {}
112 
113 
115 (
116  const polyMesh& mesh,
117  Istream& is
118 )
119 :
120  topoSetSource(mesh),
121  zoneName_(checkIs(is))
122 {}
123 
124 
125 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
126 
128 {}
129 
130 
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 
134 (
135  const topoSetSource::setAction action,
136  topoSet& set
137 ) const
138 {
139  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
140  {
141  Info<< " Adding all points of pointZone " << zoneName_ << " ..."
142  << endl;
143 
144  combine(set, true);
145  }
146  else if (action == topoSetSource::DELETE)
147  {
148  Info<< " Removing all points of pointZone " << zoneName_ << " ..."
149  << endl;
150 
151  combine(set, false);
152  }
153 }
154 
155 
156 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
virtual ~zoneToPoint()
Destructor.
Definition: zoneToPoint.C:127
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
List< label > labelList
A List of labels.
Definition: labelList.H:56
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
#define WarningInFunction
Report a warning using Foam::Warning.
Class with constructor to add usage string to table.
zoneToPoint(const polyMesh &mesh, const word &zoneName)
Construct from components.
Definition: zoneToPoint.C:93
messageStream Info
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: zoneToPoint.C:134
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812