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

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