Skip to content

Commit 7ed1e04

Browse files
committed
Added tet-quality mesh adaptor criterion.
1 parent 74791e1 commit 7ed1e04

3 files changed

Lines changed: 135 additions & 0 deletions

File tree

FEAMR/FEAMR.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ SOFTWARE.*/
3838
#include "FEFilterAdaptorCriterion.h"
3939
#include "FEDomainErrorCriterion.h"
4040
#include "FEElementDataCriterion.h"
41+
#include "FETetQualityCriterion.h"
4142

4243
//-----------------------------------------------------------------------------
4344
void FEAMR::InitModule()
@@ -57,4 +58,5 @@ REGISTER_FECORE_CLASS(FEScaleAdaptorCriterion , "math");
5758
REGISTER_FECORE_CLASS(FEMinMaxFilterAdaptorCriterion, "min-max filter");
5859
REGISTER_FECORE_CLASS(FEDomainErrorCriterion, "relative error");
5960
REGISTER_FECORE_CLASS(FEElementDataCriterion, "element data");
61+
REGISTER_FECORE_CLASS(FETetQualityCriterion, "tet-quality");
6062
}

FEAMR/FETetQualityCriterion.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*This file is part of the FEBio source code and is licensed under the MIT license
2+
listed below.
3+
4+
See Copyright-FEBio.txt for details.
5+
6+
Copyright (c) 2026 University of Utah, The Trustees of Columbia University in
7+
the City of New York, and others.
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.*/
26+
#include "FETetQualityCriterion.h"
27+
#include <FECore/FEElement.h>
28+
#include <FECore/FEModel.h>
29+
30+
BEGIN_FECORE_CLASS(FETetQualityCriterion, FEMeshAdaptorCriterion)
31+
ADD_PARAMETER(minQuality, "min_quality")->setLongName("Minimum tet quality");
32+
END_FECORE_CLASS();
33+
34+
FETetQualityCriterion::FETetQualityCriterion(FEModel* fem) : FEMeshAdaptorCriterion(fem)
35+
{
36+
minQuality = 0.0;
37+
}
38+
39+
bool FETetQualityCriterion::GetElementValue(FEElement& el, double& value)
40+
{
41+
if (el.Shape() != ET_TET4) return false;
42+
value = TetQuality(el);
43+
return (value >= minQuality);
44+
}
45+
46+
double FETetQualityCriterion::TetQuality(FEElement& el)
47+
{
48+
FEModel* fem = GetFEModel();
49+
FEMesh& mesh = fem->GetMesh();
50+
51+
// get the tet's nodal coordinates
52+
vec3d p[4];
53+
for (int i = 0; i < 4; ++i) p[i] = mesh.Node(el.m_node[i]).m_rt;
54+
55+
// setup system of equation
56+
mat3d A;
57+
A[0][0] = p[1].x - p[0].x; A[0][1] = p[1].y - p[0].y; A[0][2] = p[1].z - p[0].z;
58+
A[1][0] = p[2].x - p[0].x; A[1][1] = p[2].y - p[0].y; A[1][2] = p[2].z - p[0].z;
59+
A[2][0] = p[3].x - p[0].x; A[2][1] = p[3].y - p[0].y; A[2][2] = p[3].z - p[0].z;
60+
A = A.inverse();
61+
62+
// setup RHS
63+
vec3d b;
64+
b.x = 0.5 * (p[1].x * p[1].x - p[0].x * p[0].x + p[1].y * p[1].y - p[0].y * p[0].y + p[1].z * p[1].z - p[0].z * p[0].z);
65+
b.y = 0.5 * (p[2].x * p[2].x - p[0].x * p[0].x + p[2].y * p[2].y - p[0].y * p[0].y + p[2].z * p[2].z - p[0].z * p[0].z);
66+
b.z = 0.5 * (p[3].x * p[3].x - p[0].x * p[0].x + p[3].y * p[3].y - p[0].y * p[0].y + p[3].z * p[3].z - p[0].z * p[0].z);
67+
68+
// find the center of the circum sphere
69+
vec3d c = A * b;
70+
71+
// find the radius of the circum sphere
72+
double R2 = (p[0].x - c.x) * (p[0].x - c.x) + (p[0].y - c.y) * (p[0].y - c.y) + (p[0].z - c.z) * (p[0].z - c.z);
73+
double R = sqrt(R2);
74+
75+
// find the shortest edge
76+
const int ET[6][2] = { { 0, 1 }, { 1, 2 }, { 2, 0 }, { 0, 3 }, { 1, 3 }, { 2, 3 } };
77+
78+
double L2, L2min = 1e99;
79+
for (int i = 0; i < 6; ++i)
80+
{
81+
int j = ET[i][0];
82+
int k = ET[i][1];
83+
L2 = (p[j].x - p[k].x) * (p[j].x - p[k].x) + (p[j].y - p[k].y) * (p[j].y - p[k].y) + (p[j].z - p[k].z) * (p[j].z - p[k].z);
84+
if (L2 < L2min) L2min = L2;
85+
}
86+
double L = sqrt(L2min);
87+
88+
return R / L;
89+
}

FEAMR/FETetQualityCriterion.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*This file is part of the FEBio source code and is licensed under the MIT license
2+
listed below.
3+
4+
See Copyright-FEBio.txt for details.
5+
6+
Copyright (c) 2026 University of Utah, The Trustees of Columbia University in
7+
the City of New York, and others.
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.*/
26+
#pragma once
27+
#include <FECore/FEMeshAdaptorCriterion.h>
28+
29+
class FETetQualityCriterion : public FEMeshAdaptorCriterion
30+
{
31+
public:
32+
FETetQualityCriterion(FEModel* fem);
33+
34+
bool GetElementValue(FEElement& el, double& value) override;
35+
36+
private:
37+
double TetQuality(FEElement& el);
38+
39+
private:
40+
double minQuality = 0.0;
41+
42+
DECLARE_FECORE_CLASS()
43+
};
44+

0 commit comments

Comments
 (0)