1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 \*---------------------------------------------------------------------------*/
29 #include "rotatedBoxToCell.H"
31 #include "cellModeller.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(rotatedBoxToCell, 0);
42 addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, word);
44 addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, istream);
49 Foam::topoSetSource::addToUsageTable Foam::rotatedBoxToCell::usage_
51 rotatedBoxToCell::typeName,
52 "\n Usage: rotatedBoxToCell (originx originy originz)"
53 " (ix iy iz) (jx jy jz) (kx ky kz)\n\n"
54 " Select all cells with cellCentre within parallelopiped\n\n"
58 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
60 void Foam::rotatedBoxToCell::combine(topoSet& set, const bool add) const
62 // Define a cell for the box
63 pointField boxPoints(8);
64 boxPoints[0] = origin_;
65 boxPoints[1] = origin_ + i_;
66 boxPoints[2] = origin_ + i_ + j_;
67 boxPoints[3] = origin_ + j_;
68 boxPoints[4] = origin_ + k_;
69 boxPoints[5] = origin_ + k_ + i_;
70 boxPoints[6] = origin_ + k_ + i_ + j_;
71 boxPoints[7] = origin_ + k_ + j_;
73 labelList boxVerts(8);
79 const cellModel& hex = *(cellModeller::lookup("hex"));
81 // Get outwards pointing faces.
82 faceList boxFaces(cellShape(hex, boxVerts).faces());
84 // Precalculate normals
85 vectorField boxFaceNormals(boxFaces.size());
88 boxFaceNormals[i] = boxFaces[i].normal(boxPoints);
90 Pout<< "Face:" << i << " position:" << boxFaces[i].centre(boxPoints)
91 << " normal:" << boxFaceNormals[i] << endl;
94 // Check whether cell centre is inside all faces of box.
96 const pointField& ctrs = mesh_.cellCentres();
104 const face& f = boxFaces[i];
106 if (((ctrs[cellI] - boxPoints[f[0]]) & boxFaceNormals[i]) > 0)
115 addOrDelete(set, cellI, add);
121 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
123 // Construct from components
124 Foam::rotatedBoxToCell::rotatedBoxToCell
126 const polyMesh& mesh,
127 const vector& origin,
141 // Construct from dictionary
142 Foam::rotatedBoxToCell::rotatedBoxToCell
144 const polyMesh& mesh,
145 const dictionary& dict
149 origin_(dict.lookup("origin")),
150 i_(dict.lookup("i")),
151 j_(dict.lookup("j")),
156 // Construct from Istream
157 Foam::rotatedBoxToCell::rotatedBoxToCell(const polyMesh& mesh, Istream& is)
167 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
169 Foam::rotatedBoxToCell::~rotatedBoxToCell()
173 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
175 void Foam::rotatedBoxToCell::applyToSet
177 const topoSetSource::setAction action,
181 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
183 Info<< " Adding cells with center within rotated box " << endl;
187 else if (action == topoSetSource::DELETE)
189 Info<< " Removing cells with center within rotated box " << endl;
196 // ************************************************************************* //