1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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
25 \*---------------------------------------------------------------------------*/
27 #include "rotatedBoxToCell.H"
29 #include "cellModeller.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(rotatedBoxToCell, 0);
40 addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, word);
42 addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, istream);
47 Foam::topoSetSource::addToUsageTable Foam::rotatedBoxToCell::usage_
49 rotatedBoxToCell::typeName,
50 "\n Usage: rotatedBoxToCell (originx originy originz)"
51 " (ix iy iz) (jx jy jz) (kx ky kz)\n\n"
52 " Select all cells with cellCentre within parallelopiped\n\n"
56 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
58 void Foam::rotatedBoxToCell::combine(topoSet& set, const bool add) const
60 // Define a cell for the box
61 pointField boxPoints(8);
62 boxPoints[0] = origin_;
63 boxPoints[1] = origin_ + i_;
64 boxPoints[2] = origin_ + i_ + j_;
65 boxPoints[3] = origin_ + j_;
66 boxPoints[4] = origin_ + k_;
67 boxPoints[5] = origin_ + k_ + i_;
68 boxPoints[6] = origin_ + k_ + i_ + j_;
69 boxPoints[7] = origin_ + k_ + j_;
71 labelList boxVerts(8);
77 const cellModel& hex = *(cellModeller::lookup("hex"));
79 // Get outwards pointing faces.
80 faceList boxFaces(cellShape(hex, boxVerts).faces());
82 // Precalculate normals
83 vectorField boxFaceNormals(boxFaces.size());
86 boxFaceNormals[i] = boxFaces[i].normal(boxPoints);
88 Pout<< "Face:" << i << " position:" << boxFaces[i].centre(boxPoints)
89 << " normal:" << boxFaceNormals[i] << endl;
92 // Check whether cell centre is inside all faces of box.
94 const pointField& ctrs = mesh_.cellCentres();
102 const face& f = boxFaces[i];
104 if (((ctrs[cellI] - boxPoints[f[0]]) & boxFaceNormals[i]) > 0)
113 addOrDelete(set, cellI, add);
119 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
121 // Construct from components
122 Foam::rotatedBoxToCell::rotatedBoxToCell
124 const polyMesh& mesh,
125 const vector& origin,
139 // Construct from dictionary
140 Foam::rotatedBoxToCell::rotatedBoxToCell
142 const polyMesh& mesh,
143 const dictionary& dict
147 origin_(dict.lookup("origin")),
148 i_(dict.lookup("i")),
149 j_(dict.lookup("j")),
154 // Construct from Istream
155 Foam::rotatedBoxToCell::rotatedBoxToCell(const polyMesh& mesh, Istream& is)
165 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
167 Foam::rotatedBoxToCell::~rotatedBoxToCell()
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
173 void Foam::rotatedBoxToCell::applyToSet
175 const topoSetSource::setAction action,
179 if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
181 Info<< " Adding cells with center within rotated box " << endl;
185 else if (action == topoSetSource::DELETE)
187 Info<< " Removing cells with center within rotated box " << endl;
194 // ************************************************************************* //