Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "cylinderToCell.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00029
00030
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
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
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
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
00120
00121 Foam::cylinderToCell::~cylinderToCell()
00122 {}
00123
00124
00125
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