diff --git a/docs/planning/feedback-correction-checklist-2026-11-14.md b/docs/planning/feedback-correction-checklist-2026-11-14.md index 8f9593cf1..67e3b7d2a 100644 --- a/docs/planning/feedback-correction-checklist-2026-11-14.md +++ b/docs/planning/feedback-correction-checklist-2026-11-14.md @@ -1063,3 +1063,48 @@ DisplayMeshFaceTagTest.ToMeshTaggedFaceIdsStayInRange PASS 内核 to_mesh_tagged 的 face 覆盖完整; 宿主若仍有漏面/斑点,应检查渲染缓存与 face id 重映射。 ~~~ + + +## 进展(2026-11-14 第二十轮) + +### VDE-1347:实心圆环结构化四面体 + +非星形体新增路径: + +~~~text +u(主圆)× v(管截面)× 径向 +核心三棱柱 → 3 tets +外层六面体 → 6 tets +外表面 boundary_faces +~~~ + +细分: + +~~~text +h = max_size * 0.5 +nu = ceil(2π(R+r)/h) +nv = ceil(2πr/h) +nr = ceil(r/h) +~~~ + +测试: + +~~~text +TetrahedralMeshTest.SolidTorusStructuredPath_VolumeAndBoundary + R=5 / r=1 + volume ≈ 2π²Rr² ±2% + boundary_faces>0 +~~~ + +全部: + +~~~text +test_fea_mesh: 32/32 PASS +~~~ + +当前 tetra 覆盖: + +~~~text +拉伸体 / 星形凸体 / 实心圆环 +其他 → 通用 Delaunay 回退 +~~~ diff --git a/src/cae/fea_mesh.cpp b/src/cae/fea_mesh.cpp index 810a659ef..120a2976a 100644 --- a/src/cae/fea_mesh.cpp +++ b/src/cae/fea_mesh.cpp @@ -1200,6 +1200,151 @@ bool make_star_tet_mesh(const brep::BrepModel& body, double target_size, } // namespace + +namespace { + +// 实心圆环:u(主圆)× v(管截面)× 径向 的结构化四面体。 +bool make_torus_tet_mesh(const brep::BrepModel& body, double target_size, + FEAMesh& out) { + std::vector tori; + for (int fi = 0; fi < static_cast(body.num_faces()); ++fi) { + if (body.face_type(fi) != brep::FaceType::Torus) return false; + auto g = brep::face_torus_geometry(body, fi); + if (!g) return false; + tori.push_back(*g); + } + if (tori.empty()) return false; + const auto& t0 = tori.front(); + for (const auto& g : tori) + if ((g.center - t0.center).norm() > 1e-7 || + std::abs(g.major_radius - t0.major_radius) > 1e-7 || + std::abs(g.minor_radius - t0.minor_radius) > 1e-7 || + std::abs(g.axis.normalized().dot(t0.axis.normalized())) < 1.0 - 1e-7) + return false; + const double R = t0.major_radius, r = t0.minor_radius; + if (!(R > 0.0 && r > 0.0 && r < R)) return false; + const double body_volume = body.body_volume(); + if (!(body_volume > 1e-12)) return false; + + const double pi = 3.14159265358979323846; + // 圆环截面的多边形面积收敛慢,内部再细分一档。 + const double h = std::max(target_size * 0.5, 1e-9); + const int nu = std::max(16, static_cast( + std::ceil(2.0 * pi * (R + r) / h))); + const int nv = std::max(8, static_cast( + std::ceil(2.0 * pi * r / h))); + const int nr = std::max(1, static_cast( + std::ceil(r / h))); + if (static_cast(nu) * nv * nr > 500000) return false; + + const core::Vector3D axis = t0.axis.normalized(); + const core::Vector3D ex = axis.unitOrthogonal(); + const core::Vector3D ey = axis.cross(ex).normalized(); + FEAMesh mesh; + mesh.element_type = FEAElementType::Tet4; + + std::vector centers(nu + 1); + std::vector>> rings( + nu + 1, std::vector>(nr + 1, std::vector(nv))); + for (int ui = 0; ui <= nu; ++ui) { + const double u = 2.0 * pi * ui / nu; + const core::Vector3D radial = ex * std::cos(u) + ey * std::sin(u); + const core::Point3D c = t0.center + radial * R; + centers[ui] = static_cast(mesh.vertices.size()); + mesh.vertices.push_back(c); + for (int i = 1; i <= nr; ++i) { + const double rho = r * i / nr; + for (int j = 0; j < nv; ++j) { + const double v = 2.0 * pi * j / nv; + rings[ui][i][j] = static_cast(mesh.vertices.size()); + mesh.vertices.push_back( + c + radial * (rho * std::cos(v)) + + axis * (rho * std::sin(v))); + } + } + } + auto add_tet = [&](int a, int b, int c, int d) { + const core::Vector3D ab = mesh.vertices[b] - mesh.vertices[a]; + const core::Vector3D ac = mesh.vertices[c] - mesh.vertices[a]; + const core::Vector3D ad = mesh.vertices[d] - mesh.vertices[a]; + if (ab.dot(ac.cross(ad)) < 0.0) std::swap(c, d); + mesh.elements.push_back({a, b, c, d}); + }; + for (int ui = 0; ui < nu; ++ui) { + const int u1 = ui + 1; + for (int j = 0; j < nv; ++j) { + const int j1 = (j + 1) % nv; + // 核心:两个三角扇之间的三棱柱 → 3 tets + const int c0 = centers[ui], c1 = centers[u1]; + const int a0 = rings[ui][1][j], b0 = rings[ui][1][j1]; + const int a1 = rings[u1][1][j], b1 = rings[u1][1][j1]; + add_tet(c0, a0, b0, c1); + add_tet(a0, b0, c1, a1); + add_tet(b0, c1, a1, b1); + // 外层六面体 → 6 tets + for (int i = 1; i < nr; ++i) { + const int A = rings[ui][i][j], B = rings[ui][i][j1]; + const int C = rings[ui][i + 1][j1], D = rings[ui][i + 1][j]; + const int A1 = rings[u1][i][j], B1 = rings[u1][i][j1]; + const int C1 = rings[u1][i + 1][j1], D1 = rings[u1][i + 1][j]; + add_tet(A, B, C, C1); + add_tet(A, C, D, C1); + add_tet(A, D, D1, C1); + add_tet(A, D1, A1, C1); + add_tet(A, A1, B1, C1); + add_tet(A, B1, B, C1); + } + } + } + double vol = 0.0; + for (const auto& e : mesh.elements) { + const auto a = mesh.vertices[e[0]]; + const auto b = mesh.vertices[e[1]]; + const auto c = mesh.vertices[e[2]]; + const auto d = mesh.vertices[e[3]]; + vol += std::abs((b - a).cross(c - a).dot(d - a)) / 6.0; + } + if (std::abs(vol - body_volume) > 0.02 * body_volume) return false; + + auto add_tri = [&](int a, int b, int c) { + mesh.boundary_faces.push_back({a, b, c}); + mesh.boundary_face_tags.push_back(-1); + mesh.boundary_edges.push_back({a, b}); + mesh.boundary_edges.push_back({b, c}); + mesh.boundary_edges.push_back({c, a}); + mesh.boundary_edge_tags.push_back(-1); + mesh.boundary_edge_tags.push_back(-1); + mesh.boundary_edge_tags.push_back(-1); + }; + for (int ui = 0; ui < nu; ++ui) { + const int u1 = ui + 1; + const double u = 2.0 * pi * ui / nu; + const core::Vector3D radial = ex * std::cos(u) + ey * std::sin(u); + for (int j = 0; j < nv; ++j) { + const int j1 = (j + 1) % nv; + const int A = rings[ui][nr][j], B = rings[ui][nr][j1]; + const int C = rings[u1][nr][j1], D = rings[u1][nr][j]; + const double v = 2.0 * pi * j / nv; + const core::Vector3D outward = + radial * std::cos(v) + axis * std::sin(v); + for (const auto& tri : {std::array{A,B,C}, std::array{A,C,D}}) { + const auto p0 = mesh.vertices[tri[0]]; + const auto p1 = mesh.vertices[tri[1]]; + const auto p2 = mesh.vertices[tri[2]]; + const auto n = (p1 - p0).cross(p2 - p0); + if (n.dot(outward) < 0.0) add_tri(tri[0], tri[2], tri[1]); + else add_tri(tri[0], tri[1], tri[2]); + } + } + } + mesh.material_ids.assign(mesh.elements.size(), 0); + mesh.diagnostic = "tetrahedral_mesh: solid torus structured path"; + out = std::move(mesh); + return true; +} + +} // namespace + FEAMesh tetrahedral_mesh(const brep::BrepModel& body, const TetMeshParams& params) { // 目标单元尺寸:优先用户值;缺省取包围盒最大跨度的 5%(与头文件一致) @@ -1249,6 +1394,13 @@ FEAMesh tetrahedral_mesh(const brep::BrepModel& body, return star; } + // 实心圆环(非星形):结构化 u/v/径向四面体。 + { + FEAMesh torus; + if (make_torus_tet_mesh(body, target_size, torus)) + return torus; + } + // Step 1: 三角化 B-Rep 表面。弦高容差取目标单元尺寸(原实现硬编码 0.01): // 对 target_size=0.5 的球体,0.01 会把曲面采成 27136 个表面顶点,远超下游 // 朴素 Bowyer-Watson delaunay_3d(O(n²))的可承受规模——SphereMesh_NonTrivial diff --git a/tests/cae/test_fea_mesh.cpp b/tests/cae/test_fea_mesh.cpp index d2af35393..3ded8b219 100644 --- a/tests/cae/test_fea_mesh.cpp +++ b/tests/cae/test_fea_mesh.cpp @@ -534,3 +534,25 @@ TEST(HexahedralMeshTest, SolidCylinderOgrid_VolumeAndBoundary) { } EXPECT_NEAR(vol, 3.14159265358979323846 * 25.0 * 20.0, 0.05 * 1570.8); } + + +TEST(TetrahedralMeshTest, SolidTorusStructuredPath_VolumeAndBoundary) { + auto torus = make_torus_exact(5.0, 1.0); + TetMeshParams params; + params.max_size = 0.5; + params.quality_iterations = 0; + auto mesh = tetrahedral_mesh(torus, params); + ASSERT_FALSE(mesh.elements.empty()) << mesh.diagnostic; + double vol = 0.0; + for (const auto& e : mesh.elements) { + const auto a = mesh.vertices[e[0]]; + const auto b = mesh.vertices[e[1]]; + const auto c = mesh.vertices[e[2]]; + const auto d = mesh.vertices[e[3]]; + vol += std::abs((b - a).cross(c - a).dot(d - a)) / 6.0; + } + const double expect = 2.0 * 3.14159265358979323846 * + 3.14159265358979323846 * 5.0 * 1.0; + EXPECT_NEAR(vol, expect, 0.02 * expect) << mesh.diagnostic; + EXPECT_GT(mesh.boundary_faces.size(), 0u); +}