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

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