1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "cylinderToCell.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(cylinderToCell, 0);
36 addToRunTimeSelectionTable(topoSetSource, cylinderToCell, word);
37 addToRunTimeSelectionTable(topoSetSource, cylinderToCell, istream);
41 Foam::topoSetSource::addToUsageTable Foam::cylinderToCell::usage_
43 cylinderToCell::typeName,
44 "\n Usage: cylinderToCell (p1X p1Y p1Z) (p2X p2Y p2Z) radius\n\n"
45 " Select all cells with cell centre within bounding cylinder\n\n"
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 void Foam::cylinderToCell::combine(topoSet& set, const bool add) const
53 const vector axis = p2_ - p1_;
54 const scalar rad2 = sqr(radius_);
55 const scalar magAxis2 = magSqr(axis);
57 const pointField& ctrs = mesh_.cellCentres();
61 vector d = ctrs[cellI] - p1_;
62 scalar magD = d & axis;
64 if ((magD > 0) && (magD < magAxis2))
66 scalar d2 = (d & d) - sqr(magD)/magAxis2;
69 addOrDelete(set, cellI, add);
76 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 Foam::cylinderToCell::cylinderToCell
93 Foam::cylinderToCell::cylinderToCell
96 const dictionary& dict
100 p1_(dict.lookup("p1")),
101 p2_(dict.lookup("p2")),
102 radius_(readScalar(dict.lookup("radius")))
106 // Construct from Istream
107 Foam::cylinderToCell::cylinderToCell
109 const polyMesh& mesh,
116 radius_(readScalar(checkIs(is)))
120 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
122 Foam::cylinderToCell::~cylinderToCell()
126 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
128 void Foam::cylinderToCell::applyToSet
130 const topoSetSource::setAction action,
134 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
136 Info<< " Adding cells with centre within cylinder, with p1 = "
137 << p1_ << ", p2 = " << p2_ << " and radius = " << radius_ << endl;
141 else if (action == topoSetSource::DELETE)
143 Info<< " Removing cells with centre within cylinder, with p1 = "
144 << p1_ << ", p2 = " << p2_ << " and radius = " << radius_ << endl;
151 // ************************************************************************* //