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 "rotatedBoxToCell.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <OpenFOAM/cellModeller.H>
00029 
00030 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00031 
00032 
00033 
00034 namespace Foam
00035 {
00036 
00037 defineTypeNameAndDebug(rotatedBoxToCell, 0);
00038 
00039 addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, word);
00040 
00041 addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, istream);
00042 
00043 }
00044 
00045 
00046 Foam::topoSetSource::addToUsageTable Foam::rotatedBoxToCell::usage_
00047 (
00048     rotatedBoxToCell::typeName,
00049     "\n    Usage: rotatedBoxToCell (originx originy originz)"
00050     " (ix iy iz) (jx jy jz) (kx ky kz)\n\n"
00051     "    Select all cells with cellCentre within parallelopiped\n\n"
00052 );
00053 
00054 
00055 
00056 
00057 void Foam::rotatedBoxToCell::combine(topoSet& set, const bool add) const
00058 {
00059     
00060     pointField boxPoints(8);
00061     boxPoints[0] = origin_;
00062     boxPoints[1] = origin_ + i_;
00063     boxPoints[2] = origin_ + i_ + j_;
00064     boxPoints[3] = origin_ + j_;
00065     boxPoints[4] = origin_ + k_;
00066     boxPoints[5] = origin_ + k_ + i_;
00067     boxPoints[6] = origin_ + k_ + i_ + j_;
00068     boxPoints[7] = origin_ + k_ + j_;
00069 
00070     labelList boxVerts(8);
00071     forAll(boxVerts, i)
00072     {
00073         boxVerts[i] = i;
00074     }
00075 
00076     const cellModel& hex = *(cellModeller::lookup("hex"));
00077 
00078     
00079     faceList boxFaces(cellShape(hex, boxVerts).faces());
00080 
00081     
00082     vectorField boxFaceNormals(boxFaces.size());
00083     forAll(boxFaces, i)
00084     {
00085         boxFaceNormals[i] = boxFaces[i].normal(boxPoints);
00086 
00087         Pout<< "Face:" << i << " position:" << boxFaces[i].centre(boxPoints)
00088             << " normal:" << boxFaceNormals[i] << endl;
00089     }
00090 
00091     
00092 
00093     const pointField& ctrs = mesh_.cellCentres();
00094 
00095     forAll(ctrs, cellI)
00096     {
00097         bool inside = true;
00098 
00099         forAll(boxFaces, i)
00100         {
00101             const face& f = boxFaces[i];
00102 
00103             if (((ctrs[cellI] - boxPoints[f[0]]) & boxFaceNormals[i]) > 0)
00104             {
00105                 inside = false;
00106                 break;
00107             }
00108         }
00109 
00110         if (inside)
00111         {
00112             addOrDelete(set, cellI, add);
00113         }
00114     }
00115 }
00116 
00117 
00118 
00119 
00120 
00121 Foam::rotatedBoxToCell::rotatedBoxToCell
00122 (
00123     const polyMesh& mesh,
00124     const vector& origin,
00125     const vector& i,
00126     const vector& j,
00127     const vector& k
00128 )
00129 :
00130     topoSetSource(mesh),
00131     origin_(origin),
00132     i_(i),
00133     j_(j),
00134     k_(k)
00135 {}
00136 
00137 
00138 
00139 Foam::rotatedBoxToCell::rotatedBoxToCell
00140 (
00141     const polyMesh& mesh,
00142     const dictionary& dict
00143 )
00144 :
00145     topoSetSource(mesh),
00146     origin_(dict.lookup("origin")),
00147     i_(dict.lookup("i")),
00148     j_(dict.lookup("j")),
00149     k_(dict.lookup("k"))
00150 {}
00151 
00152 
00153 
00154 Foam::rotatedBoxToCell::rotatedBoxToCell(const polyMesh& mesh, Istream& is)
00155 :
00156     topoSetSource(mesh),
00157     origin_(is),
00158     i_(is),
00159     j_(is),
00160     k_(is)
00161 {}
00162 
00163 
00164 
00165 
00166 Foam::rotatedBoxToCell::~rotatedBoxToCell()
00167 {}
00168 
00169 
00170 
00171 
00172 void Foam::rotatedBoxToCell::applyToSet
00173 (
00174     const topoSetSource::setAction action,
00175     topoSet& set
00176 ) const
00177 {
00178     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00179     {
00180         Info<< "    Adding cells with center within rotated box " << endl;
00181 
00182         combine(set, true);
00183     }
00184     else if (action == topoSetSource::DELETE)
00185     {
00186         Info<< "    Removing cells with center within rotated box " << endl;
00187 
00188         combine(set, false);
00189     }
00190 }
00191 
00192 
00193