tetrahedron: triangle: Improved barycentric handling on tets and tris
Updated the tetrahedron and triangle classes to use the barycentric primitives. Removed duplicate code for generating random positions in tets and tris, and fixed bug in tri random position.
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -97,7 +97,7 @@ Foam::scalarField Foam::cellShapeControl::cellSize
|
||||
|
||||
Foam::scalar Foam::cellShapeControl::cellSize(const point& pt) const
|
||||
{
|
||||
FixedList<scalar, 4> bary;
|
||||
barycentric bary;
|
||||
cellShapeControlMesh::Cell_handle ch;
|
||||
|
||||
shapeControlMesh_.barycentricCoords(pt, bary, ch);
|
||||
@ -172,7 +172,7 @@ Foam::scalar Foam::cellShapeControl::cellSize(const point& pt) const
|
||||
|
||||
Foam::tensor Foam::cellShapeControl::cellAlignment(const point& pt) const
|
||||
{
|
||||
FixedList<scalar, 4> bary;
|
||||
barycentric bary;
|
||||
cellShapeControlMesh::Cell_handle ch;
|
||||
|
||||
shapeControlMesh_.barycentricCoords(pt, bary, ch);
|
||||
@ -244,7 +244,7 @@ void Foam::cellShapeControl::cellSizeAndAlignment
|
||||
tensor& alignment
|
||||
) const
|
||||
{
|
||||
FixedList<scalar, 4> bary;
|
||||
barycentric bary;
|
||||
cellShapeControlMesh::Cell_handle ch;
|
||||
|
||||
shapeControlMesh_.barycentricCoords(pt, bary, ch);
|
||||
|
||||
@ -452,7 +452,7 @@ Foam::cellShapeControlMesh::~cellShapeControlMesh()
|
||||
void Foam::cellShapeControlMesh::barycentricCoords
|
||||
(
|
||||
const Foam::point& pt,
|
||||
FixedList<scalar, 4>& bary,
|
||||
barycentric& bary,
|
||||
Cell_handle& ch
|
||||
) const
|
||||
{
|
||||
@ -472,7 +472,7 @@ void Foam::cellShapeControlMesh::barycentricCoords
|
||||
topoint(ch->vertex(3)->point())
|
||||
);
|
||||
|
||||
tet.barycentric(pt, bary);
|
||||
bary = tet.pointToBarycentric(pt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -122,7 +122,7 @@ public:
|
||||
void barycentricCoords
|
||||
(
|
||||
const Foam::point& pt,
|
||||
FixedList<scalar, 4>& bary,
|
||||
barycentric& bary,
|
||||
Cell_handle& ch
|
||||
) const;
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -118,8 +118,7 @@ Foam::scalar Foam::nonUniformField::interpolate
|
||||
pts[faceHitByPt[2]]
|
||||
);
|
||||
|
||||
FixedList<scalar, 3> bary;
|
||||
tri.barycentric(pt, bary);
|
||||
const barycentric2D bary = tri.pointToBarycentric(pt);
|
||||
|
||||
// return pointCellSize_[pMap[faceHitByPt[0]]]*bary[0]
|
||||
// + pointCellSize_[pMap[faceHitByPt[1]]]*bary[1]
|
||||
|
||||
@ -129,6 +129,7 @@ primitives/polynomialEqns/cubicEqn/cubicEqn.C
|
||||
primitives/polynomialEqns/quadraticEqn/quadraticEqn.C
|
||||
|
||||
primitives/Barycentric/barycentric/barycentric.C
|
||||
primitives/Barycentric2D/barycentric2D/barycentric2D.C
|
||||
|
||||
containers/HashTables/HashTable/HashTableCore.C
|
||||
containers/HashTables/StaticHashTable/StaticHashTableCore.C
|
||||
|
||||
@ -48,6 +48,7 @@ SourceFiles
|
||||
#include "UList.H"
|
||||
#include "triPointRef.H"
|
||||
#include "boundBox.H"
|
||||
#include "barycentric.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -174,13 +175,18 @@ public:
|
||||
// uniform distribution
|
||||
inline Point randomPoint(cachedRandom& rndGen) const;
|
||||
|
||||
//- Calculate the barycentric coordinates of the given
|
||||
// point, in the same order as a, b, c, d. Returns the
|
||||
// determinant of the solution.
|
||||
inline scalar barycentric
|
||||
//- Calculate the point from the given barycentric coordinates.
|
||||
inline Point barycentricToPoint(const barycentric& bary) const;
|
||||
|
||||
//- Calculate the barycentric coordinates from the given point
|
||||
inline barycentric pointToBarycentric(const point& pt) const;
|
||||
|
||||
//- Calculate the barycentric coordinates from the given point.
|
||||
// Returns the determinant.
|
||||
inline scalar pointToBarycentric
|
||||
(
|
||||
const point& pt,
|
||||
FixedList<scalar, 4>& bary
|
||||
barycentric& bary
|
||||
) const;
|
||||
|
||||
//- Return nearest point to p on tetrahedron. Is p itself
|
||||
|
||||
@ -245,33 +245,7 @@ inline Point Foam::tetrahedron<Point, PointRef>::randomPoint
|
||||
Random& rndGen
|
||||
) const
|
||||
{
|
||||
// Adapted from
|
||||
// http://vcg.isti.cnr.it/activities/geometryegraphics/pointintetraedro.html
|
||||
|
||||
scalar s = rndGen.scalar01();
|
||||
scalar t = rndGen.scalar01();
|
||||
scalar u = rndGen.scalar01();
|
||||
|
||||
if (s + t > 1.0)
|
||||
{
|
||||
s = 1.0 - s;
|
||||
t = 1.0 - t;
|
||||
}
|
||||
|
||||
if (t + u > 1.0)
|
||||
{
|
||||
scalar tmp = u;
|
||||
u = 1.0 - s - t;
|
||||
t = 1.0 - tmp;
|
||||
}
|
||||
else if (s + t + u > 1.0)
|
||||
{
|
||||
scalar tmp = u;
|
||||
u = s + t + u - 1.0;
|
||||
s = 1.0 - t - tmp;
|
||||
}
|
||||
|
||||
return (1 - s - t - u)*a_ + s*b_ + t*c_ + u*d_;
|
||||
return barycentricToPoint(barycentric01(rndGen));
|
||||
}
|
||||
|
||||
|
||||
@ -281,41 +255,37 @@ inline Point Foam::tetrahedron<Point, PointRef>::randomPoint
|
||||
cachedRandom& rndGen
|
||||
) const
|
||||
{
|
||||
// Adapted from
|
||||
// http://vcg.isti.cnr.it/activities/geometryegraphics/pointintetraedro.html
|
||||
|
||||
scalar s = rndGen.sample01<scalar>();
|
||||
scalar t = rndGen.sample01<scalar>();
|
||||
scalar u = rndGen.sample01<scalar>();
|
||||
|
||||
if (s + t > 1.0)
|
||||
{
|
||||
s = 1.0 - s;
|
||||
t = 1.0 - t;
|
||||
}
|
||||
|
||||
if (t + u > 1.0)
|
||||
{
|
||||
scalar tmp = u;
|
||||
u = 1.0 - s - t;
|
||||
t = 1.0 - tmp;
|
||||
}
|
||||
else if (s + t + u > 1.0)
|
||||
{
|
||||
scalar tmp = u;
|
||||
u = s + t + u - 1.0;
|
||||
s = 1.0 - t - tmp;
|
||||
}
|
||||
|
||||
return (1 - s - t - u)*a_ + s*b_ + t*c_ + u*d_;
|
||||
return barycentricToPoint(barycentric01(rndGen));
|
||||
}
|
||||
|
||||
|
||||
template<class Point, class PointRef>
|
||||
Foam::scalar Foam::tetrahedron<Point, PointRef>::barycentric
|
||||
inline Point Foam::tetrahedron<Point, PointRef>::barycentricToPoint
|
||||
(
|
||||
const barycentric& bary
|
||||
) const
|
||||
{
|
||||
return bary[0]*a_ + bary[1]*b_ + bary[2]*c_ + bary[3]*d_;
|
||||
}
|
||||
|
||||
|
||||
template<class Point, class PointRef>
|
||||
inline Foam::barycentric Foam::tetrahedron<Point, PointRef>::pointToBarycentric
|
||||
(
|
||||
const point& pt
|
||||
) const
|
||||
{
|
||||
barycentric bary;
|
||||
pointToBarycentric(pt, bary);
|
||||
return bary;
|
||||
}
|
||||
|
||||
|
||||
template<class Point, class PointRef>
|
||||
inline Foam::scalar Foam::tetrahedron<Point, PointRef>::pointToBarycentric
|
||||
(
|
||||
const point& pt,
|
||||
FixedList<scalar, 4>& bary
|
||||
barycentric& bary
|
||||
) const
|
||||
{
|
||||
// Reference:
|
||||
@ -336,9 +306,9 @@ Foam::scalar Foam::tetrahedron<Point, PointRef>::barycentric
|
||||
|
||||
if (Foam::mag(detT) < SMALL)
|
||||
{
|
||||
// Degenerate tetrahedron, returning 1/4 barycentric coordinates.
|
||||
// Degenerate tetrahedron, returning 1/4 barycentric coordinates
|
||||
|
||||
bary = List<scalar>(4, 0.25);
|
||||
bary = barycentric(0.25, 0.25, 0.25, 0.25);
|
||||
|
||||
return detT;
|
||||
}
|
||||
@ -348,7 +318,7 @@ Foam::scalar Foam::tetrahedron<Point, PointRef>::barycentric
|
||||
bary[0] = res.x();
|
||||
bary[1] = res.y();
|
||||
bary[2] = res.z();
|
||||
bary[3] = (1.0 - res.x() - res.y() - res.z());
|
||||
bary[3] = 1 - cmptSum(res);
|
||||
|
||||
return detT;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -44,6 +44,7 @@ SourceFiles
|
||||
#include "FixedList.H"
|
||||
#include "UList.H"
|
||||
#include "linePointRef.H"
|
||||
#include "barycentric2D.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -167,13 +168,18 @@ public:
|
||||
// distribution
|
||||
inline Point randomPoint(cachedRandom& rndGen) const;
|
||||
|
||||
//- Calculate the barycentric coordinates of the given
|
||||
// point, in the same order as a, b, c. Returns the
|
||||
// determinant of the solution.
|
||||
inline scalar barycentric
|
||||
//- Calculate the point from the given barycentric coordinates.
|
||||
inline Point barycentricToPoint(const barycentric2D& bary) const;
|
||||
|
||||
//- Calculate the barycentric coordinates from the given point
|
||||
inline barycentric2D pointToBarycentric(const point& pt) const;
|
||||
|
||||
//- Calculate the barycentric coordinates from the given point.
|
||||
// Returns the determinant.
|
||||
inline scalar pointToBarycentric
|
||||
(
|
||||
const point& pt,
|
||||
FixedList<scalar, 3>& bary
|
||||
barycentric2D& bary
|
||||
) const;
|
||||
|
||||
//- Return point intersection with a ray.
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -231,16 +231,7 @@ inline Foam::tensor Foam::triangle<Point, PointRef>::inertia
|
||||
template<class Point, class PointRef>
|
||||
inline Point Foam::triangle<Point, PointRef>::randomPoint(Random& rndGen) const
|
||||
{
|
||||
// Generating Random Points in Triangles
|
||||
// by Greg Turk
|
||||
// from "Graphics Gems", Academic Press, 1990
|
||||
// http://tog.acm.org/GraphicsGems/gems/TriPoints.c
|
||||
|
||||
scalar s = rndGen.scalar01();
|
||||
|
||||
scalar t = sqrt(rndGen.scalar01());
|
||||
|
||||
return (1 - t)*a_ + (1 - s)*t*b_ + s*t*c_;
|
||||
return barycentricToPoint(barycentric2D01(rndGen));
|
||||
}
|
||||
|
||||
|
||||
@ -250,24 +241,37 @@ inline Point Foam::triangle<Point, PointRef>::randomPoint
|
||||
cachedRandom& rndGen
|
||||
) const
|
||||
{
|
||||
// Generating Random Points in Triangles
|
||||
// by Greg Turk
|
||||
// from "Graphics Gems", Academic Press, 1990
|
||||
// http://tog.acm.org/GraphicsGems/gems/TriPoints.c
|
||||
|
||||
scalar s = rndGen.sample01<scalar>();
|
||||
|
||||
scalar t = sqrt(rndGen.sample01<scalar>());
|
||||
|
||||
return (1 - t)*a_ + (1 - s)*t*b_ + s*t*c_;
|
||||
return barycentricToPoint(barycentric2D01(rndGen));
|
||||
}
|
||||
|
||||
|
||||
template<class Point, class PointRef>
|
||||
Foam::scalar Foam::triangle<Point, PointRef>::barycentric
|
||||
inline Point Foam::triangle<Point, PointRef>::barycentricToPoint
|
||||
(
|
||||
const barycentric2D& bary
|
||||
) const
|
||||
{
|
||||
return bary[0]*a_ + bary[1]*b_ + bary[2]*c_;
|
||||
}
|
||||
|
||||
|
||||
template<class Point, class PointRef>
|
||||
inline Foam::barycentric2D Foam::triangle<Point, PointRef>::pointToBarycentric
|
||||
(
|
||||
const point& pt
|
||||
) const
|
||||
{
|
||||
barycentric2D bary;
|
||||
pointToBarycentric(pt, bary);
|
||||
return bary;
|
||||
}
|
||||
|
||||
|
||||
template<class Point, class PointRef>
|
||||
inline Foam::scalar Foam::triangle<Point, PointRef>::pointToBarycentric
|
||||
(
|
||||
const point& pt,
|
||||
FixedList<scalar, 3>& bary
|
||||
barycentric2D& bary
|
||||
) const
|
||||
{
|
||||
// Reference:
|
||||
@ -289,7 +293,7 @@ Foam::scalar Foam::triangle<Point, PointRef>::barycentric
|
||||
{
|
||||
// Degenerate triangle, returning 1/3 barycentric coordinates.
|
||||
|
||||
bary = FixedList<scalar, 3>(1.0/3.0);
|
||||
bary = barycentric2D(1.0/3.0, 1.0/3.0, 1.0/3.0);
|
||||
|
||||
return denom;
|
||||
}
|
||||
|
||||
114
src/OpenFOAM/primitives/Barycentric2D/Barycentric2D.H
Normal file
114
src/OpenFOAM/primitives/Barycentric2D/Barycentric2D.H
Normal file
@ -0,0 +1,114 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::Barycentric2D
|
||||
|
||||
Description
|
||||
Templated 2D Barycentric derived from VectorSpace. Has 3 components, one of
|
||||
which is redundant.
|
||||
|
||||
SourceFiles
|
||||
Barycentric2DI.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Barycentric2D_H
|
||||
#define Barycentric2D_H
|
||||
|
||||
#include "VectorSpace.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class Barycentric2D Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Cmpt>
|
||||
class Barycentric2D
|
||||
:
|
||||
public VectorSpace<Barycentric2D<Cmpt>, Cmpt, 3>
|
||||
{
|
||||
public:
|
||||
|
||||
//- Equivalent type of labels used for valid component indexing
|
||||
typedef Barycentric2D<label> labelType;
|
||||
|
||||
|
||||
// Member constants
|
||||
|
||||
//- Rank of Barycentric2D is 1
|
||||
static const direction rank = 1;
|
||||
|
||||
|
||||
//- Component labeling enumeration
|
||||
enum components { A, B, C };
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
inline Barycentric2D();
|
||||
|
||||
//- Construct initialized to zero
|
||||
inline Barycentric2D(const Foam::zero);
|
||||
|
||||
//- Construct given four components
|
||||
inline Barycentric2D
|
||||
(
|
||||
const Cmpt& va,
|
||||
const Cmpt& vb,
|
||||
const Cmpt& vc
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
inline const Cmpt& a() const;
|
||||
inline const Cmpt& b() const;
|
||||
inline const Cmpt& c() const;
|
||||
|
||||
inline Cmpt& a();
|
||||
inline Cmpt& b();
|
||||
inline Cmpt& c();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "Barycentric2DI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
120
src/OpenFOAM/primitives/Barycentric2D/Barycentric2DI.H
Normal file
120
src/OpenFOAM/primitives/Barycentric2D/Barycentric2DI.H
Normal file
@ -0,0 +1,120 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANB WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Cmpt>
|
||||
inline Foam::Barycentric2D<Cmpt>::Barycentric2D()
|
||||
{}
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
inline Foam::Barycentric2D<Cmpt>::Barycentric2D(const Foam::zero)
|
||||
:
|
||||
Barycentric2D::vsType(Zero)
|
||||
{}
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
inline Foam::Barycentric2D<Cmpt>::Barycentric2D
|
||||
(
|
||||
const Cmpt& va,
|
||||
const Cmpt& vb,
|
||||
const Cmpt& vc
|
||||
)
|
||||
{
|
||||
this->v_[A] = va;
|
||||
this->v_[B] = vb;
|
||||
this->v_[C] = vc;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Cmpt>
|
||||
inline const Cmpt& Foam::Barycentric2D<Cmpt>::a() const
|
||||
{
|
||||
return this->v_[A];
|
||||
}
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
inline const Cmpt& Foam::Barycentric2D<Cmpt>::b() const
|
||||
{
|
||||
return this->v_[B];
|
||||
}
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
inline const Cmpt& Foam::Barycentric2D<Cmpt>::c() const
|
||||
{
|
||||
return this->v_[C];
|
||||
}
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
inline Cmpt& Foam::Barycentric2D<Cmpt>::a()
|
||||
{
|
||||
return this->v_[A];
|
||||
}
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
inline Cmpt& Foam::Barycentric2D<Cmpt>::b()
|
||||
{
|
||||
return this->v_[B];
|
||||
}
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
inline Cmpt& Foam::Barycentric2D<Cmpt>::c()
|
||||
{
|
||||
return this->v_[C];
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class Cmpt>
|
||||
inline Cmpt operator&
|
||||
(
|
||||
const Barycentric2D<Cmpt>& b1,
|
||||
const Barycentric2D<Cmpt>& b2
|
||||
)
|
||||
{
|
||||
return b1.a()*b2.a() + b1.b()*b2.b() + b1.c()*b2.c();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,75 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "barycentric2D.H"
|
||||
#include "Random.H"
|
||||
#include "cachedRandom.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::barycentric2D barycentric2D01
|
||||
(
|
||||
Foam::scalar s,
|
||||
Foam::scalar t
|
||||
)
|
||||
{
|
||||
// Transform the random point in the unit square to a random point in the
|
||||
// unit tri by reflecting across the diagonal
|
||||
|
||||
if (s + t > 1)
|
||||
{
|
||||
s = 1 - s;
|
||||
t = 1 - t;
|
||||
}
|
||||
|
||||
return Foam::barycentric2D(1 - s - t, s, t);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::barycentric2D Foam::barycentric2D01(Random& rndGen)
|
||||
{
|
||||
return
|
||||
::barycentric2D01
|
||||
(
|
||||
rndGen.scalar01(),
|
||||
rndGen.scalar01()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Foam::barycentric2D Foam::barycentric2D01(cachedRandom& rndGen)
|
||||
{
|
||||
return
|
||||
::barycentric2D01
|
||||
(
|
||||
rndGen.sample01<scalar>(),
|
||||
rndGen.sample01<scalar>()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,74 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Typedef
|
||||
Foam::barycentric2D
|
||||
|
||||
Description
|
||||
A scalar version of the templated Barycentric2D
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef barycentric2D_H
|
||||
#define barycentric2D_H
|
||||
|
||||
#include "scalar.H"
|
||||
#include "Barycentric2D.H"
|
||||
#include "contiguous.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class Random;
|
||||
class cachedRandom;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
typedef Barycentric2D<scalar> barycentric2D;
|
||||
|
||||
|
||||
//- Generate a random barycentric coordinate within the unit triangle
|
||||
barycentric2D barycentric2D01(Random& rndGen);
|
||||
barycentric2D barycentric2D01(cachedRandom& rndGen);
|
||||
|
||||
|
||||
template<>
|
||||
inline bool contiguous<barycentric2D>()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -62,7 +62,7 @@ void Foam::cellPointWeight::findTetrahedron
|
||||
const tetIndices& tetIs = cellTets[tetI];
|
||||
|
||||
// Barycentric coordinates of the position
|
||||
scalar det = tetIs.tet(mesh).barycentric(position, weights_);
|
||||
scalar det = tetIs.tet(mesh).pointToBarycentric(position, weights_);
|
||||
|
||||
if (mag(det/cellVolume) > tol)
|
||||
{
|
||||
@ -123,7 +123,7 @@ void Foam::cellPointWeight::findTetrahedron
|
||||
// Barycentric coordinates of the position, ignoring if the
|
||||
// determinant is suitable. If not, the return from barycentric
|
||||
// to weights_ is safe.
|
||||
tetIs.tet(mesh).barycentric(position, weights_);
|
||||
weights_ = tetIs.tet(mesh).pointToBarycentric(position);
|
||||
|
||||
faceVertices_ = tetIs.faceTriIs(mesh);
|
||||
}
|
||||
@ -156,10 +156,10 @@ void Foam::cellPointWeight::findTriangle
|
||||
{
|
||||
const tetIndices& tetIs = faceTets[tetI];
|
||||
|
||||
FixedList<scalar, 3> triWeights;
|
||||
|
||||
// Barycentric coordinates of the position
|
||||
scalar det = tetIs.faceTri(mesh).barycentric(position, triWeights);
|
||||
barycentric2D triWeights;
|
||||
const scalar det =
|
||||
tetIs.faceTri(mesh).pointToBarycentric(position, triWeights);
|
||||
|
||||
if (0.25*mag(det)/faceAreaSqr > tol)
|
||||
{
|
||||
@ -222,9 +222,8 @@ void Foam::cellPointWeight::findTriangle
|
||||
// determinant is suitable. If not, the return from barycentric
|
||||
// to triWeights is safe.
|
||||
|
||||
FixedList<scalar, 3> triWeights;
|
||||
|
||||
tetIs.faceTri(mesh).barycentric(position, triWeights);
|
||||
const barycentric2D triWeights =
|
||||
tetIs.faceTri(mesh).pointToBarycentric(position);
|
||||
|
||||
// Weight[0] is for the cell centre.
|
||||
weights_[0] = 0;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -36,6 +36,8 @@ SourceFiles
|
||||
#define cellPointWeight_H
|
||||
|
||||
#include "vector.H"
|
||||
#include "barycentric.H"
|
||||
#include "triFace.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -57,11 +59,12 @@ protected:
|
||||
//- Cell index
|
||||
const label celli_;
|
||||
|
||||
//- Weights applied to tet vertices
|
||||
FixedList<scalar, 4> weights_;
|
||||
//- Weights applied to tet vertices. Equal to the barycentric coordinates
|
||||
// of the interpolation position.
|
||||
barycentric weights_;
|
||||
|
||||
//- Face vertex indices
|
||||
FixedList<label, 3> faceVertices_;
|
||||
triFace faceVertices_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
@ -112,13 +115,13 @@ public:
|
||||
}
|
||||
|
||||
//- Interpolation weights
|
||||
inline const FixedList<scalar, 4>& weights() const
|
||||
inline const barycentric& weights() const
|
||||
{
|
||||
return weights_;
|
||||
}
|
||||
|
||||
//- Interpolation addressing for points on face
|
||||
inline const FixedList<label, 3>& faceVertices() const
|
||||
inline const triFace& faceVertices() const
|
||||
{
|
||||
return faceVertices_;
|
||||
}
|
||||
|
||||
@ -31,8 +31,8 @@ inline Type Foam::interpolationCellPoint<Type>::interpolate
|
||||
const cellPointWeight& cpw
|
||||
) const
|
||||
{
|
||||
const FixedList<scalar, 4>& weights = cpw.weights();
|
||||
const FixedList<label, 3>& faceVertices = cpw.faceVertices();
|
||||
const barycentric& weights = cpw.weights();
|
||||
const triFace& faceVertices = cpw.faceVertices();
|
||||
|
||||
Type t = this->psi_[cpw.cell()]*weights[0];
|
||||
t += psip_[faceVertices[0]]*weights[1];
|
||||
@ -79,9 +79,8 @@ inline Type Foam::interpolationCellPoint<Type>::interpolate
|
||||
}
|
||||
}
|
||||
|
||||
FixedList<scalar, 4> weights;
|
||||
|
||||
tetIs.tet(this->pMesh_).barycentric(position, weights);
|
||||
const barycentric weights =
|
||||
tetIs.tet(this->pMesh_).pointToBarycentric(position);
|
||||
|
||||
// Order of weights is the same as that of the vertices of the tet, i.e.
|
||||
// cellCentre, faceBasePt, facePtA, facePtB.
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -31,8 +31,8 @@ inline Type Foam::interpolationCellPointWallModified<Type>::interpolate
|
||||
const cellPointWeightWallModified& cpw
|
||||
) const
|
||||
{
|
||||
const FixedList<scalar, 4>& weights = cpw.weights();
|
||||
const FixedList<label, 3>& faceVertices = cpw.faceVertices();
|
||||
const barycentric& weights = cpw.weights();
|
||||
const triFace& faceVertices = cpw.faceVertices();
|
||||
|
||||
Type t = this->psi_[cpw.cell()]*weights[0];
|
||||
t += this->psip_[faceVertices[0]]*weights[1];
|
||||
|
||||
Reference in New Issue
Block a user