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

cylinderToCell.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 "cylinderToCell.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034     defineTypeNameAndDebug(cylinderToCell, 0);
00035     addToRunTimeSelectionTable(topoSetSource, cylinderToCell, word);
00036     addToRunTimeSelectionTable(topoSetSource, cylinderToCell, istream);
00037 }
00038 
00039 
00040 Foam::topoSetSource::addToUsageTable Foam::cylinderToCell::usage_
00041 (
00042     cylinderToCell::typeName,
00043     "\n    Usage: cylinderToCell (p1X p1Y p1Z) (p2X p2Y p2Z) radius\n\n"
00044     "    Select all cells with cell centre within bounding cylinder\n\n"
00045 );
00046 
00047 
00048 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00049 
00050 void Foam::cylinderToCell::combine(topoSet& set, const bool add) const
00051 {
00052     const vector axis = p2_ - p1_;
00053     const scalar rad2 = sqr(radius_);
00054     const scalar magAxis2 = magSqr(axis);
00055 
00056     const pointField& ctrs = mesh_.cellCentres();
00057 
00058     forAll(ctrs, cellI)
00059     {
00060         vector d = ctrs[cellI] - p1_;
00061         scalar magD = d & axis;
00062 
00063         if ((magD > 0) && (magD < magAxis2))
00064         {
00065             scalar d2 = (d & d) - sqr(magD)/magAxis2;
00066             if (d2 < rad2)
00067             {
00068                 addOrDelete(set, cellI, add);
00069             }
00070         }
00071     }
00072 }
00073 
00074 
00075 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00076 
00077 Foam::cylinderToCell::cylinderToCell
00078 (
00079     const polyMesh& mesh,
00080     const vector& p1,
00081     const vector& p2,
00082     const scalar radius
00083 )
00084 :
00085     topoSetSource(mesh),
00086     p1_(p1),
00087     p2_(p2),
00088     radius_(radius)
00089 {}
00090 
00091 
00092 Foam::cylinderToCell::cylinderToCell
00093 (
00094     const polyMesh& mesh,
00095     const dictionary& dict
00096 )
00097 :
00098     topoSetSource(mesh),
00099     p1_(dict.lookup("p1")),
00100     p2_(dict.lookup("p2")),
00101     radius_(readScalar(dict.lookup("radius")))
00102 {}
00103 
00104 
00105 // Construct from Istream
00106 Foam::cylinderToCell::cylinderToCell
00107 (
00108     const polyMesh& mesh,
00109     Istream& is
00110 )
00111 :
00112     topoSetSource(mesh),
00113     p1_(checkIs(is)),
00114     p2_(checkIs(is)),
00115     radius_(readScalar(checkIs(is)))
00116 {}
00117 
00118 
00119 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00120 
00121 Foam::cylinderToCell::~cylinderToCell()
00122 {}
00123 
00124 
00125 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00126 
00127 void Foam::cylinderToCell::applyToSet
00128 (
00129     const topoSetSource::setAction action,
00130     topoSet& set
00131 ) const
00132 {
00133     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00134     {
00135         Info<< "    Adding cells with centre within cylinder, with p1 = "
00136             << p1_ << ", p2 = " << p2_ << " and radius = " << radius_ << endl;
00137 
00138         combine(set, true);
00139     }
00140     else if (action == topoSetSource::DELETE)
00141     {
00142         Info<< "    Removing cells with centre within cylinder, with p1 = "
00143             << p1_ << ", p2 = " << p2_ << " and radius = " << radius_ << endl;
00144 
00145         combine(set, false);
00146     }
00147 }
00148 
00149 
00150 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines