1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 "sphereToCell.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(sphereToCell, 0);
36 addToRunTimeSelectionTable(topoSetSource, sphereToCell, word);
37 addToRunTimeSelectionTable(topoSetSource, sphereToCell, istream);
41 Foam::topoSetSource::addToUsageTable Foam::sphereToCell::usage_
43 sphereToCell::typeName,
44 "\n Usage: sphereToCell (centreX centreY centreZ) radius\n\n"
45 " Select all cells with cellCentre within bounding sphere\n\n"
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 void Foam::sphereToCell::combine(topoSet& set, const bool add) const
53 const pointField& ctrs = mesh_.cellCentres();
55 const scalar radSquared = radius_*radius_;
59 scalar offset = magSqr(centre_ - ctrs[cellI]);
60 if (offset <= radSquared)
62 addOrDelete(set, cellI, add);
68 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
70 Foam::sphereToCell::sphereToCell
83 Foam::sphereToCell::sphereToCell
86 const dictionary& dict
90 centre_(dict.lookup("centre")),
91 radius_(readScalar(dict.lookup("radius")))
95 // Construct from Istream
96 Foam::sphereToCell::sphereToCell
103 centre_(checkIs(is)),
104 radius_(readScalar(checkIs(is)))
108 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
110 Foam::sphereToCell::~sphereToCell()
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 void Foam::sphereToCell::applyToSet
118 const topoSetSource::setAction action,
122 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
124 Info<< " Adding cells with centre within sphere, with centre = "
125 << centre_ << " and radius = " << radius_ << endl;
129 else if (action == topoSetSource::DELETE)
131 Info<< " Removing cells with centre within sphere, with centre = "
132 << centre_ << " and radius = " << radius_ << endl;
139 // ************************************************************************* //