04c517f882de723863e2665e32c6a9586f39d1ad
[OpenFOAM-1.6.x.git] / src / meshTools / sets / cellSources / cylinderToCell / cylinderToCell.C
blob04c517f882de723863e2665e32c6a9586f39d1ad
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "cylinderToCell.H"
28 #include "polyMesh.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35     defineTypeNameAndDebug(cylinderToCell, 0);
36     addToRunTimeSelectionTable(topoSetSource, cylinderToCell, word);
37     addToRunTimeSelectionTable(topoSetSource, cylinderToCell, istream);
41 Foam::topoSetSource::addToUsageTable Foam::cylinderToCell::usage_
43     cylinderToCell::typeName,
44     "\n    Usage: cylinderToCell (p1X p1Y p1Z) (p2X p2Y p2Z) radius\n\n"
45     "    Select all cells with cell centre within bounding cylinder\n\n"
49 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
51 void Foam::cylinderToCell::combine(topoSet& set, const bool add) const
53     const vector axis = p2_ - p1_;
54     const scalar rad2 = sqr(radius_);
55     const scalar magAxis2 = magSqr(axis);
57     const pointField& ctrs = mesh_.cellCentres();
59     forAll(ctrs, cellI)
60     {
61         vector d = ctrs[cellI] - p1_;
62         scalar magD = d & axis;
64         if ((magD > 0) && (magD < magAxis2))
65         {
66             scalar d2 = (d & d) - sqr(magD)/magAxis2;
67             if (d2 < rad2)
68             {
69                 addOrDelete(set, cellI, add);
70             }
71         }
72     }
76 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
78 Foam::cylinderToCell::cylinderToCell
80     const polyMesh& mesh,
81     const vector& p1,
82     const vector& p2,
83     const scalar radius
86     topoSetSource(mesh),
87     p1_(p1),
88     p2_(p2),
89     radius_(radius)
93 Foam::cylinderToCell::cylinderToCell
95     const polyMesh& mesh,
96     const dictionary& dict
99     topoSetSource(mesh),
100     p1_(dict.lookup("p1")),
101     p2_(dict.lookup("p2")),
102     radius_(readScalar(dict.lookup("radius")))
106 // Construct from Istream
107 Foam::cylinderToCell::cylinderToCell
109     const polyMesh& mesh,
110     Istream& is
113     topoSetSource(mesh),
114     p1_(checkIs(is)),
115     p2_(checkIs(is)),
116     radius_(readScalar(checkIs(is)))
120 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
122 Foam::cylinderToCell::~cylinderToCell()
126 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
128 void Foam::cylinderToCell::applyToSet
130     const topoSetSource::setAction action,
131     topoSet& set
132 ) const
134     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
135     {
136         Info<< "    Adding cells with centre within cylinder, with p1 = "
137             << p1_ << ", p2 = " << p2_ << " and radius = " << radius_ << endl;
139         combine(set, true);
140     }
141     else if (action == topoSetSource::DELETE)
142     {
143         Info<< "    Removing cells with centre within sphere, with p1 = "
144             << p1_ << ", p2 = " << p2_ << " and radius = " << radius_ << endl;
146         combine(set, false);
147     }
151 // ************************************************************************* //