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 | Copyright (C) 2011 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 
41 (
42  cylinderToCell::typeName,
43  "\n Usage: cylinderToCell (p1X p1Y p1Z) (p2X p2Y p2Z) radius\n\n"
44  " Select all cells with cell centre within bounding cylinder\n\n"
45 );
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::cylinderToCell::combine(topoSet& set, const bool add) const
51 {
52  const vector axis = p2_ - p1_;
53  const scalar rad2 = sqr(radius_);
54  const scalar magAxis2 = magSqr(axis);
55 
56  const pointField& ctrs = mesh_.cellCentres();
57 
58  forAll(ctrs, cellI)
59  {
60  vector d = ctrs[cellI] - p1_;
61  scalar magD = d & axis;
62 
63  if ((magD > 0) && (magD < magAxis2))
64  {
65  scalar d2 = (d & d) - sqr(magD)/magAxis2;
66  if (d2 < rad2)
67  {
68  addOrDelete(set, cellI, add);
69  }
70  }
71  }
72 }
73 
74 
75 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
76 
78 (
79  const polyMesh& mesh,
80  const vector& p1,
81  const vector& p2,
82  const scalar radius
83 )
84 :
86  p1_(p1),
87  p2_(p2),
88  radius_(radius)
89 {}
90 
91 
93 (
94  const polyMesh& mesh,
95  const dictionary& dict
96 )
97 :
99  p1_(dict.lookup("p1")),
100  p2_(dict.lookup("p2")),
101  radius_(readScalar(dict.lookup("radius")))
102 {}
103 
104 
105 // Construct from Istream
107 (
108  const polyMesh& mesh,
109  Istream& is
110 )
111 :
113  p1_(checkIs(is)),
114  p2_(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 p1 = "
136  << p1_ << ", p2 = " << p2_ << " and radius = " << radius_ << endl;
137 
138  combine(set, true);
139  }
140  else if (action == topoSetSource::DELETE)
141  {
142  Info<< " Removing cells with centre within cylinder, with p1 = "
143  << p1_ << ", p2 = " << p2_ << " and radius = " << radius_ << endl;
144 
145  combine(set, false);
146  }
147 }
148 
149 
150 // ************************************************************************* //
Foam::cylinderToCell::radius_
scalar radius_
Radius.
Definition: cylinderToCell.H:65
Foam::topoSetSource::ADD
@ ADD
Definition: topoSetSource.H:87
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::ListListOps::combine
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:100
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Foam::topoSetSource::NEW
@ NEW
Definition: topoSetSource.H:85
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::cylinderToCell::~cylinderToCell
virtual ~cylinderToCell()
Destructor.
Definition: cylinderToCell.C:121
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Info
messageStream Info
Foam::cylinderToCell::combine
void combine(topoSet &set, const bool add) const
Definition: cylinderToCell.C:50
Foam::cylinderToCell::p2_
vector p2_
Second point on cylinder axis.
Definition: cylinderToCell.H:62
Foam::topoSetSource::DELETE
@ DELETE
Definition: topoSetSource.H:88
Foam::cylinderToCell::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: cylinderToCell.C:128
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::cylinderToCell::usage_
static addToUsageTable usage_
Add usage string.
Definition: cylinderToCell.H:56
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:870
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:211
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
Foam::Vector< scalar >
Foam::cylinderToCell::cylinderToCell
cylinderToCell(const polyMesh &mesh, const vector &p1, const vector &p2, const scalar radius)
Construct from components.
Definition: cylinderToCell.C:78
Foam::cylinderToCell::p1_
vector p1_
First point on cylinder axis.
Definition: cylinderToCell.H:59
cylinderToCell.H
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Definition: topoSetSource.H:126
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label cellI, const bool) const
Add (if bool) cellI to set or delete cellI from set.
Definition: topoSetSource.C:140