From 14b12aad79539ebebe0f87f7b1c095aba51e29f9 Mon Sep 17 00:00:00 2001
From: andy <a.heather@opencfd.co.uk>
Date: Tue, 9 Dec 2008 19:11:12 +0000
Subject: [PATCH] adding cyclinderToCell cell source

---
 src/meshTools/Make/files                      |   1 +
 .../cylinderToCell/cylinderToCell.C           | 151 ++++++++++++++++++
 .../cylinderToCell/cylinderToCell.H           | 131 +++++++++++++++
 3 files changed, 283 insertions(+)
 create mode 100644 src/meshTools/sets/cellSources/cylinderToCell/cylinderToCell.C
 create mode 100644 src/meshTools/sets/cellSources/cylinderToCell/cylinderToCell.H

diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files
index 99587f8d3c0..86d1fe3ddb7 100644
--- a/src/meshTools/Make/files
+++ b/src/meshTools/Make/files
@@ -87,6 +87,7 @@ $(cellSources)/nearestToCell/nearestToCell.C
 $(cellSources)/nbrToCell/nbrToCell.C
 $(cellSources)/zoneToCell/zoneToCell.C
 $(cellSources)/sphereToCell/sphereToCell.C
+$(cellSources)/cylinderToCell/cylinderToCell.C
 
 faceSources = sets/faceSources
 $(faceSources)/faceToFace/faceToFace.C
diff --git a/src/meshTools/sets/cellSources/cylinderToCell/cylinderToCell.C b/src/meshTools/sets/cellSources/cylinderToCell/cylinderToCell.C
new file mode 100644
index 00000000000..63e46114583
--- /dev/null
+++ b/src/meshTools/sets/cellSources/cylinderToCell/cylinderToCell.C
@@ -0,0 +1,151 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "cylinderToCell.H"
+#include "polyMesh.H"
+#include "addToRunTimeSelectionTable.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    defineTypeNameAndDebug(cylinderToCell, 0);
+    addToRunTimeSelectionTable(topoSetSource, cylinderToCell, word);
+    addToRunTimeSelectionTable(topoSetSource, cylinderToCell, istream);
+}
+
+
+Foam::topoSetSource::addToUsageTable Foam::cylinderToCell::usage_
+(
+    cylinderToCell::typeName,
+    "\n    Usage: cylinderToCell (p1X p1Y p1Z) (p2X p2Y p2Z) radius\n\n"
+    "    Select all cells with cell centre within bounding cylinder\n\n"
+);
+
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+void Foam::cylinderToCell::combine(topoSet& set, const bool add) const
+{
+    const vector axis = p2_ - p1_;
+    const scalar rad2 = sqr(radius_);
+    const scalar magAxis2 = magSqr(axis);
+
+    const pointField& ctrs = mesh_.cellCentres();
+
+    forAll(ctrs, cellI)
+    {
+        vector d = ctrs[cellI] - p1_;
+        scalar magD = d & axis;
+
+        if ((magD > 0) && (magD < magAxis2))
+        {
+            scalar d2 = (d & d) - sqr(magD)/magAxis2;
+            if (d2 < rad2)
+            {
+                addOrDelete(set, cellI, add);
+            }
+        }
+    }
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::cylinderToCell::cylinderToCell
+(
+    const polyMesh& mesh,
+    const vector& p1,
+    const vector& p2,
+    const scalar radius
+)
+:
+    topoSetSource(mesh),
+    p1_(p1),
+    p2_(p2),
+    radius_(radius)
+{}
+
+
+Foam::cylinderToCell::cylinderToCell
+(
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    topoSetSource(mesh),
+    p1_(dict.lookup("p1")),
+    p2_(dict.lookup("p2")),
+    radius_(readScalar(dict.lookup("radius")))
+{}
+
+
+// Construct from Istream
+Foam::cylinderToCell::cylinderToCell
+(
+    const polyMesh& mesh,
+    Istream& is
+)
+:
+    topoSetSource(mesh),
+    p1_(checkIs(is)),
+    p2_(checkIs(is)),
+    radius_(readScalar(checkIs(is)))
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::cylinderToCell::~cylinderToCell()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::cylinderToCell::applyToSet
+(
+    const topoSetSource::setAction action,
+    topoSet& set
+) const
+{
+    if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
+    {
+        Info<< "    Adding cells with centre within cylinder, with p1 = "
+            << p1_ << ", p2 = " << p2_ << " and radius = " << radius_ << endl;
+
+        combine(set, true);
+    }
+    else if (action == topoSetSource::DELETE)
+    {
+        Info<< "    Removing cells with centre within sphere, with p1 = "
+            << p1_ << ", p2 = " << p2_ << " and radius = " << radius_ << endl;
+
+        combine(set, false);
+    }
+}
+
+
+// ************************************************************************* //
diff --git a/src/meshTools/sets/cellSources/cylinderToCell/cylinderToCell.H b/src/meshTools/sets/cellSources/cylinderToCell/cylinderToCell.H
new file mode 100644
index 00000000000..0401e3f3efd
--- /dev/null
+++ b/src/meshTools/sets/cellSources/cylinderToCell/cylinderToCell.H
@@ -0,0 +1,131 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    Foam::cylinderToCell
+
+Description
+    A topoSetSource to select cells based on cell centres inside a cylinder.
+
+SourceFiles
+    cylinderToCell.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef cylinderToCell_H
+#define cylinderToCell_H
+
+#include "topoSetSource.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+                       Class cylinderToCell Declaration
+\*---------------------------------------------------------------------------*/
+
+class cylinderToCell
+:
+    public topoSetSource
+{
+
+    // Private data
+
+        //- Add usage string
+        static addToUsageTable usage_;
+
+        //- First point on cylinder axis
+        vector p1_;
+
+        //- Second point on cylinder axis
+        vector p2_;
+
+        //- Radius
+        scalar radius_;
+
+
+    // Private Member Functions
+
+        void combine(topoSet& set, const bool add) const;
+
+
+public:
+
+    //- Runtime type information
+    TypeName("cylinderToCell");
+
+
+    // Constructors
+
+        //- Construct from components
+        cylinderToCell
+        (
+            const polyMesh& mesh,
+            const vector& p1,
+            const vector& p2,
+            const scalar radius
+        );
+
+        //- Construct from dictionary
+        cylinderToCell
+        (
+            const polyMesh& mesh,
+            const dictionary& dict
+        );
+
+        //- Construct from Istream
+        cylinderToCell
+        (
+            const polyMesh& mesh,
+            Istream&
+        );
+
+
+    // Destructor
+
+        virtual ~cylinderToCell();
+
+
+    // Member Functions
+
+        virtual void applyToSet
+        (
+            const topoSetSource::setAction action,
+            topoSet&
+        ) const;
+
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
-- 
GitLab