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 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 void Foam::cylinderToCell::combine(topoSet& set, const bool add) const
42 {
43  const vector axis = point2_ - point1_;
44  const scalar rad2 = sqr(radius_);
45  const scalar magAxis2 = magSqr(axis);
46 
47  const pointField& ctrs = mesh_.cellCentres();
48 
49  forAll(ctrs, celli)
50  {
51  vector d = ctrs[celli] - point1_;
52  scalar magD = d & axis;
53 
54  if ((magD > 0) && (magD < magAxis2))
55  {
56  scalar d2 = (d & d) - sqr(magD)/magAxis2;
57  if (d2 < rad2)
58  {
59  addOrDelete(set, celli, add);
60  }
61  }
62  }
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
67 
69 (
70  const polyMesh& mesh,
71  const vector& point1,
72  const vector& point2,
73  const scalar radius
74 )
75 :
76  topoSetSource(mesh),
77  point1_(point1),
78  point2_(point2),
79  radius_(radius)
80 {}
81 
82 
84 (
85  const polyMesh& mesh,
86  const dictionary& dict
87 )
88 :
89  topoSetSource(mesh),
90  point1_(dict.lookupBackwardsCompatible<point>({"point1", "p1"})),
91  point2_(dict.lookupBackwardsCompatible<point>({"point2", "p2"})),
92  radius_(dict.lookup<scalar>("radius"))
93 {}
94 
95 
96 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
97 
99 {}
100 
101 
102 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
103 
105 (
106  const topoSetSource::setAction action,
107  topoSet& set
108 ) const
109 {
110  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
111  {
112  Info<< " Adding cells with centre within cylinder, with point1 = "
113  << point1_ << ", point2 = " << point2_ << " and radius = "
114  << radius_ << endl;
115 
116  combine(set, true);
117  }
118  else if (action == topoSetSource::DELETE)
119  {
120  Info<< " Removing cells with centre within cylinder, with point1 = "
121  << point1_ << ", point2 = " << point2_ << " and radius = "
122  << radius_ << endl;
123 
124  combine(set, false);
125  }
126 }
127 
128 
129 // ************************************************************************* //
#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)
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
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.
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
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
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:875
Namespace for OpenFOAM.
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:77
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864