feat(cae/brep): Wave16 fixed-size volume convergence, analytic volume disasters, midsurface pairing
- A32: prism end-cap sampling retry (1/4 step, <=3 levels), revolved-body tetra path (make_revolved_tet_mesh, strict coaxial/generator criteria), star-path compact-body guard (skip when max_r > 4*target_size), near-miss best watertight surface fallback. Fixed-window 250: 166/59 -> 191/41 (+25, 0 reversals, mesh_rejected 7 -> 0). - A33: coarse closed-rim resampling in add_shared_edge_sample / mesh_face_trimmed (both gated on n < 8 coarse criterion) + untrimmed single-curved-face fallback; integration fix: closed_exact was bypassing the n<8 gate, densifying fine rims and cracking SpringEnd to_mesh (162 open edges, mesh volume 1.437906 -> 1.217774). Restored analytic 1.458958 / mesh 1.437906 / ratio 1.015 and test_measure case. - A34: non-pairing midsurface coverage (single-edge closed loops sampled at 32 params, constant-thickness contour fallback) -> mids 145->149, chain_failed 87->83. - A35: single curved closed face angular resolution floor res>=32 -> bug24283 sphere tets 0 -> 1984, relerr 0.455725 -> 0.00888095. - Tests: test_fea_mesh +5 cases / rewritten star+best-surface cases, 3 auto fingerprints re-baselined after fine-rim fix; test_vde1346_cae_preprocess +4 cases.
This commit is contained in:
+180
-36
@@ -5,6 +5,8 @@
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -97,8 +99,64 @@ std::vector<std::vector<core::Point3D>> sample_loops(
|
||||
std::vector<std::vector<core::Point3D>> loops;
|
||||
std::vector<std::vector<int>> edge_ids_out;
|
||||
const auto& f = body.face(fi);
|
||||
// 采样环的收尾(去重 + 绕向对齐 + 落盘):多边环与闭合单边环共用。
|
||||
auto commit = [&](std::vector<core::Point3D> pts,
|
||||
std::vector<int> ids) {
|
||||
std::vector<core::Point3D> clean;
|
||||
std::vector<int> clean_ids;
|
||||
for (size_t k = 0; k < pts.size(); ++k)
|
||||
if (clean.empty() || (clean.back() - pts[k]).norm() > 1e-12) {
|
||||
clean.push_back(pts[k]);
|
||||
clean_ids.push_back(ids[k]);
|
||||
}
|
||||
while (clean.size() >= 2 &&
|
||||
(clean.front() - clean.back()).norm() <= 1e-12) {
|
||||
clean.pop_back();
|
||||
clean_ids.pop_back();
|
||||
}
|
||||
if (clean.size() < 3) return;
|
||||
// 使环绕向与面法向一致(外环逆时针、内环顺时针):Newell 法向
|
||||
// 与面法向同向时不反转。共面 tile 只有在绕向一致时公共边才会以
|
||||
// 相反方向出现,几何并集才能正确抵消。
|
||||
core::Vector3D newell{0, 0, 0};
|
||||
const core::Point3D base = clean[0];
|
||||
for (size_t k = 0; k < clean.size(); ++k) {
|
||||
const core::Vector3D a = clean[k] - base;
|
||||
const core::Vector3D b = clean[(k + 1) % clean.size()] - base;
|
||||
newell = newell + a.cross(b);
|
||||
}
|
||||
auto pg = body.face_plane_geometry(fi);
|
||||
if (pg && newell.dot(pg->normal) < 0.0) {
|
||||
std::reverse(clean.begin(), clean.end());
|
||||
std::reverse(clean_ids.begin(), clean_ids.end());
|
||||
}
|
||||
loops.push_back(std::move(clean));
|
||||
edge_ids_out.push_back(std::move(clean_ids));
|
||||
};
|
||||
for (int lid : f.loops) {
|
||||
const auto& lp = body.loop_by_id(lid);
|
||||
// 整圆/闭合曲线单边环(VDE-1346 §7 补充修复):旧实现把
|
||||
// v_start==v_end 的单边闭环按「退化」跳过,带圆孔或圆形轮廓的平面
|
||||
// (垫圈/轴套端面/圆盘端面)因此 loops 为空、面积 0,在配对阶段被
|
||||
// 静默丢弃(四类失败计数全 0)。这里沿解析曲线按 32 等分采闭合
|
||||
// 折线,与多边环共用同一套去重/绕向对齐逻辑。
|
||||
if (lp.edges.size() == 1) {
|
||||
const auto& e = body.edge(lp.edges.front());
|
||||
if (e.v_start == e.v_end && e.curve && e.curve->degree() > 1) {
|
||||
constexpr int kClosedSamples = 32;
|
||||
std::vector<core::Point3D> pts;
|
||||
std::vector<int> ids;
|
||||
pts.reserve(kClosedSamples);
|
||||
ids.reserve(kClosedSamples);
|
||||
for (int k = 0; k < kClosedSamples; ++k) {
|
||||
pts.push_back(e.curve->evaluate(
|
||||
static_cast<double>(k) / kClosedSamples));
|
||||
ids.push_back(e.id);
|
||||
}
|
||||
commit(std::move(pts), std::move(ids));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (lp.edges.size() < 2) continue;
|
||||
struct LoopEdge {
|
||||
int ei = -1; // edges_ 数组下标
|
||||
@@ -190,38 +248,7 @@ std::vector<std::vector<core::Point3D>> sample_loops(
|
||||
append_edge(e, e.reversed ? e.v_end : e.v_start, &pts, &ids);
|
||||
}
|
||||
}
|
||||
std::vector<core::Point3D> clean;
|
||||
std::vector<int> clean_ids;
|
||||
for (size_t k = 0; k < pts.size(); ++k)
|
||||
if (clean.empty() || (clean.back() - pts[k]).norm() > 1e-12) {
|
||||
clean.push_back(pts[k]);
|
||||
clean_ids.push_back(ids[k]);
|
||||
}
|
||||
while (clean.size() >= 2 &&
|
||||
(clean.front() - clean.back()).norm() <= 1e-12) {
|
||||
clean.pop_back();
|
||||
clean_ids.pop_back();
|
||||
}
|
||||
if (clean.size() >= 3) {
|
||||
// 使环绕向与面法向一致(外环逆时针、内环顺时针):Newell 法向
|
||||
// 与面法向同向时不反转。共面 tile 只有在绕向一致时公共边才会以
|
||||
// 相反方向出现,几何并集才能正确抵消。
|
||||
core::Vector3D newell{0, 0, 0};
|
||||
const core::Point3D base = clean[0];
|
||||
for (size_t k = 0; k < clean.size(); ++k) {
|
||||
const core::Vector3D a = clean[k] - base;
|
||||
const core::Vector3D b =
|
||||
clean[(k + 1) % clean.size()] - base;
|
||||
newell = newell + a.cross(b);
|
||||
}
|
||||
auto pg = body.face_plane_geometry(fi);
|
||||
if (pg && newell.dot(pg->normal) < 0.0) {
|
||||
std::reverse(clean.begin(), clean.end());
|
||||
std::reverse(clean_ids.begin(), clean_ids.end());
|
||||
}
|
||||
loops.push_back(std::move(clean));
|
||||
edge_ids_out.push_back(std::move(clean_ids));
|
||||
}
|
||||
commit(std::move(pts), std::move(ids));
|
||||
}
|
||||
if (loop_edge_ids) *loop_edge_ids = std::move(edge_ids_out);
|
||||
return loops;
|
||||
@@ -243,6 +270,29 @@ double projected_outer_area(const std::vector<std::vector<core::Point3D>>& loops
|
||||
return best;
|
||||
}
|
||||
|
||||
// 内环(投影面积最小的环)面积:环形壁面(垫圈/带孔板/法兰)的孔轮廓。
|
||||
// 用于区分「外缘倒角使上下环面积不同」(同一孔、外缘修边,仍是薄板)与
|
||||
// 「上下轮廓本身不同」(非均匀薄壁,VDE-1346 约定拒绝)。
|
||||
double inner_loop_area(const std::vector<std::vector<core::Point3D>>& loops,
|
||||
const core::Vector3D& ex, const core::Vector3D& ey,
|
||||
const core::Point3D& origin) {
|
||||
if (loops.empty()) return 0.0;
|
||||
double best = -1.0;
|
||||
for (const auto& lp : loops) {
|
||||
if (lp.size() < 3) continue;
|
||||
double a = 0.0;
|
||||
for (size_t i = 0; i < lp.size(); ++i) {
|
||||
const auto d0 = lp[i] - origin;
|
||||
const auto d1 = lp[(i + 1) % lp.size()] - origin;
|
||||
a += d0.dot(ex) * d1.dot(ey) - d1.dot(ex) * d0.dot(ey);
|
||||
}
|
||||
const double area = std::abs(0.5 * a);
|
||||
if (area <= 0.0) continue;
|
||||
best = best < 0.0 ? area : std::min(best, area);
|
||||
}
|
||||
return best < 0.0 ? 0.0 : best;
|
||||
}
|
||||
|
||||
// 2D 投影点包含判断。与下方 legacy shell_mesh 使用的 point_in_loop 算法相同,
|
||||
// 独立命名以免同一编译单元内重复定义(VDE-1346 §7)。
|
||||
bool point_inside_loop2d(const std::vector<core::Point3D>& poly,
|
||||
@@ -1070,13 +1120,32 @@ MidSurface extract_midsurface(const brep::BrepModel& body,
|
||||
const bool nested = loops_fully_nested(
|
||||
wsmall.loops, wl.loops, wl.base_ex, wl.base_ey,
|
||||
wl.origin);
|
||||
if (!nested) continue;
|
||||
const double perim =
|
||||
outer_loop_perimeter(wl.loops, wl.base_ex, wl.base_ey);
|
||||
const double expect = perim * h0;
|
||||
if (!nested) continue;
|
||||
if (!(expect > 0.0) ||
|
||||
std::abs(area_diff - expect) > 0.2 * expect)
|
||||
continue;
|
||||
const bool equal_thickness_shell =
|
||||
expect > 0.0 &&
|
||||
std::abs(area_diff - expect) <= 0.2 * expect;
|
||||
if (!equal_thickness_shell) {
|
||||
// 外缘倒角/圆角修边的环形薄板(垫圈、法兰):上下环形壁面
|
||||
// 孔轮廓一致、环数一致、外轮廓包含关系成立时,面积差来自
|
||||
// 外缘倒角带而非上下轮廓不同,仍按等厚度薄板配对。仅对
|
||||
// 同孔环形面放行,实心轮廓(单环)与不同孔的台阶件不受
|
||||
// 影响。
|
||||
const size_t nloops_a = wa.loops.size();
|
||||
const size_t nloops_b = wb.loops.size();
|
||||
if (nloops_a != nloops_b || nloops_a < 2) continue;
|
||||
if (amin < 0.7 * amax) continue;
|
||||
const double hole_a = inner_loop_area(
|
||||
wa.loops, wa.base_ex, wa.base_ey, wa.origin);
|
||||
const double hole_b = inner_loop_area(
|
||||
wb.loops, wa.base_ex, wa.base_ey, wa.origin);
|
||||
const double hole_ref = std::max(hole_a, hole_b);
|
||||
if (!(hole_ref > 0.0) ||
|
||||
std::abs(hole_a - hole_b) > 2e-2 * hole_ref)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// 两壁面必须覆盖同一区域:tile 化后单块面远小于壁面,不能按
|
||||
// 单面面积比较,改用投影包围盒重叠度。
|
||||
@@ -1532,6 +1601,81 @@ MidSurface extract_midsurface(const brep::BrepModel& body,
|
||||
p.patch_id = compute_patch_id(p);
|
||||
}
|
||||
|
||||
// ── 调试探针(VDE-A34,env 门控,默认静默)─────────────────────────
|
||||
// VDE_CAE_MIDS_DEBUG=1 时把体包围盒、逐面几何(类型/面积/环数/单边闭环
|
||||
// 数)、壁面(法向/偏移/面积/成员面/环数/是否配对)与四档失败计数打到
|
||||
// stderr,供中面 KPI 逐件归因。只读探针:不参与任何判定,不改变输出,
|
||||
// 默认(未设 env)逐位静默。
|
||||
if (std::getenv("VDE_CAE_MIDS_DEBUG") != nullptr) {
|
||||
const core::Vector3D ext = body.bounds().extent();
|
||||
std::fprintf(stderr,
|
||||
"MIDSDBG body faces=%zu verts=%zu bbox=(%.4g,%.4g,%.4g) "
|
||||
"ratio=%.6g\n",
|
||||
body.num_faces(), body.num_vertices(), ext.x(), ext.y(),
|
||||
ext.z(), max_thickness_ratio);
|
||||
for (int fi = 0; fi < static_cast<int>(body.num_faces()); ++fi) {
|
||||
const auto& tf = body.face(fi);
|
||||
int closed_loops = 0; // 单边闭环(整圆/闭合曲线)环数
|
||||
int closed_edges = 0; // v_start==v_end 的边数
|
||||
for (int lid : tf.loops) {
|
||||
const auto& lp = body.loop_by_id(lid);
|
||||
if (lp.edges.size() == 1 &&
|
||||
body.edge(lp.edges.front()).v_start ==
|
||||
body.edge(lp.edges.front()).v_end)
|
||||
++closed_loops;
|
||||
for (int ei : lp.edges)
|
||||
if (body.edge(ei).v_start == body.edge(ei).v_end)
|
||||
++closed_edges;
|
||||
}
|
||||
std::fprintf(stderr,
|
||||
"MIDSDBG face=%d type=%d area=%.6g loops=%zu "
|
||||
"single_closed_loops=%d closed_edges=%d sampled=%zu",
|
||||
fi, static_cast<int>(body.face_type(fi)),
|
||||
body.face_area(fi), tf.loops.size(), closed_loops,
|
||||
closed_edges, sample_loops(body, fi).size());
|
||||
if (auto pg = body.face_plane_geometry(fi))
|
||||
std::fprintf(stderr, " plane n=(%.6g,%.6g,%.6g) off=%.6g",
|
||||
pg->normal.x(), pg->normal.y(), pg->normal.z(),
|
||||
pg->point.dot(pg->normal));
|
||||
if (auto cg = body.face_cylinder_geometry(fi))
|
||||
std::fprintf(stderr,
|
||||
" cyl r=%.6g inner=%d axis=(%.4g,%.4g,%.4g) "
|
||||
"ap=(%.4g,%.4g,%.4g)",
|
||||
cg->radius, cg->inner ? 1 : 0, cg->axis.x(),
|
||||
cg->axis.y(), cg->axis.z(), cg->axis_point.x(),
|
||||
cg->axis_point.y(), cg->axis_point.z());
|
||||
if (auto sg = body.face_sphere_geometry(fi))
|
||||
std::fprintf(stderr, " sph r=%.6g c=(%.4g,%.4g,%.4g)",
|
||||
sg->radius, sg->center.x(), sg->center.y(),
|
||||
sg->center.z());
|
||||
if (auto qg = body.face_cone_geometry(fi))
|
||||
std::fprintf(stderr,
|
||||
" cone half=%.6g inner=%d apex=(%.4g,%.4g,%.4g)",
|
||||
qg->half_angle, qg->inner ? 1 : 0, qg->apex.x(),
|
||||
qg->apex.y(), qg->apex.z());
|
||||
if (auto tg = brep::face_torus_geometry(body, fi))
|
||||
std::fprintf(stderr, " torus R=%.6g r=%.6g inner=%d",
|
||||
tg->major_radius, tg->minor_radius,
|
||||
tg->inner ? 1 : 0);
|
||||
std::fprintf(stderr, "\n");
|
||||
}
|
||||
for (size_t wi = 0; wi < walls.size(); ++wi) {
|
||||
const PlaneWall& w = walls[wi];
|
||||
std::fprintf(stderr,
|
||||
"MIDSDBG wall=%zu n0=(%.6g,%.6g,%.6g) off=%.6g "
|
||||
"area=%.6g faces=%zu loops=%zu paired=%d\n",
|
||||
wi, w.n0.x(), w.n0.y(), w.n0.z(), w.offset, w.area,
|
||||
w.faces.size(), w.loops.size(), w.paired ? 1 : 0);
|
||||
}
|
||||
std::fprintf(stderr,
|
||||
"MIDSDBG const out=%zu tg=%d cg=%d no=%d af=%d\n",
|
||||
out.size(), const_thickness_gate, const_contour_gate,
|
||||
const_no_opposite, const_apply_fail);
|
||||
if (!chain_code.empty() || !chain_message.empty())
|
||||
std::fprintf(stderr, "MIDSDBG chain code=%s message=%s\n",
|
||||
chain_code.c_str(), chain_message.c_str());
|
||||
}
|
||||
|
||||
MidSurface result;
|
||||
|
||||
// 边界与接头(VDE-1346 §7.2-5):按 B-Rep 边聚合使用它的 patch 与面。
|
||||
|
||||
+464
-11
@@ -1080,11 +1080,12 @@ bool build_prism_loops(const brep::BrepModel& body, int face,
|
||||
return !loops.empty();
|
||||
}
|
||||
|
||||
bool make_extruded_prism_tet_mesh(const brep::BrepModel& body,
|
||||
const TetMeshParams& params,
|
||||
double target_size,
|
||||
bool auto_adaptive_sampling,
|
||||
FEAMesh& out) {
|
||||
bool make_extruded_prism_tet_mesh_impl(const brep::BrepModel& body,
|
||||
const TetMeshParams& params,
|
||||
double target_size,
|
||||
bool auto_adaptive_sampling,
|
||||
double loop_sample_step,
|
||||
FEAMesh& out) {
|
||||
// 找一对平行平面端盖,且所有顶点都落在两端盖平面上。
|
||||
int cap_a = -1, cap_b = -1;
|
||||
core::Vector3D normal_a;
|
||||
@@ -1136,11 +1137,11 @@ bool make_extruded_prism_tet_mesh(const brep::BrepModel& body,
|
||||
ex = ey.cross(normal_a).normalized();
|
||||
|
||||
std::vector<PrismCapLoop> loops;
|
||||
if (!build_prism_loops(body, cap_a, ex, ey, origin, target_size, auto_adaptive_sampling, loops))
|
||||
if (!build_prism_loops(body, cap_a, ex, ey, origin, loop_sample_step, auto_adaptive_sampling, loops))
|
||||
return false;
|
||||
// 另一端盖必须与底端盖同形;否则是锥台/变截面,不能按等截面棱柱拉伸。
|
||||
std::vector<PrismCapLoop> top_loops;
|
||||
if (!build_prism_loops(body, cap_b, ex, ey, origin, target_size, auto_adaptive_sampling, top_loops))
|
||||
if (!build_prism_loops(body, cap_b, ex, ey, origin, loop_sample_step, auto_adaptive_sampling, top_loops))
|
||||
return false;
|
||||
if (top_loops.size() != loops.size()) return false;
|
||||
const double cap_tol = std::max(1e-7, target_size * 1e-6);
|
||||
@@ -1302,6 +1303,417 @@ bool make_extruded_prism_tet_mesh(const brep::BrepModel& body,
|
||||
return true;
|
||||
}
|
||||
|
||||
// [A32] 棱柱快速路径的体积自检 + 端盖采样步长自适应重试。
|
||||
//
|
||||
// Wave16 固定窗口的 7 件 prism mesh_rejected(xr1-tc-rod / xr1-tu-rod /
|
||||
// xr1-db-214_7 / 1177-B1P-A / 1176-B1P-A / 1178-B1P-A / 2__2.STEP)诊断都是
|
||||
// 「extruded prism fast path」,最终校验体积误差只有 2.5~2.8%,刚好越过 2%
|
||||
// 容差。根因不是拉伸逻辑:端盖圆的弧边若拆成两条开放圆弧,显式 max_size 模式
|
||||
// 按弦长/采样步长采段(n=clamp(ceil(chord/sample_step),8,128)),半径 4~8 mm
|
||||
// 的端盖圆在 sample_step=5 mm 时每半圆只采到 8 段 -> 端盖成 16 边内接多边形,
|
||||
// 面积亏 2.55%(= 1 - (16/2π)sin(2π/16)),与实测 2.5~2.8% 完全吻合。
|
||||
//
|
||||
// 修法:先按既有口径(loop_sample_step = target_size)生成候选并自检;通过
|
||||
// 即逐位返回既有输出(所有当前通过件不受影响、固定窗口 166 件逐位不变)。
|
||||
// 仅当自检失败时把端盖采样步长按 1/4 递减重试(只影响端盖离散精度,不改目标
|
||||
// 尺寸/分层/单元类型),仍不通过则返回其中相对误差最小者(与既有拒绝语义一致,
|
||||
// 不放松 2% 容差)。全程确定性,无墙钟/随机。
|
||||
bool make_extruded_prism_tet_mesh(const brep::BrepModel& body,
|
||||
const TetMeshParams& params,
|
||||
double target_size,
|
||||
bool auto_adaptive_sampling,
|
||||
FEAMesh& out) {
|
||||
FEAMesh first;
|
||||
if (!make_extruded_prism_tet_mesh_impl(body, params, target_size,
|
||||
auto_adaptive_sampling,
|
||||
target_size, first))
|
||||
return false;
|
||||
const VolumeMeshValidation first_check =
|
||||
validate_volume_mesh(body, first, 0.02);
|
||||
tetra_probe("[tetra] prism attempt=0 loop_step=%.6g tets=%zu "
|
||||
"rel=%.6f ok=%d\n",
|
||||
target_size, first.elements.size(),
|
||||
first_check.relative_error, first_check.ok ? 1 : 0);
|
||||
if (first_check.ok) {
|
||||
out = std::move(first);
|
||||
return true;
|
||||
}
|
||||
double best_err = first_check.relative_error;
|
||||
FEAMesh best = std::move(first);
|
||||
// 端盖重采样:1/4、1/16、1/64、1/256 四档。
|
||||
for (int attempt = 1; attempt <= 4; ++attempt) {
|
||||
const double loop_step = target_size * std::pow(0.25, attempt);
|
||||
FEAMesh cand;
|
||||
if (!make_extruded_prism_tet_mesh_impl(body, params, target_size,
|
||||
auto_adaptive_sampling,
|
||||
loop_step, cand))
|
||||
break;
|
||||
const VolumeMeshValidation check =
|
||||
validate_volume_mesh(body, cand, 0.02);
|
||||
tetra_probe("[tetra] prism attempt=%d loop_step=%.6g tets=%zu "
|
||||
"rel=%.6f ok=%d\n",
|
||||
attempt, loop_step, cand.elements.size(),
|
||||
check.relative_error, check.ok ? 1 : 0);
|
||||
if (check.ok) {
|
||||
out = std::move(cand);
|
||||
return true;
|
||||
}
|
||||
if (check.relative_error < best_err) {
|
||||
best_err = check.relative_error;
|
||||
best = std::move(cand);
|
||||
}
|
||||
}
|
||||
out = std::move(best);
|
||||
return true;
|
||||
}
|
||||
|
||||
// [A32] 旋转体快速路径(显式固定尺寸的体积拒绝救援)。
|
||||
//
|
||||
// Wave16 固定窗口的 5 件小型倒角垫圈(ChamferedWasher iso7090 M5/M7/M8/M10/M12)
|
||||
// 体积拒绝的根因不在 Delaunay:显式 max_size=5 mm 时 B-Rep 圆弧按“最大弦高”
|
||||
// 采样,外径 8 mm 的端盖圆只剩 4 段(内接正方形,面积亏 36.34%),表面“水密但
|
||||
// 形状错误”,通用路径无论体元多细都无法把体积误差拉回 2%。这些件的几何严格是
|
||||
// 旋转体:全部面为 Plane/Cylinder/Cone,母线投影到 (r,z) 平面是一条闭合折线。
|
||||
// 这里直接按“截面 2D 三角化 + 周向旋转”生成结构化四面体网格:体积误差只来自
|
||||
// 周向内接多边形(n=48 时 0.29%),确定性、不迭代。
|
||||
//
|
||||
// 检测严格(任何不确定即返回 false,绝不改变既有路径的输出):所有圆柱/圆锥面
|
||||
// 同轴;平面面法向平行轴(环形端面);每个面的顶点投影到 (r,z) 后恰好只有 2 个
|
||||
// 不同点(该面是一条母线);这些母线恰好组成覆盖全部面的单一闭环;截面不含轴
|
||||
// 上的极点(本路径只处理垫圈/套筒这类空心旋转体)。边界三角形按无向边配对即
|
||||
// 可(validate_volume_mesh 的口径),体元体积按 |det| 求和,不依赖朝向。
|
||||
bool make_revolved_tet_mesh(const brep::BrepModel& body, double target_size,
|
||||
FEAMesh& out) {
|
||||
constexpr double kPi = 3.14159265358979323846;
|
||||
auto fail = [](const char* reason) {
|
||||
tetra_probe("[tetra] revolve path skipped: %s\n", reason);
|
||||
return false;
|
||||
};
|
||||
const int nf = static_cast<int>(body.num_faces());
|
||||
if (nf < 3) return fail("faces<3");
|
||||
const double body_volume = body.body_volume();
|
||||
if (!(std::abs(body_volume) > 1e-12)) return fail("body volume ~ 0");
|
||||
const AABB3D bb = body.bounds();
|
||||
const double bbox_diag = bb.extent().norm();
|
||||
if (!(bbox_diag > 1e-12)) return fail("degenerate bounds");
|
||||
const double tol = std::max(1e-9, bbox_diag * 1e-7);
|
||||
|
||||
// ---- 1) 轴线:所有圆柱/圆锥面必须同轴(轴向共线 + 轴点共线)----
|
||||
core::Point3D axis_p(0.0, 0.0, 0.0);
|
||||
core::Vector3D axis_d(0.0, 0.0, 1.0);
|
||||
bool have_axis = false;
|
||||
for (int i = 0; i < nf; ++i) {
|
||||
const auto ft = body.face_type(i);
|
||||
core::Point3D fp;
|
||||
core::Vector3D fd;
|
||||
if (ft == brep::FaceType::Cylinder) {
|
||||
const auto g = body.face_cylinder_geometry(i);
|
||||
if (!g) return fail("cylinder geometry missing");
|
||||
fp = g->axis_point;
|
||||
fd = g->axis;
|
||||
} else if (ft == brep::FaceType::Cone) {
|
||||
const auto g = body.face_cone_geometry(i);
|
||||
if (!g) return fail("cone geometry missing");
|
||||
fp = g->apex;
|
||||
fd = g->axis;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if (!(fd.norm() > 1e-12)) return fail("degenerate axis");
|
||||
fd = fd.normalized();
|
||||
if (!have_axis) {
|
||||
axis_p = fp;
|
||||
axis_d = fd;
|
||||
have_axis = true;
|
||||
continue;
|
||||
}
|
||||
if (std::abs(axis_d.dot(fd)) < 1.0 - 1e-6)
|
||||
return fail("not coaxial");
|
||||
const core::Vector3D w = fp - axis_p;
|
||||
if ((w - axis_d * w.dot(axis_d)).norm() > tol)
|
||||
return fail("axis points not collinear");
|
||||
}
|
||||
if (!have_axis) return fail("no cylinder/cone face");
|
||||
|
||||
// ---- 2) 面类型白名单 + 平面必须垂直于轴(环形端面)----
|
||||
for (int i = 0; i < nf; ++i) {
|
||||
const auto ft = body.face_type(i);
|
||||
if (ft == brep::FaceType::Plane) {
|
||||
const auto g = body.face_plane_geometry(i);
|
||||
if (!g || !(g->normal.norm() > 1e-12))
|
||||
return fail("plane geometry missing");
|
||||
if (std::abs(g->normal.normalized().dot(axis_d)) < 1.0 - 1e-6)
|
||||
return fail("plane not perpendicular to axis");
|
||||
} else if (ft != brep::FaceType::Cylinder &&
|
||||
ft != brep::FaceType::Cone) {
|
||||
return fail("face type outside Plane/Cylinder/Cone");
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 3) 顶点投影到 (r,z):每面恰好一条母线 ----
|
||||
auto radial = [&](const core::Point3D& p) {
|
||||
const core::Vector3D w = p - axis_p;
|
||||
return w - axis_d * w.dot(axis_d);
|
||||
};
|
||||
auto project = [&](const core::Point3D& p) {
|
||||
const core::Vector3D w = p - axis_p;
|
||||
const double z = w.dot(axis_d);
|
||||
return core::Point2D(radial(p).norm(), z);
|
||||
};
|
||||
std::vector<core::Point2D> profile;
|
||||
std::vector<std::pair<int, int>> face_chord;
|
||||
face_chord.reserve(static_cast<std::size_t>(nf));
|
||||
for (int i = 0; i < nf; ++i) {
|
||||
const auto& f = body.face(i);
|
||||
std::vector<int> ids;
|
||||
for (int lid : f.loops) {
|
||||
const auto& lp = body.loop_by_id(lid);
|
||||
for (int ei : lp.edges) {
|
||||
const auto& e = body.edge(ei);
|
||||
const int vids[2] = {e.v_start, e.v_end};
|
||||
for (int k = 0; k < 2; ++k) {
|
||||
const int vi = vids[k];
|
||||
if (vi < 0 || vi >= static_cast<int>(body.num_vertices()))
|
||||
return fail("edge vertex index out of range");
|
||||
const core::Point2D q = project(body.vertex(vi).point);
|
||||
int found = -1;
|
||||
for (std::size_t pi = 0; pi < profile.size(); ++pi) {
|
||||
if (std::abs(profile[pi].x() - q.x()) <= tol &&
|
||||
std::abs(profile[pi].y() - q.y()) <= tol) {
|
||||
found = static_cast<int>(pi);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found < 0) {
|
||||
found = static_cast<int>(profile.size());
|
||||
profile.push_back(q);
|
||||
}
|
||||
bool dup = false;
|
||||
for (int id : ids)
|
||||
if (id == found) dup = true;
|
||||
if (!dup) ids.push_back(found);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ids.size() != 2) return fail("face is not one profile chord");
|
||||
face_chord.push_back({ids[0], ids[1]});
|
||||
}
|
||||
|
||||
// ---- 4) 母线必须构成覆盖全部面的单一闭环 ----
|
||||
const int m = static_cast<int>(profile.size());
|
||||
if (m != nf) return fail("profile points != faces");
|
||||
if (m < 3) return fail("profile too short");
|
||||
std::vector<std::vector<std::pair<int, int>>> adj(
|
||||
static_cast<std::size_t>(m));
|
||||
for (int fi = 0; fi < nf; ++fi) {
|
||||
const int a = face_chord[static_cast<std::size_t>(fi)].first;
|
||||
const int b = face_chord[static_cast<std::size_t>(fi)].second;
|
||||
if (a == b) return fail("degenerate chord");
|
||||
adj[static_cast<std::size_t>(a)].push_back({b, fi});
|
||||
adj[static_cast<std::size_t>(b)].push_back({a, fi});
|
||||
}
|
||||
for (int i = 0; i < m; ++i)
|
||||
if (adj[static_cast<std::size_t>(i)].size() != 2)
|
||||
return fail("profile is not a simple cycle");
|
||||
std::vector<int> order;
|
||||
std::vector<bool> face_used(static_cast<std::size_t>(nf), false);
|
||||
order.reserve(static_cast<std::size_t>(m));
|
||||
order.push_back(0);
|
||||
int cur = adj[0][0].first;
|
||||
int last_face = adj[0][0].second;
|
||||
face_used[static_cast<std::size_t>(last_face)] = true;
|
||||
while (cur != 0) {
|
||||
if (order.size() > static_cast<std::size_t>(m))
|
||||
return fail("profile cycle too long");
|
||||
order.push_back(cur);
|
||||
int next_p = -1;
|
||||
int next_f = -1;
|
||||
for (const auto& en : adj[static_cast<std::size_t>(cur)]) {
|
||||
if (en.second == last_face) continue;
|
||||
if (face_used[static_cast<std::size_t>(en.second)])
|
||||
return fail("profile splits into multiple cycles");
|
||||
next_p = en.first;
|
||||
next_f = en.second;
|
||||
break;
|
||||
}
|
||||
if (next_p < 0) return fail("profile cycle open");
|
||||
face_used[static_cast<std::size_t>(next_f)] = true;
|
||||
last_face = next_f;
|
||||
cur = next_p;
|
||||
}
|
||||
if (order.size() != static_cast<std::size_t>(m))
|
||||
return fail("profile cycle does not close");
|
||||
for (int i = 0; i < nf; ++i)
|
||||
if (!face_used[static_cast<std::size_t>(i)])
|
||||
return fail("profile cycle misses faces");
|
||||
|
||||
// 统一为 (r,z) 平面逆时针,便于 CDT 与 point_in_polygon。
|
||||
double area2 = 0.0;
|
||||
for (int k = 0; k < m; ++k) {
|
||||
const core::Point2D& p = profile[static_cast<std::size_t>(order[
|
||||
static_cast<std::size_t>(k)])];
|
||||
const core::Point2D& q = profile[static_cast<std::size_t>(order[
|
||||
static_cast<std::size_t>((k + 1) % m)])];
|
||||
area2 += p.x() * q.y() - q.x() * p.y();
|
||||
}
|
||||
if (!(std::abs(area2) > 1e-12 * std::max(1.0, bbox_diag * bbox_diag)))
|
||||
return fail("profile area ~ 0");
|
||||
if (area2 < 0.0) std::reverse(order.begin(), order.end());
|
||||
|
||||
std::vector<core::Point2D> poly;
|
||||
poly.reserve(static_cast<std::size_t>(m));
|
||||
for (int k = 0; k < m; ++k) {
|
||||
poly.push_back(profile[static_cast<std::size_t>(order[
|
||||
static_cast<std::size_t>(k)])]);
|
||||
if (poly.back().x() <= tol)
|
||||
return fail("profile meets the axis (not a hollow revolve)");
|
||||
}
|
||||
|
||||
// ---- 5) 截面 2D 三角化(保留落在剖面内的三角形)----
|
||||
std::vector<std::pair<int, int>> cons;
|
||||
cons.reserve(static_cast<std::size_t>(m));
|
||||
for (int k = 0; k < m; ++k)
|
||||
cons.push_back({k, (k + 1) % m});
|
||||
const auto cdt = constrained_delaunay_2d(poly, cons);
|
||||
if (cdt.triangles.empty()) return fail("profile CDT failed");
|
||||
if (cdt.vertices.size() != poly.size())
|
||||
return fail("profile CDT added vertices");
|
||||
std::vector<std::array<int, 3>> tris;
|
||||
for (const auto& t : cdt.triangles) {
|
||||
const auto& a = cdt.vertices[static_cast<std::size_t>(t[0])];
|
||||
const auto& b = cdt.vertices[static_cast<std::size_t>(t[1])];
|
||||
const auto& c = cdt.vertices[static_cast<std::size_t>(t[2])];
|
||||
const double cx = (a.x() + b.x() + c.x()) / 3.0;
|
||||
const double cy = (a.y() + b.y() + c.y()) / 3.0;
|
||||
if (!point_in_polygon(poly, cx, cy)) continue;
|
||||
std::array<int, 3> tri{t[0], t[1], t[2]};
|
||||
std::sort(tri.begin(), tri.end());
|
||||
tris.push_back(tri);
|
||||
}
|
||||
if (tris.empty()) return fail("profile triangulation empty");
|
||||
|
||||
double r_max = 0.0;
|
||||
for (const auto& p : poly) r_max = std::max(r_max, p.x());
|
||||
if (!(r_max > tol)) return fail("max radius ~ 0");
|
||||
|
||||
// 周向分段:先按 target_size 定段数(下限 48 保证内接多边形体积误差
|
||||
// 0.29%),自检不通过时再逐级加倍(最多到 1024)。
|
||||
const double ts = std::max(target_size, 1e-9);
|
||||
const int n_base =
|
||||
static_cast<int>(std::ceil(2.0 * kPi * r_max / ts));
|
||||
const int n_theta = std::clamp(n_base, 48, 512);
|
||||
|
||||
// 正交基:e1/e2 张成垂直于轴的平面。
|
||||
core::Vector3D e1(1.0, 0.0, 0.0);
|
||||
bool have_e1 = false;
|
||||
for (std::size_t vi = 0; vi < body.num_vertices(); ++vi) {
|
||||
const core::Vector3D rv =
|
||||
radial(body.vertex(static_cast<int>(vi)).point);
|
||||
if (rv.norm() > tol) {
|
||||
e1 = rv.normalized();
|
||||
have_e1 = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!have_e1) return fail("no off-axis vertex");
|
||||
core::Vector3D e2 = axis_d.cross(e1);
|
||||
if (!(e2.norm() > 1e-12)) return fail("degenerate basis");
|
||||
e2 = e2.normalized();
|
||||
e1 = e2.cross(axis_d).normalized();
|
||||
|
||||
const std::size_t pn = poly.size();
|
||||
auto build = [&](int n, FEAMesh& mesh) {
|
||||
const long long total_vertices =
|
||||
static_cast<long long>(pn) * static_cast<long long>(n);
|
||||
const long long total_elements = static_cast<long long>(tris.size()) *
|
||||
static_cast<long long>(n) * 3;
|
||||
if (total_vertices > 500000 || total_elements > 2000000)
|
||||
return false;
|
||||
mesh = FEAMesh{};
|
||||
mesh.element_type = FEAElementType::Tet4;
|
||||
mesh.vertices.reserve(static_cast<std::size_t>(total_vertices));
|
||||
for (int j = 0; j < n; ++j) {
|
||||
const double th =
|
||||
2.0 * kPi * static_cast<double>(j) / static_cast<double>(n);
|
||||
const double cs = std::cos(th);
|
||||
const double sn = std::sin(th);
|
||||
for (const auto& p : cdt.vertices) {
|
||||
const double r = p.x();
|
||||
const double z = p.y();
|
||||
mesh.vertices.push_back(axis_p + axis_d * z +
|
||||
e1 * (r * cs) + e2 * (r * sn));
|
||||
}
|
||||
}
|
||||
const int pni = static_cast<int>(pn);
|
||||
auto vertex = [pni](int sector, int i) { return sector * pni + i; };
|
||||
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 j = 0; j < n; ++j) {
|
||||
const int jn = (j + 1) % n;
|
||||
for (const auto& t : tris) {
|
||||
const int b0 = vertex(j, t[0]);
|
||||
const int b1 = vertex(j, t[1]);
|
||||
const int b2 = vertex(j, t[2]);
|
||||
const int t0 = vertex(jn, t[0]);
|
||||
const int t1 = vertex(jn, t[1]);
|
||||
const int t2 = vertex(jn, t[2]);
|
||||
add_tet(b0, b1, b2, t2);
|
||||
add_tet(b0, b1, t1, t2);
|
||||
add_tet(b0, t0, t1, t2);
|
||||
}
|
||||
}
|
||||
mesh.material_ids.assign(mesh.elements.size(), 0);
|
||||
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);
|
||||
};
|
||||
// 侧边界:每条母线(剖面弦)在每个周向扇区对应 2 个三角形;
|
||||
// 360° 闭环、无端盖。每个无向边恰好出现 2 次 -> validate 判闭合。
|
||||
for (int k = 0; k < m; ++k) {
|
||||
const int a = k;
|
||||
const int b = (k + 1) % m;
|
||||
for (int j = 0; j < n; ++j) {
|
||||
const int jn = (j + 1) % n;
|
||||
add_tri(vertex(j, a), vertex(j, b), vertex(jn, b));
|
||||
add_tri(vertex(j, a), vertex(jn, b), vertex(jn, a));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
for (int attempt = 0; attempt < 3; ++attempt) {
|
||||
const int n = n_theta << attempt;
|
||||
if (n > 1024) break;
|
||||
FEAMesh candidate;
|
||||
if (!build(n, candidate)) break;
|
||||
const VolumeMeshValidation check =
|
||||
validate_volume_mesh(body, candidate, 0.02);
|
||||
tetra_probe("[tetra] revolve path attempt=%d n_theta=%d tets=%zu "
|
||||
"rel=%.6f closed=%d open=%zu ok=%d\n",
|
||||
attempt, n, candidate.elements.size(),
|
||||
check.relative_error, check.closed ? 1 : 0,
|
||||
check.open_edges, check.ok ? 1 : 0);
|
||||
if (check.ok) {
|
||||
candidate.diagnostic =
|
||||
"tetrahedral_mesh: solid-of-revolution fast path";
|
||||
out = std::move(candidate);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -1319,6 +1731,21 @@ bool make_star_tet_mesh(const brep::BrepModel& body, double target_size,
|
||||
Point3D center(0, 0, 0);
|
||||
for (const auto& p : tagged.verts) center += p;
|
||||
center = center * (1.0 / static_cast<double>(tagged.verts.size()));
|
||||
// [A32b] 星形路径只适用于「紧凑」封闭体(球/凸块):每个四面体都是
|
||||
// 表面三角形 + 同一质心,细长件(长轴圆轴/套筒)会得到跨越整个零件的
|
||||
// 狭长单元,体积虽能过 2% 门但 FEA 质量不可接受。A33 修好粗口径整周环
|
||||
// 采样后,这类件的粗表面体积反而落进 2% 门,星形路径开始「抢走」原本
|
||||
// 由通用 Delaunay + 细化路径产出的网格(固定窗口 1011/1012/SAD02 从
|
||||
// 3 万单元掉到 252)。此处按质心最大半径设门:超过 4×target_size 视为
|
||||
// 非紧凑体,交回通用路径。紧凑件(球、垫圈)逐位不变。
|
||||
double star_max_r = 0.0;
|
||||
for (const auto& p : tagged.verts)
|
||||
star_max_r = std::max(star_max_r, (p - center).norm());
|
||||
if (star_max_r > 4.0 * target_size) {
|
||||
tetra_probe("[tetra] star path skipped: max_r=%.6g > 4*target=%.6g\n",
|
||||
star_max_r, 4.0 * target_size);
|
||||
return false;
|
||||
}
|
||||
|
||||
FEAMesh mesh;
|
||||
mesh.element_type = FEAElementType::Tet4;
|
||||
@@ -4905,6 +5332,13 @@ FEAMesh tetrahedral_mesh_linear(const brep::BrepModel& body,
|
||||
: std::abs(body.body_volume());
|
||||
double first_watertight_defl = 0.0;
|
||||
double first_watertight_rel = -1.0;
|
||||
// [A32b] 记录水密候选里表面体积误差最小者(不一定是首档):
|
||||
// 粗口径整周环采样修好后,首档可能只是「碰巧水密」的粗表面,
|
||||
// 后续档位 rel 非单调(FOOT: 4.34%→5.68%→3.88%→1.635%),
|
||||
// 用首档做 fallback 会让细化从最粗表面重入而失败。回退到
|
||||
// best 候选既保持「水密」前提,又给细化最准的表面。
|
||||
double best_watertight_defl = 0.0;
|
||||
double best_watertight_rel = -1.0;
|
||||
double suspect_rel = -1.0;
|
||||
double prev_watertight_rel = -1.0;
|
||||
bool surface_vol_converged = false;
|
||||
@@ -4962,6 +5396,11 @@ FEAMesh tetrahedral_mesh_linear(const brep::BrepModel& body,
|
||||
first_watertight_defl = surface_defl;
|
||||
first_watertight_rel = cand_rel;
|
||||
}
|
||||
if (best_watertight_defl == 0.0 ||
|
||||
cand_rel < best_watertight_rel) {
|
||||
best_watertight_defl = surface_defl;
|
||||
best_watertight_rel = cand_rel;
|
||||
}
|
||||
// 基准可疑判据(高偏差件):首档体积偏差 >10% 视为「解析基准
|
||||
// 可能偏」的强信号(A27/D30 类),只允许再试一档;若下一档
|
||||
// 无明显改进(<10%)说明表面体积收敛不到 body_volume,继续
|
||||
@@ -4986,12 +5425,12 @@ FEAMesh tetrahedral_mesh_linear(const brep::BrepModel& body,
|
||||
refine_depth + 1, surface_defl, suspect_rel);
|
||||
} else if (surface_vol_converged) {
|
||||
finer_watertight = true;
|
||||
} else if (first_watertight_defl > 0.0) {
|
||||
surface_defl = first_watertight_defl;
|
||||
} else if (best_watertight_defl > 0.0) {
|
||||
surface_defl = best_watertight_defl;
|
||||
finer_watertight = true;
|
||||
tetra_probe("[tetra] near-miss surface fallback defl=%.6g "
|
||||
"rel=%.6f (no volume convergence)\n",
|
||||
surface_defl, first_watertight_rel);
|
||||
"rel=%.6f (no volume convergence, best)\n",
|
||||
surface_defl, best_watertight_rel);
|
||||
}
|
||||
} else {
|
||||
TaggedSurface finer = tessellate_body_tagged(body, next_size);
|
||||
@@ -5093,6 +5532,20 @@ FEAMesh tetrahedral_mesh_linear(const brep::BrepModel& body,
|
||||
}
|
||||
}
|
||||
}
|
||||
// [A32] 显式固定尺寸的旋转体救援:小型倒角垫圈等“表面水密但端盖圆被采成
|
||||
// 内接多边形”的件,通用 Delaunay 的细化重试永远拉不回 2%;若几何严格是
|
||||
// 旋转体则直接按 (r,z) 截面 + 周向分段生成结构化网格(见
|
||||
// make_revolved_tet_mesh)。只在 !accepted 且显式尺寸顶层触发:auto 路径、
|
||||
// 既有通过件、递归调用与灾难/近失分支的正常输出均逐位不变。
|
||||
if (!accepted && !auto_size_engaged && params.max_size > 0.0 &&
|
||||
refine_depth == 0 && (near_miss_refine || catastrophic_refine)) {
|
||||
FEAMesh revolved;
|
||||
if (make_revolved_tet_mesh(body, target_size, revolved)) {
|
||||
// 显式 target_size 未被修改:沿用既有 max_size_used=0 语义。
|
||||
revolved.max_size_used = 0.0;
|
||||
return revolved;
|
||||
}
|
||||
}
|
||||
if (!accepted) {
|
||||
if (fallback_taken) {
|
||||
// 没有任何一轮同时满足「2-流形 + 体积达标」:退回体积误差最小的
|
||||
|
||||
@@ -1118,6 +1118,38 @@ static void add_shared_edge_sample(const BrepModel& model, int eid, int cap,
|
||||
if (sag <= sag_tol) break;
|
||||
}
|
||||
n = std::clamp(n, std::min(3, cap), cap);
|
||||
// A33:与 mesh_face_trimmed 内逐边采样同一处修正(共享采样表也要救)。
|
||||
// 弦高判据只约束曲面偏差、不约束环拓扑:CAE 固定 size=5(sag_tol=2.5)下
|
||||
// r=2 的整圆周 rim 只需 2 段即满足弦高,rim 环点仅 3 个 → 整周带识别
|
||||
// (conic_band_domain,空角隙阈值 0.35/0.45rad)拒绝 → 圆柱/锥面带静默
|
||||
// 输出 0 三角,表面缺整面(Bolt/SCJ02/SpringEnd 固定窗口 err 0.70~1.0)。
|
||||
// 判据:(a) 两端顶点重合的闭合边;(b) 弦高判据仍很粗(n<8,即该口径下
|
||||
// 曲率几乎不可见)且首末点弦长 < 0.7 倍弧长的近整周边(STEP 导入 rim 的
|
||||
// seam 两端顶点常差 1e-1 量级)。补到 32 段:角隙 11.25°=0.196rad 低于
|
||||
// 0.35 硬阈,环多边形面积/体积亏损 1-(n/2π)sin(2π/n)=0.64%(16 段时
|
||||
// 2.55%,Bolt 表面体积仍差 2.0% 过不了 2% 门控)。仅粗口径触发:细口径
|
||||
// 弦高本已 n≥8~64 逐位不变(细弦差下稠密段数远超拓扑需要)。
|
||||
{
|
||||
double len = 0.0;
|
||||
Point3D prev = ec->evaluate(dom.first);
|
||||
for (int i = 1; i <= 16; ++i) {
|
||||
const Point3D p = ec->evaluate(dom.first + span * (double(i) / 16.0));
|
||||
len += (p - prev).norm();
|
||||
prev = p;
|
||||
}
|
||||
const double chord = (pa - pb).norm();
|
||||
// n<8 是"粗口径"门(见上):细口径下弦高本已 n≥8~64,必须逐位不变。
|
||||
// Wave16 回归教训:closed_exact 曾绕过该门,细弦差(deflection=0.02)
|
||||
// 下 SpringEnd 的 r=0.25 整圆 rim(n=16)也被补到 32 段,to_mesh(0.02)
|
||||
// 出现 162 条开放边、网格体积 1.4379→1.2178(test_measure
|
||||
// CorpusSpringEndTorusBandAnalyticMeshConsistency 失败);闭合边同样
|
||||
// 只在 n<8 的粗口径补密。
|
||||
const bool coarse = n < 8 && ec->degree() > 1 && len > 1e-12;
|
||||
const bool coarse_closed = coarse && chord < 1e-9;
|
||||
const bool coarse_ring = coarse && chord < 0.7 * len;
|
||||
if (coarse_closed || coarse_ring)
|
||||
n = std::min(std::max(n, 32), cap);
|
||||
}
|
||||
std::vector<Point3D> smp;
|
||||
smp.reserve(static_cast<size_t>(n) + 1);
|
||||
for (int i = 0; i <= n; ++i)
|
||||
@@ -4671,6 +4703,35 @@ BrepModel::FaceMeshStatus BrepModel::mesh_face_trimmed(
|
||||
if (sag <= sag_tol) break;
|
||||
}
|
||||
n = std::clamp(n, 2, 64);
|
||||
// A33:弦高判据只约束曲面偏差,不约束环拓扑。粗弦差
|
||||
// (CAE 固定 size=5 → sag_tol=2.5)下 r=4 整圆只需 2~4
|
||||
// 段即满足弦高:环点角隙 90°~180° > 整周带识别阈值
|
||||
// 0.45rad(src/mesh/brep_to_mesh.cpp:715
|
||||
// max_gap_full_circle),带面/投影路径拒绝后该面静默
|
||||
// 输出 0 三角:表面缺整面(Housing 圆柱壁 表面 1152 vs
|
||||
// 解析 750,err 0.536;Bolt/SCJ02/SpringEnd 同类)。
|
||||
// 判据分两类:(a) 两端顶点重合的闭合边;(b) 弦高判据已
|
||||
// 退化到 n=2(曲线在此口径下"看不出弯曲")且首末点弦长
|
||||
// 相对弧长 < 0.9 的近整周边(STEP 导入圆柱 rim 常见:
|
||||
// seam 两端顶点差 1e-1 量级,非严格闭合)。两类都补到
|
||||
// 至少 32 段(角隙 11.25°=0.196rad 低于 0.35 硬阈,环多边形
|
||||
// 面积/体积亏损 1-(n/2π)sin(2π/n)=0.64%;16 段时 2.55%)。
|
||||
// 仅 n<8 的粗口径触发:细口径下同类曲线弦高判据本已
|
||||
// n≥8~64,逐位不变。
|
||||
{
|
||||
const double chord = (pa - pb).norm();
|
||||
// 同 add_shared_edge_sample:闭合边的补密也必须过
|
||||
// n<8 的粗口径门,否则细口径(display/measure 的
|
||||
// deflection=0.02)下 n=16 的整圆 rim 会被抬到 32 段,
|
||||
// 环点集与裁剪域采样错位后网格裂开(Wave16
|
||||
// SpringEnd to_mesh(0.02) 162 条开放边的同类根因)。
|
||||
const bool coarse =
|
||||
n < 8 && nc.degree() > 1 && len > 1e-12;
|
||||
const bool coarse_closed = coarse && chord < 1e-9;
|
||||
const bool coarse_ring = coarse && chord < 0.7 * len;
|
||||
if (coarse_closed || coarse_ring)
|
||||
n = std::max(n, 32);
|
||||
}
|
||||
}
|
||||
std::vector<Point3D> s;
|
||||
s.reserve(static_cast<size_t>(n) + 1);
|
||||
@@ -5753,6 +5814,25 @@ BrepModel::FaceMeshStatus BrepModel::mesh_face_consistent(const BrepModel& body,
|
||||
}
|
||||
}
|
||||
int res = planar_fb ? 4 : std::max(4, static_cast<int>(1.0 / deflection));
|
||||
// A33:无裁剪环的闭合双参数曲面(整球/整环面,如 occ__bug24283
|
||||
// spheres 的单一球面 F=1)走本兜底时,res=1/deflection 在粗口径
|
||||
// (deflection=5 → res=4)只给出 4×4 经纬网格:内接多面体体积仅为
|
||||
// 球的 0.543 倍(体心到面片不再覆盖曲面轮廓),网格体积 2.280 vs
|
||||
// 解析 4.189 → err 0.456 被拒。闭合曲面(u/v 双向周期)的离散体积
|
||||
// 误差由角分辨率主导,与 deflection 无平滑关系:补到 res≥32(内接
|
||||
// 球多面体体积比 0.9912,误差 0.88% ≤2% 门控)。仅 !planar 且双向
|
||||
// 闭合时生效,非闭合面/细口径(1/deflection≥32)逐位不变。
|
||||
//
|
||||
// A35:OCC 导入的完整球面参数化是 u 周期、v 非周期(v 两端是塌缩
|
||||
// 为极点的退化行,NurbsSurface::is_closed(false) 因此返回 false),
|
||||
// A33 的双向闭合判定不成立 → occ__bug24283_spheres 的 F=1 球仍退回
|
||||
// 4×4。补判据:非平面面且 body 只有这一张面 → 整面就是整个体的闭
|
||||
// 合边界(单一球面 body),其离散体积同样只由角分辨率主导,与
|
||||
// deflection 无平滑关系,按与双向闭合相同的最小分辨率兜底。
|
||||
if (!planar_fb &&
|
||||
((surf.is_closed(true) && surf.is_closed(false)) ||
|
||||
body.num_faces() == 1))
|
||||
res = std::max(res, 32);
|
||||
res = std::min(res, 200);
|
||||
auto [verts, tris] = surf.tessellate(res, res);
|
||||
const int offset = static_cast<int>(out_verts.size());
|
||||
|
||||
+239
-72
@@ -2430,6 +2430,9 @@ TEST(AutoSize, SmallBorePinPeriodicBandAutoSizePassesValidation) {
|
||||
EXPECT_TRUE(fixed_v.closed) << fixed_v.diagnostic;
|
||||
EXPECT_TRUE(fixed_v.ok) << fixed_v.diagnostic;
|
||||
EXPECT_LE(std::abs(fixed_v.relative_error), 0.002) << fixed_v.diagnostic;
|
||||
// [Wave16/A33] 粗口径整周 rim 环采样补到 ≥32 段,但 0.25 mm 细口径不触发
|
||||
// 该补密;A33 细口径回归修正(closed_exact 也过 n<8 门)后固定 0.25 网格
|
||||
// 回到 Wave15 指纹 51822(closed/ok/rel<0.2% 不变)。
|
||||
EXPECT_EQ(fixed_mesh.elements.size(), 51822u) << fixed_mesh.diagnostic;
|
||||
|
||||
// 自动尺寸:必须真正水密并通过 2% 体积校验。
|
||||
@@ -2782,15 +2785,27 @@ TEST(AutoSize, NearMissSurfaceVolumeConvergenceRecoversCylindricalBands) {
|
||||
const char* src_root = std::getenv("VDE_SOURCE_DIR");
|
||||
const std::string root =
|
||||
std::string(src_root ? src_root : "D:/20_AI/ViewDesignEngine");
|
||||
const char* names[] = {
|
||||
"1011-A2P-A.STEP",
|
||||
"1012-A2P-A.STEP",
|
||||
"1056-A2P-A.STEP",
|
||||
"occ__xr1-tc-blt__2.stp",
|
||||
"occ__xr1-tu-blt__2.stp",
|
||||
"paddle 2 pick.stp",
|
||||
// Wave16/A32b 后的稳定指纹(auto 尺寸 → 网格;均 closed/ok、|relerr|≤2%)。
|
||||
// tc-blt/tu-blt 在 Wave16 互换角色:tc-blt 由 A31 门在推导尺寸 1.99625 下
|
||||
// 接受,tu-blt 门放弃后走 A28 减半 0.998123。
|
||||
// A33 细口径回归修正后(closed_exact 只在 n<8 粗口径触发),1011/1012 的
|
||||
// rim 不再被误补到 32 段,首档表面体积即达标、不再走减半:尺寸回到推导值
|
||||
// 0.971102/0.970792、tets 53277/51864、err 0.570% 左右(Wave15 指纹)。
|
||||
struct NearMissCase {
|
||||
const char* name;
|
||||
double size;
|
||||
std::size_t tets;
|
||||
double err;
|
||||
} cases[] = {
|
||||
{"1011-A2P-A.STEP", 0.971102, 53277, 0.005701905},
|
||||
{"1012-A2P-A.STEP", 0.970792, 51864, 0.005700688},
|
||||
{"1056-A2P-A.STEP", 0.71657, 37825, 0.010517581},
|
||||
{"occ__xr1-tc-blt__2.stp", 1.9962465, 22416, 0.002106620},
|
||||
{"occ__xr1-tu-blt__2.stp", 0.99812324, 34475, 0.011098611},
|
||||
{"paddle 2 pick.stp", 0.325038, 35334, 0.007998771},
|
||||
};
|
||||
for (const char* name : names) {
|
||||
for (const auto& c : cases) {
|
||||
const std::string name = c.name;
|
||||
const std::string path = root + "/corpus/real/step/" + name;
|
||||
std::ifstream in(path);
|
||||
if (!in.good()) GTEST_SKIP() << "corpus file missing: " << path;
|
||||
@@ -2806,20 +2821,14 @@ TEST(AutoSize, NearMissSurfaceVolumeConvergenceRecoversCylindricalBands) {
|
||||
const auto mesh = tetrahedral_mesh(b, autop);
|
||||
ASSERT_FALSE(mesh.elements.empty()) << name << ": " << mesh.diagnostic;
|
||||
EXPECT_GT(mesh.max_size_used, 0.0) << name << ": " << mesh.diagnostic;
|
||||
// A28 减半路径件报告减半后的实际尺寸(初始推导 1.9422/1.94158/0.99812/0.71657…)。
|
||||
// A31 表面体积收敛门会保持推导 target_size 不被改写:tu-blt 的初始水密
|
||||
// 粗表面 rel 亏 7.59%,门在 target_size=1.99625 下逐级细表面至 1.10%
|
||||
// 后首轮即通过,不再走 A28 的 target 减半(size 保持 1.99625)。
|
||||
if (std::string(name) == "occ__xr1-tu-blt__2.stp") {
|
||||
EXPECT_NEAR(mesh.max_size_used, 1.99625, 1e-5)
|
||||
<< name << ": A31 门不得改写推导 target_size: " << mesh.diagnostic;
|
||||
} else {
|
||||
EXPECT_LT(mesh.max_size_used, 1.5) << name << ": " << mesh.diagnostic;
|
||||
}
|
||||
EXPECT_NEAR(mesh.max_size_used, c.size, 1e-4)
|
||||
<< name << ": 近失重试后的实际尺寸漂移: " << mesh.diagnostic;
|
||||
EXPECT_EQ(mesh.elements.size(), c.tets) << name << ": " << mesh.diagnostic;
|
||||
const auto v = validate_volume_mesh(b, mesh, 0.02);
|
||||
EXPECT_TRUE(v.closed) << name << ": " << v.diagnostic;
|
||||
EXPECT_TRUE(v.ok) << name << ": " << v.diagnostic;
|
||||
EXPECT_LE(std::abs(v.relative_error), 0.02) << name << ": " << v.diagnostic;
|
||||
EXPECT_NEAR(std::abs(v.relative_error), c.err, 1e-8)
|
||||
<< name << ": " << v.diagnostic;
|
||||
std::fprintf(stderr, "A28 %s size=%.6g tets=%zu err=%.9f\n", name,
|
||||
mesh.max_size_used, mesh.elements.size(),
|
||||
v.relative_error);
|
||||
@@ -2878,9 +2887,10 @@ TEST(AutoSize, CatastrophicRefineGateIsAdditiveAndDeterministic) {
|
||||
// 闭合粗表面后,回退诊断口径同步修正为 33.2%(0.332305000,仍是结构化
|
||||
// 体积拒绝)——不再作为 >0.35 的稳定指纹。故本用例不写死易漂移的误差
|
||||
// 数值,改为锚定「仍是体积拒绝(err>2%)+ 两路门控 additive + 逐位确定」;
|
||||
// >0.35 灾难门触发条件的可观测性由
|
||||
// ExplicitSize.ChamferedWasherCatastrophicOutcomeIsDiagnosable(M8 垫圈
|
||||
// 固定 5mm,仍 err>0.35)继续锁定。
|
||||
// >0.35 灾难门触发条件本身当前没有稳定指纹件(Wave16/A32 后 M8 垫圈
|
||||
// 已被旋转体快速路径恢复,见
|
||||
// ExplicitSize.ChamferedWasherRevolvePathRecoversAtFixedSize);本用例只
|
||||
// 锚定「结构化体积拒绝(err>2%)+ additive + 确定性」。
|
||||
// 该件真实表面在所有细化级都有开放边,水密预检必然放弃细化,因此开关两种
|
||||
// 门控都必须落到原有拒绝路径:证明灾难模式是 additive(只增加有限次数的
|
||||
// 尺寸减半尝试,不改变既有拒绝语义、无墙钟门控),且同一门控下逐位确定。
|
||||
@@ -2937,6 +2947,10 @@ TEST(ExplicitSize, RefineRetryRecoversCylindricalBandNearMiss) {
|
||||
// 1011 圆柱带件:固定 5mm 时体积误差 2.13%(刚越过 2% 近失门),Wave14
|
||||
// 之前显式 max_size 是宿主权威值、不允许重试。A29 起显式尺寸模式也启用
|
||||
// 同一套确定性减半重试(5→2.5,A28 表面弦高搜索后递归),实测恢复。
|
||||
// Wave16/A33 修好粗口径整周 rim 环采样(闭合环 ≥32 段)后,该件首轮
|
||||
// 粗表面已足够准:通用 Delaunay 直接在 target=5 下通过 2% 门(tets=14763、
|
||||
// max_size_used=0、err 0.56%),不再需要尺寸减半;A32b 星形路径紧凑性
|
||||
// 护栏(max_r 174 > 4×5)阻止细长件被星形质心路径接走。
|
||||
const char* src_root = std::getenv("VDE_SOURCE_DIR");
|
||||
const std::string path =
|
||||
std::string(src_root ? src_root : "D:/20_AI/ViewDesignEngine") +
|
||||
@@ -2952,12 +2966,13 @@ TEST(ExplicitSize, RefineRetryRecoversCylindricalBandNearMiss) {
|
||||
tp.quality_iterations = 0;
|
||||
const auto mesh = tetrahedral_mesh(b, tp);
|
||||
ASSERT_FALSE(mesh.elements.empty()) << mesh.diagnostic;
|
||||
// 细化成功时报告实际细化尺寸(5 的一半),而不是停在 5 或 0。
|
||||
EXPECT_DOUBLE_EQ(mesh.max_size_used, 2.5) << mesh.diagnostic;
|
||||
// Wave16:首轮即在 target=5 通过,max_size_used 保持 0(未改写宿主尺寸)。
|
||||
EXPECT_DOUBLE_EQ(mesh.max_size_used, 0.0) << mesh.diagnostic;
|
||||
EXPECT_EQ(mesh.elements.size(), std::size_t{14763}) << mesh.diagnostic;
|
||||
const auto v = validate_volume_mesh(b, mesh, 0.02);
|
||||
EXPECT_TRUE(v.closed) << v.diagnostic;
|
||||
EXPECT_TRUE(v.ok) << v.diagnostic;
|
||||
EXPECT_LE(std::abs(v.relative_error), 0.02) << v.diagnostic;
|
||||
EXPECT_NEAR(std::abs(v.relative_error), 0.005562612, 1e-8) << v.diagnostic;
|
||||
std::fprintf(stderr,
|
||||
"EXPLICIT 1011 recovered size=%.6g tets=%zu err=%.9f\n",
|
||||
mesh.max_size_used, mesh.elements.size(), v.relative_error);
|
||||
@@ -3001,11 +3016,16 @@ TEST(ExplicitSize, RecoversOrRejectsHeadFrontFixedSizeDiagnosably) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ExplicitSize, ChamferedWasherCatastrophicOutcomeIsDiagnosable) {
|
||||
// mechbench M8 垫圈:固定 5mm 时体积误差 35.9%(>35% 灾难门),A21 灾难
|
||||
// 细化(≤2 级)在显式模式下也启用。实测:5→2.5 的表面镶嵌焊接后仍有开放
|
||||
// 边,水密预检放弃细化,因此该件保持既有拒绝诊断(err 不变);若将来表面
|
||||
// 水密门修复使其恢复,则按恢复语义断言(自适应,不写死方向)。
|
||||
TEST(ExplicitSize, ChamferedWasherRevolvePathRecoversAtFixedSize) {
|
||||
// [Wave16/A32] mechbench M8 垫圈:固定 5mm 时首轮通用 Delaunay 体积误差
|
||||
// 35.9%,是 Wave11 灾难门(>35% 体积误差)的指纹件。A32 新增严格旋转体
|
||||
// 快速路径(make_revolved_tet_mesh:全部面 Plane/Cylinder/Cone 同轴、每面
|
||||
// 投影恰好一条母线、母线闭合成覆盖全部面的单一截面环)后,本件首轮即被
|
||||
// 该路径接走恢复:tets=511、体积误差 0.53%、水密闭合,不再触发灾难门。
|
||||
// 断言恢复语义:网格非空、宿主显式尺寸不被改写(max_size_used==0)、
|
||||
// 2% 体积门内水密、两次调用逐位一致。>35% 灾难门的可观测性不再由本件
|
||||
// 锁定(本件已被快速路径接走);AutoSize 的 HAU61 用例仍锚定结构化体积
|
||||
// 拒绝(err>2%),灾难门本身的自适应/确定性由该用例覆盖。
|
||||
const char* src_root = std::getenv("VDE_SOURCE_DIR");
|
||||
const std::string path =
|
||||
std::string(src_root ? src_root : "D:/20_AI/ViewDesignEngine") +
|
||||
@@ -3019,30 +3039,28 @@ TEST(ExplicitSize, ChamferedWasherCatastrophicOutcomeIsDiagnosable) {
|
||||
TetMeshParams tp;
|
||||
tp.max_size = 5.0;
|
||||
tp.quality_iterations = 0;
|
||||
const auto mesh = tetrahedral_mesh(b, tp);
|
||||
if (!mesh.elements.empty()) {
|
||||
EXPECT_DOUBLE_EQ(mesh.max_size_used, 2.5) << mesh.diagnostic;
|
||||
const auto v = validate_volume_mesh(b, mesh, 0.02);
|
||||
EXPECT_TRUE(v.closed) << v.diagnostic;
|
||||
EXPECT_TRUE(v.ok) << v.diagnostic;
|
||||
EXPECT_LE(std::abs(v.relative_error), 0.02) << v.diagnostic;
|
||||
std::fprintf(stderr,
|
||||
"EXPLICIT washer M8 recovered size=%.6g tets=%zu "
|
||||
"err=%.9f\n",
|
||||
mesh.max_size_used, mesh.elements.size(),
|
||||
v.relative_error);
|
||||
} else {
|
||||
EXPECT_NE(mesh.diagnostic.find("rejected"), std::string::npos)
|
||||
<< mesh.diagnostic;
|
||||
// 灾难门触发条件可观测:诊断里的体积误差必须仍 >0.35(说明保持的是
|
||||
// 原始回退结果,而不是被更细尺寸的校验失败改写)。
|
||||
const double err = refine_diag_volume_error(mesh.diagnostic);
|
||||
EXPECT_GT(err, 0.35)
|
||||
<< "M8 垫圈的灾难门体积误差应可观测: " << mesh.diagnostic;
|
||||
std::fprintf(stderr,
|
||||
"EXPLICIT washer M8 still-rejected err=%.9f size=%.6g\n",
|
||||
err, mesh.max_size_used);
|
||||
}
|
||||
const auto m1 = tetrahedral_mesh(b, tp);
|
||||
const auto m2 = tetrahedral_mesh(b, tp);
|
||||
ASSERT_FALSE(m1.elements.empty()) << m1.diagnostic;
|
||||
ASSERT_FALSE(m2.elements.empty()) << m2.diagnostic;
|
||||
EXPECT_EQ(m1.elements.size(), 511u) << m1.diagnostic;
|
||||
EXPECT_EQ(m1.vertices.size(), 176u) << m1.diagnostic;
|
||||
// 快速路径只替换体网格,不修改宿主显式 target_size。
|
||||
EXPECT_DOUBLE_EQ(m1.max_size_used, 0.0) << m1.diagnostic;
|
||||
EXPECT_DOUBLE_EQ(m2.max_size_used, 0.0) << m2.diagnostic;
|
||||
const auto v = validate_volume_mesh(b, m1, 0.02);
|
||||
EXPECT_TRUE(v.closed) << v.diagnostic;
|
||||
EXPECT_TRUE(v.ok) << v.diagnostic;
|
||||
EXPECT_NEAR(std::abs(v.relative_error), 0.00528672, 1e-6) << v.diagnostic;
|
||||
// 旋转体路径必须确定性(同一参数两次调用逐位一致)。
|
||||
EXPECT_EQ(m1.diagnostic, m2.diagnostic);
|
||||
ASSERT_EQ(m1.elements.size(), m2.elements.size());
|
||||
for (size_t i = 0; i < m1.elements.size(); ++i)
|
||||
EXPECT_EQ(m1.elements[i], m2.elements[i]);
|
||||
std::fprintf(stderr,
|
||||
"EXPLICIT washer M8 revolve recovered tets=%zu size=%.6g "
|
||||
"err=%.9f\n",
|
||||
m1.elements.size(), m1.max_size_used, v.relative_error);
|
||||
}
|
||||
|
||||
TEST(ExplicitSize, SurfaceLockRetryRecoversLathePartAtHostSize) {
|
||||
@@ -3109,6 +3127,11 @@ TEST(AutoSize, SurfaceVolumeGateRestoresPinAndHousingBitIdentically) {
|
||||
// Housing:rel=5.32%(789.96/750.09)→ 0.469042(80 tri,1.346%)接受:
|
||||
// tets=22730、size=0.938083、err=1.31%,同样逐位一致。门只替换表面 hint,
|
||||
// 不改写推导尺寸:max_size_used 仍是基线推导值(不是减半后的值)。
|
||||
// [Wave16/A33] 整周 rim 环采样补到 ≥32 段只影响粗口径(n<8);A33 细口径
|
||||
// 回归修正后,auto 初始表面与门收敛档位回到 Wave15 指纹(build/w15_base_auto.log):
|
||||
// Pin → tets=48272、err=0.99%;Housing → tets=22730、err=1.31%;
|
||||
// max_size_used 仍为推导值 0.403113/0.938083(门不改写目标尺寸),多级
|
||||
// 表面重镶仍确定性。下列数字是回归修正后的稳定指纹。
|
||||
const char* src_root = std::getenv("VDE_SOURCE_DIR");
|
||||
const std::string root =
|
||||
std::string(src_root ? src_root : "D:/20_AI/ViewDesignEngine");
|
||||
@@ -3118,8 +3141,8 @@ TEST(AutoSize, SurfaceVolumeGateRestoresPinAndHousingBitIdentically) {
|
||||
double size;
|
||||
double err;
|
||||
} cases[] = {
|
||||
{"Pin.stp", 48272, 0.403113, 0.00994397},
|
||||
{"Housing.stp", 22730, 0.938083, 0.0130924},
|
||||
{"Pin.stp", 48272, 0.403113, 0.009943971},
|
||||
{"Housing.stp", 22730, 0.938083, 0.013092440},
|
||||
};
|
||||
for (const auto& c : cases) {
|
||||
const std::string path = root + "/corpus/real/step/" + c.name;
|
||||
@@ -3167,16 +3190,17 @@ TEST(AutoSize, SurfaceVolumeGateAbandonsWhenRefinementStalls) {
|
||||
// A31 门的回退契约:auto 下初始水密粗表面 rel>1.5% 时门会尝试逐级减半
|
||||
// 表面弦高;若某级表面体积误差没有 >=20% 的改进,则触发护栏②立即放弃,
|
||||
// 丢弃所有候选表面、保留原镶嵌与既有路径(与无门行为逐位一致),不新增
|
||||
// 拒绝/标签。tc-blt:门进入时表面 rel=10.87%(2852.50/3200.38)→
|
||||
// level1 defl=0.998123(124 tri)rel=2.84%,level2 defl=0.499062(124 tri)
|
||||
// rel=2.84%(0% 改进)→ abandoned;随后走既有 A28 减半路径得到
|
||||
// size=0.998123、tets=34938、err=0.84%,仍 mesh_ok。
|
||||
// 拒绝/标签。Wave16/A33 后指纹件为 tu-blt:门进入时表面 rel=6.81%
|
||||
// (2982.56/3200.38)→ level1 defl=0.998123(196 tri)rel=7.59%(变差)
|
||||
// → abandoned;随后走既有 A28 减半路径得到 size=0.998123、tets=34475、
|
||||
// err=1.11%,仍 mesh_ok。tc-blt 在 Wave16 改为门接受(推导尺寸 1.99625
|
||||
// 下表面收敛),见 NearMiss 用例。
|
||||
// 断言锁定该回退行为(若门错误收敛/接受,size 会停在推导值 1.99625 或
|
||||
// 更细表面,tets 亦会变化)。
|
||||
const char* src_root = std::getenv("VDE_SOURCE_DIR");
|
||||
const std::string path =
|
||||
std::string(src_root ? src_root : "D:/20_AI/ViewDesignEngine") +
|
||||
"/corpus/real/step/occ__xr1-tc-blt__2.stp";
|
||||
"/corpus/real/step/occ__xr1-tu-blt__2.stp";
|
||||
std::ifstream in(path);
|
||||
if (!in.good()) GTEST_SKIP() << "corpus file missing: " << path;
|
||||
auto r = vde::brep::import_cad(path);
|
||||
@@ -3189,22 +3213,26 @@ TEST(AutoSize, SurfaceVolumeGateAbandonsWhenRefinementStalls) {
|
||||
autop.quality_iterations = 0;
|
||||
const auto mesh = tetrahedral_mesh(b, autop);
|
||||
ASSERT_FALSE(mesh.elements.empty()) << mesh.diagnostic;
|
||||
EXPECT_EQ(mesh.elements.size(), std::size_t{34938})
|
||||
EXPECT_EQ(mesh.elements.size(), std::size_t{34475})
|
||||
<< "门放弃后应保持既有 A28 路径结果: " << mesh.diagnostic;
|
||||
EXPECT_NEAR(mesh.max_size_used, 0.998123, 1e-5)
|
||||
<< "门放弃后不得改写/保持推导尺寸: " << mesh.diagnostic;
|
||||
const auto v = validate_volume_mesh(b, mesh, 0.02);
|
||||
EXPECT_TRUE(v.closed) << v.diagnostic;
|
||||
EXPECT_TRUE(v.ok) << v.diagnostic;
|
||||
EXPECT_NEAR(std::abs(v.relative_error), 0.00841391, 1e-6) << v.diagnostic;
|
||||
std::fprintf(stderr, "A31 gate-abandon tc-blt tets=%zu size=%.6g err=%.9f\n",
|
||||
EXPECT_NEAR(std::abs(v.relative_error), 0.011098611, 1e-8) << v.diagnostic;
|
||||
std::fprintf(stderr, "A31 gate-abandon tu-blt tets=%zu size=%.6g err=%.9f\n",
|
||||
mesh.elements.size(), mesh.max_size_used, v.relative_error);
|
||||
}
|
||||
|
||||
TEST(ExplicitSize, LeavesAcceptedFixedSizePieceBitIdentical) {
|
||||
// 已接受的显式尺寸件(FOOT,固定 5mm,基线 tet=2964、err≈0.063%)完全
|
||||
// 不受细化重试影响:两次调用逐位一致、max_size_used 保持 0(未细化)、
|
||||
// 体积校验仍通过 —— additive 契约的「显式收益件不被触碰」对照。
|
||||
TEST(ExplicitSize, NearMissFallbackUsesBestWatertightSurface) {
|
||||
// [Wave16/A32b] FOOT 固定 5mm:A33 修好粗口径整周 rim 环采样后首轮表面
|
||||
// (818 tri)已水密但体积亏 4.34%,旧路径因此跳过「水密细化」循环,且
|
||||
// near-miss 回退用首档候选表面(defl=2.5,rel=4.34%)重入细化而失败。
|
||||
// A32b 把回退改为「rel 最小的水密候选」:本件 4 级候选 rel 依次
|
||||
// 4.34%/5.68%/3.88%/1.64%,回退选 defl=0.3125,refine level=1 后体积
|
||||
// 误差 1.36%,恢复 mesh_ok(tets=10838、max_size_used=2.5)。
|
||||
// 断言:宿主显式尺寸只按 0.5x 细化(2.5)、网格水密可信、两次调用逐位一致。
|
||||
const char* src_root = std::getenv("VDE_SOURCE_DIR");
|
||||
const std::string path =
|
||||
std::string(src_root ? src_root : "D:/20_AI/ViewDesignEngine") +
|
||||
@@ -3222,8 +3250,8 @@ TEST(ExplicitSize, LeavesAcceptedFixedSizePieceBitIdentical) {
|
||||
const auto m2 = tetrahedral_mesh(b, tp);
|
||||
ASSERT_FALSE(m1.elements.empty()) << m1.diagnostic;
|
||||
ASSERT_FALSE(m2.elements.empty()) << m2.diagnostic;
|
||||
EXPECT_DOUBLE_EQ(m1.max_size_used, 0.0)
|
||||
<< "已接受件未细化,max_size_used 必须为 0";
|
||||
EXPECT_EQ(m1.elements.size(), std::size_t{10838}) << m1.diagnostic;
|
||||
EXPECT_DOUBLE_EQ(m1.max_size_used, 2.5) << m1.diagnostic;
|
||||
ASSERT_EQ(m1.vertices.size(), m2.vertices.size());
|
||||
for (size_t i = 0; i < m1.vertices.size(); ++i) {
|
||||
EXPECT_DOUBLE_EQ(m1.vertices[i].x(), m2.vertices[i].x());
|
||||
@@ -3236,9 +3264,9 @@ TEST(ExplicitSize, LeavesAcceptedFixedSizePieceBitIdentical) {
|
||||
const auto v = validate_volume_mesh(b, m1, 0.02);
|
||||
EXPECT_TRUE(v.closed) << v.diagnostic;
|
||||
EXPECT_TRUE(v.ok) << v.diagnostic;
|
||||
EXPECT_LE(std::abs(v.relative_error), 0.02) << v.diagnostic;
|
||||
EXPECT_NEAR(std::abs(v.relative_error), 0.013646433, 1e-8) << v.diagnostic;
|
||||
std::fprintf(stderr,
|
||||
"EXPLICIT FOOT unchanged tets=%zu size=%.6g err=%.9f\n",
|
||||
"EXPLICIT FOOT best-fallback tets=%zu size=%.6g err=%.9f\n",
|
||||
m1.elements.size(), m1.max_size_used, v.relative_error);
|
||||
}
|
||||
|
||||
@@ -3283,3 +3311,142 @@ TEST(AutoSize, MainBodySolidAngleStaysRejectedOrRecoversDiagnosably) {
|
||||
err, m1.max_size_used);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// Wave16/A32:棱柱端盖环采样 1/4 递减重试(2% 门不放松)
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(ExplicitSize, PrismCapSamplingRefinesEndCapLoopsToWatertight) {
|
||||
// 固定 5mm 时棱柱快速路径的端盖环采样步长原本等于 target_size:短边
|
||||
// 端盖只采到 4 个点,端面多边形面积亏 2.55%,体网格体积误差同量级被
|
||||
// 2% 门拒绝。A32 改为 loop_sample_step = target_size * 0.25^attempt
|
||||
// 逐级重试(最多 4 次,validate 的 2% 容差不放松,全部失败时返回误差
|
||||
// 最小者):1176-B1P-A 在 0.3125 处 354 tets / 0.014% 恢复;
|
||||
// 2__2.STEP 在 1.25 处 102 tets / 1.97% 恢复(首档 2.55% 被拒后)。
|
||||
const char* src_root = std::getenv("VDE_SOURCE_DIR");
|
||||
const std::string root =
|
||||
std::string(src_root ? src_root : "D:/20_AI/ViewDesignEngine");
|
||||
struct PrismCase {
|
||||
const char* name;
|
||||
std::size_t tets;
|
||||
double err;
|
||||
} cases[] = {
|
||||
{"1176-B1P-A.step", 354, 0.000140172},
|
||||
{"2__2.STEP", 102, 0.0196721},
|
||||
};
|
||||
for (const auto& c : cases) {
|
||||
const std::string path = root + "/corpus/real/step/" + c.name;
|
||||
std::ifstream in(path);
|
||||
if (!in.good()) GTEST_SKIP() << "corpus file missing: " << path;
|
||||
auto r = vde::brep::import_cad(path);
|
||||
ASSERT_TRUE(r.ok) << c.name << ": " << r.diagnostic.summary();
|
||||
ASSERT_FALSE(r.bodies.empty()) << c.name;
|
||||
const auto& b = r.bodies.front();
|
||||
TetMeshParams tp;
|
||||
tp.max_size = 5.0;
|
||||
tp.quality_iterations = 0;
|
||||
const auto m = tetrahedral_mesh(b, tp);
|
||||
ASSERT_FALSE(m.elements.empty()) << c.name << ": " << m.diagnostic;
|
||||
EXPECT_EQ(m.elements.size(), c.tets)
|
||||
<< c.name << ": 端盖环重试应恢复到精确网格: " << m.diagnostic;
|
||||
EXPECT_NE(m.diagnostic.find("extruded prism fast path"),
|
||||
std::string::npos)
|
||||
<< c.name << ": " << m.diagnostic;
|
||||
// 棱柱快速路径不改写宿主显式 target_size。
|
||||
EXPECT_DOUBLE_EQ(m.max_size_used, 0.0) << c.name << ": "
|
||||
<< m.diagnostic;
|
||||
const auto v = validate_volume_mesh(b, m, 0.02);
|
||||
EXPECT_TRUE(v.closed) << c.name << ": " << v.diagnostic;
|
||||
EXPECT_TRUE(v.ok) << c.name << ": " << v.diagnostic;
|
||||
EXPECT_NEAR(std::abs(v.relative_error), c.err, 1e-6)
|
||||
<< c.name << ": " << v.diagnostic;
|
||||
std::fprintf(stderr, "EXPLICIT prism %s tets=%zu err=%.9f\n",
|
||||
c.name, m.elements.size(), v.relative_error);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// Wave16/A33:粗口径闭合 rim 环补采样(周期带面不再静默缺面)
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(ExplicitSize, CoarseRimSamplingKeepsPeriodicBandFacesWatertight) {
|
||||
// 固定 5mm(sag_tol=2.5)下半径 2~4 的整周圆柱 rim 闭合环原本只采到
|
||||
// 2~4 段(弦高判据用 1e-3 周期过严),空角隙 1.57~3.14 超过周期带面
|
||||
// 识别门限(0.35/0.45 rad)→ 带面整体回退通用 UV 投影并静默产出 0
|
||||
// 三角:表面缺面使体积误差达 54%~100%。A33 对「两端顶点重合」或
|
||||
// 「n<8 且弦长<0.7 弧长」的闭合环补到 32 段(角隙 11.25°):Bolt /
|
||||
// SCJ02 / Housing 固定 5mm 全部回到 2% 门内。
|
||||
const char* src_root = std::getenv("VDE_SOURCE_DIR");
|
||||
const std::string root =
|
||||
std::string(src_root ? src_root : "D:/20_AI/ViewDesignEngine");
|
||||
struct RimCase {
|
||||
const char* name;
|
||||
std::size_t tets;
|
||||
double err;
|
||||
} cases[] = {
|
||||
{"Bolt.stp", 388, 0.0114417},
|
||||
{"Housing.stp", 498, 0.0109869},
|
||||
{"SCJ02-D12-L85-M5-N5.stp", 8598, 0.00566517},
|
||||
};
|
||||
for (const auto& c : cases) {
|
||||
const std::string path = root + "/corpus/real/step/" + c.name;
|
||||
std::ifstream in(path);
|
||||
if (!in.good()) GTEST_SKIP() << "corpus file missing: " << path;
|
||||
auto r = vde::brep::import_cad(path);
|
||||
ASSERT_TRUE(r.ok) << c.name << ": " << r.diagnostic.summary();
|
||||
ASSERT_FALSE(r.bodies.empty()) << c.name;
|
||||
const auto& b = r.bodies.front();
|
||||
TetMeshParams tp;
|
||||
tp.max_size = 5.0;
|
||||
tp.quality_iterations = 0;
|
||||
const auto m = tetrahedral_mesh(b, tp);
|
||||
ASSERT_FALSE(m.elements.empty()) << c.name << ": " << m.diagnostic;
|
||||
EXPECT_EQ(m.elements.size(), c.tets)
|
||||
<< c.name << ": rim 补采样应恢复到精确网格: " << m.diagnostic;
|
||||
const auto v = validate_volume_mesh(b, m, 0.02);
|
||||
EXPECT_TRUE(v.closed) << c.name << ": " << v.diagnostic;
|
||||
EXPECT_TRUE(v.ok) << c.name << ": " << v.diagnostic;
|
||||
EXPECT_NEAR(std::abs(v.relative_error), c.err, 1e-6)
|
||||
<< c.name << ": " << v.diagnostic;
|
||||
std::fprintf(stderr, "EXPLICIT rim %s tets=%zu err=%.9f\n",
|
||||
c.name, m.elements.size(), v.relative_error);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// Wave16/A35:单面非平面闭合体(整球)的角分辨率兜底
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(ExplicitSize, SingleCurvedFaceBodyUsesDenseFaceParametrization) {
|
||||
// occ__bug24283_spheres__2.stp 是单个 OCC 球面(F=1;u 周期、v 在两极
|
||||
// 退化,is_closed(false)==false),整面即整个体的闭合边界。此前 Untrimmed
|
||||
// 整面兜底只认「u/v 双向闭合」,该件片面只按 4x4 参数网格镶嵌(80 三角,
|
||||
// 内接体积 2.276 vs 4.189,误差 45.6%)→ 四面体化被体积门拒绝。
|
||||
// A35 把兜底条件扩为「双向闭合 或 body.num_faces()==1」:32x32 球面在 2%
|
||||
// 门内,星形质心路径给出 tets=1984、水密、err=0.888%;宿主显式尺寸不被
|
||||
// 改写(max_size_used==0)。
|
||||
const char* src_root = std::getenv("VDE_SOURCE_DIR");
|
||||
const std::string path =
|
||||
std::string(src_root ? src_root : "D:/20_AI/ViewDesignEngine") +
|
||||
"/corpus/real/step/occ__bug24283_spheres__2.stp";
|
||||
std::ifstream in(path);
|
||||
if (!in.good()) GTEST_SKIP() << "corpus file missing: " << path;
|
||||
auto r = vde::brep::import_cad(path);
|
||||
ASSERT_TRUE(r.ok) << r.diagnostic.summary();
|
||||
ASSERT_FALSE(r.bodies.empty());
|
||||
const auto& b = r.bodies.front();
|
||||
EXPECT_EQ(b.num_faces(), std::size_t{1});
|
||||
TetMeshParams tp;
|
||||
tp.max_size = 5.0;
|
||||
tp.quality_iterations = 0;
|
||||
const auto m = tetrahedral_mesh(b, tp);
|
||||
ASSERT_FALSE(m.elements.empty()) << m.diagnostic;
|
||||
EXPECT_EQ(m.elements.size(), std::size_t{1984}) << m.diagnostic;
|
||||
EXPECT_DOUBLE_EQ(m.max_size_used, 0.0) << m.diagnostic;
|
||||
const auto v = validate_volume_mesh(b, m, 0.02);
|
||||
EXPECT_TRUE(v.closed) << v.diagnostic;
|
||||
EXPECT_TRUE(v.ok) << v.diagnostic;
|
||||
EXPECT_NEAR(std::abs(v.relative_error), 0.00888095, 1e-8) << v.diagnostic;
|
||||
std::fprintf(stderr, "EXPLICIT sphere tets=%zu err=%.9f\n",
|
||||
m.elements.size(), v.relative_error);
|
||||
}
|
||||
|
||||
@@ -670,3 +670,146 @@ TEST(VDE1346CaePreprocess, SuccessfulMidsurfaceHasNoDiagnostics) {
|
||||
EXPECT_TRUE(surface.message.empty());
|
||||
EXPECT_TRUE(surface.diagnostics.empty());
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// Wave16 / VDE-A34:87 件 mids=0 真实语料分类与「闭合薄壁环形板」修正。
|
||||
// - 整圆/闭合曲线单边环采样修复(sample_loops):垫圈/轴套类环形壁面
|
||||
// 不再因「整圆单边闭环」被静默跳过(PlainWasher/Bolt 转正)。
|
||||
// - 常厚度配对轮廓门槛修正:上下环形壁面「孔轮廓一致 + 环数一致 + 外轮廓
|
||||
// 包含 + 面积比 >= 0.7」时允许外缘倒角带造成的面积差 —— 倒角垫圈转正。
|
||||
// 非薄壁/非水密/单面片体仍按 VDE-1346 §2.1/§7.2 拒绝(本组用例守住该口径)。
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
namespace {
|
||||
|
||||
std::string a34_corpus_path(const char* rel) {
|
||||
const char* src_root = std::getenv("VDE_SOURCE_DIR");
|
||||
return std::string(src_root ? src_root : "D:/20_AI/ViewDesignEngine") +
|
||||
"/corpus/real/" + rel;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// §7.6-1(A34-C 类转正):corpus/real/step/mechbench__ChamferedWasher_iso7090_M6__2.step
|
||||
// 倒角垫圈:5 面(上下环形平面 + 外柱 r6 + 内柱 r3.2 + 外缘倒角锥),厚 1.8。
|
||||
// 修正前上下环形壁面面积差 14.4% 被轮廓门槛拒绝(contour_gate=2);倒角只削
|
||||
// 外缘一圈,孔轮廓(r3.2)两壁面一致,按等厚度薄板配对出 1 张平面中面。
|
||||
TEST(VDE1346CaePreprocess, CorpusChamferedWasherAnnularMidsurface) {
|
||||
const std::string path = a34_corpus_path(
|
||||
"step/mechbench__ChamferedWasher_iso7090_M6__2.step");
|
||||
std::ifstream in(path);
|
||||
if (!in.good()) GTEST_SKIP() << "corpus file missing: " << path;
|
||||
auto imported = vde::brep::import_cad(path);
|
||||
ASSERT_TRUE(imported.ok) << imported.diagnostic.summary();
|
||||
ASSERT_FALSE(imported.bodies.empty());
|
||||
const auto& body = imported.bodies.front();
|
||||
ASSERT_EQ(body.num_faces(), 5);
|
||||
EXPECT_NEAR(body.body_volume(), 141.837, 0.5);
|
||||
|
||||
const auto surface = vde::cae::extract_midsurface(body, 0.2);
|
||||
ASSERT_TRUE(surface.valid) << surface.message;
|
||||
ASSERT_EQ(surface.patches.size(), 1u) << surface.message;
|
||||
const auto& p = surface.patches[0];
|
||||
EXPECT_EQ(p.kind, vde::cae::MidsurfaceKind::Plane);
|
||||
EXPECT_NEAR(std::abs(p.normal.z()), 1.0, 1e-6);
|
||||
EXPECT_NEAR(p.origin.z(), 0.9, 1e-6);
|
||||
EXPECT_NEAR(p.thickness, 1.8, 1e-6);
|
||||
EXPECT_NEAR(p.thickness_min, 1.8, 1e-6);
|
||||
EXPECT_NEAR(p.thickness_mean, 1.8, 1e-6);
|
||||
EXPECT_NEAR(p.thickness_max, 1.8, 1e-6);
|
||||
// 环形壁面:外轮廓 + 内孔轮廓都必须保留(孔不能被采样丢掉)。
|
||||
ASSERT_EQ(p.loops.size(), 2u);
|
||||
for (const auto& lp : p.loops) EXPECT_GE(lp.size(), 8u);
|
||||
EXPECT_FALSE(p.source_faces.empty());
|
||||
// 成功路径不写 diagnostics(旧调用方语义不变)。
|
||||
EXPECT_TRUE(surface.message.empty());
|
||||
EXPECT_TRUE(surface.diagnostics.empty());
|
||||
|
||||
// 确定性:同一输入两次提取逐位一致。
|
||||
const auto again = vde::cae::extract_midsurface(body, 0.2);
|
||||
ASSERT_TRUE(again.valid) << again.message;
|
||||
ASSERT_EQ(again.patches.size(), 1u);
|
||||
EXPECT_EQ(again.patches[0].patch_id, p.patch_id);
|
||||
EXPECT_EQ(again.patches[0].faces, p.faces);
|
||||
EXPECT_EQ(again.patches[0].loops, p.loops);
|
||||
EXPECT_NEAR(again.patches[0].thickness, p.thickness, 0.0);
|
||||
}
|
||||
|
||||
// §7.6-2(误报守卫):corpus/real/step/test_cube.STEP 100 mm 立方体(V=1e6)。
|
||||
// 三个方向壁厚都超过 ratio 门槛 → 必须仍无中面(thickness_gate=面数)。
|
||||
TEST(VDE1346CaePreprocess, CorpusThickSolidHasNoMidsurface) {
|
||||
const std::string path = a34_corpus_path("step/test_cube.STEP");
|
||||
std::ifstream in(path);
|
||||
if (!in.good()) GTEST_SKIP() << "corpus file missing: " << path;
|
||||
auto imported = vde::brep::import_cad(path);
|
||||
ASSERT_TRUE(imported.ok) << imported.diagnostic.summary();
|
||||
ASSERT_FALSE(imported.bodies.empty());
|
||||
const auto& body = imported.bodies.front();
|
||||
ASSERT_EQ(body.num_faces(), 6);
|
||||
EXPECT_NEAR(body.body_volume(), 1.0e6, 1.0);
|
||||
|
||||
const auto surface = vde::cae::extract_midsurface(body, 0.2);
|
||||
EXPECT_FALSE(surface.valid);
|
||||
EXPECT_TRUE(surface.patches.empty());
|
||||
EXPECT_NE(surface.message.find("回退中面链"), std::string::npos)
|
||||
<< surface.message;
|
||||
EXPECT_EQ(diagnostic_int(surface.message, "pairs"), 0) << surface.message;
|
||||
EXPECT_EQ(diagnostic_int(surface.message, "thickness_gate"), 6)
|
||||
<< surface.message;
|
||||
EXPECT_EQ(diagnostic_int(surface.message, "contour_gate"), 0)
|
||||
<< surface.message;
|
||||
EXPECT_EQ(surface.diagnostics.size(), 2u);
|
||||
}
|
||||
|
||||
// §7.6-3(误报守卫):corpus/real/step/2__2.STEP 厚环(OD10/ID3/L3)。两个平行
|
||||
// 环形端面(下壁面投影面积 78.03、间距 3 > 0.2*sqrt(78.03)=1.77)仍应被厚度
|
||||
// 门槛拒绝 —— 环形放行规则只解决「外缘倒角导致面积差」,不放行厚壁环。
|
||||
TEST(VDE1346CaePreprocess, CorpusThickRingHasNoMidsurface) {
|
||||
const std::string path = a34_corpus_path("step/2__2.STEP");
|
||||
std::ifstream in(path);
|
||||
if (!in.good()) GTEST_SKIP() << "corpus file missing: " << path;
|
||||
auto imported = vde::brep::import_cad(path);
|
||||
ASSERT_TRUE(imported.ok) << imported.diagnostic.summary();
|
||||
ASSERT_FALSE(imported.bodies.empty());
|
||||
const auto& body = imported.bodies.front();
|
||||
ASSERT_EQ(body.num_faces(), 6);
|
||||
EXPECT_NEAR(body.body_volume(), 214.393, 0.5);
|
||||
|
||||
const auto surface = vde::cae::extract_midsurface(body, 0.2);
|
||||
EXPECT_FALSE(surface.valid);
|
||||
EXPECT_TRUE(surface.patches.empty());
|
||||
EXPECT_EQ(diagnostic_int(surface.message, "pairs"), 0)
|
||||
<< surface.message;
|
||||
EXPECT_GT(diagnostic_int(surface.message, "thickness_gate"), 0)
|
||||
<< surface.message;
|
||||
EXPECT_EQ(diagnostic_int(surface.message, "apply_fail"), 0)
|
||||
<< surface.message;
|
||||
}
|
||||
|
||||
// §7.6-4(契约口径):corpus/real/step/occ__trj7_c2-ct-203__2.stp 单面片体
|
||||
// (1 个平面、体积 0、非水密)。VDE-1346 §2.1/§7.2:非薄壁/非水密/无法配对时
|
||||
// valid=false 并给诊断,不静默造面 → 中面必须为空。
|
||||
TEST(VDE1346CaePreprocess, CorpusOpenSheetHasNoMidsurface) {
|
||||
const std::string path =
|
||||
a34_corpus_path("step/occ__trj7_c2-ct-203__2.stp");
|
||||
std::ifstream in(path);
|
||||
if (!in.good()) GTEST_SKIP() << "corpus file missing: " << path;
|
||||
auto imported = vde::brep::import_cad(path);
|
||||
ASSERT_TRUE(imported.ok) << imported.diagnostic.summary();
|
||||
ASSERT_FALSE(imported.bodies.empty());
|
||||
const auto& body = imported.bodies.front();
|
||||
ASSERT_EQ(body.num_faces(), 1);
|
||||
|
||||
const auto surface = vde::cae::extract_midsurface(body, 0.2);
|
||||
EXPECT_FALSE(surface.valid);
|
||||
EXPECT_TRUE(surface.patches.empty());
|
||||
EXPECT_NE(surface.message.find("stage=constant_thickness"),
|
||||
std::string::npos) << surface.message;
|
||||
EXPECT_EQ(diagnostic_int(surface.message, "pairs"), 0)
|
||||
<< surface.message;
|
||||
EXPECT_EQ(diagnostic_int(surface.message, "no_opposite"), 1)
|
||||
<< surface.message;
|
||||
EXPECT_NE(surface.message.find("e_unpaired_face"), std::string::npos)
|
||||
<< surface.message;
|
||||
ASSERT_EQ(surface.diagnostics.size(), 2u);
|
||||
EXPECT_EQ(surface.diagnostics[1].rfind("stage=chain", 0), 0u);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user