Commit 771a8434 authored by Franjo's avatar Franjo
Browse files

Updated mesh checks

parent 264432b6
...@@ -479,7 +479,6 @@ bool checkTetQuality ...@@ -479,7 +479,6 @@ bool checkTetQuality
const labelList& owner = mesh.owner(); const labelList& owner = mesh.owner();
const labelList& neighbour = mesh.neighbour(); const labelList& neighbour = mesh.neighbour();
const vectorField& fCentres = mesh.addressingData().faceCentres();
const vectorField& cCentres = mesh.addressingData().cellCentres(); const vectorField& cCentres = mesh.addressingData().cellCentres();
label nBadFaces(0); label nBadFaces(0);
...@@ -494,89 +493,168 @@ bool checkTetQuality ...@@ -494,89 +493,168 @@ bool checkTetQuality
const face& f = faces[faceI]; const face& f = faces[faceI];
forAll(f, eI) const label nDecomposed = f.size() - 1;
{
//- check the tet on the neighbour side
tetrahedron<point, point> tetOwn
(
fCentres[faceI],
points[f[eI]],
points[f.nextLabel(eI)],
cCentres[owner[faceI]]
);
const scalar tetQualityOwn = help::tetQuality(tetOwn); forAll(f, pI)
{
bool badQualityFace(false);
if( tetQualityOwn < minTetQuality ) for(label j=1;j<nDecomposed;++j)
{ {
++nBadFaces; const label fpJ = f[(pI+j) % f.size()];
const label nfpJ = f[(pI+j+1) % f.size()];
if( report ) //- check the tet on the neighbour side
tetrahedron<point, point> tetOwn
(
cCentres[owner[faceI]],
points[f[pI]],
points[fpJ],
points[nfpJ]
);
const scalar tetQualityOwn = help::tetQuality(tetOwn);
if( tetQualityOwn < minTetQuality )
{ {
# ifdef USE_OMP ++nBadFaces;
# pragma omp critical
# endif if( report )
Pout<< "Face " << faceI {
<< " has a triangle that points the wrong way." # ifdef USE_OMP
<< endl # pragma omp critical(output)
<< "Tet quality: " << tetQualityOwn # endif
<< " Face " << faceI Pout<< "Face " << faceI
<< endl; << " has a triangle that points the wrong way."
<< endl
<< "Tet quality: " << tetQualityOwn
<< " Face " << faceI
<< endl;
}
if( setPtr )
{
# ifdef USE_OMP
# pragma omp critical(insertingBadFaces)
# endif
setPtr->insert(faceI);
}
//- found a problematic face. Do not search further
badQualityFace = true;
continue;
} }
if( setPtr ) if( neighbour[faceI] < 0 )
continue;
//- check the tet on the neighbour side
tetrahedron<point, point> tetNei
(
cCentres[neighbour[faceI]],
points[f[pI]],
points[nfpJ],
points[fpJ]
);
const scalar tetQualityNei = help::tetQuality(tetNei);
if( tetQualityNei < minTetQuality )
{ {
# ifdef USE_OMP ++nBadFaces;
# pragma omp critical(insertingBadFaces)
# endif if( report )
setPtr->insert(faceI); {
# ifdef USE_OMP
# pragma omp critical(output)
# endif
Pout<< "Face " << faceI
<< " has a triangle that points the wrong way."
<< endl
<< "Tet quality: " << tetQualityNei
<< " Face " << faceI
<< endl;
}
if( setPtr )
{
# ifdef USE_OMP
# pragma omp critical(insertingBadFaces)
# endif
setPtr->insert(faceI);
}
//- found a problematic face. Do not search further
badQualityFace = true;
continue;
} }
} }
if( neighbour[faceI] < 0 ) if( badQualityFace )
continue; continue;
}
}
//- check the tet on the neighbour side reduce(nBadFaces, sumOp<label>());
tetrahedron<point, point> tetNei
( if( Pstream::parRun() && nBadFaces && setPtr )
fCentres[faceI], {
points[f.nextLabel(eI)], //- make sure that processor faces are marked on both sides
points[f[eI]], const PtrList<processorBoundaryPatch>& procBoundaries =
cCentres[neighbour[faceI]] mesh.procBoundaries();
);
const scalar tetQualityNei = help::tetQuality(tetNei); //- send and receive data where needed
forAll(procBoundaries, patchI)
{
const label start = procBoundaries[patchI].patchStart();
const label size = procBoundaries[patchI].patchSize();
if( tetQualityNei < minTetQuality ) labelLongList markedFaces;
for(label faceI=0;faceI<size;++faceI)
{ {
++nBadFaces; if( setPtr->found(start+faceI) )
markedFaces.append(faceI);
}
if( report ) OPstream toOtherProc
{ (
# ifdef USE_OMP Pstream::blocking,
# pragma omp critical procBoundaries[patchI].neiProcNo(),
# endif markedFaces.byteSize()
Pout<< "Face " << faceI );
<< " has a triangle that points the wrong way."
<< endl
<< "Tet quality: " << tetQualityNei
<< " Face " << faceI
<< endl;
}
if( setPtr ) toOtherProc << markedFaces;
{ }
# ifdef USE_OMP
# pragma omp critical(insertingBadFaces) forAll(procBoundaries, patchI)
# endif {
setPtr->insert(faceI); labelList receivedData;
} IPstream fromOtheProc
} (
Pstream::blocking,
procBoundaries[patchI].neiProcNo()
);
fromOtheProc >> receivedData;
const label start = procBoundaries[patchI].patchStart();
forAll(receivedData, i)
setPtr->insert(start+receivedData[i]);
} }
} }
if( nBadFaces != 0 ) if( nBadFaces != 0 )
{
WarningIn
(
"bool checkTetQuality("
"const polyMeshGen&, const bool, const scalar,"
" labelHashSet*, const boolList*)"
) << "Found " << nBadFaces
<< " faces with negative tet decomposition (minTetQuality < "
<< minTetQuality << ")." << endl;
return true; return true;
}
return false; return false;
} }
...@@ -622,7 +700,7 @@ bool checkMinTwist ...@@ -622,7 +700,7 @@ bool checkMinTwist
# endif # endif
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp for schedule(static, 1) # pragma omp for schedule(guided, 100)
# endif # endif
for(label faceI=0; faceI<nInternalFaces;++faceI) for(label faceI=0; faceI<nInternalFaces;++faceI)
{ {
...@@ -658,7 +736,7 @@ bool checkMinTwist ...@@ -658,7 +736,7 @@ bool checkMinTwist
if( setPtr ) if( setPtr )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(badFace)
# endif # endif
setPtr->insert(faceI); setPtr->insert(faceI);
} }
...@@ -715,7 +793,7 @@ bool checkMinTwist ...@@ -715,7 +793,7 @@ bool checkMinTwist
if( setPtr ) if( setPtr )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(badFace)
# endif # endif
setPtr->insert(faceI); setPtr->insert(faceI);
} }
...@@ -906,17 +984,17 @@ bool checkCellDeterminant ...@@ -906,17 +984,17 @@ bool checkCellDeterminant
{ {
if( affectedCells[cI] ) if( affectedCells[cI] )
{ {
const cell& cFaces = cells[cI]; const cell& c = cells[cI];
const vectorField& areas = mesh.addressingData().faceAreas(); const vectorField& areas = mesh.addressingData().faceAreas();
tensor areaSum(tensor::zero); tensor areaSum(tensor::zero);
scalar magAreaSum = 0.0; scalar magAreaSum = 0.0;
forAll(cFaces, cFaceI) forAll(c, fI)
{ {
label faceI = cFaces[cFaceI]; const label faceI = c[fI];
scalar magArea = mag(areas[faceI]) + VSMALL; const scalar magArea = mag(areas[faceI]) + VSMALL;
magAreaSum += magArea; magAreaSum += magArea;
areaSum += areas[faceI]*(areas[faceI]/magArea); areaSum += areas[faceI]*(areas[faceI]/magArea);
...@@ -934,12 +1012,12 @@ bool checkCellDeterminant ...@@ -934,12 +1012,12 @@ bool checkCellDeterminant
if( setPtr ) if( setPtr )
{ {
//Insert all faces of the cell //Insert all faces of the cell
forAll(cFaces, cFaceI) forAll(c, fI)
{ {
label faceI = cFaces[cFaceI]; const label faceI = c[fI];
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(badFace)
# endif # endif
setPtr->insert(faceI); setPtr->insert(faceI);
} }
...@@ -950,7 +1028,7 @@ bool checkCellDeterminant ...@@ -950,7 +1028,7 @@ bool checkCellDeterminant
} }
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(minDet)
# endif # endif
minDet = min(minDet, localMinDet); minDet = min(minDet, localMinDet);
} }
...@@ -1017,13 +1095,14 @@ void checkMinVolRatio ...@@ -1017,13 +1095,14 @@ void checkMinVolRatio
const scalarField& vols = mesh.addressingData().cellVolumes(); const scalarField& vols = mesh.addressingData().cellVolumes();
volRatio.setSize(own.size()); volRatio.setSize(own.size());
volRatio = 1.0;
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp parallel for schedule (dynamic, 100) # pragma omp parallel for schedule (dynamic, 100)
# endif # endif
for(label faceI=0; faceI<nInternalFaces;++faceI) for(label faceI=0; faceI<nInternalFaces;++faceI)
{ {
volRatio[faceI] = 1.0;
if( changedFacePtr && !changedFacePtr->operator[](faceI) ) if( changedFacePtr && !changedFacePtr->operator[](faceI) )
continue; continue;
...@@ -1142,7 +1221,7 @@ bool checkMinVolRatio ...@@ -1142,7 +1221,7 @@ bool checkMinVolRatio
if( setPtr ) if( setPtr )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(badFace)
# endif # endif
setPtr->insert(faceI); setPtr->insert(faceI);
} }
...@@ -1156,7 +1235,7 @@ bool checkMinVolRatio ...@@ -1156,7 +1235,7 @@ bool checkMinVolRatio
} }
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(minVolRatio)
# endif # endif
{ {
maxVolRatio = Foam::max(maxVolRatio , localMaxVolRatio); maxVolRatio = Foam::max(maxVolRatio , localMaxVolRatio);
...@@ -1321,7 +1400,7 @@ bool checkTriangleTwist ...@@ -1321,7 +1400,7 @@ bool checkTriangleTwist
if( setPtr ) if( setPtr )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(badFace)
# endif # endif
setPtr->insert(faceI); setPtr->insert(faceI);
} }
...@@ -1420,7 +1499,7 @@ bool checkCellPartTetrahedra ...@@ -1420,7 +1499,7 @@ bool checkCellPartTetrahedra
if( report ) if( report )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(report)
# endif # endif
Pout<< "Zero or negative cell volume detected for cell " Pout<< "Zero or negative cell volume detected for cell "
<< owner[faceI] << "." << endl; << owner[faceI] << "." << endl;
...@@ -1445,7 +1524,7 @@ bool checkCellPartTetrahedra ...@@ -1445,7 +1524,7 @@ bool checkCellPartTetrahedra
if( report ) if( report )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(report)
# endif # endif
Pout<< "Zero or negative cell volume detected for cell " Pout<< "Zero or negative cell volume detected for cell "
<< neighbour[faceI] << "." << endl; << neighbour[faceI] << "." << endl;
...@@ -1460,7 +1539,7 @@ bool checkCellPartTetrahedra ...@@ -1460,7 +1539,7 @@ bool checkCellPartTetrahedra
if( setPtr ) if( setPtr )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(badFace)
# endif # endif
setPtr->insert(faceI); setPtr->insert(faceI);
} }
...@@ -1687,7 +1766,7 @@ bool checkFaceDotProduct ...@@ -1687,7 +1766,7 @@ bool checkFaceDotProduct
{ {
// Severe non-orthogonality but mesh still OK // Severe non-orthogonality but mesh still OK
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(report)
# endif # endif
Pout<< "Severe non-orthogonality for face " << faceI Pout<< "Severe non-orthogonality for face " << faceI
<< " between cells " << own[faceI] << " between cells " << own[faceI]
...@@ -1700,7 +1779,7 @@ bool checkFaceDotProduct ...@@ -1700,7 +1779,7 @@ bool checkFaceDotProduct
if( setPtr ) if( setPtr )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(badFace)
# endif # endif
setPtr->insert(faceI); setPtr->insert(faceI);
} }
...@@ -1714,7 +1793,7 @@ bool checkFaceDotProduct ...@@ -1714,7 +1793,7 @@ bool checkFaceDotProduct
if( setPtr ) if( setPtr )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(badFace)
# endif # endif
setPtr->insert(faceI); setPtr->insert(faceI);
} }
...@@ -1726,7 +1805,7 @@ bool checkFaceDotProduct ...@@ -1726,7 +1805,7 @@ bool checkFaceDotProduct
} }
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(minDDotS)
# endif # endif
minDDotS = Foam::min(minDDotS, localMinDDotS); minDDotS = Foam::min(minDDotS, localMinDDotS);
} }
...@@ -1765,7 +1844,7 @@ bool checkFaceDotProduct ...@@ -1765,7 +1844,7 @@ bool checkFaceDotProduct
{ {
// Severe non-orthogonality but mesh still OK // Severe non-orthogonality but mesh still OK
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(report)
# endif # endif
{ {
const scalar angle const scalar angle
...@@ -1784,7 +1863,7 @@ bool checkFaceDotProduct ...@@ -1784,7 +1863,7 @@ bool checkFaceDotProduct
if( setPtr ) if( setPtr )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(badFace)
# endif # endif
setPtr->insert(start+faceI); setPtr->insert(start+faceI);
} }
...@@ -1798,7 +1877,7 @@ bool checkFaceDotProduct ...@@ -1798,7 +1877,7 @@ bool checkFaceDotProduct
if( setPtr ) if( setPtr )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(badFace)
# endif # endif
setPtr->insert(start+faceI); setPtr->insert(start+faceI);
} }
...@@ -1812,7 +1891,7 @@ bool checkFaceDotProduct ...@@ -1812,7 +1891,7 @@ bool checkFaceDotProduct
} }
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(minDDotS)
# endif # endif
minDDotS = Foam::min(minDDotS, localMinDDotS); minDDotS = Foam::min(minDDotS, localMinDDotS);
} }
...@@ -1910,7 +1989,7 @@ bool checkFacePyramids ...@@ -1910,7 +1989,7 @@ bool checkFacePyramids
if( report ) if( report )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(report)
# endif # endif
Pout<< "bool checkFacePyramids(" Pout<< "bool checkFacePyramids("
<< "const bool, const scalar, labelHashSet*) : " << "const bool, const scalar, labelHashSet*) : "
...@@ -1942,7 +2021,7 @@ bool checkFacePyramids ...@@ -1942,7 +2021,7 @@ bool checkFacePyramids
if( report ) if( report )
{ {
# ifdef USE_OMP # ifdef USE_OMP
# pragma omp critical # pragma omp critical(report)
# endif # endif