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 tmp<pointField> tctrs(this->transform(mesh_.points()));
96  const pointField& ctrs = tctrs();
97 
98  forAll(ctrs, elemi)
99  {
100  for (const auto& bb : bbs_)
101  {
102  if (bb.contains(ctrs[elemi]))
103  {
104  addOrDelete(set, elemi, add);
105  break;
106  }
107  }
108  }
109 }
110 
111 
112 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
113 
115 (
116  const polyMesh& mesh,
117  const treeBoundBoxList& bbs
118 )
119 :
121  bbs_(bbs)
122 {}
123 
124 
126 (
127  const polyMesh& mesh,
128  treeBoundBoxList&& bbs
129 )
130 :
132  bbs_(std::move(bbs))
133 {}
134 
135 
137 (
138  const polyMesh& mesh,
139  const dictionary& dict
140 )
141 :
143  bbs_()
144 {
145  // Accept 'boxes', 'box' or 'min/max'
146  if (!dict.readIfPresent("boxes", bbs_))
147  {
148  bbs_.resize(1);
149  if (!dict.readIfPresent("box", bbs_.front()))
150  {
152  }
153  }
154 }
155 
156 
158 (
159  const polyMesh& mesh,
160  Istream& is
161 )
162 :
163  topoSetPointSource(mesh),
164  bbs_(one{}, treeBoundBox(checkIs(is)))
165 {}
166 
167 
168 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
169 
171 (
172  const topoSetSource::setAction action,
173  topoSet& set
174 ) const
175 {
176  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
177  {
178  if (verbose_)
179  {
180  Info<< " Adding points that are within boxes "
181  << bbs_ << " ..." << endl;
182  }
183 
184  combine(set, true);
185  }
186  else if (action == topoSetSource::SUBTRACT)
187  {
188  if (verbose_)
189  {
190  Info<< " Removing points that are within boxes "
191  << bbs_ << " ..." << endl;
192  }
193 
194  combine(set, false);
195  }
196 }
197 
198 
199 // ************************************************************************* //
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:153
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:230
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:108
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.
tmp< pointField > transform(const pointField &points) const
Coordinate transform (optionally) coordinates. Returns reference to input data if no transform is act...
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:164
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
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.