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 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 {
36  defineTypeNameAndDebug(rotatedBoxToFace, 0);
37  addToRunTimeSelectionTable(topoSetSource, rotatedBoxToFace, word);
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(dict.lookupOrDefault<vector>("centre", bb.midpoint()));
138  const vector n1(normalised(dict.lookup<vector>("n1")));
139  const vector n2(normalised(dict.lookup<vector>("n2")));
140 
141  const tensor R(rotationTensor(n1, n2));
142  const pointField bbPoints(bb.points());
143 
144  origin_ = (R & (bb.min() - c)) + c;
145  i_ = R & (bbPoints[1] - bb.min());
146  j_ = R & (bbPoints[3] - bb.min());
147  k_ = R & (bbPoints[4] - bb.min());
148  }
149  else
150  {
151  origin_ = dict.lookup<point>("origin");
152  i_ = dict.lookup<vector>("i");
153  j_ = dict.lookup<vector>("j");
154  k_ = dict.lookup<vector>("k");
155  }
156 }
157 
158 
159 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
160 
162 {}
163 
164 
165 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
166 
168 (
169  const topoSetSource::setAction action,
170  topoSet& set
171 ) const
172 {
173  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
174  {
175  Info<< " Adding faces with center within rotated box " << endl;
176 
177  combine(set, true);
178  }
179  else if (action == topoSetSource::DELETE)
180  {
181  Info<< " Removing faces with center within rotated box " << endl;
182 
183  combine(set, false);
184  }
185 }
186 
187 
188 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:663
#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
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
rotatedBoxToFace(const polyMesh &mesh, const vector &origin, const vector &i, const vector &j, const vector &k)
Construct from components.
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from unit vector n1 to n2.
Definition: transform.H:47
const dimensionedScalar c
Speed of light in a vacuum.
Macros for easy insertion into run-time selection tables.
virtual ~rotatedBoxToFace()
Destructor.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Form normalised(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:413
3D tensor transformation operations.
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
List< label > labelList
A List of labels.
Definition: labelList.H:56
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
#define R(A, B, C, D, E, F, K, M)
messageStream Info
Field< vector > vectorField
Specialisation of Field<T> for vector.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
Namespace for OpenFOAM.
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:77
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864