Commit 5d2ad922 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: separate areaNormal/unitNormal method for primitives (issue #885)

parent a410f52e
......@@ -81,7 +81,7 @@ Foam::label Foam::face::mostConcaveAngle
scalar& maxAngle
) const
{
vector n(normal(points));
vector n(areaNormal(points));
label index = 0;
maxAngle = -GREAT;
......@@ -542,17 +542,16 @@ Foam::point Foam::face::centre(const UList<point>& points) const
}
Foam::vector Foam::face::normal(const UList<point>& p) const
Foam::vector Foam::face::areaNormal(const UList<point>& p) const
{
const label nPoints = size();
// Calculate the normal by summing the face triangle normals.
// Calculate the area normal by summing the face triangle area normals.
// Changed to deal with small concavity by using a central decomposition
//
// If the face is a triangle, do a direct calculation to avoid round-off
// error-related problems
//
if (nPoints == 3)
{
return triPointRef
......@@ -560,7 +559,7 @@ Foam::vector Foam::face::normal(const UList<point>& p) const
p[operator[](0)],
p[operator[](1)],
p[operator[](2)]
).normal();
).areaNormal();
}
label pI;
......@@ -594,7 +593,7 @@ Foam::vector Foam::face::normal(const UList<point>& p) const
p[operator[](pI)],
nextPoint,
centrePoint
).normal();
).areaNormal();
}
return n;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -39,7 +39,6 @@ SourceFiles
faceTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef face_H
#define face_H
......@@ -194,12 +193,22 @@ public:
const Field<Type>& fld
) const;
//- The area normal - with magnitude equal to area of face
vector areaNormal(const UList<point>& p) const;
//- The unit normal
inline vector unitNormal(const UList<point>& p) const;
//- Legacy name for areaNormal.
// \deprecated Deprecated for new use (JUN-2018)
inline vector normal(const UList<point>& p) const
{
return areaNormal(p); // Legacy definition
}
//- Magnitude of face area
inline scalar mag(const UList<point>& p) const;
//- Vector normal; magnitude is equal to area of face
vector normal(const UList<point>& p) const;
//- Return face with reverse direction
// The starting points of the original and reverse face are identical.
face reverseFace() const;
......
......@@ -37,10 +37,8 @@ Foam::scalar Foam::face::contactSphereDiameter
const UList<point>& meshPoints
) const
{
scalar magN = Foam::mag(n);
vector n1 = n/(magN + SMALL);
vector n2 = normal(meshPoints);
vector n1 = n/(Foam::mag(n) + SMALL);
vector n2 = areaNormal(meshPoints);
n2 /= Foam::mag(n2) + SMALL;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -105,9 +105,17 @@ inline Foam::pointField Foam::face::points
}
inline Foam::vector Foam::face::unitNormal(const UList<point>& p) const
{
const vector n(areaNormal(p));
const scalar s(Foam::mag(n));
return s < ROOTVSMALL ? Zero : n/s;
}
inline Foam::scalar Foam::face::mag(const UList<point>& p) const
{
return ::Foam::mag(normal(p));
return ::Foam::mag(areaNormal(p));
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -124,12 +124,22 @@ public:
template<class Type>
Type average(const UList<point>& unused, const Field<Type>& fld) const;
//- The area normal - with magnitude equal to area of face
inline vector areaNormal(const UList<point>& points) const;
//- The unit normal
inline vector unitNormal(const UList<point>& points) const;
//- Legacy name for areaNormal.
// \deprecated Deprecated for new use (JUN-2018)
inline vector normal(const UList<point>& points) const
{
return areaNormal(points); // Legacy definition
}
//- Magnitude of face area
inline scalar mag(const UList<point>& points) const;
//- Vector normal; magnitude is equal to area of face
inline vector normal(const UList<point>& points) const;
//- Number of triangles after splitting
inline label nTriangles() const;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -171,15 +171,9 @@ inline Foam::point Foam::triFace::centre(const UList<point>& points) const
}
inline Foam::scalar Foam::triFace::mag(const UList<point>& points) const
{
return ::Foam::mag(normal(points));
}
// could also delegate to triPointRef(...).normal()
inline Foam::vector Foam::triFace::normal(const UList<point>& points) const
inline Foam::vector Foam::triFace::areaNormal(const UList<point>& points) const
{
// As per triPointRef(...).areaNormal()
return 0.5*
(
(points[operator[](1)] - points[operator[](0)])
......@@ -188,6 +182,20 @@ inline Foam::vector Foam::triFace::normal(const UList<point>& points) const
}
inline Foam::vector Foam::triFace::unitNormal(const UList<point>& points) const
{
const vector n(areaNormal(points));
const scalar s(Foam::mag(n));
return s < ROOTVSMALL ? Zero : n/s;
}
inline Foam::scalar Foam::triFace::mag(const UList<point>& points) const
{
return ::Foam::mag(areaNormal(points));
}
inline Foam::label Foam::triFace::nTriangles() const
{
return 1;
......
......@@ -172,7 +172,7 @@ public:
//- Operate on a triangle
result operator()(const FixedList<point, 3>& p) const
{
return result(triPointRef(p[0], p[1], p[2]).normal());
return result(triPointRef(p[0], p[1], p[2]).areaNormal());
}
};
......
......@@ -106,8 +106,9 @@ typename Foam::cut::opAddResult<AboveOp, BelowOp>::type Foam::triCut
{
// Set the level set to the signed distance from the plane
FixedList<scalar, 3> level;
for (label i = 0; i < 3; ++ i)
for (label i = 0; i < 3; ++i)
{
// uses unit-normal
level[i] = (tri[i] - p.refPoint()) & p.normal();
}
......@@ -251,8 +252,9 @@ typename Foam::cut::opAddResult<AboveOp, BelowOp>::type Foam::tetCut
{
// Set the level set to the signed distance from the plane
FixedList<scalar, 4> level;
for (label i = 0; i < 4; ++ i)
for (label i = 0; i < 4; ++i)
{
// uses unit-normal
level[i] = (tet[i] - p.refPoint()) & p.normal();
}
......
......@@ -195,7 +195,7 @@ public:
// Member Functions
//- Return plane normal
//- Return the plane unit normal
const vector& normal() const;
//- Return plane base point
......
......@@ -89,7 +89,7 @@ inline Foam::scalar Foam::pyramid<Point, PointRef, polygonRef>::mag
const UList<point>& points
) const
{
return (1.0/3.0)*(base_.normal(points)&(height(points)));
return (1.0/3.0)*(base_.areaNormal(points) & (height(points)));
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -54,13 +54,12 @@ SourceFiles
namespace Foam
{
// Forward declarations
class Istream;
class Ostream;
class tetPoints;
class plane;
// Forward declaration of friend functions and operators
template<class Point, class PointRef> class tetrahedron;
template<class Point, class PointRef>
......@@ -210,13 +209,16 @@ public:
// Properties
//- Return face normal
//- Face area normal for side a
inline vector Sa() const;
//- Face area normal for side b
inline vector Sb() const;
//- Face area normal for side c
inline vector Sc() const;
//- Face area normal for side d
inline vector Sd() const;
//- Return centre (centroid)
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -133,28 +133,28 @@ inline Foam::triPointRef Foam::tetrahedron<Point, PointRef>::tri
template<class Point, class PointRef>
inline Foam::vector Foam::tetrahedron<Point, PointRef>::Sa() const
{
return triangle<Point, PointRef>(b_, c_, d_).normal();
return triangle<Point, PointRef>(b_, c_, d_).areaNormal();
}
template<class Point, class PointRef>
inline Foam::vector Foam::tetrahedron<Point, PointRef>::Sb() const
{
return triangle<Point, PointRef>(a_, d_, c_).normal();
return triangle<Point, PointRef>(a_, d_, c_).areaNormal();
}
template<class Point, class PointRef>
inline Foam::vector Foam::tetrahedron<Point, PointRef>::Sc() const
{
return triangle<Point, PointRef>(a_, b_, d_).normal();
return triangle<Point, PointRef>(a_, b_, d_).areaNormal();
}
template<class Point, class PointRef>
inline Foam::vector Foam::tetrahedron<Point, PointRef>::Sd() const
{
return triangle<Point, PointRef>(a_, c_, b_).normal();
return triangle<Point, PointRef>(a_, c_, b_).areaNormal();
}
......@@ -415,7 +415,7 @@ bool Foam::tetrahedron<Point, PointRef>::inside(const point& pt) const
// "definitively" shown otherwise by obtaining a positive dot
// product greater than a tolerance of SMALL.
// The tet is defined: tet(Cc, tetBasePt, pA, pB) where the normal
// The tet is defined: tet(Cc, tetBasePt, pA, pB) where the area normal
// vectors and base points for the half-space planes are:
// area[0] = Sa();
// area[1] = Sb();
......@@ -575,10 +575,11 @@ inline void Foam::tetrahedron<Point, PointRef>::tetSliceWithPlane
label nPos = 0;
forAll(tet, i)
{
// with plane unit-normal
d[i] = ((tet[i] - pl.refPoint()) & pl.normal());
if (d[i] > 0)
{
nPos++;
++nPos;
}
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -206,12 +206,22 @@ public:
//- Return centre (centroid)
inline Point centre() const;
//- The area normal - with magnitude equal to area of triangle
inline vector areaNormal() const;
//- Return unit normal
inline vector unitNormal() const;
//- Legacy name for areaNormal.
// \deprecated Deprecated for new use (JUN-2018)
inline vector normal() const
{
return areaNormal();
}
//- Return scalar magnitude
inline scalar mag() const;
//- Return vector normal
inline vector normal() const;
//- Return circum-centre
inline Point circumCentre() const;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -106,16 +106,25 @@ inline Point Foam::triangle<Point, PointRef>::centre() const
template<class Point, class PointRef>
inline Foam::scalar Foam::triangle<Point, PointRef>::mag() const
inline Foam::vector Foam::triangle<Point, PointRef>::areaNormal() const
{
return Foam::mag(normal());
return 0.5*((b_ - a_)^(c_ - a_));
}
template<class Point, class PointRef>
inline Foam::vector Foam::triangle<Point, PointRef>::normal() const
inline Foam::vector Foam::triangle<Point, PointRef>::unitNormal() const
{
return 0.5*((b_ - a_)^(c_ - a_));
const vector n(areaNormal());
const scalar s(Foam::mag(n));
return s < ROOTVSMALL ? Zero : n/s;
}
template<class Point, class PointRef>
inline Foam::scalar Foam::triangle<Point, PointRef>::mag() const
{
return ::Foam::mag(areaNormal());
}
......@@ -392,7 +401,7 @@ inline Foam::pointHit Foam::triangle<Point, PointRef>::ray
|| (alg == intersection::HALF_RAY && dist > -planarPointTol)
|| (
alg == intersection::VISIBLE
&& ((q1 & normal()) < -VSMALL)
&& ((q1 & areaNormal()) < -VSMALL)
);
if (hit && eligible)
......
......@@ -526,11 +526,6 @@ public:
// current tet.
inline vector normal() const;
//- Return the normal of the tri on tetFacei_ for the
// current tet at the start of the timestep, i.e. based
// on oldPoints
inline vector oldNormal() const;
//- Is the particle on a face?
inline bool onFace() const;
......
......@@ -280,12 +280,6 @@ inline Foam::vector Foam::particle::normal() const
}
inline Foam::vector Foam::particle::oldNormal() const
{
return currentTetIndices().oldFaceTri(mesh_).normal();
}
inline bool Foam::particle::onFace() const
{
return facei_ >= 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment