boxToPoint.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-2021 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 "boxToPoint.H"
30 #include "polyMesh.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(boxToPoint, 0);
38  addToRunTimeSelectionTable(topoSetSource, boxToPoint, word);
39  addToRunTimeSelectionTable(topoSetSource, boxToPoint, istream);
40  addToRunTimeSelectionTable(topoSetPointSource, boxToPoint, word);
41  addToRunTimeSelectionTable(topoSetPointSource, boxToPoint, istream);
43  (
44  topoSetPointSource,
45  boxToPoint,
46  word,
47  box
48  );
50  (
51  topoSetPointSource,
52  boxToPoint,
53  istream,
54  box
55  );
56 }
57 
58 
59 Foam::topoSetSource::addToUsageTable Foam::boxToPoint::usage_
60 (
61  boxToPoint::typeName,
62  "\n Usage: boxToPoint ((minx miny minz) (maxx maxy maxz))\n\n"
63  " Select all points with coordinate within bounding box\n\n"
64 );
65 
66 
67 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
68 
69 namespace Foam
70 {
71 
72 // Read min/max or min/span
73 static void readBoxDim(const dictionary& dict, treeBoundBox& bb)
74 {
76 
77  dict.readEntry("min", bb.min(), keyType::LITERAL, readOpt);
78 
79  if (dict.readIfPresent("span", bb.max(), keyType::LITERAL))
80  {
81  bb.max() += bb.min();
83  }
84 
85  dict.readEntry("max", bb.max(), keyType::LITERAL, readOpt);
86 }
87 
88 } // End namespace Foam
89 
90 
91 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
92 
93 void Foam::boxToPoint::combine(topoSet& set, const bool add) const
94 {
95  const pointField& ctrs = mesh_.points();
96 
97  forAll(ctrs, elemi)
98  {
99  for (const auto& bb : bbs_)
100  {
101  if (bb.contains(ctrs[elemi]))
102  {
103  addOrDelete(set, elemi, add);
104  break;
105  }
106  }
107  }
108 }
109 
110 
111 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
112 
114 (
115  const polyMesh& mesh,
116  const treeBoundBoxList& bbs
117 )
118 :
120  bbs_(bbs)
121 {}
122 
123 
125 (
126  const polyMesh& mesh,
127  treeBoundBoxList&& bbs
128 )
129 :
131  bbs_(std::move(bbs))
132 {}
133 
134 
136 (
137  const polyMesh& mesh,
138  const dictionary& dict
139 )
140 :
142  bbs_()
143 {
144  // Accept 'boxes', 'box' or 'min/max'
145  if (!dict.readIfPresent("boxes", bbs_))
146  {
147  bbs_.resize(1);
148  if (!dict.readIfPresent("box", bbs_.front()))
149  {
151  }
152  }
153 }
154 
155 
157 (
158  const polyMesh& mesh,
159  Istream& is
160 )
161 :
162  topoSetPointSource(mesh),
163  bbs_(one{}, treeBoundBox(checkIs(is)))
164 {}
165 
166 
167 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
168 
170 (
171  const topoSetSource::setAction action,
172  topoSet& set
173 ) const
174 {
175  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
176  {
177  if (verbose_)
178  {
179  Info<< " Adding points that are within boxes "
180  << bbs_ << " ..." << endl;
181  }
182 
183  combine(set, true);
184  }
185  else if (action == topoSetSource::SUBTRACT)
186  {
187  if (verbose_)
188  {
189  Info<< " Removing points that are within boxes "
190  << bbs_ << " ..." << endl;
191  }
192 
193  combine(set, false);
194  }
195 }
196 
197 
198 // ************************************************************************* //
static void readBoxDim(const dictionary &dict, treeBoundBox &bb)
Definition: searchableBox.C:53
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:160
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Create a new set and ADD elements to it.
Add elements to current set.
T & front()
Access first element of the list, position [0].
Definition: UListI.H:237
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
List< treeBoundBox > treeBoundBoxList
A List of treeBoundBox.
Definition: treeBoundBox.H:83
const point & min() const noexcept
Minimum describing the bounding box.
Definition: boundBoxI.H:162
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)
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1078
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val. FatalIOError if it is found and the number of tokens is incorrect...
const point & max() const noexcept
Maximum describing the bounding box.
Definition: boundBoxI.H:168
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:62
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
setAction
Enumeration defining various actions.
Reading is optional [identical to LAZY_READ].
String literal.
Definition: keyType.H:82
const polyMesh & mesh_
Reference to the mesh.
boxToPoint(const polyMesh &mesh, const treeBoundBoxList &bbs)
Construct from components, copying bounding boxes.
Definition: boxToPoint.C:107
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
defineTypeNameAndDebug(combustionModel, 0)
Subtract elements from current set.
Class with constructor to add usage string to table.
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:90
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: boxToPoint.C:163
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
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
readOption
Enumeration defining read preferences.