trackingI.H
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) 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 "tracking.H"
27 #include "tetIndices.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace tracking
34 {
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 // Tetrahedra
39 
40  //- Get the vertices of the current tet
41  inline void stationaryTetGeometry
42  (
43  const polyMesh& mesh,
44  const label celli,
45  const label facei,
46  const label faceTrii,
47  vector& centre,
48  vector& base,
49  vector& vertex1,
50  vector& vertex2
51  );
52 
53  //- Get the transformation associated with the current tet. This
54  // will convert a barycentric position within the tet to a
55  // cartesian position in the global coordinate system. The
56  // conversion is x = A & y, where x is the cartesian position, y is
57  // the barycentric position and A is the transformation tensor.
59  (
60  const polyMesh& mesh,
61  const label celli,
62  const label facei,
63  const label faceTrii
64  );
65 
66  //- Get the vertices of the current moving tet. Two values are
67  // returned for each vertex. The first is a constant, and the
68  // second is a linear coefficient of the track fraction.
69  inline void movingTetGeometry
70  (
71  const polyMesh& mesh,
72  const label celli,
73  const label facei,
74  const label faceTrii,
75  const scalar startStepFraction,
76  const scalar endStepFraction,
77  Pair<vector>& centre,
78  Pair<vector>& base,
79  Pair<vector>& vertex1,
80  Pair<vector>& vertex2
81  );
82 
83  //- Get the transformation associated with the current, moving, tet.
84  // This is of the same form as for the static case. As with the
85  // moving geometry, a linear function of the tracking fraction is
86  // returned for each component.
87  inline Pair<barycentricTensor> movingTetTransform
88  (
89  const polyMesh& mesh,
90  const label celli,
91  const label facei,
92  const label faceTrii,
93  const scalar startStepFraction,
94  const scalar endStepFraction
95  );
96 
97 
98 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
99 
100 } // End namespace tracking
101 } // End namespace Foam
102 
103 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104 
106 (
107  const polyMesh& mesh,
108  const label celli,
109  const label facei,
110  const label faceTrii,
111  vector& centre,
112  vector& base,
113  vector& vertex1,
114  vector& vertex2
115 )
116 {
117  const triFace triIs(tetIndices(celli, facei, faceTrii).faceTriIs(mesh));
118  const vectorField& ccs = mesh.cellCentres();
119  const pointField& pts = mesh.points();
120 
121  centre = ccs[celli];
122  base = pts[triIs[0]];
123  vertex1 = pts[triIs[1]];
124  vertex2 = pts[triIs[2]];
125 }
126 
127 
129 (
130  const polyMesh& mesh,
131  const label celli,
132  const label facei,
133  const label faceTrii
134 )
135 {
136  vector centre, base, vertex1, vertex2;
138  (
139  mesh,
140  celli,
141  facei,
142  faceTrii,
143  centre,
144  base,
145  vertex1,
146  vertex2
147  );
148 
149  return barycentricTensor(centre, base, vertex1, vertex2);
150 }
151 
152 
154 (
155  const polyMesh& mesh,
156  const label celli,
157  const label facei,
158  const label faceTrii,
159  const scalar startStepFraction,
160  const scalar endStepFraction,
161  Pair<vector>& centre,
162  Pair<vector>& base,
163  Pair<vector>& vertex1,
164  Pair<vector>& vertex2
165 )
166 {
167  const triFace triIs(tetIndices(celli, facei, faceTrii).faceTriIs(mesh));
168  const pointField& ptsOld = mesh.oldPoints();
169  const pointField& ptsNew = mesh.points();
170  const vector ccOld = mesh.oldCellCentres()[celli];
171  const vector ccNew = mesh.cellCentres()[celli];
172 
173  const scalar f0 = startStepFraction, f1 = endStepFraction;
174 
175  centre[0] = ccOld + f0*(ccNew - ccOld);
176  base[0] = ptsOld[triIs[0]] + f0*(ptsNew[triIs[0]] - ptsOld[triIs[0]]);
177  vertex1[0] = ptsOld[triIs[1]] + f0*(ptsNew[triIs[1]] - ptsOld[triIs[1]]);
178  vertex2[0] = ptsOld[triIs[2]] + f0*(ptsNew[triIs[2]] - ptsOld[triIs[2]]);
179 
180  centre[1] = f1*(ccNew - ccOld);
181  base[1] = f1*(ptsNew[triIs[0]] - ptsOld[triIs[0]]);
182  vertex1[1] = f1*(ptsNew[triIs[1]] - ptsOld[triIs[1]]);
183  vertex2[1] = f1*(ptsNew[triIs[2]] - ptsOld[triIs[2]]);
184 }
185 
186 
188 (
189  const polyMesh& mesh,
190  const label celli,
191  const label facei,
192  const label faceTrii,
193  const scalar startStepFraction,
194  const scalar endStepFraction
195 )
196 {
197  Pair<vector> centre, base, vertex1, vertex2;
199  (
200  mesh,
201  celli,
202  facei,
203  faceTrii,
204  startStepFraction,
205  endStepFraction,
206  centre,
207  base,
208  vertex1,
209  vertex2
210  );
211 
212  return
214  (
215  barycentricTensor(centre[0], base[0], vertex1[0], vertex2[0]),
216  barycentricTensor(centre[1], base[1], vertex1[1], vertex2[1])
217  );
218 }
219 
220 
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 
224 (
225  const polyMesh& mesh,
226  const barycentric& coordinates,
227  const label celli,
228  const label facei,
229  const label faceTrii,
230  const scalar stepFraction
231 )
232 {
233  if (mesh.moving() && stepFraction != 1)
234  {
235  return
236  movingTetTransform(mesh, celli, facei, faceTrii, stepFraction, 1)[0]
237  & coordinates;
238  }
239  else
240  {
241  return
242  stationaryTetTransform(mesh, celli, facei, faceTrii)
243  & coordinates;
244  }
245 }
246 
247 
248 // ************************************************************************* //
Templated 4x3 tensor derived from VectorSpace. Has 12 components. Can represent a barycentric transfo...
An ordered pair of two objects of type <Type> with first() and second() elements.
Definition: Pair.H:66
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
virtual const pointField & oldPoints() const
Return old points for mesh motion.
Definition: polyMesh.C:1369
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1331
virtual const pointField & oldCellCentres() const
Return old cell centres for mesh motion.
Definition: polyMesh.C:1387
bool moving() const
Is mesh moving.
Definition: polyMesh.H:473
const vectorField & cellCentres() const
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
Definition: tetIndices.H:82
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:71
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
barycentric coordinates(const polyMesh &mesh, const point &position, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the coordinates given the position and tet topology.
Definition: tracking.C:1259
void stationaryTetGeometry(const polyMesh &mesh, const label celli, const label facei, const label faceTrii, vector &centre, vector &base, vector &vertex1, vector &vertex2)
Get the vertices of the current tet.
Definition: trackingI.H:106
barycentricTensor stationaryTetTransform(const polyMesh &mesh, const label celli, const label facei, const label faceTrii)
Get the transformation associated with the current tet. This.
Definition: trackingI.H:129
void movingTetGeometry(const polyMesh &mesh, const label celli, const label facei, const label faceTrii, const scalar startStepFraction, const scalar endStepFraction, Pair< vector > &centre, Pair< vector > &base, Pair< vector > &vertex1, Pair< vector > &vertex2)
Get the vertices of the current moving tet. Two values are.
Definition: trackingI.H:154
Pair< barycentricTensor > movingTetTransform(const polyMesh &mesh, const label celli, const label facei, const label faceTrii, const scalar startStepFraction, const scalar endStepFraction)
Get the transformation associated with the current, moving, tet.
Definition: trackingI.H:188
point position(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the position given the coordinates and tet topology.
Definition: trackingI.H:224
Namespace for OpenFOAM.
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
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
BarycentricTensor< scalar > barycentricTensor
A scalar version of the templated BarycentricTensor.