path.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) 2025 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 "path.H"
27 #include "edgeMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace extrudeModels
35 {
38 }
39 }
40 
41 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
42 
43 Foam::vector Foam::extrudeModels::path::orthogonal(const vector& dirn)
44 {
45  scalar maxOrthogonality = -1;
46  direction maxOrthogonalityDir = 0;
47 
48  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
49  {
50  vector dir(Zero);
51  dir[cmpt] = 1;
52 
53  const scalar orthogonality = magSqr(dir ^ dirn);
54 
55  if (orthogonality > maxOrthogonality)
56  {
57  maxOrthogonality = orthogonality;
58  maxOrthogonalityDir = cmpt;
59  }
60  }
61 
62  vector dir(Zero);
63  dir[maxOrthogonalityDir] = 1;
64 
65  return dir;
66 }
67 
68 
69 Foam::tensor Foam::extrudeModels::path::orthonormalBasis
70 (
71  const vector& T,
72  const vector& N
73 )
74 {
75  const vector B(normalised(T ^ N));
76  const vector TNT(normalised(B ^ T));
77 
78  return tensor
79  (
80  T.x(), TNT.x(), B.x(),
81  T.y(), TNT.y(), B.y(),
82  T.z(), TNT.z(), B.z()
83  );
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
90 :
92  eMeshPtr_(edgeMesh::New(dict.lookup("path"))),
93  distances_(eMeshPtr_->points().size(), scalar(0)),
94  directions_(distances_.size()),
95  normals_(directions_.size()),
96  R0T_(Zero)
97 {
98  const pointField& points = eMeshPtr_->points();
99 
100  directions_[0] = normalised(points[1] - points[0]);
101  normals_[0] = orthogonal(directions_[0]);
102 
103  for (label i = 0; i < distances_.size() - 1; i++)
104  {
105  const vector d(points[i + 1] - points[i]);
106 
107  distances_[i + 1] = distances_[i] + mag(d);
108  directions_[i + 1] = normalised(d);
109  normals_[i + 1] =
110  normals_[i] - 2*(directions_[i] & normals_[i])*directions_[i];
111  }
112 
113  R0T_ = orthonormalBasis(directions_.first(), normals_.first()).T();
114 }
115 
116 
117 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
118 
120 {}
121 
122 
123 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
124 
125 Foam::label Foam::extrudeModels::path::findFrameIndex
126 (
127  const scalar distance
128 ) const
129 {
130  forAll(distances_, i)
131  {
132  if (distances_[i] <= distance && distance < distances_[i + 1])
133  {
134  return i;
135  }
136  }
137 
138  return distances_.size() - 1;
139 }
140 
141 
142 // * * * * * * * * * * * * * * * * Operators * * * * * * * * * * * * * * * * //
143 
144 Foam::point Foam::extrudeModels::path::operator()
145 (
146  const point& surfacePoint,
147  const vector& surfaceNormal,
148  const label layer
149 ) const
150 {
151  const pointField& points = eMeshPtr_->points();
152 
153  const scalar d = sumThickness(layer)*distances_.last();
154  const label frame = findFrameIndex(d);
155 
156  vector localCoords(R0T_ & (surfacePoint - points.first()));
157  localCoords.x() = 0;
158 
159  const tensor R(orthonormalBasis( directions_[frame], normals_[frame]));
160 
161  return
162  (
163  points[frame]
164  + directions_[frame]*(d - distances_[frame])
165  + (R & localCoords)
166  );
167 }
168 
169 
170 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Macros for easy insertion into run-time selection tables.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Tensor< Cmpt > T() const
Return transpose.
Definition: TensorI.H:331
T & first()
Return the first element of the list.
Definition: UListI.H:114
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:105
const Cmpt & x() const
Definition: VectorI.H:75
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Points connected by edges.
Definition: edgeMesh.H:72
Top level extrusion model class.
Definition: extrudeModel.H:52
Extrudes by transforming points along an curve defined as an edgeMesh.
Definition: path.H:62
virtual ~path()
Destructor.
Definition: path.C:119
path(const dictionary &dict)
Construct from dictionary.
Definition: path.C:89
const pointField & points
defineTypeNameAndDebug(cyclicSector, 0)
addToRunTimeSelectionTable(extrudeModel, cyclicSector, dictionary)
static const coefficient B("B", dimless, 18.678)
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:51
void T(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1)
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
dimensionSet normalised(const dimensionSet &)
Definition: dimensionSet.C:507
static scalar R(const scalar a, const scalar x)
Definition: invIncGamma.C:102
void magSqr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
uint8_t direction
Definition: direction.H:45
dictionary dict