triIntersectTemplates.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) 2021-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 "triIntersect.H"
27 #include "vtkWritePolyData.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 template<class PointField>
33 (
34  const word& name,
35  const PointField& ps
36 )
37 {
38  Info<< indent << "Writing face to " << name + ".vtk" << endl;
40  (
41  name + ".vtk",
42  name,
43  false,
44  ps,
45  labelList(),
46  labelListList(),
47  labelListList(1, identity(ps.size()))
48  );
49 }
50 
51 
52 template<class Type>
54 (
55  const barycentric2D& y,
56  const FixedList<Type, 3>& srcPsis
57 )
58 {
59  const label yMini = findMin(y);
60 
61  // Inside the triangle
62  if (y[yMini] >= 0)
63  {
64  return y[0]*srcPsis[0] + y[1]*srcPsis[1] + y[2]*srcPsis[2];
65  }
66 
67  barycentric2D z(y);
68  z[yMini] = vGreat;
69  const label yMidi = findMin(z);
70 
71  // Outside an edge
72  if (y[yMidi] >= 0)
73  {
74  const label yi0 = (yMini + 1) % 3, yi1 = (yi0 + 1) % 3;
75  return (y[yi0]*srcPsis[yi0] + y[yi1]*srcPsis[yi1])/(y[yi0] + y[yi1]);
76  }
77 
78  const label yMaxi = findMax(y);
79 
80  // Outside a corner
81  return srcPsis[yMaxi];
82 }
83 
84 
85 template<class Type>
87 (
88  const barycentric2D& y,
89  const FixedList<Type, 3>& tgtPsis
90 )
91 {
92  return y.a()*tgtPsis[0] + y.b()*tgtPsis[1] + y.c()*tgtPsis[2];
93 }
94 
95 
96 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const Cmpt & c() const
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
label findMin(const ListType &, const label start=0)
Find index of min element (and less than given element).
const Cmpt & a() const
Templated 2D Barycentric derived from VectorSpace. Has 3 components, one of which is redundant...
Definition: Barycentric2D.H:50
A class for handling words, derived from string.
Definition: word.H:59
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
List< label > labelList
A List of labels.
Definition: labelList.H:56
Type tgtTriInterpolate(const barycentric2D &y, const FixedList< Type, 3 > &tgtPsis)
Use the coordinates obtained from srcPointTgtTriIntersection to interpolate.
label findMax(const ListType &, const label start=0)
Find index of max element (and larger than given element).
Type srcTriInterpolate(const barycentric2D &y, const FixedList< Type, 3 > &tgtPsis)
Use the coordinates obtained from srcTriTgtPointIntersection to interpolate.
void writePolygon(const word &name, const PointField &ps)
Write a VTK file of a polygon.
messageStream Info
const Cmpt & b() const
Functions with which to perform an intersection of a pair of triangles; the source and target...