rotatedBoxToFace.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) 2022-2024 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 "rotatedBoxToFace.H"
27 #include "polyMesh.H"
28 #include "cellModeller.H"
29 #include "transform.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
38 }
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 void Foam::rotatedBoxToFace::combine(topoSet& set, const bool add) const
44 {
45  // Define a cell for the box
46  const pointField boxPoints
47  (
48  {
49  origin_,
50  origin_ + i_,
51  origin_ + i_ + j_,
52  origin_ + j_,
53  origin_ + k_,
54  origin_ + k_ + i_,
55  origin_ + k_ + i_ + j_,
56  origin_ + k_ + j_
57  }
58  );
59 
60  const labelList boxVerts({0, 1, 2, 3, 4, 5, 6, 7});
61 
62  const cellModel& hex = *(cellModeller::lookup("hex"));
63 
64  // Get outwards pointing faces.
65  const faceList boxFaces(cellShape(hex, boxVerts).faces());
66 
67  // Precalculate normals
68  vectorField boxFaceNormals(boxFaces.size());
69  forAll(boxFaces, i)
70  {
71  boxFaceNormals[i] = boxFaces[i].area(boxPoints);
72  }
73 
74  // Check whether face centre is inside all faces of box.
75 
76  const pointField& ctrs = mesh_.faceCentres();
77 
78  forAll(ctrs, facei)
79  {
80  bool inside = true;
81 
82  forAll(boxFaces, i)
83  {
84  if
85  (
86  ((ctrs[facei] - boxPoints[boxFaces[i][0]]) & boxFaceNormals[i])
87  > 0
88  )
89  {
90  inside = false;
91  break;
92  }
93  }
94 
95  if (inside)
96  {
97  addOrDelete(set, facei, add);
98  }
99  }
100 }
101 
102 
103 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
104 
106 (
107  const polyMesh& mesh,
108  const vector& origin,
109  const vector& i,
110  const vector& j,
111  const vector& k
112 )
113 :
114  topoSetSource(mesh),
115  origin_(origin),
116  i_(i),
117  j_(j),
118  k_(k)
119 {}
120 
121 
123 (
124  const polyMesh& mesh,
125  const dictionary& dict
126 )
127 :
128  topoSetSource(mesh),
129  origin_(),
130  i_(),
131  j_(),
132  k_()
133 {
134  if (dict.found("box"))
135  {
136  const boundBox bb(dict.lookup("box"));
137  const vector c
138  (
139  dict.lookupOrDefault<point>("centre", dimLength, bb.midpoint())
140  );
141  const vector n1(normalised(dict.lookup<vector>("n1", dimless)));
142  const vector n2(normalised(dict.lookup<vector>("n2", dimless)));
143 
144  const tensor R(rotationTensor(n1, n2));
145  const pointField bbPoints(bb.points());
146 
147  origin_ = (R & (bb.min() - c)) + c;
148  i_ = R & (bbPoints[1] - bb.min());
149  j_ = R & (bbPoints[3] - bb.min());
150  k_ = R & (bbPoints[4] - bb.min());
151  }
152  else
153  {
154  origin_ = dict.lookup<point>("origin", dimLength);
155  i_ = dict.lookup<vector>("i", dimLength);
156  j_ = dict.lookup<vector>("j", dimLength);
157  k_ = dict.lookup<vector>("k", dimLength);
158  }
159 }
160 
161 
162 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
163 
165 {}
166 
167 
168 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
169 
171 (
172  const topoSetSource::setAction action,
173  topoSet& set
174 ) const
175 {
176  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
177  {
178  Info<< " Adding faces with center within rotated box " << endl;
179 
180  combine(set, true);
181  }
182  else if (action == topoSetSource::DELETE)
183  {
184  Info<< " Removing faces with center within rotated box " << endl;
185 
186  combine(set, false);
187  }
188 }
189 
190 
191 // ************************************************************************* //
label k
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:59
const point & min() const
Minimum point defining the bounding box.
Definition: boundBoxI.H:60
point midpoint() const
The midpoint of the bounding box.
Definition: boundBoxI.H:84
tmp< pointField > points() const
Return corner points in an order corresponding to a 'hex' cell.
Definition: boundBox.C:138
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:162
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const vectorField & faceCentres() const
A topoSetSource to select faces based on cell centres inside a rotated and/or skewed box.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
virtual ~rotatedBoxToFace()
Destructor.
rotatedBoxToFace(const polyMesh &mesh, const vector &origin, const vector &i, const vector &j, const vector &k)
Construct from components.
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
Definition: topoSetSource.C:96
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:65
A class for handling words, derived from string.
Definition: word.H:62
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for OpenFOAM.
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from unit vector n1 to n2.
Definition: transform.H:47
List< label > labelList
A List of labels.
Definition: labelList.H:56
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
const dimensionSet dimless
IOstream & hex(IOstream &io)
Definition: IOstream.H:561
messageStream Info
const dimensionSet dimLength
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensionSet normalised(const dimensionSet &)
Definition: dimensionSet.C:510
defineTypeNameAndDebug(combustionModel, 0)
Field< vector > vectorField
Specialisation of Field<T> for vector.
static scalar R(const scalar a, const scalar x)
Definition: invIncGamma.C:102
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
List< face > faceList
Definition: faceListFwd.H:41
dictionary dict
3D tensor transformation operations.