cylinderAnnulusToCell.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "cylinderAnnulusToCell.H"
27 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(cylinderAnnulusToCell, 0);
35  addToRunTimeSelectionTable(topoSetSource, cylinderAnnulusToCell, word);
36  addToRunTimeSelectionTable(topoSetSource, cylinderAnnulusToCell, istream);
37 }
38 
39 
40 Foam::topoSetSource::addToUsageTable Foam::cylinderAnnulusToCell::usage_
41 (
42  cylinderAnnulusToCell::typeName,
43  "\n Usage: cylinderAnnulusToCell (point1X point1Y point1Z)"
44  " (point2X point2Y point2Z) outerRadius innerRadius\n\n"
45  " Select all cells with cell centre within bounding cylinder annulus\n\n"
46 );
47 
48 
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 
51 void Foam::cylinderAnnulusToCell::combine(topoSet& set, const bool add) const
52 {
53  const vector axis = point2_ - point1_;
54  const scalar orad2 = sqr(outerRadius_);
55  const scalar irad2 = sqr(innerRadius_);
56  const scalar magAxis2 = magSqr(axis);
57 
58  const pointField& ctrs = mesh_.cellCentres();
59 
60  forAll(ctrs, celli)
61  {
62  vector d = ctrs[celli] - point1_;
63  scalar magD = d & axis;
64 
65  if ((magD > 0) && (magD < magAxis2))
66  {
67  scalar d2 = (d & d) - sqr(magD)/magAxis2;
68  if ((d2 < orad2) && (d2 > irad2))
69  {
70  addOrDelete(set, celli, add);
71  }
72  }
73  }
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 
80 (
81  const polyMesh& mesh,
82  const vector& point1,
83  const vector& point2,
84  const scalar outerRadius,
85  const scalar innerRadius
86 )
87 :
88  topoSetSource(mesh),
89  point1_(point1),
90  point2_(point2),
91  outerRadius_(outerRadius),
92  innerRadius_(innerRadius)
93 {}
94 
95 
97 (
98  const polyMesh& mesh,
99  const dictionary& dict
100 )
101 :
102  topoSetSource(mesh),
103  point1_(dict.lookupBackwardsCompatible<point>({"point1", "p1"})),
104  point2_(dict.lookupBackwardsCompatible<point>({"point2", "p2"})),
105  outerRadius_(dict.lookup<scalar>("outerRadius")),
106  innerRadius_(dict.lookup<scalar>("innerRadius"))
107 {}
108 
109 
111 (
112  const polyMesh& mesh,
113  Istream& is
114 )
115 :
116  topoSetSource(mesh),
117  point1_(checkIs(is)),
118  point2_(checkIs(is)),
119  outerRadius_(readScalar(checkIs(is))),
120  innerRadius_(readScalar(checkIs(is)))
121 {}
122 
123 
124 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
125 
127 {}
128 
129 
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 
133 (
134  const topoSetSource::setAction action,
135  topoSet& set
136 ) const
137 {
138  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
139  {
140  Info<< " Adding cells with centre within cylinder annulus,"
141  << " with point1 = "
142  << point1_ << ", point2 = " << point2_ << " and outer radius = "
143  << outerRadius_ << " and inner radius = " << innerRadius_ << endl;
144 
145  combine(set, true);
146  }
147  else if (action == topoSetSource::DELETE)
148  {
149  Info<< " Removing cells with centre within cylinder, with point1 = "
150  << point1_ << ", point2 = " << point2_ << " and outer radius = "
151  << outerRadius_ << " and inner radius " << innerRadius_ << endl;
152 
153  combine(set, false);
154  }
155 }
156 
157 
158 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
dimensionedSymmTensor sqr(const dimensionedVector &dv)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
cylinderAnnulusToCell(const polyMesh &mesh, const vector &point1, const vector &point2, const scalar outerRadius, const scalar innerRadius)
Construct from components.
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
dimensioned< scalar > magSqr(const dimensioned< Type > &)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Class with constructor to add usage string to table.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
ITstream & lookupBackwardsCompatible(const wordList &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream, trying a list of keywords.
Definition: dictionary.C:855
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844