Commit c1964d78 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: distinguish between face areaNormal/unitNormal in the code

parent b81a2f2f
......@@ -188,19 +188,17 @@ label findInternalFace(const primitiveMesh& mesh, const labelList& meshF)
bool correctOrientation(const pointField& points, const cellShape& shape)
{
// Get centre of shape.
point cc(shape.centre(points));
const point cc(shape.centre(points));
// Get outwards pointing faces.
faceList faces(shape.faces());
forAll(faces, i)
for (const face& f : faces)
{
const face& f = faces[i];
vector n(f.normal(points));
const vector areaNorm(f.areaNormal(points));
// Check if vector from any point on face to cc points outwards
if (((points[f[0]] - cc) & n) < 0)
if (((points[f[0]] - cc) & areaNorm) < 0)
{
// Incorrectly oriented
return false;
......
......@@ -225,9 +225,10 @@ int main(int argc, char *argv[])
// Determine orientation of tri v.s. cell centre.
point cc(cll.centre(points));
point fc(tri.centre(points));
vector fn(tri.normal(points));
if (((fc - cc) & fn) < 0)
const vector areaNorm(tri.areaNormal(points));
if (((fc - cc) & areaNorm) < 0)
{
// Boundary face points inwards. Flip.
boundaryFaces[facei].flip();
......
......@@ -1832,11 +1832,11 @@ void Foam::conformalVoronoiMesh::createFacesOwnerNeighbourAndPatches
}
vector correctNormal = calcSharedPatchNormal(vc1, vc2);
correctNormal /= mag(correctNormal);
correctNormal.normalise();
Info<< " cN " << correctNormal << endl;
vector fN = f.normal(pts);
vector fN = f.areaNormal(pts);
if (mag(fN) < SMALL)
{
......@@ -1844,7 +1844,7 @@ void Foam::conformalVoronoiMesh::createFacesOwnerNeighbourAndPatches
continue;
}
fN /= mag(fN);
fN.normalise();
Info<< " fN " << fN << endl;
if ((fN & correctNormal) > 0)
......
......@@ -481,10 +481,9 @@ void Foam::conformalVoronoiMesh::calcFaceZones
norm
);
vector fN = faces[facei].normal(mesh.points());
fN /= mag(fN) + SMALL;
const vector areaNorm = faces[facei].areaNormal(mesh.points());
if ((norm[0] & fN) < 0)
if ((norm[0] & areaNorm) < 0)
{
flipMap[facei] = true;
}
......
......@@ -89,11 +89,9 @@ void Foam::conformationSurfaces::hasBoundedVolume
Info<< " Index = " << surfaces_[s] << endl;
Info<< " Offset = " << regionOffset_[s] << endl;
forAll(triSurf, sI)
for (const labelledTri& f : triSurf)
{
const label patchID =
triSurf[sI].region()
+ regionOffset_[s];
const label patchID = f.region() + regionOffset_[s];
// Don't include baffle surfaces in the calculation
if
......@@ -102,15 +100,15 @@ void Foam::conformationSurfaces::hasBoundedVolume
!= extendedFeatureEdgeMesh::BOTH
)
{
sum += triSurf[sI].normal(surfPts);
sum += f.areaNormal(surfPts);
}
else
{
nBaffles++;
++nBaffles;
}
}
Info<< " has " << nBaffles << " baffles out of "
<< triSurf.size() << " triangles" << endl;
<< triSurf.size() << " triangles" << nl;
totalTriangles += triSurf.size();
}
......
......@@ -271,8 +271,8 @@ Foam::label Foam::meshDualiser::addInternalFace
);
//pointField dualPoints(meshMod.points());
//vector n(newFace.normal(dualPoints));
//n /= mag(n);
//const vector n(newFace.unitNormal(dualPoints));
//
//Pout<< "Generated internal dualFace:" << dualFacei
// << " verts:" << newFace
// << " points:" << UIndirectList<point>(meshMod.points(), newFace)
......@@ -298,8 +298,8 @@ Foam::label Foam::meshDualiser::addInternalFace
);
//pointField dualPoints(meshMod.points());
//vector n(newFace.normal(dualPoints));
//n /= mag(n);
//const vector n(newFace.unitNormal(dualPoints));
//
//Pout<< "Generated internal dualFace:" << dualFacei
// << " verts:" << newFace
// << " points:" << UIndirectList<point>(meshMod.points(), newFace)
......@@ -355,8 +355,8 @@ Foam::label Foam::meshDualiser::addBoundaryFace
);
//pointField dualPoints(meshMod.points());
//vector n(newFace.normal(dualPoints));
//n /= mag(n);
//const vector n(newFace.unitNormal(dualPoints));
//
//Pout<< "Generated boundary dualFace:" << dualFacei
// << " verts:" << newFace
// << " points:" << UIndirectList<point>(meshMod.points(), newFace)
......
......@@ -89,11 +89,8 @@ tmp<vectorField> calcVertexNormals(const triSurface& surf)
{
// Weighted average of normals of faces attached to the vertex
// Weight = fA / (mag(e0)^2 * mag(e1)^2);
tmp<vectorField> tpointNormals
(
new pointField(surf.nPoints(), Zero)
);
vectorField& pointNormals = tpointNormals.ref();
auto tpointNormals = tmp<vectorField>::New(surf.nPoints(), Zero);
auto& pointNormals = tpointNormals.ref();
const pointField& points = surf.points();
const labelListList& pointFaces = surf.pointFaces();
......@@ -108,20 +105,20 @@ tmp<vectorField> calcVertexNormals(const triSurface& surf)
const label faceI = pFaces[fI];
const triFace& f = surf[faceI];
vector fN = f.normal(points);
vector areaNorm = f.areaNormal(points);
scalar weight = calcVertexNormalWeight
(
f,
meshPoints[pI],
fN,
areaNorm,
points
);
pointNormals[pI] += weight*fN;
pointNormals[pI] += weight * areaNorm;
}
pointNormals[pI] /= mag(pointNormals[pI]) + VSMALL;
pointNormals[pI].normalise();
}
return tpointNormals;
......@@ -168,9 +165,9 @@ tmp<vectorField> calcPointNormals
// Get average edge normal
vector n = Zero;
forAll(eFaces, i)
for (const label facei : eFaces)
{
n += s.faceNormals()[eFaces[i]];
n += s.faceNormals()[facei];
}
n /= eFaces.size();
......
......@@ -1375,7 +1375,7 @@ bool Foam::polyMesh::pointInCell
vector proj = p - faceTri.centre();
if ((faceTri.normal() & proj) > 0)
if ((faceTri.areaNormal() & proj) > 0)
{
return false;
}
......@@ -1405,7 +1405,7 @@ bool Foam::polyMesh::pointInCell
vector proj = p - faceTri.centre();
if ((faceTri.normal() & proj) > 0)
if ((faceTri.areaNormal() & proj) > 0)
{
return false;
}
......
......@@ -60,9 +60,9 @@ Foam::label Foam::cyclicPolyPatch::findMaxArea
forAll(faces, facei)
{
scalar areaSqr = magSqr(faces[facei].normal(points));
scalar areaSqr = magSqr(faces[facei].areaNormal(points));
if (areaSqr > maxAreaSqr)
if (maxAreaSqr < areaSqr)
{
maxAreaSqr = areaSqr;
maxI = facei;
......@@ -81,7 +81,7 @@ void Foam::cyclicPolyPatch::calcTransforms()
vectorField half0Areas(half0.size());
forAll(half0, facei)
{
half0Areas[facei] = half0[facei].normal(half0.points());
half0Areas[facei] = half0[facei].areaNormal(half0.points());
}
// Half1
......@@ -89,7 +89,7 @@ void Foam::cyclicPolyPatch::calcTransforms()
vectorField half1Areas(half1.size());
forAll(half1, facei)
{
half1Areas[facei] = half1[facei].normal(half1.points());
half1Areas[facei] = half1[facei].areaNormal(half1.points());
}
calcTransforms
......@@ -260,19 +260,17 @@ void Foam::cyclicPolyPatch::calcTransforms
// use calculated normals.
vector n0 = findFaceMaxRadius(half0Ctrs);
vector n1 = -findFaceMaxRadius(half1Ctrs);
n0 /= mag(n0) + VSMALL;
n1 /= mag(n1) + VSMALL;
n0.normalise();
n1.normalise();
if (debug)
{
scalar theta = radToDeg(acos(n0 & n1));
Pout<< "cyclicPolyPatch::calcTransforms :"
<< " patch:" << name()
<< " Specified rotation :"
<< " n0:" << n0 << " n1:" << n1
<< " swept angle: " << theta << " [deg]"
<< endl;
<< " swept angle: " << radToDeg(acos(n0 & n1))
<< " [deg]" << endl;
}
// Extended tensor from two local coordinate systems calculated
......@@ -420,18 +418,17 @@ void Foam::cyclicPolyPatch::getCentresAndAnchors
{
vector n0 = findFaceMaxRadius(half0Ctrs);
vector n1 = -findFaceMaxRadius(half1Ctrs);
n0 /= mag(n0) + VSMALL;
n1 /= mag(n1) + VSMALL;
n0.normalise();
n1.normalise();
if (debug)
{
scalar theta = radToDeg(acos(n0 & n1));
Pout<< "cyclicPolyPatch::getCentresAndAnchors :"
<< " patch:" << name()
<< " Specified rotation :"
<< " n0:" << n0 << " n1:" << n1
<< " swept angle: " << theta << " [deg]"
<< " swept angle: "
<< radToDeg(acos(n0 & n1)) << " [deg]"
<< endl;
}
......@@ -499,12 +496,10 @@ void Foam::cyclicPolyPatch::getCentresAndAnchors
// Determine the face with max area on both halves. These
// two faces are used to determine the transformation tensors
label max0I = findMaxArea(pp0.points(), pp0);
vector n0 = pp0[max0I].normal(pp0.points());
n0 /= mag(n0) + VSMALL;
const vector n0 = pp0[max0I].unitNormal(pp0.points());
label max1I = findMaxArea(pp1.points(), pp1);
vector n1 = pp1[max1I].normal(pp1.points());
n1 /= mag(n1) + VSMALL;
const vector n1 = pp1[max1I].unitNormal(pp1.points());
if (mag(n0 & n1) < 1-matchTolerance())
{
......
......@@ -92,9 +92,9 @@ Foam::label Foam::oldCyclicPolyPatch::findMaxArea
forAll(faces, facei)
{
scalar areaSqr = magSqr(faces[facei].normal(points));
scalar areaSqr = magSqr(faces[facei].areaNormal(points));
if (areaSqr > maxAreaSqr)
if (maxAreaSqr < areaSqr)
{
maxAreaSqr = areaSqr;
maxI = facei;
......@@ -359,12 +359,10 @@ void Foam::oldCyclicPolyPatch::getCentresAndAnchors
// Determine the face with max area on both halves. These
// two faces are used to determine the transformation tensors
label max0I = findMaxArea(pp.points(), half0Faces);
vector n0 = half0Faces[max0I].normal(pp.points());
n0 /= mag(n0) + VSMALL;
const vector n0 = half0Faces[max0I].unitNormal(pp.points());
label max1I = findMaxArea(pp.points(), half1Faces);
vector n1 = half1Faces[max1I].normal(pp.points());
n1 /= mag(n1) + VSMALL;
const vector n1 = half1Faces[max1I].unitNormal(pp.points());
if (mag(n0 & n1) < 1-matchTolerance())
{
......
......@@ -281,9 +281,9 @@ calcPointNormals() const
const labelList& curFaces = pf[pointi];
forAll(curFaces, facei)
for (const label facei : curFaces)
{
curNormal += faceUnitNormals[curFaces[facei]];
curNormal += faceUnitNormals[facei];
}
curNormal /= mag(curNormal) + VSMALL;
......@@ -425,7 +425,7 @@ calcFaceAreas() const
forAll(n, facei)
{
n[facei] = this->operator[](facei).normal(points_);
n[facei] = this->operator[](facei).areaNormal(points_);
}
if (debug)
......@@ -472,8 +472,7 @@ calcFaceNormals() const
forAll(n, facei)
{
n[facei] = this->operator[](facei).normal(points_);
n[facei] /= mag(n[facei]) + VSMALL;
n[facei] = this->operator[](facei).unitNormal(points_);
}
if (debug)
......
......@@ -1006,8 +1006,9 @@ void Foam::polyDualMesh::calcDual
{
// Check orientation.
const face& f = dynDualFaces.last();
vector n = f.normal(dualPoints);
if (((mesh.points()[owner] - dualPoints[f[0]]) & n) > 0)
const vector areaNorm = f.areaNormal(dualPoints);
if (((mesh.points()[owner] - dualPoints[f[0]]) & areaNorm) > 0)
{
WarningInFunction
<< " on boundary edge:" << edgeI
......@@ -1121,8 +1122,9 @@ void Foam::polyDualMesh::calcDual
{
// Check orientation.
const face& f = dynDualFaces.last();
vector n = f.normal(dualPoints);
if (((mesh.points()[owner] - dualPoints[f[0]]) & n) > 0)
const vector areaNorm = f.areaNormal(dualPoints);
if (((mesh.points()[owner] - dualPoints[f[0]]) & areaNorm) > 0)
{
WarningInFunction
<< " on internal edge:" << edgeI
......
......@@ -1363,28 +1363,26 @@ bool Foam::cellCuts::loopAnchorConsistent
// Create identity face for ease of calculation of normal etc.
face f(identity(loopPts.size()));
vector normal = f.normal(loopPts);
point ctr = f.centre(loopPts);
const vector areaNorm = f.areaNormal(loopPts);
const point ctr = f.centre(loopPts);
// Get average position of anchor points.
vector avg(Zero);
forAll(anchorPoints, ptI)
for (const label pointi : anchorPoints)
{
avg += mesh().points()[anchorPoints[ptI]];
avg += mesh().points()[pointi];
}
avg /= anchorPoints.size();
if (((avg - ctr) & normal) > 0)
if (((avg - ctr) & areaNorm) > 0)
{
return true;
}
else
{
return false;
}
return false;
}
......
......@@ -1646,7 +1646,7 @@ bool Foam::polyMeshGeometry::checkFaceTwist
// p[f[fpI]],
// p[f.nextLabel(fpI)],
// fc
// ).normal()
// ).areaNormal()
// );
//
// scalar magTri = mag(triArea);
......@@ -1721,7 +1721,7 @@ bool Foam::polyMeshGeometry::checkFaceTwist
p[f[fpI]],
p[f.nextLabel(fpI)],
fc
).normal()
).areaNormal()
);
scalar magTri = mag(triArea);
......@@ -1826,7 +1826,7 @@ bool Foam::polyMeshGeometry::checkTriangleTwist
p[f[fp]],
p[f.nextLabel(fp)],
fc
).normal();
).areaNormal();
scalar magTri = mag(prevN);
......@@ -1853,7 +1853,7 @@ bool Foam::polyMeshGeometry::checkTriangleTwist
p[f[fp]],
p[f.nextLabel(fp)],
fc
).normal()
).areaNormal()
);
scalar magTri = mag(triN);
......
......@@ -55,9 +55,8 @@ bool Foam::combineFaces::convexFace
const face& f
)
{
// Get outwards pointing normal of f.
vector n = f.normal(points);
n /= mag(n);
// Get outwards pointing normal of f, only the sign matters.
const vector areaNorm = f.areaNormal(points);
// Get edge from f[0] to f[size-1];
vector ePrev(points[f.first()] - points[f.last()]);
......@@ -78,7 +77,7 @@ bool Foam::combineFaces::convexFace
{
vector edgeNormal = ePrev ^ e10;
if ((edgeNormal & n) < 0)
if ((edgeNormal & areaNorm) < 0)
{
// Concave. Check angle.
if ((ePrev & e10) < minConcaveCos)
......@@ -150,12 +149,10 @@ void Foam::combineFaces::regioniseFaces
// - small angle
if (p0 != -1 && p0 == p1 && !patches[p0].coupled())
{
vector f0Normal = mesh_.faceAreas()[f0];
f0Normal /= mag(f0Normal);
vector f1Normal = mesh_.faceAreas()[f1];
f1Normal /= mag(f1Normal);
vector f0Normal = normalised(mesh_.faceAreas()[f0]);
vector f1Normal = normalised(mesh_.faceAreas()[f1]);
if ((f0Normal&f1Normal) > minCos)
if ((f0Normal & f1Normal) > minCos)
{
Map<label>::const_iterator f0Fnd = faceRegion.find(f0);
......
......@@ -835,11 +835,11 @@ void Foam::hexRef8::checkInternalOrientation
face compactFace(identity(newFace.size()));
pointField compactPoints(meshMod.points(), newFace);
vector n(compactFace.normal(compactPoints));
const vector areaNorm(compactFace.areaNormal(compactPoints));
vector dir(neiPt - ownPt);
const vector dir(neiPt - ownPt);
if ((dir & n) < 0)
if ((dir & areaNorm) < 0)
{
FatalErrorInFunction
<< "cell:" << celli << " old face:" << facei
......@@ -850,9 +850,9 @@ void Foam::hexRef8::checkInternalOrientation
<< abort(FatalError);
}
vector fcToOwn(compactFace.centre(compactPoints) - ownPt);
const vector fcToOwn(compactFace.centre(compactPoints) - ownPt);
scalar s = (fcToOwn&n) / (dir&n);
const scalar s = (fcToOwn & areaNorm) / (dir & areaNorm);
if (s < 0.1 || s > 0.9)
{
......@@ -881,11 +881,11 @@ void Foam::hexRef8::checkBoundaryOrientation
face compactFace(identity(newFace.size()));
pointField compactPoints(meshMod.points(), newFace);
vector n(compactFace.normal(compactPoints));
const vector areaNorm(compactFace.areaNormal(compactPoints));
vector dir(boundaryPt - ownPt);
const vector dir(boundaryPt - ownPt);
if ((dir & n) < 0)
if ((dir & areaNorm) < 0)
{
FatalErrorInFunction
<< "cell:" << celli << " old face:" << facei
......@@ -896,9 +896,9 @@ void Foam::hexRef8::checkBoundaryOrientation
<< abort(FatalError);
}
vector fcToOwn(compactFace.centre(compactPoints) - ownPt);
const vector fcToOwn(compactFace.centre(compactPoints) - ownPt);
scalar s = (fcToOwn&dir) / magSqr(dir);
const scalar s = (fcToOwn & dir) / magSqr(dir);
if (s < 0.7 || s > 1.3)
{
......
......@@ -150,8 +150,7 @@ void Foam::enrichedPatch::calcCutFaces() const
}
// Grab face normal
vector normal = curLocalFace.normal(lp);
normal /= mag(normal);
const vector normal = curLocalFace.unitNormal(lp);
while (edgeSeeds.size())
{
......
......@@ -143,9 +143,8 @@ inline void Foam::STLtriangle::write
const point& pt2
)
{
// calculate the normal ourselves
vector norm = triPointRef(pt0, pt1, pt2).normal();
norm /= mag(norm) + VSMALL;
// Calculate the normal ourselves
const vector norm = triPointRef(pt0, pt1, pt2).unitNormal();
write(os, norm, pt0, pt1, pt2);
}
......
......@@ -979,10 +979,10 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
);
const point bottomCc(bottom.centre());
const vector bottomNormal(bottom.normal());
const vector bottomNormal(bottom.areaNormal());