cylinderToCell.C
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
00027 #include "cylinderToCell.H"
00028 #include "polyMesh.H"
00029 #include "addToRunTimeSelectionTable.H"
00030
00031
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
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
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
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
00121
00122 Foam::cylinderToCell::~cylinderToCell()
00123 {}
00124
00125
00126
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