OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "sphereToCell.H"
00028 #include "polyMesh.H"
00029 #include "addToRunTimeSelectionTable.H"
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035     defineTypeNameAndDebug(sphereToCell, 0);
00036     addToRunTimeSelectionTable(topoSetSource, sphereToCell, word);
00037     addToRunTimeSelectionTable(topoSetSource, sphereToCell, istream);
00038 }
00039 
00040 
00041 Foam::topoSetSource::addToUsageTable Foam::sphereToCell::usage_
00042 (
00043     sphereToCell::typeName,
00044     "\n    Usage: sphereToCell (centreX centreY centreZ) radius\n\n"
00045     "    Select all cells with cellCentre within bounding sphere\n\n"
00046 );
00047 
00048 
00049 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00050 
00051 void Foam::sphereToCell::combine(topoSet& set, const bool add) const
00052 {
00053     const pointField& ctrs = mesh_.cellCentres();
00054 
00055     const scalar radSquared = radius_*radius_;
00056 
00057     forAll(ctrs, cellI)
00058     {
00059         scalar offset = magSqr(centre_ - ctrs[cellI]);
00060         if (offset <= radSquared)
00061         {
00062             addOrDelete(set, cellI, add);
00063         }
00064     }
00065 }
00066 
00067 
00068 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00069 
00070 Foam::sphereToCell::sphereToCell
00071 (
00072     const polyMesh& mesh,
00073     const vector& centre,
00074     const scalar radius
00075 )
00076 :
00077     topoSetSource(mesh),
00078     centre_(centre),
00079     radius_(radius)
00080 {}
00081 
00082 
00083 Foam::sphereToCell::sphereToCell
00084 (
00085     const polyMesh& mesh,
00086     const dictionary& dict
00087 )
00088 :
00089     topoSetSource(mesh),
00090     centre_(dict.lookup("centre")),
00091     radius_(readScalar(dict.lookup("radius")))
00092 {}
00093 
00094 
00095 // Construct from Istream
00096 Foam::sphereToCell::sphereToCell
00097 (
00098     const polyMesh& mesh,
00099     Istream& is
00100 )
00101 :
00102     topoSetSource(mesh),
00103     centre_(checkIs(is)),
00104     radius_(readScalar(checkIs(is)))
00105 {}
00106 
00107 
00108 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00109 
00110 Foam::sphereToCell::~sphereToCell()
00111 {}
00112 
00113 
00114 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00115 
00116 void Foam::sphereToCell::applyToSet
00117 (
00118     const topoSetSource::setAction action,
00119     topoSet& set
00120 ) const
00121 {
00122     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00123     {
00124         Info<< "    Adding cells with centre within sphere, with centre = "
00125             << centre_ << " and radius = " << radius_ << endl;
00126 
00127         combine(set, true);
00128     }
00129     else if (action == topoSetSource::DELETE)
00130     {
00131         Info<< "    Removing cells with centre within sphere, with centre = "
00132             << centre_ << " and radius = " << radius_ << endl;
00133 
00134         combine(set, false);
00135     }
00136 }
00137 
00138 
00139 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd