rotatedBoxToCell.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(rotatedBoxToCell, 0);
36  addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, word);
37  addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, istream);
38 }
39 
40 
41 Foam::topoSetSource::addToUsageTable Foam::rotatedBoxToCell::usage_
42 (
43  rotatedBoxToCell::typeName,
44  "\n Usage: rotatedBoxToCell (originx originy originz)"
45  " (ix iy iz) (jx jy jz) (kx ky kz)\n\n"
46  " Select all cells with cellCentre within parallelepiped\n\n"
47 );
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 void Foam::rotatedBoxToCell::combine(topoSet& set, const bool add) const
53 {
54  // Define a cell for the box
55  pointField boxPoints(8);
56  boxPoints[0] = origin_;
57  boxPoints[1] = origin_ + i_;
58  boxPoints[2] = origin_ + i_ + j_;
59  boxPoints[3] = origin_ + j_;
60  boxPoints[4] = origin_ + k_;
61  boxPoints[5] = origin_ + k_ + i_;
62  boxPoints[6] = origin_ + k_ + i_ + j_;
63  boxPoints[7] = origin_ + k_ + j_;
64 
65  labelList boxVerts(8);
66  forAll(boxVerts, i)
67  {
68  boxVerts[i] = i;
69  }
70 
71  const cellModel& hex = *(cellModeller::lookup("hex"));
72 
73  // Get outwards pointing faces.
74  faceList boxFaces(cellShape(hex, boxVerts).faces());
75 
76  // Precalculate normals
77  vectorField boxFaceNormals(boxFaces.size());
78  forAll(boxFaces, i)
79  {
80  boxFaceNormals[i] = boxFaces[i].area(boxPoints);
81  }
82 
83  // Check whether cell centre is inside all faces of box.
84 
85  const pointField& ctrs = mesh_.cellCentres();
86 
87  forAll(ctrs, celli)
88  {
89  bool inside = true;
90 
91  forAll(boxFaces, i)
92  {
93  const face& f = boxFaces[i];
94 
95  if (((ctrs[celli] - boxPoints[f[0]]) & boxFaceNormals[i]) > 0)
96  {
97  inside = false;
98  break;
99  }
100  }
101 
102  if (inside)
103  {
104  addOrDelete(set, celli, add);
105  }
106  }
107 }
108 
109 
110 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
111 
113 (
114  const polyMesh& mesh,
115  const vector& origin,
116  const vector& i,
117  const vector& j,
118  const vector& k
119 )
120 :
121  topoSetSource(mesh),
122  origin_(origin),
123  i_(i),
124  j_(j),
125  k_(k)
126 {}
127 
128 
130 (
131  const polyMesh& mesh,
132  const dictionary& dict
133 )
134 :
135  topoSetSource(mesh),
136  origin_(dict.lookup("origin")),
137  i_(dict.lookup("i")),
138  j_(dict.lookup("j")),
139  k_(dict.lookup("k"))
140 {}
141 
142 
144 :
145  topoSetSource(mesh),
146  origin_(is),
147  i_(is),
148  j_(is),
149  k_(is)
150 {}
151 
152 
153 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
154 
156 {}
157 
158 
159 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 
162 (
163  const topoSetSource::setAction action,
164  topoSet& set
165 ) const
166 {
167  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
168  {
169  Info<< " Adding cells with center within rotated box " << endl;
170 
171  combine(set, true);
172  }
173  else if (action == topoSetSource::DELETE)
174  {
175  Info<< " Removing cells with center within rotated box " << endl;
176 
177  combine(set, false);
178  }
179 }
180 
181 
182 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
Definition: cellModeller.C:100
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
List< label > labelList
A List of labels.
Definition: labelList.H:56
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Class with constructor to add usage string to table.
messageStream Info
Field< vector > vectorField
Specialisation of Field<T> for vector.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual ~rotatedBoxToCell()
Destructor.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844
rotatedBoxToCell(const polyMesh &mesh, const vector &origin, const vector &i, const vector &j, const vector &k)
Construct from components.