cylinderToCell.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 "cylinderToCell.H"
27 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(cylinderToCell, 0);
35  addToRunTimeSelectionTable(topoSetSource, cylinderToCell, word);
36  addToRunTimeSelectionTable(topoSetSource, cylinderToCell, istream);
37 }
38 
39 
40 Foam::topoSetSource::addToUsageTable Foam::cylinderToCell::usage_
41 (
42  cylinderToCell::typeName,
43  "\n Usage: cylinderToCell (point1X point1Y point1Z)"
44  " (point2X point2Y point2Z) radius\n\n"
45  " Select all cells with cell centre within bounding cylinder\n\n"
46 );
47 
48 
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 
51 void Foam::cylinderToCell::combine(topoSet& set, const bool add) const
52 {
53  const vector axis = point2_ - point1_;
54  const scalar rad2 = sqr(radius_);
55  const scalar magAxis2 = magSqr(axis);
56 
57  const pointField& ctrs = mesh_.cellCentres();
58 
59  forAll(ctrs, celli)
60  {
61  vector d = ctrs[celli] - point1_;
62  scalar magD = d & axis;
63 
64  if ((magD > 0) && (magD < magAxis2))
65  {
66  scalar d2 = (d & d) - sqr(magD)/magAxis2;
67  if (d2 < rad2)
68  {
69  addOrDelete(set, celli, add);
70  }
71  }
72  }
73 }
74 
75 
76 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
77 
79 (
80  const polyMesh& mesh,
81  const vector& point1,
82  const vector& point2,
83  const scalar radius
84 )
85 :
86  topoSetSource(mesh),
87  point1_(point1),
88  point2_(point2),
89  radius_(radius)
90 {}
91 
92 
94 (
95  const polyMesh& mesh,
96  const dictionary& dict
97 )
98 :
99  topoSetSource(mesh),
100  point1_(dict.lookupBackwardsCompatible<point>({"point1", "p1"})),
101  point2_(dict.lookupBackwardsCompatible<point>({"point2", "p2"})),
102  radius_(dict.lookup<scalar>("radius"))
103 {}
104 
105 
107 (
108  const polyMesh& mesh,
109  Istream& is
110 )
111 :
112  topoSetSource(mesh),
113  point1_(checkIs(is)),
114  point2_(checkIs(is)),
115  radius_(readScalar(checkIs(is)))
116 {}
117 
118 
119 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
120 
122 {}
123 
124 
125 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 
128 (
129  const topoSetSource::setAction action,
130  topoSet& set
131 ) const
132 {
133  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
134  {
135  Info<< " Adding cells with centre within cylinder, with point1 = "
136  << point1_ << ", point2 = " << point2_ << " and radius = "
137  << radius_ << endl;
138 
139  combine(set, true);
140  }
141  else if (action == topoSetSource::DELETE)
142  {
143  Info<< " Removing cells with centre within cylinder, with point1 = "
144  << point1_ << ", point2 = " << point2_ << " and radius = "
145  << radius_ << endl;
146 
147  combine(set, false);
148  }
149 }
150 
151 
152 // ************************************************************************* //
#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
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
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
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
cylinderToCell(const polyMesh &mesh, const vector &point1, const vector &point2, const scalar radius)
Construct from components.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
dimensioned< scalar > magSqr(const dimensioned< Type > &)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
virtual ~cylinderToCell()
Destructor.
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