cylinderToPoint.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) 2017 OpenFOAM Foundation
9  Copyright (C) 2018-2020 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 "cylinderToPoint.H"
30 #include "polyMesh.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(cylinderToPoint, 0);
38  addToRunTimeSelectionTable(topoSetSource, cylinderToPoint, word);
39  addToRunTimeSelectionTable(topoSetSource, cylinderToPoint, istream);
40  addToRunTimeSelectionTable(topoSetPointSource, cylinderToPoint, word);
41  addToRunTimeSelectionTable(topoSetPointSource, cylinderToPoint, istream);
43  (
44  topoSetPointSource,
45  cylinderToPoint,
46  word,
47  cylinder
48  );
50  (
51  topoSetPointSource,
52  cylinderToPoint,
53  istream,
54  cylinder
55  );
56 }
57 
58 
59 Foam::topoSetSource::addToUsageTable Foam::cylinderToPoint::usage_
60 (
61  cylinderToPoint::typeName,
62  "\n Usage: cylinderToPoint (p1X p1Y p1Z) (p2X p2Y p2Z) radius\n\n"
63  " Select points within bounding cylinder\n\n"
64 );
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
69 void Foam::cylinderToPoint::combine(topoSet& set, const bool add) const
70 {
71  const pointField& ctrs = mesh_.points();
72 
73  const vector axis = (point2_ - point1_);
74  const scalar magAxis2 = magSqr(axis);
75  const scalar orad2 = sqr(radius_);
76  const scalar irad2 = innerRadius_ > 0 ? sqr(innerRadius_) : -1;
77 
78  // Treat innerRadius == 0 like unspecified innerRadius (always accept)
79 
80  forAll(ctrs, elemi)
81  {
82  const vector d = ctrs[elemi] - point1_;
83  const scalar magD = d & axis;
84 
85  if ((magD > 0) && (magD < magAxis2))
86  {
87  const scalar d2 = (d & d) - sqr(magD)/magAxis2;
88  if ((d2 < orad2) && (d2 > irad2))
89  {
90  addOrDelete(set, elemi, add);
91  }
92  }
93  }
94 }
95 
96 
97 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
98 
100 (
101  const polyMesh& mesh,
102  const point& point1,
103  const point& point2,
104  const scalar radius,
105  const scalar innerRadius
106 )
107 :
109  point1_(point1),
110  point2_(point2),
111  radius_(radius),
112  innerRadius_(innerRadius)
113 {}
114 
115 
117 (
118  const polyMesh& mesh,
119  const dictionary& dict
120 )
121 :
123  (
124  mesh,
125  dict.get<point>("p1"),
126  dict.get<point>("p2"),
127  dict.getCheck<scalar>("radius", scalarMinMax::ge(0)),
128  dict.getCheckOrDefault<scalar>("innerRadius", 0, scalarMinMax::ge(0))
129  )
130 {}
131 
132 
134 (
135  const polyMesh& mesh,
136  Istream& is
137 )
138 :
140  point1_(checkIs(is)),
141  point2_(checkIs(is)),
142  radius_(readScalar(checkIs(is))),
143  innerRadius_(0)
144 {}
145 
146 
147 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
148 
150 (
151  const topoSetSource::setAction action,
152  topoSet& set
153 ) const
154 {
155  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
156  {
157  if (verbose_)
158  {
159  Info<< " Adding faces with centre within cylinder,"
160  << " with p1 = " << point1_ << ", p2 = " << point2_
161  << ", radius = " << radius_;
162 
163  if (innerRadius_ > 0)
164  {
165  Info<< ", innerRadius = " << innerRadius_;
166  }
167 
168  Info<< endl;
169  }
170 
171  combine(set, true);
172  }
173  else if (action == topoSetSource::SUBTRACT)
174  {
175  if (verbose_)
176  {
177  Info<< " Removing faces with centre within cylinder,"
178  << " with p1 = " << point1_ << ", p2 = " << point2_
179  << ", radius = " << radius_;
180 
181  if (innerRadius_ > 0)
182  {
183  Info<< ", innerRadius = " << innerRadius_;
184  }
185 
186  Info<< endl;
187  }
188 
189  combine(set, false);
190  }
191 }
192 
193 
194 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1069
Foam::topoSetSource::ADD
Add elements to current set.
Definition: topoSetSource.H:103
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::cylinderToPoint::cylinderToPoint
cylinderToPoint(const polyMesh &mesh, const point &point1, const point &point2, const scalar radius, const scalar innerRadius=0)
Construct from components.
Definition: cylinderToPoint.C:100
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:129
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:104
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
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)
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
Foam::topoSetPointSource
The topoSetPointSource is a intermediate class for handling topoSet sources for selecting points.
Definition: topoSetPointSource.H:54
Foam::dictionary::getCheckOrDefault
T getCheckOrDefault(const word &keyword, const T &deflt, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:209
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
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 current set.
Definition: topoSetSource.H:105
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::cylinderToPoint::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: cylinderToPoint.C:150
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::cylinderToPoint
A topoSetPointSource to select all points which are inside a given bounding cylinder or cylinder annu...
Definition: cylinderToPoint.H:164
Foam::MinMax::ge
static MinMax< T > ge(const T &minVal)
A semi-infinite range from minVal to the type max.
Definition: MinMaxI.H:31
Foam::Vector< scalar >
Foam::dictionary::getCheck
T getCheck(const word &keyword, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:120
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
Definition: topoSetSource.C:171
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:156
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
cylinderToPoint.H