FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
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 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00056 
00057 void Foam::rotatedBoxToCell::combine(topoSet& set, const bool add) const
00058 {
00059     // Define a cell for the box
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     // Get outwards pointing faces.
00079     faceList boxFaces(cellShape(hex, boxVerts).faces());
00080 
00081     // Precalculate normals
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     // Check whether cell centre is inside all faces of box.
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 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00119 
00120 // Construct from components
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 // Construct from dictionary
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 // Construct from Istream
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 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00165 
00166 Foam::rotatedBoxToCell::~rotatedBoxToCell()
00167 {}
00168 
00169 
00170 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
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 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines