ENH: distinguish between face areaNormal/unitNormal in the code

This commit is contained in:
Mark Olesen
2018-08-10 15:43:06 +02:00
parent b81a2f2fa6
commit c1964d7807
52 changed files with 200 additions and 256 deletions

View File

@ -87,7 +87,7 @@ void Foam::directAMI<SourcePatch, TargetPatch>::appendToDirectSeeds
// second attempt: match by shooting a ray into the tgt face
if (!found)
{
const vector srcN = srcF.normal(srcPoints);
const vector srcN = srcF.areaNormal(srcPoints);
for (const label tgtI : tgtNbr)
{
@ -117,7 +117,7 @@ void Foam::directAMI<SourcePatch, TargetPatch>::appendToDirectSeeds
{
Pout<< "source face not found: id=" << srcI
<< " centre=" << srcCf[srcI]
<< " normal=" << srcF.normal(srcPoints)
<< " normal=" << srcF.areaNormal(srcPoints)
<< " points=" << srcF.points(srcPoints)
<< endl;
@ -128,7 +128,7 @@ void Foam::directAMI<SourcePatch, TargetPatch>::appendToDirectSeeds
Pout<< "face id: " << tgtI
<< " centre=" << tgtF.centre(tgtPoints)
<< " normal=" << tgtF.normal(tgtPoints)
<< " normal=" << tgtF.areaNormal(tgtPoints)
<< " points=" << tgtF.points(tgtPoints)
<< endl;
}

View File

@ -197,8 +197,8 @@ void Foam::cyclicAMIPolyPatch::calcTransforms
reduce(n0, maxMagSqrOp<point>());
reduce(n1, maxMagSqrOp<point>());
n0 /= mag(n0) + VSMALL;
n1 /= mag(n1) + VSMALL;
n0.normalise();
n1.normalise();
// Extended tensor from two local coordinate systems calculated
// using normal and rotation axis
@ -367,14 +367,14 @@ void Foam::cyclicAMIPolyPatch::calcTransforms()
vectorField half0Areas(half0.size());
forAll(half0, facei)
{
half0Areas[facei] = half0[facei].normal(half0.points());
half0Areas[facei] = half0[facei].areaNormal(half0.points());
}
const cyclicAMIPolyPatch& half1 = neighbPatch();
vectorField half1Areas(half1.size());
forAll(half1, facei)
{
half1Areas[facei] = half1[facei].normal(half1.points());
half1Areas[facei] = half1[facei].areaNormal(half1.points());
}
calcTransforms

View File

@ -172,7 +172,7 @@ Foam::volumeType Foam::treeDataPrimitivePatch<PatchType>::getVolumeType
// already have point.
pointHit curHit = f.nearestPoint(sample, points);
const vector area = f.normal(points);
const vector area = f.areaNormal(points);
const point& curPt = curHit.rawPoint();
//

View File

@ -1023,13 +1023,11 @@ bool Foam::primitiveMeshGeometry::checkFaceTwist
label nWarped = 0;
forAll(checkFaces, i)
for (const label facei : checkFaces)
{
label facei = checkFaces[i];
const face& f = fcs[facei];
scalar magArea = mag(faceAreas[facei]);
const scalar magArea = mag(faceAreas[facei]);
if (f.size() > 3 && magArea > VSMALL)
{
@ -1039,21 +1037,21 @@ bool Foam::primitiveMeshGeometry::checkFaceTwist
forAll(f, fpI)
{
vector triArea
const vector triArea
(
triPointRef
(
p[f[fpI]],
p[f.nextLabel(fpI)],
fc
).normal()
).areaNormal()
);
scalar magTri = mag(triArea);
const scalar magTri = mag(triArea);
if (magTri > VSMALL && ((nf & triArea/magTri) < minTwist))
{
nWarped++;
++nWarped;
if (setPtr)
{

View File

@ -752,8 +752,8 @@ void Foam::triSurfaceMesh::getNormal
{
if (info[i].hit())
{
label facei = info[i].index();
normal[i] = s[facei].normal(pts);
const label facei = info[i].index();
normal[i] = s[facei].unitNormal(pts);
scalar qual = s[facei].tri(pts).quality();
@ -768,12 +768,10 @@ void Foam::triSurfaceMesh::getNormal
if (nbrQual > qual)
{
qual = nbrQual;
normal[i] = s[nbri].normal(pts);
normal[i] = s[nbri].unitNormal(pts);
}
}
}
normal[i] /= mag(normal[i]) + VSMALL;
}
else
{
@ -789,12 +787,9 @@ void Foam::triSurfaceMesh::getNormal
if (info[i].hit())
{
const label facei = info[i].index();
// Cached:
//normal[i] = faceNormals()[facei];
// Uncached
normal[i] = s[facei].normal(pts);
normal[i] /= mag(normal[i]) + VSMALL;
normal[i] = s[facei].unitNormal(pts);
}
else
{

View File

@ -62,11 +62,7 @@ void Foam::rotatedBoxToCell::combine(topoSet& set, const bool add) const
boxPoints[6] = origin_ + k_ + i_ + j_;
boxPoints[7] = origin_ + k_ + j_;
labelList boxVerts(8);
forAll(boxVerts, i)
{
boxVerts[i] = i;
}
labelList boxVerts(identity(8));
const cellModel& hex = cellModel::ref(cellModel::HEX);
@ -77,7 +73,7 @@ void Foam::rotatedBoxToCell::combine(topoSet& set, const bool add) const
vectorField boxFaceNormals(boxFaces.size());
forAll(boxFaces, i)
{
boxFaceNormals[i] = boxFaces[i].normal(boxPoints);
boxFaceNormals[i] = boxFaces[i].areaNormal(boxPoints);
//Pout<< "Face:" << i << " position:" << boxFaces[i].centre(boxPoints)
// << " normal:" << boxFaceNormals[i] << endl;

View File

@ -124,7 +124,7 @@ void Foam::setAndNormalToFaceZone::applyToSet
{
newAddressing.append(facei);
vector n = faces[facei].normal(points);
const vector n = faces[facei].areaNormal(points);
if ((n & normal_) > 0)
{
newFlipMap.append(false);

View File

@ -52,7 +52,7 @@ void Foam::tetOverlapVolume::tetTetOverlap
tetPointRef tetATet = tetA.tet();
for (label facei = 0; facei < 4; ++facei)
{
tetAFaceAreas[facei] = -tetATet.tri(facei).normal();
tetAFaceAreas[facei] = -tetATet.tri(facei).areaNormal();
tetAMag2FaceAreas[facei] = magSqr(tetAFaceAreas[facei]);
if (tetAMag2FaceAreas[facei] < ROOTVSMALL)
{
@ -65,7 +65,7 @@ void Foam::tetOverlapVolume::tetTetOverlap
tetPointRef tetBTet = tetB.tet();
for (label facei = 0; facei < 4; ++facei)
{
tetBFaceAreas[facei] = -tetBTet.tri(facei).normal();
tetBFaceAreas[facei] = -tetBTet.tri(facei).areaNormal();
tetBMag2FaceAreas[facei] = magSqr(tetBFaceAreas[facei]);
if (tetBMag2FaceAreas[facei] < ROOTVSMALL)
{

View File

@ -1021,7 +1021,7 @@ Foam::faceList Foam::intersectedSurface::splitFace
// See if normal needs flipping.
faces.shrink();
vector n = faces[0].normal(eSurf.points());
const vector n = faces[0].areaNormal(eSurf.points());
if ((n & surf.faceNormals()[facei]) < 0)
{

View File

@ -54,8 +54,8 @@ Foam::tmp<Foam::vectorField> Foam::faceTriangulation::calcEdges
const pointField& points
)
{
tmp<vectorField> tedges(new vectorField(f.size()));
vectorField& edges = tedges.ref();
auto tedges = tmp<vectorField>::New(f.size());
auto& edges = tedges.ref();
forAll(f, i)
{
@ -63,9 +63,8 @@ Foam::tmp<Foam::vectorField> Foam::faceTriangulation::calcEdges
point nextPt = points[f[f.fcIndex(i)]];
vector vec(nextPt - thisPt);
vec /= mag(vec) + VSMALL;
edges[i] = vec;
edges[i] = vec.normalise();
}
return tedges;
@ -159,9 +158,9 @@ bool Foam::faceTriangulation::triangleContainsPoint
const point& pt
)
{
scalar area01Pt = triPointRef(p0, p1, pt).normal() & n;
scalar area12Pt = triPointRef(p1, p2, pt).normal() & n;
scalar area20Pt = triPointRef(p2, p0, pt).normal() & n;
const scalar area01Pt = triPointRef(p0, p1, pt).areaNormal() & n;
const scalar area12Pt = triPointRef(p1, p2, pt).areaNormal() & n;
const scalar area20Pt = triPointRef(p2, p0, pt).areaNormal() & n;
if ((area01Pt > 0) && (area12Pt > 0) && (area20Pt > 0))
{
@ -172,10 +171,8 @@ bool Foam::faceTriangulation::triangleContainsPoint
FatalErrorInFunction << abort(FatalError);
return false;
}
else
{
return false;
}
return false;
}
@ -209,7 +206,7 @@ void Foam::faceTriangulation::findDiagonal
);
// rayDir should be normalized already but is not due to rounding errors
// so normalize.
rayDir /= mag(rayDir) + VSMALL;
rayDir.normalise();
//
@ -309,8 +306,8 @@ void Foam::faceTriangulation::findDiagonal
{
// pt inside triangle (so perhaps visible)
// Select based on minimal angle (so guaranteed visible).
vector edgePt0 = pt - startPt;
edgePt0 /= mag(edgePt0);
vector edgePt0 = (pt - startPt);
edgePt0.normalise();
scalar cos = rayDir & edgePt0;
if (cos > maxCos)
@ -598,14 +595,12 @@ bool Foam::faceTriangulation::split
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Null constructor
Foam::faceTriangulation::faceTriangulation()
:
triFaceList()
{}
// Construct from components
Foam::faceTriangulation::faceTriangulation
(
const pointField& points,
@ -615,8 +610,7 @@ Foam::faceTriangulation::faceTriangulation
:
triFaceList(f.size()-2)
{
vector avgNormal = f.normal(points);
avgNormal /= mag(avgNormal) + VSMALL;
const vector avgNormal = f.unitNormal(points);
label triI = 0;
@ -629,7 +623,6 @@ Foam::faceTriangulation::faceTriangulation
}
// Construct from components
Foam::faceTriangulation::faceTriangulation
(
const pointField& points,
@ -651,7 +644,6 @@ Foam::faceTriangulation::faceTriangulation
}
// Construct from Istream
Foam::faceTriangulation::faceTriangulation(Istream& is)
:
triFaceList(is)

View File

@ -68,8 +68,8 @@ Foam::triSurfaceTools::vertexNormals(const triSurface& surf)
Info<< "Calculating vertex normals" << endl;
tmp<vectorField> tfld(new vectorField(surf.nPoints(), Zero));
vectorField& pointNormals = tfld.ref();
auto tpointNormals = tmp<vectorField>::New(surf.nPoints(), Zero);
auto& pointNormals = tpointNormals.ref();
const pointField& points = surf.points();
const labelListList& pointFaces = surf.pointFaces();
@ -79,28 +79,27 @@ Foam::triSurfaceTools::vertexNormals(const triSurface& surf)
{
const labelList& pFaces = pointFaces[pI];
forAll(pFaces, fI)
for (const label facei : pFaces)
{
const label facei = pFaces[fI];
const triFace& f = surf[facei];
vector fN = f.normal(points);
const vector areaNorm = f.areaNormal(points);
const scalar weight = vertexNormalWeight
(
f,
meshPoints[pI],
fN,
areaNorm,
points
);
pointNormals[pI] += weight*fN;
pointNormals[pI] += weight * areaNorm;
}
pointNormals[pI] /= mag(pointNormals[pI]) + VSMALL;
pointNormals[pI].normalise();
}
return tfld;
return tpointNormals;
}
@ -114,8 +113,8 @@ Foam::triSurfaceTools::vertexTriads
const pointField& points = surf.points();
const Map<label>& meshPointMap = surf.meshPointMap();
tmp<triadField> tfld(new triadField(points.size()));
triadField& pointTriads = tfld.ref();
auto tpointTriads = tmp<triadField>::New(points.size());
auto& pointTriads = tpointTriads.ref();
forAll(points, pI)
{
@ -131,16 +130,13 @@ Foam::triSurfaceTools::vertexTriads
plane p(pt, normal);
// Pick arbitrary point in plane
vector dir1 = pt - p.somePointInPlane(1e-3);
dir1 /= mag(dir1);
vector dir2 = dir1 ^ normal;
dir2 /= mag(dir2);
vector dir1 = normalised(pt - p.somePointInPlane(1e-3));
vector dir2 = normalised(dir1 ^ normal);
pointTriads[meshPointMap[pI]] = triad(dir1, dir2, normal);
}
return tfld;
return tpointTriads;
}
@ -187,7 +183,7 @@ Foam::triSurfaceTools::curvatures
// Set up a local coordinate system for the face
const vector& e0 = edgeVectors[0];
const vector eN = f.normal(points);
const vector eN = f.areaNormal(points);
const vector e1 = (e0 ^ eN);
if (magSqr(eN) < ROOTVSMALL)
@ -276,7 +272,7 @@ Foam::triSurfaceTools::curvatures
(
f,
meshPoints[patchPointIndex],
f.normal(points),
f.areaNormal(points),
points
);
@ -304,8 +300,8 @@ Foam::triSurfaceTools::curvatures
}
}
tmp<scalarField> tfld(new scalarField(points.size(), Zero));
scalarField& curvatureAtPoints = tfld.ref();
auto tcurvatureAtPoints = tmp<scalarField>::New(points.size(), Zero);
scalarField& curvatureAtPoints = tcurvatureAtPoints.ref();
forAll(curvatureAtPoints, pI)
{
@ -325,7 +321,7 @@ Foam::triSurfaceTools::curvatures
curvatureAtPoints[meshPoints[pI]] = curvature;
}
return tfld;
return tcurvatureAtPoints;
}
@ -356,8 +352,8 @@ Foam::triSurfaceTools::writeCurvature
{
Info<< "Extracting curvature of surface at the points." << endl;
tmp<scalarField> tfld = triSurfaceTools::curvatures(surf);
scalarField& curv = tfld.ref();
tmp<scalarField> tcurv = triSurfaceTools::curvatures(surf);
scalarField& curv = tcurv.ref();
triSurfacePointScalarField outputField
(
@ -379,7 +375,7 @@ Foam::triSurfaceTools::writeCurvature
outputField.write();
outputField.swap(curv);
return tfld;
return tcurv;
}