OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

rotatedBoxToCell.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "rotatedBoxToCell.H"
00030 #include "polyMesh.H"
00031 #include "cellModeller.H"
00032 
00033 #include "addToRunTimeSelectionTable.H"
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 
00040 defineTypeNameAndDebug(rotatedBoxToCell, 0);
00041 
00042 addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, word);
00043 
00044 addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, istream);
00045 
00046 }
00047 
00048 
00049 Foam::topoSetSource::addToUsageTable Foam::rotatedBoxToCell::usage_
00050 (
00051     rotatedBoxToCell::typeName,
00052     "\n    Usage: rotatedBoxToCell (originx originy originz)"
00053     " (ix iy iz) (jx jy jz) (kx ky kz)\n\n"
00054     "    Select all cells with cellCentre within parallelopiped\n\n"
00055 );
00056 
00057 
00058 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00059 
00060 void Foam::rotatedBoxToCell::combine(topoSet& set, const bool add) const
00061 {
00062     // Define a cell for the box
00063     pointField boxPoints(8);
00064     boxPoints[0] = origin_;
00065     boxPoints[1] = origin_ + i_;
00066     boxPoints[2] = origin_ + i_ + j_;
00067     boxPoints[3] = origin_ + j_;
00068     boxPoints[4] = origin_ + k_;
00069     boxPoints[5] = origin_ + k_ + i_;
00070     boxPoints[6] = origin_ + k_ + i_ + j_;
00071     boxPoints[7] = origin_ + k_ + j_;
00072 
00073     labelList boxVerts(8);
00074     forAll(boxVerts, i)
00075     {
00076         boxVerts[i] = i;
00077     }
00078 
00079     const cellModel& hex = *(cellModeller::lookup("hex"));
00080     
00081     // Get outwards pointing faces.
00082     faceList boxFaces(cellShape(hex, boxVerts).faces());
00083 
00084     // Precalculate normals
00085     vectorField boxFaceNormals(boxFaces.size());
00086     forAll(boxFaces, i)
00087     {
00088         boxFaceNormals[i] = boxFaces[i].normal(boxPoints);
00089 
00090         Pout<< "Face:" << i << " position:" << boxFaces[i].centre(boxPoints)
00091             << " normal:" << boxFaceNormals[i] << endl;
00092     }    
00093 
00094     // Check whether cell centre is inside all faces of box.
00095 
00096     const pointField& ctrs = mesh_.cellCentres();
00097 
00098     forAll(ctrs, cellI)
00099     {
00100         bool inside = true;
00101 
00102         forAll(boxFaces, i)
00103         {
00104             const face& f = boxFaces[i];
00105 
00106             if (((ctrs[cellI] - boxPoints[f[0]]) & boxFaceNormals[i]) > 0)
00107             {
00108                 inside = false;
00109                 break;
00110             }
00111         }
00112 
00113         if (inside)
00114         {
00115             addOrDelete(set, cellI, add);
00116         }
00117     }
00118 }
00119 
00120 
00121 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00122 
00123 // Construct from components
00124 Foam::rotatedBoxToCell::rotatedBoxToCell
00125 (
00126     const polyMesh& mesh,
00127     const vector& origin,
00128     const vector& i,
00129     const vector& j,
00130     const vector& k
00131 )
00132 :
00133     topoSetSource(mesh),
00134     origin_(origin_),
00135     i_(i),
00136     j_(j),
00137     k_(k)
00138 {}
00139 
00140 
00141 // Construct from dictionary
00142 Foam::rotatedBoxToCell::rotatedBoxToCell
00143 (
00144     const polyMesh& mesh,
00145     const dictionary& dict
00146 )
00147 :
00148     topoSetSource(mesh),
00149     origin_(dict.lookup("origin")),
00150     i_(dict.lookup("i")),
00151     j_(dict.lookup("j")),
00152     k_(dict.lookup("k"))
00153 {}
00154 
00155 
00156 // Construct from Istream
00157 Foam::rotatedBoxToCell::rotatedBoxToCell(const polyMesh& mesh, Istream& is)
00158 :
00159     topoSetSource(mesh),
00160     origin_(is),
00161     i_(is),
00162     j_(is),
00163     k_(is)
00164 {}
00165 
00166 
00167 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00168 
00169 Foam::rotatedBoxToCell::~rotatedBoxToCell()
00170 {}
00171 
00172 
00173 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00174 
00175 void Foam::rotatedBoxToCell::applyToSet
00176 (
00177     const topoSetSource::setAction action,
00178     topoSet& set
00179 ) const
00180 {
00181     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00182     {
00183         Info<< "    Adding cells with center within rotated box " << endl;
00184 
00185         combine(set, true);
00186     }
00187     else if (action == topoSetSource::DELETE)
00188     {
00189         Info<< "    Removing cells with center within rotated box " << endl;
00190 
00191         combine(set, false);
00192     }
00193 }
00194 
00195 
00196 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd