ENH: add face/triFace/triangle magSqr() method (as per edge, boundBox etc)

This commit is contained in:
Mark Olesen
2025-04-24 10:53:22 +02:00
parent 5c44f360fe
commit 2d77f7ae26
13 changed files with 74 additions and 18 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd.
Copyright (C) 2017-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -207,6 +207,9 @@ public:
//- Magnitude of face area
inline scalar mag(const UList<point>& p) const;
//- Magnitude squared of face area
inline scalar magSqr(const UList<point>& p) const;
//- The enclosing (bounding) box for the face
inline Pair<point> box(const UList<point>& pts) const;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd.
Copyright (C) 2017-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -115,6 +115,12 @@ inline Foam::scalar Foam::face::mag(const UList<point>& p) const
}
inline Foam::scalar Foam::face::magSqr(const UList<point>& p) const
{
return ::Foam::magSqr(areaNormal(p));
}
inline Foam::Pair<Foam::point>
Foam::face::box(const UList<point>& pts) const
{

View File

@ -181,6 +181,9 @@ public:
//- Magnitude of face area
inline scalar mag(const UList<point>& points) const;
//- Magnitude squared of face area
inline scalar magSqr(const UList<point>& points) const;
//- The enclosing (bounding) box for the face
inline Pair<point> box(const UList<point>& points) const;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd.
Copyright (C) 2017-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -201,6 +201,12 @@ inline Foam::scalar Foam::triFace::mag(const UList<point>& points) const
}
inline Foam::scalar Foam::triFace::magSqr(const UList<point>& points) const
{
return ::Foam::magSqr(areaNormal(points));
}
inline Foam::Pair<Foam::point>
Foam::triFace::box(const UList<point>& points) const
{

View File

@ -53,8 +53,8 @@ namespace Foam
Foam::label Foam::cyclicPolyPatch::findMaxArea
(
const pointField& points,
const faceList& faces
const UList<point>& points,
const UList<face>& faces
)
{
label maxI = -1;
@ -62,7 +62,7 @@ Foam::label Foam::cyclicPolyPatch::findMaxArea
forAll(faces, facei)
{
scalar areaSqr = magSqr(faces[facei].areaNormal(points));
scalar areaSqr = faces[facei].magSqr(points);
if (maxAreaSqr < areaSqr)
{

View File

@ -112,7 +112,7 @@ class cyclicPolyPatch
// Private Member Functions
//- Find amongst selected faces the one with the largest area
static label findMaxArea(const pointField&, const faceList&);
static label findMaxArea(const UList<point>&, const UList<face>&);
void calcTransforms
(

View File

@ -85,8 +85,8 @@ Foam::pointField Foam::oldCyclicPolyPatch::getAnchorPoints
Foam::label Foam::oldCyclicPolyPatch::findMaxArea
(
const pointField& points,
const faceList& faces
const UList<point>& points,
const UList<face>& faces
)
{
label maxI = -1;
@ -94,7 +94,7 @@ Foam::label Foam::oldCyclicPolyPatch::findMaxArea
forAll(faces, facei)
{
scalar areaSqr = magSqr(faces[facei].areaNormal(points));
scalar areaSqr = faces[facei].magSqr(points);
if (maxAreaSqr < areaSqr)
{

View File

@ -38,8 +38,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef oldCyclicPolyPatch_H
#define oldCyclicPolyPatch_H
#ifndef Foam_oldCyclicPolyPatch_H
#define Foam_oldCyclicPolyPatch_H
#include "coupledPolyPatch.H"
@ -80,7 +80,7 @@ class oldCyclicPolyPatch
// Private member functions
//- Find amongst selected faces the one with the largest area
static label findMaxArea(const pointField&, const faceList&);
static label findMaxArea(const UList<point>&, const UList<face>&);
void calcTransforms();

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2018-2022 OpenCFD Ltd.
Copyright (C) 2018-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -128,6 +128,9 @@ public:
//- The magnitude (length) of the line
inline scalar mag() const;
//- The magnitude squared (length squared) of the line
inline scalar magSqr() const;
//- Return start-to-end vector
inline vector vec() const;
@ -214,6 +217,9 @@ public:
//- The magnitude (length) of the line
inline scalar mag() const;
//- The magnitude squared (length squared) of the line
inline scalar magSqr() const;
//- Return start-to-end vector
inline Point vec() const;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2018-2022 OpenCFD Ltd.
Copyright (C) 2018-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -112,6 +112,19 @@ inline Foam::scalar Foam::linePoints::mag() const
}
template<class Point, class PointRef>
inline Foam::scalar Foam::line<Point, PointRef>::magSqr() const
{
return ::Foam::magSqr(b() - a());
}
inline Foam::scalar Foam::linePoints::magSqr() const
{
return ::Foam::magSqr(b() - a());
}
template<class Point, class PointRef>
inline Point Foam::line<Point, PointRef>::vec() const
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2024 OpenCFD Ltd.
Copyright (C) 2018-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -161,6 +161,9 @@ public:
//- The magnitude of the triangle area
inline scalar mag() const;
//- The magnitude squared of the triangle area
inline scalar magSqr() const;
//- The enclosing (bounding) box for the triangle
inline Pair<point> box() const;
@ -378,6 +381,9 @@ public:
//- The magnitude of the triangle area
inline scalar mag() const;
//- The magnitude squared of the triangle area
inline scalar magSqr() const;
//- The enclosing (bounding) box for the triangle
inline Pair<Point> box() const;

View File

@ -319,6 +319,19 @@ inline Foam::scalar Foam::triangle<Point, PointRef>::mag() const
}
inline Foam::scalar Foam::triPoints::magSqr() const
{
return ::Foam::magSqr(areaNormal());
}
template<class Point, class PointRef>
inline Foam::scalar Foam::triangle<Point, PointRef>::magSqr() const
{
return ::Foam::magSqr(areaNormal());
}
template<class Point, class PointRef>
inline Point Foam::triangle<Point, PointRef>::circumCentre() const
{

View File

@ -431,7 +431,7 @@ Foam::scalar Foam::hexRef8::getLevel0EdgeLength() const
{
const edge& e = mesh_.edges()[edgeI];
scalar edgeLenSqr = magSqr(e.vec(mesh_.points()));
scalar edgeLenSqr = e.magSqr(mesh_.points());
typEdgeLenSqr[eLevel] = min(typEdgeLenSqr[eLevel], edgeLenSqr);
}
@ -468,7 +468,7 @@ Foam::scalar Foam::hexRef8::getLevel0EdgeLength() const
{
const edge& e = mesh_.edges()[cEdges[i]];
scalar edgeLenSqr = magSqr(e.vec(mesh_.points()));
scalar edgeLenSqr = e.magSqr(mesh_.points());
maxEdgeLenSqr[cLevel] = max(maxEdgeLenSqr[cLevel], edgeLenSqr);
}