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