Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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"
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35namespace Foam
36{
43 (
46 word,
47 box
48 );
50 (
53 istream,
54 box
55 );
56}
57
58
59Foam::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
67// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
68
69namespace Foam
70{
71
72// Read min/max or min/span
73static 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
93void 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 }
108 }
109}
110
111
112// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
113
115(
116 const polyMesh& mesh,
117 const treeBoundBoxList& bbs
119:
121 bbs_(bbs)
122{}
123
124
126(
127 const polyMesh& mesh,
128 treeBoundBoxList&& bbs
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()))
151 readBoxDim(dict, bbs_.front());
152 }
153 }
154}
155
156
158(
159 const polyMesh& mesh,
160 Istream& is
161)
162:
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
readOption
Enumeration defining read preferences.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ MUST_READ
Reading required.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
const point & max() const noexcept
Maximum describing the bounding box.
Definition boundBoxI.H:168
const point & min() const noexcept
Minimum describing the bounding box.
Definition boundBoxI.H:162
A topoSetPointSource to select all points based on whether they are inside given bounding box(es).
Definition boxToPoint.H:167
boxToPoint(const polyMesh &mesh, const treeBoundBoxList &bbs)
Construct from components, copying bounding boxes.
Definition boxToPoint.C:108
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition boxToPoint.C:164
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
@ LITERAL
String literal.
Definition keyType.H:82
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition one.H:57
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
virtual const pointField & points() const
Return raw points.
Definition polyMesh.C:1063
The topoSetPointSource is a intermediate class for handling topoSet sources for selecting points.
topoSetPointSource(const polyMesh &mesh)
Construct from mesh.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
setAction
Enumeration defining various actions.
@ SUBTRACT
Subtract elements from current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
bool verbose_
Output verbosity (default: true).
const polyMesh & mesh() const noexcept
Reference to the mesh.
const polyMesh & mesh_
Reference to the mesh.
static Istream & checkIs(Istream &is)
Check state of stream.
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
Standard boundBox with extra functionality for use in octree.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
Namespace for OpenFOAM.
List< treeBoundBox > treeBoundBoxList
A List of treeBoundBox.
refinementData transform(const tensor &, const refinementData val)
No-op rotational transform for base types.
messageStream Info
Information stream (stdout output on master, null elsewhere).
static void readBoxDim(const dictionary &dict, treeBoundBox &bb)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
vectorField pointField
pointField is a vectorField.
dict add("bounds", meshBb)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299