VDE-1347 / VDE-1346 follow-up on the 1.0.478 real-corpus CAE baseline (250 STEP files): - Sub-2 mm periodic-face trim domains (A17): the closed-band planarity gate used the base-surface control-net extent (imported cylinders/cones span +/-1e6 -> 2.0 mm tolerance), so hole walls with radius < 1 mm were classified planar, the band path was skipped and the inner cylinder area collapsed to 0 (analytic volume +14.7%). mesh_face_trimmed / build_face_trim_domain now use nurbs_surface_is_planar_for_trim with the trim-loop local extent. iso7089_M1.6 inner area 0 -> 1.869248 (true 1.869026), analytic volume 4.13276 -> 3.603139 (true 3.603794); washer family 75/75. test_measure 162 -> 164. - Midsurface diagnostics (A18): cae::MidSurface gains additive diagnostics lines with constant-thickness stage counts (thickness_gate/contour_gate/no_opposite/apply_fail) and the chain-fallback code/message; failures also append a 'diagnostics:' segment to message. The 87 mids=0 KPI files are no longer all lumped as chain_failed. test_vde1346_cae_preprocess 17 -> 21 (17 existing cases bit-identical). - Near-miss volume refinement (A19): in auto_size mode a 2-manifold fallback mesh with volume error in (2%, 35%] is retried recursively at half the target size (<=3 levels, convergence gate < 0.7x, watertight pre-check), with max_size_used reporting the size actually used. HEAD_FRONT 0.030272 -> 0.000571823, FOOT 0.057298 -> 0.000175378, wheel axis2 0.101637 -> 0.0182983; explicit max_size is unaffected. test_fea_mesh 83 -> 86. Integration: full Release build OK; 23 suites 879 passed / 0 failed; PR gate 1011/1011 (90.98 s). Upstream test_b1_kpi_regression needed an MSVC __VERSION__ guard to compile; its DefaultSuiteNoDegradation failure is a pre-existing stale baseline (boolean kernel changed after the baseline was generated) and is not caused by this batch. 250-file KPI (baseline 1.0.478): fixed-size 63/86 unchanged (A17 fixes the analytic reference; fixed-size prism sampling stays chord-based); auto-size tet_ok 158 -> 168 (72.4%), rejected 68 -> 61, 0 regressions, 919 s (baseline 927 s). New passes: 4 A19 refinements (HEAD/HEAD_FRONT/FOOT/wheel axis2), 2 A17 bolts, 3 sub-2 mm washers. Mid-surface KPI: the 87 mids=0 files now break down as 35 single-face sheets, 45 low-face solids (thickness/no-opposite gate), 5 multi-feature and 2 complex parts, all chain_code=e_not_shell_body - i.e. none are thin-wall shells. Docs: new wave10 report, KPI doc section, remaining-gaps closing record, feedback status, api-reference-mesh (refine retry + cae_preprocess diagnostics), VDE-1346/VDE-1347 updates.
246 lines
12 KiB
C++
246 lines
12 KiB
C++
#pragma once
|
||
/**
|
||
* @file cae_preprocess.h
|
||
* @brief CAE 预处理:圆柱流道/孔中心线提取(VDE-1346);薄壁中面壳网格
|
||
* Tri3/Tri6/Quad4/Quad8、厚度/偏置/法向/边界边(VDE-1360)。
|
||
*/
|
||
#include <array>
|
||
#include <string>
|
||
#include <vector>
|
||
#include "vde/brep/brep.h"
|
||
|
||
namespace vde::cae {
|
||
|
||
struct CylindricalCenterline {
|
||
core::Point3D start{0, 0, 0};
|
||
core::Point3D end{0, 0, 0};
|
||
double radius = 0.0;
|
||
bool inner = false; ///< true = 内孔/流道壁;false = 外圆柱
|
||
};
|
||
|
||
/// 从 B-Rep 圆柱面提取同轴中心线段;无圆柱面返回空。
|
||
[[nodiscard]] std::vector<CylindricalCenterline>
|
||
extract_cylindrical_centerlines(const brep::BrepModel& body,
|
||
double tolerance = 1e-7);
|
||
|
||
|
||
enum class MidsurfaceKind { Plane, Cylinder, Sphere, Torus, Cone };
|
||
|
||
/// 中面提取的失败原因项(VDE-1346 §7.2-6):逐 B-Rep 面给出原因。
|
||
struct MidsurfaceIssue {
|
||
int face = -1; ///< 出问题的 B-Rep 面索引;-1 表示整体性原因
|
||
std::string message; ///< 具体原因(中文),可直接展示给用户
|
||
};
|
||
|
||
/// 相邻中面片之间的接头棱线(VDE-1346 §7.2-5):同一条 B-Rep 边被两侧
|
||
/// patch 共享。按 patch 对聚合:一对 patch 对应一条 junction,内部可包含多条
|
||
/// 共享边(如 T 形接头/加强筋根部的两段棱线)。
|
||
struct MidsurfaceJunction {
|
||
int patch_a = -1; ///< 一侧 patch 的稳定 patch_id
|
||
int patch_b = -1; ///< 另一侧 patch 的稳定 patch_id
|
||
int edge = -1; ///< 代表性共享 B-Rep 边 id(edges 中最小值)
|
||
std::vector<int> edges; ///< 该接头对的全部分享 B-Rep 边 id(升序)
|
||
};
|
||
|
||
struct MidsurfacePatch {
|
||
MidsurfaceKind kind = MidsurfaceKind::Plane;
|
||
core::Point3D origin{0, 0, 0}; ///< 中面原点(平面)/球心(Sphere)
|
||
/// 中面法向(平面;单位向量)。基准:与 source_faces[0](= faces[0])的
|
||
/// 外法向同侧,即 normal·(faces[0] 外法向) > 0;壳单元绕向按右手定则与
|
||
/// 之对齐(单元法向 = normal)。非平行面配对时取两侧法向的角平分方向。
|
||
core::Vector3D normal{0, 0, 1};
|
||
double thickness = 0.0; ///< 原薄壁厚度(= thickness_mean,旧字段)
|
||
std::vector<std::vector<core::Point3D>> loops; ///< 中面外环/孔环(采样折线)
|
||
|
||
// 圆柱中面(kind == Cylinder)
|
||
core::Point3D axis_point{0, 0, 0};
|
||
core::Vector3D axis{0, 0, 1};
|
||
double radius = 0.0;
|
||
double v0 = 0.0; ///< 轴向起点(沿 axis 的参数)
|
||
double v1 = 0.0; ///< 轴向终点
|
||
double major_radius = 0.0; ///< 圆环中面主半径
|
||
double minor_radius = 0.0; ///< 圆环中面管半径
|
||
double r0 = 0.0; ///< 圆锥中面起点半径
|
||
double r1 = 0.0; ///< 圆锥中面终点半径
|
||
|
||
/// 与 loops 一一对应的 B-Rep 边 id;loop_edge_ids[li][k] 是 loops[li][k]
|
||
/// 到 loops[li][k+1] 这一段所在的 B-Rep 边 id(不是 face_edges 数组下标;
|
||
/// -1 表示未知)。
|
||
std::vector<std::vector<int>> loop_edge_ids;
|
||
/// 该中面片来自的 B-Rep 面索引(通常 2 个;旧字段,保留兼容)。
|
||
std::vector<int> source_faces;
|
||
|
||
// ── VDE-1346 §7 中面片元数据 ────────────────────────────────
|
||
/// 稳定 patch 身份(§7.2-2):由 patch 几何/参数量化后做 FNV-1a 哈希,
|
||
/// 与 B-Rep 面枚举顺序、网格细分无关;同一几何 + 同一参数重复提取必得
|
||
/// 同一值。-1 表示手工构造、尚未赋值。不得用集合下标充当身份。
|
||
int patch_id = -1;
|
||
/// 该 patch 覆盖的 B-Rep 面索引(§7.2-1,与 source_faces 同义)。
|
||
std::vector<int> faces;
|
||
/// patch 边界对应的 B-Rep 边 id(升序去重;取值同 loop_edge_ids)。
|
||
std::vector<int> edges;
|
||
/// 厚度可追溯(§7.2-3,单位 mm):变厚度件三者互不相等。
|
||
double thickness_min = 0.0;
|
||
double thickness_max = 0.0;
|
||
double thickness_mean = 0.0;
|
||
/// 逐顶点厚度(变厚度件):与 thickness_per_vertex 一一对应;顶点位于
|
||
/// 中面环上,厚度为该点沿 -normal 方向到配对面的距离(mm)。
|
||
std::vector<core::Point3D> thickness_vertices;
|
||
std::vector<double> thickness_per_vertex;
|
||
};
|
||
|
||
/// 中面提取结果(VDE-1346 §7;VDE-1360 规格中的 MidSurface)。
|
||
///
|
||
/// 保留旧调用方依赖的 std::vector<MidsurfacePatch> 语义(size/empty/
|
||
/// operator[]/begin/end/push_back 等),既可当 patch 数组使用,也可读取
|
||
/// 整体语义:有效标志、失败原因、接头棱线与特征边。
|
||
struct MidSurface {
|
||
std::vector<MidsurfacePatch> patches; ///< 中面片
|
||
std::vector<MidsurfaceJunction> junctions; ///< 相邻 patch 的棱线接头
|
||
std::vector<int> feature_edges; ///< 中面自由边界/特征棱的 B-Rep 边 id
|
||
bool valid = false; ///< 是否提取到至少一张有效中面片(§7.2-6)
|
||
std::string message; ///< 失败原因汇总(成功时为空串)
|
||
std::vector<MidsurfaceIssue> issues; ///< 逐面失败原因(§7.2-6)
|
||
/// 分阶段失败诊断(additive,默认空):常厚度配对 0 patch 触发回退时填充,
|
||
/// 每个元素为空格分隔的 key=value,形如
|
||
/// "stage=constant_thickness faces=6 pairs=0 issues=6 thickness_gate=6
|
||
/// contour_gate=0 no_opposite=0 apply_fail=0 ratio=0.100000
|
||
/// first_issue=<首条逐面原因原文>"
|
||
/// "stage=chain ok=0 chain_code=e_not_shell_body message=<回退原文>"
|
||
/// 提取失败时这些行同时拼入 message(保留既有中文摘要),便于宿主按
|
||
/// chain_code= / faces= / pairs= / issues= 等 ASCII 标记统计失败原因;
|
||
/// 既有成功路径(常厚度配对出 patch)不填充该字段,其余字段逐位不变。
|
||
std::vector<std::string> diagnostics;
|
||
|
||
// ── std::vector 兼容转发(保持 VDE-1346/1360 既有调用方源码不变)──
|
||
[[nodiscard]] size_t size() const { return patches.size(); }
|
||
[[nodiscard]] bool empty() const { return patches.empty(); }
|
||
[[nodiscard]] bool has_value() const { return !patches.empty(); }
|
||
explicit operator bool() const { return !patches.empty(); }
|
||
void clear() {
|
||
patches.clear();
|
||
junctions.clear();
|
||
feature_edges.clear();
|
||
issues.clear();
|
||
diagnostics.clear();
|
||
valid = false;
|
||
message.clear();
|
||
}
|
||
void reserve(size_t n) { patches.reserve(n); }
|
||
void push_back(MidsurfacePatch patch) { patches.push_back(std::move(patch)); }
|
||
MidsurfacePatch& operator[](size_t i) { return patches[i]; }
|
||
const MidsurfacePatch& operator[](size_t i) const { return patches[i]; }
|
||
MidsurfacePatch& at(size_t i) { return patches.at(i); }
|
||
const MidsurfacePatch& at(size_t i) const { return patches.at(i); }
|
||
MidsurfacePatch& front() { return patches.front(); }
|
||
const MidsurfacePatch& front() const { return patches.front(); }
|
||
MidsurfacePatch& back() { return patches.back(); }
|
||
const MidsurfacePatch& back() const { return patches.back(); }
|
||
MidsurfacePatch* data() { return patches.data(); }
|
||
const MidsurfacePatch* data() const { return patches.data(); }
|
||
std::vector<MidsurfacePatch>::iterator begin() { return patches.begin(); }
|
||
std::vector<MidsurfacePatch>::iterator end() { return patches.end(); }
|
||
std::vector<MidsurfacePatch>::const_iterator begin() const {
|
||
return patches.begin();
|
||
}
|
||
std::vector<MidsurfacePatch>::const_iterator end() const {
|
||
return patches.end();
|
||
}
|
||
std::vector<MidsurfacePatch>::const_iterator cbegin() const {
|
||
return patches.cbegin();
|
||
}
|
||
std::vector<MidsurfacePatch>::const_iterator cend() const {
|
||
return patches.cend();
|
||
}
|
||
/// 隐式转换为 patch 数组,兼容按 std::vector<MidsurfacePatch> 传参的旧代码。
|
||
operator const std::vector<MidsurfacePatch>&() const { return patches; }
|
||
};
|
||
|
||
/// 从薄壁体提取中面 patch(VDE-1346 §7)。
|
||
///
|
||
/// 先按常厚度配对提取成对平行/近似平行平面薄壁(厚度阈值
|
||
/// max_thickness_ratio * sqrt(面积))以及同轴圆柱、同心球、同轴圆环、同轴圆台
|
||
/// 薄壳;若该路径完全失败(典型:上下轮廓不同的锥形/变厚度薄壁),再回退到
|
||
/// brep 的双面成链中面(支持 graded/local 厚度场),给出带
|
||
/// thickness_min/max/mean 与逐顶点厚度的平面/圆柱 patch(remaining-gaps ①)。
|
||
/// 成功时 valid=true;失败(如非薄壁实体)时 valid=false、patches 为空,
|
||
/// message 汇总原因(含回退诊断)、issues 逐面给出原因 —— 不会返回
|
||
/// 「部分有效」的空壳。
|
||
/// 常厚度配对失败(触发链式回退)时另以 diagnostics 给出分阶段可机读诊断
|
||
/// (stage=constant_thickness / stage=chain 行,同时拼入 message 的「诊断:」
|
||
/// 段),成功路径不填充、既有字段不变。
|
||
[[nodiscard]] MidSurface extract_midsurface(const brep::BrepModel& body,
|
||
double max_thickness_ratio = 0.1);
|
||
|
||
|
||
|
||
/// 壳单元类型。节点排序契约(与 Abaqus/ANSYS 一致):
|
||
/// Tri3 : 0-2 逆时针角节点;
|
||
/// Tri6 : 0-2 角节点,3=(0,1)、4=(1,2)、5=(2,0) 边中节点;
|
||
/// Quad4 : 0-3 逆时针角节点;
|
||
/// Quad8 : 0-3 角节点,4=(0,1)、5=(1,2)、6=(2,3)、7=(3,0) 边中节点。
|
||
enum class ShellElementType { Tri3, Tri6, Quad4, Quad8 };
|
||
|
||
/// 薄壁中面壳网格参数(VDE-1360)。
|
||
struct ShellMeshParams {
|
||
double max_edge_length = 5.0; ///< 目标最大边长;<=0 时按中面尺寸自动取。
|
||
double min_edge_length = 0.2; ///< 最小边长;自动细分时不会低于该值。
|
||
int subdivisions = 0; ///< 额外均匀细分次数(0 = 不细分)。
|
||
ShellElementType element_type = ShellElementType::Tri3;
|
||
bool quad_dominant = false; ///< true 时优先生成四边形单元。
|
||
};
|
||
|
||
/// 一个壳单元。nodes 的前 node_count 项有效,排序契约见 ShellElementType。
|
||
/// 同一中面片内单元法向连续(不会随机翻转)。
|
||
struct ShellElement {
|
||
std::array<int, 8> nodes{-1, -1, -1, -1, -1, -1, -1, -1};
|
||
int node_count = 3;
|
||
double thickness = 0.0; ///< 单元厚度(中面处)。
|
||
double offset = 0.0; ///< 相对中面的有符号偏置,沿 normal:+ 为法向侧
|
||
///< (如 top surface 取 +thickness/2)。偏置只是
|
||
///< 单元字段,不改变 vertices 中的中面坐标。
|
||
core::Vector3D normal{0, 0, 1}; ///< 单元法向(单位向量)。
|
||
int source_face_a = -1; ///< 中面片来源 B-Rep 面。
|
||
int source_face_b = -1;
|
||
};
|
||
|
||
/// 薄壁中面壳网格(VDE-1360)。旧字段 vertices/triangles/patch_ids/diagnostic
|
||
/// 保留,供 VDE-1346 旧接口与既有调用方使用。
|
||
struct ShellMesh {
|
||
// VDE-1346 旧字段(三角面片视图)
|
||
std::vector<core::Point3D> vertices;
|
||
std::vector<std::array<int, 3>> triangles;
|
||
std::vector<int> patch_ids;
|
||
std::string diagnostic;
|
||
|
||
// VDE-1360 壳单元视图
|
||
bool valid = false;
|
||
std::string message;
|
||
ShellElementType element_type = ShellElementType::Tri3;
|
||
std::vector<ShellElement> elements;
|
||
/// 自由边/孔边。每个边界单元边出现一次;tag 对应 B-Rep 边 id,
|
||
/// 无法匹配时为 -1(供压力/固定约束选择)。
|
||
std::vector<std::array<int, 2>> boundary_edges;
|
||
std::vector<int> boundary_edge_tags;
|
||
std::vector<double> nodal_thickness;
|
||
std::vector<int> material_ids;
|
||
};
|
||
|
||
/// 旧接口:薄壁中面三角壳网格;max_size<=0 时取中面尺寸的 5%。
|
||
[[nodiscard]] ShellMesh shell_mesh(const brep::BrepModel& body,
|
||
double max_size = 0.0);
|
||
|
||
/// VDE-1360:由单张中面片生成 Tri3/Tri6/Quad4/Quad8 壳网格。
|
||
[[nodiscard]] ShellMesh shell_mesh(const MidsurfacePatch& patch,
|
||
const ShellMeshParams& params = {});
|
||
|
||
/// VDE-1360:由多张中面片生成壳网格。
|
||
[[nodiscard]] ShellMesh shell_mesh(const MidSurface& mid,
|
||
const ShellMeshParams& params = {});
|
||
|
||
/// VDE-1360:直接由薄壁体提取中面并生成壳网格。
|
||
[[nodiscard]] ShellMesh shell_mesh(const brep::BrepModel& body,
|
||
const ShellMeshParams& params);
|
||
|
||
} // namespace vde::cae
|