cylinderAnnulusToFace.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 "cylinderAnnulusToFace.H"
30 #include "polyMesh.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(cylinderAnnulusToFace, 0);
38  addToRunTimeSelectionTable(topoSetSource, cylinderAnnulusToFace, word);
39  addToRunTimeSelectionTable(topoSetSource, cylinderAnnulusToFace, istream);
41  (
42  topoSetFaceSource,
43  cylinderAnnulusToFace,
44  word
45  );
47  (
48  topoSetFaceSource,
49  cylinderAnnulusToFace,
50  istream
51  );
53  (
54  topoSetFaceSource,
55  cylinderAnnulusToFace,
56  word,
57  cylinderAnnulus
58  );
60  (
61  topoSetFaceSource,
62  cylinderAnnulusToFace,
63  istream,
64  cylinderAnnulus
65  );
66 }
67 
68 
69 Foam::topoSetSource::addToUsageTable Foam::cylinderAnnulusToFace::usage_
70 (
71  cylinderAnnulusToFace::typeName,
72  "\n Usage: cylinderAnnulusToFace (p1X p1Y p1Z) (p2X p2Y p2Z)"
73  " outerRadius innerRadius\n\n"
74  " Select all faces with face centre within bounding cylinder annulus\n\n"
75 );
76 
77 
78 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
79 
80 void Foam::cylinderAnnulusToFace::combine(topoSet& set, const bool add) const
81 {
82  const pointField& ctrs = mesh_.faceCentres();
83 
84  const vector axis = (point2_ - point1_);
85  const scalar magAxis2 = magSqr(axis);
86  const scalar orad2 = sqr(radius_);
87  const scalar irad2 = innerRadius_ > 0 ? sqr(innerRadius_) : -1;
88 
89  // Treat innerRadius == 0 like unspecified innerRadius (always accept)
90 
91  forAll(ctrs, elemi)
92  {
93  const vector d = ctrs[elemi] - point1_;
94  const scalar magD = d & axis;
95 
96  if ((magD > 0) && (magD < magAxis2))
97  {
98  const scalar d2 = (d & d) - sqr(magD)/magAxis2;
99  if ((d2 < orad2) && (d2 > irad2))
100  {
101  addOrDelete(set, elemi, add);
102  }
103  }
104  }
105 }
106 
107 
108 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
109 
111 (
112  const polyMesh& mesh,
113  const point& point1,
114  const point& point2,
115  const scalar radius,
116  const scalar innerRadius
117 )
118 :
120  point1_(point1),
121  point2_(point2),
122  radius_(radius),
123  innerRadius_(innerRadius)
124 {
125  if (innerRadius_ > radius_)
126  {
128  << "inner radius = " << innerRadius_ << " cannot be larger than "
129  << "outer radius = " << radius_
130  << exit(FatalError);
131  }
132 }
133 
134 
136 (
137  const polyMesh& mesh,
138  const dictionary& dict
139 )
140 :
142  (
143  mesh,
144  dict.get<point>("p1"),
145  dict.get<point>("p2"),
146  dict.getCheck<scalar>("outerRadius", scalarMinMax::ge(SMALL)),
147  dict.getCheck<scalar>("innerRadius", scalarMinMax::ge(0))
148  )
149 {}
150 
151 
153 (
154  const polyMesh& mesh,
155  Istream& is
156 )
157 :
159  point1_(checkIs(is)),
160  point2_(checkIs(is)),
161  radius_(readScalar(checkIs(is))),
162  innerRadius_(readScalar(checkIs(is)))
163 {}
164 
165 
166 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
167 
169 (
170  const topoSetSource::setAction action,
171  topoSet& set
172 ) const
173 {
174  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
175  {
176  if (verbose_)
177  {
178  Info<< " Adding faces with centre within cylinder annulus,"
179  << " with p1 = " << point1_ << ", p2 = " << point2_
180  << ", radius = " << radius_
181  << ", inner radius = " << innerRadius_
182  << endl;
183  }
184 
185  combine(set, true);
186  }
187  else if (action == topoSetSource::SUBTRACT)
188  {
189  if (verbose_)
190  {
191  Info<< " Removing faces with centre within cylinder annulus,"
192  << " with p1 = " << point1_ << ", p2 = " << point2_
193  << ", radius = " << radius_
194  << ", inner radius = " << innerRadius_
195  << endl;
196  }
197 
198  combine(set, false);
199  }
200 }
201 
202 
203 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
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::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:129
Foam::cylinderAnnulusToFace
A topoSetFaceSource to select all faces whose face centre inside a given bounding cylinder annulus.
Definition: cylinderAnnulusToFace.H:165
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::topoSetFaceSource
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces.
Definition: topoSetFaceSource.H:54
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)
cylinderAnnulusToFace.H
Foam::cylinderAnnulusToFace::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Apply specified action to the topoSet.
Definition: cylinderAnnulusToFace.C:169
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
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::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
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::primitiveMesh::faceCentres
const vectorField & faceCentres() const
Definition: primitiveMeshFaceCentresAndAreas.C:77
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)
Foam::cylinderAnnulusToFace::cylinderAnnulusToFace
cylinderAnnulusToFace(const polyMesh &mesh, const point &point1, const point &point2, const scalar radius, const scalar innerRadius=0)
Construct from components.
Definition: cylinderAnnulusToFace.C:111