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 pointField& ctrs = mesh_.cellCentres();
100 
101  forAll(ctrs, celli)
102  {
103  bool inside = true;
104 
105  forAll(boxFaces, i)
106  {
107  const face& f = boxFaces[i];
108 
109  if (((ctrs[celli] - boxPoints[f[0]]) & boxFaceNormals[i]) > 0)
110  {
111  inside = false;
112  break;
113  }
114  }
115 
116  if (inside)
117  {
118  addOrDelete(set, celli, add);
119  }
120  }
121 }
122 
123 
124 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
125 
127 (
128  const polyMesh& mesh,
129  const vector& origin,
130  const vector& i,
131  const vector& j,
132  const vector& k
133 )
134 :
135  topoSetCellSource(mesh),
136  origin_(origin),
137  i_(i),
138  j_(j),
139  k_(k)
140 {}
141 
142 
144 (
145  const polyMesh& mesh,
146  const dictionary& dict
147 )
148 :
150  (
151  mesh,
152  dict.get<point>("origin"),
153  dict.get<vector>("i"),
154  dict.get<vector>("j"),
155  dict.get<vector>("k")
156  )
157 {}
158 
159 
161 :
163  origin_(is),
164  i_(is),
165  j_(is),
166  k_(is)
167 {}
168 
169 
170 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
171 
173 (
174  const topoSetSource::setAction action,
175  topoSet& set
176 ) const
177 {
178  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
179  {
180  if (verbose_)
181  {
182  Info<< " Adding cells with centre within rotated box"
183  << endl;
184  }
185 
186  combine(set, true);
187  }
188  else if (action == topoSetSource::SUBTRACT)
189  {
190  if (verbose_)
191  {
192  Info<< " Removing cells with centre within rotated box"
193  << endl;
194  }
195 
196  combine(set, false);
197  }
198 }
199 
200 
201 // ************************************************************************* //
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
A topoSetCellSource to select cells based on cell centres inside a given parallopiped (i...
Subtract elements from current set.
Class with constructor to add usage string to table.
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:74
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.