cylinderToCell.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-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 "cylinderToCell.H"
30 #include "polyMesh.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(cylinderToCell, 0);
38  addToRunTimeSelectionTable(topoSetSource, cylinderToCell, word);
39  addToRunTimeSelectionTable(topoSetSource, cylinderToCell, istream);
40  addToRunTimeSelectionTable(topoSetCellSource, cylinderToCell, word);
41  addToRunTimeSelectionTable(topoSetCellSource, cylinderToCell, istream);
43  (
44  topoSetCellSource,
45  cylinderToCell,
46  word,
47  cylinder
48  );
50  (
51  topoSetCellSource,
52  cylinderToCell,
53  istream,
54  cylinder
55  );
56 }
57 
58 
59 Foam::topoSetSource::addToUsageTable Foam::cylinderToCell::usage_
60 (
61  cylinderToCell::typeName,
62  "\n Usage: cylinderToCell (p1X p1Y p1Z) (p2X p2Y p2Z) radius\n\n"
63  " Select all cells with cell centre within bounding cylinder\n\n"
64 );
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
69 void Foam::cylinderToCell::combine(topoSet& set, const bool add) const
70 {
71  const pointField& ctrs = mesh_.cellCentres();
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  if (innerRadius_ > radius_)
115  {
117  << "inner radius = " << innerRadius_ << " cannot be larger than "
118  << "outer radius = " << radius_
119  << exit(FatalError);
120  }
121 }
122 
123 
125 (
126  const polyMesh& mesh,
127  const dictionary& dict
128 )
129 :
131  (
132  mesh,
133  dict.get<point>("p1"),
134  dict.get<point>("p2"),
135  dict.getCheck<scalar>("radius", scalarMinMax::ge(SMALL)),
136  dict.getCheckOrDefault<scalar>("innerRadius", 0, scalarMinMax::ge(0))
137  )
138 {}
139 
140 
142 (
143  const polyMesh& mesh,
144  Istream& is
145 )
146 :
148  point1_(checkIs(is)),
149  point2_(checkIs(is)),
150  radius_(readScalar(checkIs(is))),
151  innerRadius_(0)
152 {}
153 
154 
155 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
156 
158 (
159  const topoSetSource::setAction action,
160  topoSet& set
161 ) const
162 {
163  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
164  {
165  if (verbose_)
166  {
167  Info<< " Adding cells with centre within cylinder,"
168  << " with p1 = " << point1_ << ", p2 = " << point2_
169  << ", radius = " << radius_;
170 
171  if (innerRadius_ > 0)
172  {
173  Info<< ", innerRadius = " << innerRadius_;
174  }
175 
176  Info<< endl;
177  }
178 
179  combine(set, true);
180  }
181  else if (action == topoSetSource::SUBTRACT)
182  {
183  if (verbose_)
184  {
185  Info<< " Removing cells with centre within cylinder,"
186  << " with p1 = " << point1_ << ", p2 = " << point2_
187  << ", radius = " << radius_;
188 
189  if (innerRadius_ > 0)
190  {
191  Info<< ", innerRadius = " << innerRadius_;
192  }
193 
194  Info<< endl;
195  }
196 
197  combine(set, false);
198  }
199 }
200 
201 
202 // ************************************************************************* //
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::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::cylinderToCell::cylinderToCell
cylinderToCell(const polyMesh &mesh, const point &point1, const point &point2, const scalar radius, const scalar innerRadius=0)
Construct from components.
Definition: cylinderToCell.C:100
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::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::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
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:84
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::topoSetCellSource
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells.
Definition: topoSetCellSource.H:54
Foam::cylinderToCell::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: cylinderToCell.C:158
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
cylinderToCell.H
Foam::cylinderToCell
A topoSetCellSource to select all cells whose cell centre inside a given bounding cylinder or cylinde...
Definition: cylinderToCell.H:165
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:156
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)