Skip to content

Commit e04ea58

Browse files
authored
Merge pull request #524 from como2099/cwm/adapt_mixed_2d_fix_develop
Add check by computing the validity (using positive area) of a quadrilateral element : Fix adapt crash for mixed-element 2D meshes with frozen quad layers
2 parents 40ecac1 + 08d787b commit e04ea58

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

ma/maQuality.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,32 @@ bool isLayerElementOk(Mesh* m, Entity* e)
569569
return isPyramidOk(m, e);
570570
if (type == apf::Mesh::PRISM)
571571
return isPrismOk(m, e);
572+
if (type == apf::Mesh::QUAD) {
573+
// Check if quad is non-degenerate without assuming a specific embedding.
574+
// The quad is considered valid if its two sub-triangles have non-zero area
575+
// and consistent orientation.
576+
577+
Entity* v[4];
578+
m->getDownward(e, 0, v);
579+
Vector p[4];
580+
for (int i = 0; i < 4; ++i)
581+
m->getPoint(v[i], 0, p[i]);
582+
583+
// Form two triangles sharing a diagonal
584+
Vector n1 = apf::cross(p[1] - p[0], p[2] - p[0]);
585+
Vector n2 = apf::cross(p[2] - p[0], p[3] - p[0]);
586+
587+
double a1 = n1.getLength();
588+
double a2 = n2.getLength();
589+
590+
// Reject degenerate triangles
591+
const double eps = 1e-14;
592+
if (a1 < eps || a2 < eps)
593+
return false;
594+
595+
// Check consistent orientation (normals point in the same general direction)
596+
return (n1 * n2) > eps * a1 * a2;
597+
}
572598
abort();
573599
return false;
574600
}

0 commit comments

Comments
 (0)