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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "rotatedBoxToCell.H"
30 #include "polyMesh.H"
31 #include "hexCell.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(rotatedBoxToCell, 0);
39  addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, word);
40  addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, istream);
41  addToRunTimeSelectionTable(topoSetCellSource, rotatedBoxToCell, word);
42  addToRunTimeSelectionTable(topoSetCellSource, rotatedBoxToCell, istream);
44  (
45  topoSetCellSource,
46  rotatedBoxToCell,
47  word,
48  rotatedBox
49  );
51  (
52  topoSetCellSource,
53  rotatedBoxToCell,
54  istream,
55  rotatedBox
56  );
57 }
58 
59 
60 Foam::topoSetSource::addToUsageTable Foam::rotatedBoxToCell::usage_
61 (
62  rotatedBoxToCell::typeName,
63  "\n Usage: rotatedBoxToCell (originx originy originz)"
64  " (ix iy iz) (jx jy jz) (kx ky kz)\n\n"
65  " Select all cells with cellCentre within parallelopiped\n\n"
66 );
67 
68 
69 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
70 
71 void Foam::rotatedBoxToCell::combine(topoSet& set, const bool add) const
72 {
73  // Define a cell for the box
74  pointField boxPoints(8, origin_);
75  // boxPoints[0] = origin_;
76  boxPoints[1] += i_;
77  boxPoints[2] += i_ + j_;
78  boxPoints[3] += j_;
79  boxPoints[4] += k_;
80  boxPoints[5] += k_ + i_;
81  boxPoints[6] += k_ + i_ + j_;
82  boxPoints[7] += k_ + j_;
83 
84  // Get outwards pointing faces.
85  faceList boxFaces(hexCell::modelFaces());
86 
87  // Precalculate normals
88  vectorField boxFaceNormals(boxFaces.size());
89  forAll(boxFaces, i)
90  {
91  boxFaceNormals[i] = boxFaces[i].areaNormal(boxPoints);
92 
93  //Pout<< "Face:" << i << " position:" << boxFaces[i].centre(boxPoints)
94  // << " normal:" << boxFaceNormals[i] << endl;
95  }
96 
97  // Check whether cell centre is inside all faces of box.
98 
99  const tmp<pointField> tctrs(this->transform(mesh_.cellCentres()));
100  const pointField& ctrs = tctrs();
101 
102  forAll(ctrs, celli)
103  {
104  bool inside = true;
105 
106  forAll(boxFaces, i)
107  {
108  const face& f = boxFaces[i];
109 
110  if (((ctrs[celli] - boxPoints[f[0]]) & boxFaceNormals[i]) > 0)
111  {
112  inside = false;
113  break;
114  }
115  }
116 
117  if (inside)
118  {
119  addOrDelete(set, celli, add);
120  }
121  }
122 }
123 
124 
125 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
126 
128 (
129  const polyMesh& mesh,
130  const vector& origin,
131  const vector& i,
132  const vector& j,
133  const vector& k
134 )
135 :
136  topoSetCellSource(mesh),
137  origin_(origin),
138  i_(i),
139  j_(j),
140  k_(k)
141 {}
142 
143 
145 (
146  const polyMesh& mesh,
147  const dictionary& dict
148 )
149 :
151  origin_(dict.get<point>("origin")),
152  i_(dict.get<vector>("i")),
153  j_(dict.get<vector>("j")),
154  k_(dict.get<vector>("k"))
155 {}
156 
157 
159 :
161  origin_(is),
162  i_(is),
163  j_(is),
164  k_(is)
165 {}
166 
167 
168 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
169 
171 (
172  const topoSetSource::setAction action,
173  topoSet& set
174 ) const
175 {
176  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
177  {
178  if (verbose_)
179  {
180  Info<< " Adding cells with centre within rotated box"
181  << endl;
182  }
183 
184  combine(set, true);
185  }
186  else if (action == topoSetSource::SUBTRACT)
187  {
188  if (verbose_)
189  {
190  Info<< " Removing cells with centre within rotated box"
191  << endl;
192  }
193 
194  combine(set, false);
195  }
196 }
197 
198 
199 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Create a new set and ADD elements to it.
Add elements to current set.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static const Foam::faceList & modelFaces()
Return the model faces.
Definition: hexCell.C:64
label k
Boltzmann constant.
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells...
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when &#39;add&#39; is true.
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
List< face > faceList
List of faces.
Definition: faceListFwd.H:39
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:62
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
setAction
Enumeration defining various actions.
Vector< scalar > vector
Definition: vector.H:57
const vectorField & cellCentres() const
const polyMesh & mesh_
Reference to the mesh.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
Subtract elements from current set.
Class with constructor to add usage string to table.
tmp< pointField > transform(const pointField &points) const
Coordinate transform (optionally) coordinates. Returns reference to input data if no transform is act...
messageStream Info
Information stream (stdout output on master, null elsewhere)
Field< vector > vectorField
Specialisation of Field<T> for vector.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
rotatedBoxToCell(const polyMesh &mesh, const vector &origin, const vector &i, const vector &j, const vector &k)
Construct from components.