zoneToPoint.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 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 "zoneToPoint.H"
30 #include "polyMesh.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(zoneToPoint, 0);
38  addToRunTimeSelectionTable(topoSetSource, zoneToPoint, word);
39  addToRunTimeSelectionTable(topoSetSource, zoneToPoint, istream);
40  addToRunTimeSelectionTable(topoSetPointSource, zoneToPoint, word);
41  addToRunTimeSelectionTable(topoSetPointSource, zoneToPoint, istream);
43  (
44  topoSetPointSource,
45  zoneToPoint,
46  word,
47  zone
48  );
50  (
51  topoSetPointSource,
52  zoneToPoint,
53  istream,
54  zone
55  );
56 }
57 
58 
59 Foam::topoSetSource::addToUsageTable Foam::zoneToPoint::usage_
60 (
61  zoneToPoint::typeName,
62  "\n Usage: zoneToPoint zone\n\n"
63  " Select all points in the pointZone."
64  " Note:accepts wildcards for zone.\n\n"
65 );
66 
67 
68 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
69 
70 void Foam::zoneToPoint::combine(topoSet& set, const bool add) const
71 {
72  bool hasMatched = false;
73 
74  for (const pointZone& zone : mesh_.pointZones())
75  {
76  if (selectedZones_.match(zone.name()))
77  {
78  hasMatched = true;
79 
80  const labelList& pointLabels = zone;
81 
82  if (verbose_)
83  {
84  Info<< " Found matching zone " << zone.name()
85  << " with " << pointLabels.size() << " points." << endl;
86  }
87 
88  for (const label pointi : pointLabels)
89  {
90  // Only do active points
91  if (pointi >= 0 && pointi < mesh_.nPoints())
92  {
93  addOrDelete(set, pointi, add);
94  }
95  }
96  }
97  }
98 
99  if (!hasMatched)
100  {
102  << "Cannot find any pointZone matching "
103  << flatOutput(selectedZones_) << nl
104  << "Valid names: " << flatOutput(mesh_.pointZones().names())
105  << endl;
106  }
107 }
108 
109 
110 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
111 
112 Foam::zoneToPoint::zoneToPoint
113 (
114  const polyMesh& mesh,
115  const wordRe& zoneName
116 )
117 :
118  topoSetPointSource(mesh),
119  selectedZones_(one(), zoneName)
120 {}
121 
122 
123 Foam::zoneToPoint::zoneToPoint
124 (
125  const polyMesh& mesh,
126  const dictionary& dict
127 )
128 :
129  topoSetPointSource(mesh),
130  selectedZones_()
131 {
132  // Look for 'zones' and 'zone', but accept 'name' as well
133  if (!dict.readIfPresent("zones", selectedZones_))
134  {
135  selectedZones_.resize(1);
136  selectedZones_.first() =
137  dict.getCompat<wordRe>("zone", {{"name", 1806}});
138  }
139 }
140 
141 
142 Foam::zoneToPoint::zoneToPoint
143 (
144  const polyMesh& mesh,
145  Istream& is
146 )
147 :
148  topoSetPointSource(mesh),
149  selectedZones_(one(), wordRe(checkIs(is)))
150 {}
151 
152 
153 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
154 
155 void Foam::zoneToPoint::applyToSet
156 (
157  const topoSetSource::setAction action,
158  topoSet& set
159 ) const
160 {
161  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
162  {
163  if (verbose_)
164  {
165  Info<< " Adding all points of point zones "
166  << flatOutput(selectedZones_) << " ..." << endl;
167  }
168 
169  combine(set, true);
170  }
171  else if (action == topoSetSource::SUBTRACT)
172  {
173  if (verbose_)
174  {
175  Info<< " Removing all points of point zones "
176  << flatOutput(selectedZones_) << " ..." << endl;
177  }
178 
179  combine(set, false);
180  }
181 }
182 
183 
184 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::topoSetSource::ADD
Add elements to the set.
Definition: topoSetSource.H:101
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:106
polyMesh.H
zoneToPoint.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::topoSetSource::SUBTRACT
Subtract elements from the set.
Definition: topoSetSource.H:102
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:298
pointLabels
labelList pointLabels(nPoints, -1)