FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

sphereToCell.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "sphereToCell.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034     defineTypeNameAndDebug(sphereToCell, 0);
00035     addToRunTimeSelectionTable(topoSetSource, sphereToCell, word);
00036     addToRunTimeSelectionTable(topoSetSource, sphereToCell, istream);
00037 }
00038 
00039 
00040 Foam::topoSetSource::addToUsageTable Foam::sphereToCell::usage_
00041 (
00042     sphereToCell::typeName,
00043     "\n    Usage: sphereToCell (centreX centreY centreZ) radius\n\n"
00044     "    Select all cells with cellCentre within bounding sphere\n\n"
00045 );
00046 
00047 
00048 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00049 
00050 void Foam::sphereToCell::combine(topoSet& set, const bool add) const
00051 {
00052     const pointField& ctrs = mesh_.cellCentres();
00053 
00054     const scalar radSquared = radius_*radius_;
00055 
00056     forAll(ctrs, cellI)
00057     {
00058         scalar offset = magSqr(centre_ - ctrs[cellI]);
00059         if (offset <= radSquared)
00060         {
00061             addOrDelete(set, cellI, add);
00062         }
00063     }
00064 }
00065 
00066 
00067 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00068 
00069 Foam::sphereToCell::sphereToCell
00070 (
00071     const polyMesh& mesh,
00072     const vector& centre,
00073     const scalar radius
00074 )
00075 :
00076     topoSetSource(mesh),
00077     centre_(centre),
00078     radius_(radius)
00079 {}
00080 
00081 
00082 Foam::sphereToCell::sphereToCell
00083 (
00084     const polyMesh& mesh,
00085     const dictionary& dict
00086 )
00087 :
00088     topoSetSource(mesh),
00089     centre_(dict.lookup("centre")),
00090     radius_(readScalar(dict.lookup("radius")))
00091 {}
00092 
00093 
00094 // Construct from Istream
00095 Foam::sphereToCell::sphereToCell
00096 (
00097     const polyMesh& mesh,
00098     Istream& is
00099 )
00100 :
00101     topoSetSource(mesh),
00102     centre_(checkIs(is)),
00103     radius_(readScalar(checkIs(is)))
00104 {}
00105 
00106 
00107 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00108 
00109 Foam::sphereToCell::~sphereToCell()
00110 {}
00111 
00112 
00113 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00114 
00115 void Foam::sphereToCell::applyToSet
00116 (
00117     const topoSetSource::setAction action,
00118     topoSet& set
00119 ) const
00120 {
00121     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00122     {
00123         Info<< "    Adding cells with centre within sphere, with centre = "
00124             << centre_ << " and radius = " << radius_ << endl;
00125 
00126         combine(set, true);
00127     }
00128     else if (action == topoSetSource::DELETE)
00129     {
00130         Info<< "    Removing cells with centre within sphere, with centre = "
00131             << centre_ << " and radius = " << radius_ << endl;
00132 
00133         combine(set, false);
00134     }
00135 }
00136 
00137 
00138 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines