rotatedBoxToCell.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "rotatedBoxToCell.H"
27 #include "polyMesh.H"
28 #include "cellModeller.H"
29 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 defineTypeNameAndDebug(rotatedBoxToCell, 0);
38 
39 addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, word);
40 
41 addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, istream);
42 
43 }
44 
45 
47 (
48  rotatedBoxToCell::typeName,
49  "\n Usage: rotatedBoxToCell (originx originy originz)"
50  " (ix iy iz) (jx jy jz) (kx ky kz)\n\n"
51  " Select all cells with cellCentre within parallelopiped\n\n"
52 );
53 
54 
55 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
56 
57 void Foam::rotatedBoxToCell::combine(topoSet& set, const bool add) const
58 {
59  // Define a cell for the box
60  pointField boxPoints(8);
61  boxPoints[0] = origin_;
62  boxPoints[1] = origin_ + i_;
63  boxPoints[2] = origin_ + i_ + j_;
64  boxPoints[3] = origin_ + j_;
65  boxPoints[4] = origin_ + k_;
66  boxPoints[5] = origin_ + k_ + i_;
67  boxPoints[6] = origin_ + k_ + i_ + j_;
68  boxPoints[7] = origin_ + k_ + j_;
69 
70  labelList boxVerts(8);
71  forAll(boxVerts, i)
72  {
73  boxVerts[i] = i;
74  }
75 
76  const cellModel& hex = *(cellModeller::lookup("hex"));
77 
78  // Get outwards pointing faces.
79  faceList boxFaces(cellShape(hex, boxVerts).faces());
80 
81  // Precalculate normals
82  vectorField boxFaceNormals(boxFaces.size());
83  forAll(boxFaces, i)
84  {
85  boxFaceNormals[i] = boxFaces[i].normal(boxPoints);
86 
87  //Pout<< "Face:" << i << " position:" << boxFaces[i].centre(boxPoints)
88  // << " normal:" << boxFaceNormals[i] << endl;
89  }
90 
91  // Check whether cell centre is inside all faces of box.
92 
93  const pointField& ctrs = mesh_.cellCentres();
94 
95  forAll(ctrs, cellI)
96  {
97  bool inside = true;
98 
99  forAll(boxFaces, i)
100  {
101  const face& f = boxFaces[i];
102 
103  if (((ctrs[cellI] - boxPoints[f[0]]) & boxFaceNormals[i]) > 0)
104  {
105  inside = false;
106  break;
107  }
108  }
109 
110  if (inside)
111  {
112  addOrDelete(set, cellI, add);
113  }
114  }
115 }
116 
117 
118 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
119 
120 // Construct from components
122 (
123  const polyMesh& mesh,
124  const vector& origin,
125  const vector& i,
126  const vector& j,
127  const vector& k
128 )
129 :
131  origin_(origin),
132  i_(i),
133  j_(j),
134  k_(k)
135 {}
136 
137 
138 // Construct from dictionary
140 (
141  const polyMesh& mesh,
142  const dictionary& dict
143 )
144 :
146  origin_(dict.lookup("origin")),
147  i_(dict.lookup("i")),
148  j_(dict.lookup("j")),
149  k_(dict.lookup("k"))
150 {}
151 
152 
153 // Construct from Istream
155 :
157  origin_(is),
158  i_(is),
159  j_(is),
160  k_(is)
161 {}
162 
163 
164 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
165 
167 {}
168 
169 
170 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
171 
173 (
174  const topoSetSource::setAction action,
175  topoSet& set
176 ) const
177 {
178  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
179  {
180  Info<< " Adding cells with center within rotated box " << endl;
181 
182  combine(set, true);
183  }
184  else if (action == topoSetSource::DELETE)
185  {
186  Info<< " Removing cells with center within rotated box " << endl;
187 
188  combine(set, false);
189  }
190 }
191 
192 
193 // ************************************************************************* //
Foam::topoSetSource::ADD
@ ADD
Definition: topoSetSource.H:87
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::ListListOps::combine
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:100
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::rotatedBoxToCell::usage_
static addToUsageTable usage_
Add usage string.
Definition: rotatedBoxToCell.H:68
Foam::rotatedBoxToCell::j_
const vector j_
Definition: rotatedBoxToCell.H:74
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Foam::topoSetSource::NEW
@ NEW
Definition: topoSetSource.H:85
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::rotatedBoxToCell::~rotatedBoxToCell
virtual ~rotatedBoxToCell()
Destructor.
Definition: rotatedBoxToCell.C:166
Foam::rotatedBoxToCell::i_
const vector i_
Definition: rotatedBoxToCell.H:73
Foam::rotatedBoxToCell::origin_
const vector origin_
Skewed box.
Definition: rotatedBoxToCell.H:72
cellModeller.H
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Info
messageStream Info
Foam::cellModeller::lookup
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or NULL.
Definition: cellModeller.C:91
Foam::topoSetSource::DELETE
@ DELETE
Definition: topoSetSource.H:88
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:870
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::cellShape
An analytical geometric cellShape.
Definition: cellShape.H:69
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
Foam::hex
IOstream & hex(IOstream &io)
Definition: IOstream.H:564
rotatedBoxToCell.H
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:211
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::rotatedBoxToCell::combine
void combine(topoSet &set, const bool add) const
Definition: rotatedBoxToCell.C:57
Foam::rotatedBoxToCell::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: rotatedBoxToCell.C:173
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::rotatedBoxToCell::k_
const vector k_
Definition: rotatedBoxToCell.H:75
Foam::cellModel
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
Definition: cellModel.H:64
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Definition: topoSetSource.H:126
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label cellI, const bool) const
Add (if bool) cellI to set or delete cellI from set.
Definition: topoSetSource.C:140
Foam::rotatedBoxToCell::rotatedBoxToCell
rotatedBoxToCell(const polyMesh &mesh, const vector &origin, const vector &i, const vector &j, const vector &k)
Construct from components.
Definition: rotatedBoxToCell.C:122