initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / sets / cellSources / rotatedBoxToCell / rotatedBoxToCell.C
blob4a63a4d213726966df6f633f2d9567722c87924d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 Description
27 \*---------------------------------------------------------------------------*/
29 #include "rotatedBoxToCell.H"
30 #include "polyMesh.H"
31 #include "cellModeller.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 namespace Foam
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);
74     forAll(boxVerts, i)
75     {
76         boxVerts[i] = i;
77     }
79     const cellModel& hex = *(cellModeller::lookup("hex"));
80     
81     // Get outwards pointing faces.
82     faceList boxFaces(cellShape(hex, boxVerts).faces());
84     // Precalculate normals
85     vectorField boxFaceNormals(boxFaces.size());
86     forAll(boxFaces, i)
87     {
88         boxFaceNormals[i] = boxFaces[i].normal(boxPoints);
90         Pout<< "Face:" << i << " position:" << boxFaces[i].centre(boxPoints)
91             << " normal:" << boxFaceNormals[i] << endl;
92     }    
94     // Check whether cell centre is inside all faces of box.
96     const pointField& ctrs = mesh_.cellCentres();
98     forAll(ctrs, cellI)
99     {
100         bool inside = true;
102         forAll(boxFaces, i)
103         {
104             const face& f = boxFaces[i];
106             if (((ctrs[cellI] - boxPoints[f[0]]) & boxFaceNormals[i]) > 0)
107             {
108                 inside = false;
109                 break;
110             }
111         }
113         if (inside)
114         {
115             addOrDelete(set, cellI, add);
116         }
117     }
121 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
123 // Construct from components
124 Foam::rotatedBoxToCell::rotatedBoxToCell
126     const polyMesh& mesh,
127     const vector& origin,
128     const vector& i,
129     const vector& j,
130     const vector& k
133     topoSetSource(mesh),
134     origin_(origin_),
135     i_(i),
136     j_(j),
137     k_(k)
141 // Construct from dictionary
142 Foam::rotatedBoxToCell::rotatedBoxToCell
144     const polyMesh& mesh,
145     const dictionary& dict
148     topoSetSource(mesh),
149     origin_(dict.lookup("origin")),
150     i_(dict.lookup("i")),
151     j_(dict.lookup("j")),
152     k_(dict.lookup("k"))
156 // Construct from Istream
157 Foam::rotatedBoxToCell::rotatedBoxToCell(const polyMesh& mesh, Istream& is)
159     topoSetSource(mesh),
160     origin_(is),
161     i_(is),
162     j_(is),
163     k_(is)
167 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
169 Foam::rotatedBoxToCell::~rotatedBoxToCell()
173 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
175 void Foam::rotatedBoxToCell::applyToSet
177     const topoSetSource::setAction action,
178     topoSet& set
179 ) const
181     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
182     {
183         Info<< "    Adding cells with center within rotated box " << endl;
185         combine(set, true);
186     }
187     else if (action == topoSetSource::DELETE)
188     {
189         Info<< "    Removing cells with center within rotated box " << endl;
191         combine(set, false);
192     }
196 // ************************************************************************* //