initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / sets / cellSources / sphereToCell / sphereToCell.C
blob664c736cc65936e07c8d24ef62cd99a2ad108765
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
28 #include "polyMesh.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
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_;
57     forAll(ctrs, cellI)
58     {
59         scalar offset = magSqr(centre_ - ctrs[cellI]);
60         if (offset <= radSquared)
61         {
62             addOrDelete(set, cellI, add);
63         }
64     }
68 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
70 Foam::sphereToCell::sphereToCell
72     const polyMesh& mesh,
73     const vector& centre,
74     const scalar radius
77     topoSetSource(mesh),
78     centre_(centre),
79     radius_(radius)
83 Foam::sphereToCell::sphereToCell
85     const polyMesh& mesh,
86     const dictionary& dict
89     topoSetSource(mesh),
90     centre_(dict.lookup("centre")),
91     radius_(readScalar(dict.lookup("radius")))
95 // Construct from Istream
96 Foam::sphereToCell::sphereToCell
98     const polyMesh& mesh,
99     Istream& is
102     topoSetSource(mesh),
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,
119     topoSet& set
120 ) const
122     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
123     {
124         Info<< "    Adding cells with centre within sphere, with centre = "
125             << centre_ << " and radius = " << radius_ << endl;
127         combine(set, true);
128     }
129     else if (action == topoSetSource::DELETE)
130     {
131         Info<< "    Removing cells with centre within sphere, with centre = "
132             << centre_ << " and radius = " << radius_ << endl;
134         combine(set, false);
135     }
139 // ************************************************************************* //