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 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 
126 
128 (
129  const polyMesh& mesh,
130  const dictionary& dict
131 )
132 :
134  (
135  mesh,
136  dict.get<point>("p1"),
137  dict.get<point>("p2"),
138  dict.get<scalar>("outerRadius"),
139  dict.get<scalar>("innerRadius")
140  )
141 {}
142 
143 
145 (
146  const polyMesh& mesh,
147  Istream& is
148 )
149 :
151  point1_(checkIs(is)),
152  point2_(checkIs(is)),
153  radius_(readScalar(checkIs(is))),
154  innerRadius_(readScalar(checkIs(is)))
155 {}
156 
157 
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 
161 (
162  const topoSetSource::setAction action,
163  topoSet& set
164 ) const
165 {
166  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
167  {
168  if (verbose_)
169  {
170  Info<< " Adding faces with centre within cylinder annulus,"
171  << " with p1 = " << point1_ << ", p2 = " << point2_
172  << ", radius = " << radius_
173  << ", inner radius = " << innerRadius_
174  << endl;
175  }
176 
177  combine(set, true);
178  }
179  else if (action == topoSetSource::SUBTRACT)
180  {
181  if (verbose_)
182  {
183  Info<< " Removing faces with centre within cylinder annulus,"
184  << " with p1 = " << point1_ << ", p2 = " << point2_
185  << ", radius = " << radius_
186  << ", inner radius = " << innerRadius_
187  << endl;
188  }
189 
190  combine(set, false);
191  }
192 }
193 
194 
195 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::topoSetSource::ADD
Add elements to the set.
Definition: topoSetSource.H:101
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
Foam::topoSetFaceSource
Base class of a topoSet source for selecting faces.
Definition: topoSetFaceSource.H:50
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:81
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:106
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:290
Foam::cylinderAnnulusToFace::cylinderAnnulusToFace
cylinderAnnulusToFace(const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: cylinderAnnulusToFace.C:128
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 (uses stdout - output is on the master only)
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:161
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:66
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:121
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 the set.
Definition: topoSetSource.H:102
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::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::Vector< scalar >
Foam::primitiveMesh::faceCentres
const vectorField & faceCentres() const
Definition: primitiveMeshFaceCentresAndAreas.C:145
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:170
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:151
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