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 "sphereToCell.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00029
00030
00031
00032 namespace Foam
00033 {
00034 defineTypeNameAndDebug(sphereToCell, 0);
00035 addToRunTimeSelectionTable(topoSetSource, sphereToCell, word);
00036 addToRunTimeSelectionTable(topoSetSource, sphereToCell, istream);
00037 }
00038
00039
00040 Foam::topoSetSource::addToUsageTable Foam::sphereToCell::usage_
00041 (
00042 sphereToCell::typeName,
00043 "\n Usage: sphereToCell (centreX centreY centreZ) radius\n\n"
00044 " Select all cells with cellCentre within bounding sphere\n\n"
00045 );
00046
00047
00048
00049
00050 void Foam::sphereToCell::combine(topoSet& set, const bool add) const
00051 {
00052 const pointField& ctrs = mesh_.cellCentres();
00053
00054 const scalar radSquared = radius_*radius_;
00055
00056 forAll(ctrs, cellI)
00057 {
00058 scalar offset = magSqr(centre_ - ctrs[cellI]);
00059 if (offset <= radSquared)
00060 {
00061 addOrDelete(set, cellI, add);
00062 }
00063 }
00064 }
00065
00066
00067
00068
00069 Foam::sphereToCell::sphereToCell
00070 (
00071 const polyMesh& mesh,
00072 const vector& centre,
00073 const scalar radius
00074 )
00075 :
00076 topoSetSource(mesh),
00077 centre_(centre),
00078 radius_(radius)
00079 {}
00080
00081
00082 Foam::sphereToCell::sphereToCell
00083 (
00084 const polyMesh& mesh,
00085 const dictionary& dict
00086 )
00087 :
00088 topoSetSource(mesh),
00089 centre_(dict.lookup("centre")),
00090 radius_(readScalar(dict.lookup("radius")))
00091 {}
00092
00093
00094
00095 Foam::sphereToCell::sphereToCell
00096 (
00097 const polyMesh& mesh,
00098 Istream& is
00099 )
00100 :
00101 topoSetSource(mesh),
00102 centre_(checkIs(is)),
00103 radius_(readScalar(checkIs(is)))
00104 {}
00105
00106
00107
00108
00109 Foam::sphereToCell::~sphereToCell()
00110 {}
00111
00112
00113
00114
00115 void Foam::sphereToCell::applyToSet
00116 (
00117 const topoSetSource::setAction action,
00118 topoSet& set
00119 ) const
00120 {
00121 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00122 {
00123 Info<< " Adding cells with centre within sphere, with centre = "
00124 << centre_ << " and radius = " << radius_ << endl;
00125
00126 combine(set, true);
00127 }
00128 else if (action == topoSetSource::DELETE)
00129 {
00130 Info<< " Removing cells with centre within sphere, with centre = "
00131 << centre_ << " and radius = " << radius_ << endl;
00132
00133 combine(set, false);
00134 }
00135 }
00136
00137
00138