Files
hm 1e9511a316 fix(feedback): R2 收口 — 第一轮审查剩余问题第二轮修复(1.0.22)
第一轮审查报告(docs/reference/52 §9)剩余问题第二轮闭环:
- VDE-1235 C API 补齐:flags VDE_DISPLAY_SMOOTH_GROUPS/ALLOW_PARTIAL;VdeDisplayMeshEx +
  vde_body_to_display_mesh_ex/_lod;VdeWireframeEx/VdeWireframeSegmentInfo + vde_body_to_wireframe_ex
  (crease/tangent/二面角/相邻面);旧 ABI 不变;Python ctypes 绑定补齐
- VDE-1235 #2 全边 chamfer 解析快速路径:轴对齐 box 全 12 棱 → 26 面解析体(0 开边、体积解析 rel=0、
  1.44ms、to_mesh 44 三角;旧逐边路径分钟级且多边结果不可用)+ chamfer_edges_ex id 映射/显式失败
- VDE-1239 §3/§4:build_wireframe 去重/短段过滤/确定性(WireframeOptions + 统计);DisplayMesh 开口边
  诊断 open_edge_count/open_edge_length(26 面圆角盒 Normal 984/1558.75、Draft 600/1558.67、box 0)
- VDE-1240:新增 curves/surface_op_status.h + 各曲面算子 *_checked(退化 ok=false+error,正常与 legacy
  逐控制点一致)
- VDE-1241:轴对齐 box 结构化四面体(边界面严格在 B-Rep 6 面、6 面 partition 非空、体积精确 72000)
- VDE-1243:共面三角对精确重叠面积(Sutherland-Hodgman;平板 area_mismatch 1.9e-15,部分重叠精确)
- VDE-1244:automatic_heal 在所有守卫/回退后以最终 body 回填报告字段
- VDE-1245:TorusGeometry/face_torus_geometry、CircleGeometry/edge_circle_geometry(≤1e-9)
- VDE-1242:带岛开口封口(环形槽体积 0.641%)、merge_boundary_layer 节点融合、开口残差结构化报告
- VDE-1231 请求3 / VDE-1237:公开 TessellationOptions + to_mesh* options 重载(env 仅默认来源,
  显式口径固定、serial==parallel==soup)

工程健壮性:
- CTest 每测试 TIMEOUT 600(防环境级挂起拖死 CI)
- to_mesh_parallel/to_triangle_soup 线程数上界钳制到硬件并发(消除 libgomp 高负载 teardown 挂起:
  SafetyEdgeCases 30/30、全量 ctest 0 timeout)
- 版本 1.0.22 全链路一致(CMake/version.h/VDE_VERSION_NUM=10022/test_version/README/docs index)

验证(docs/reference/53 独立验证报告):
- Lead 最终 build 全量 ctest 7184/7184 PASS(0 failed、22 skipped、245.5s)
- verifier 独立构建复跑 7184/7184 PASS(0 failed、0 timeout、333.2s);18 组/268 项独立探针 267 PASS
  (唯一 FAIL 为独立复现的内核既有布尔朝向问题,已记录剩余问题);独立全量构建 896/896,0 error
- R2 新增/扩展测试全绿(display 8、C API 11、legacy mesh 14、chamfer 5、heal 9、FEA 16、
  interface map 14、checked API 19、entity 20、fluid 28 等)
2026-10-28 07:30:31 +08:00

135 lines
6.0 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
/**
* @file interface_map.h
* @brief FSI / CHT 非匹配网格交界面映射(VDE-1243)
*
* 在两层不共节点的表面网格之间建立「目标节点 ← 源节点」的守恒插值权重:
* 最近点投影 + 法向一致性筛选 + 面积加权归一化,并提供面积失配
* (`area_mismatch`)与未匹配面片统计用于应用层提示"界面未贴合"。
*
* 设计口径:
* - 输入 `FEAMesh` 的表面由 `boundary_faces` 给出(多边形按扇形三角化);
* 若 `boundary_faces` 为空则从体单元提取外表面(Tet4/Hex8/Wedge6)。
* - patch id 复用 VDE-1241 的 `boundary_face_tags`(B-Rep face 索引),
* 因此 VDE-1241 的命名选择集可直接与 patch 组合;无 tag 时为 -1。
* - 只映射真实重叠区域:目标节点到源三角面的距离必须 ≤
* `search_tolerance × 包围盒对角线`,且法向同向(点积 > 0)。
* - 确定性:全流程按数组下标顺序遍历,不使用哈希遍历序,重复调用结果逐元素一致。
*
* @ingroup mesh
*/
#include "vde/mesh/fea_mesh.h"
#include <string>
#include <vector>
namespace vde::mesh {
/**
* @brief 交界面映射选项(VDE-1243)
* @ingroup mesh
*/
struct InterfaceMapOptions {
/// 搜索容差(相对两侧网格联合包围盒对角线);超过此距离的面片不参与映射;
/// 同时作为"共面三角对"的平面距离容差
double search_tolerance = 1e-4;
/// 每个目标三角片 / 目标节点最多参与的源面数(0 = 不限制)
int max_neighbors = 8;
/// 是否做守恒归一化(每行权重和 = 1;关掉则保留原始面积/重心权重)
bool normalize_conservative = true;
/// 是否要求源面片法向与目标节点法向同向(`n_source·n_target > 0`)
bool require_normal_consistency = true;
};
/**
* @brief 非匹配网格交界面映射结果(VDE-1243)
*
* 权重以稀疏三元组给出:`target_node_ids[k]` ← `source_node_ids[k]`
* (行 = 目标节点,列 = 源节点),`weights[k]` 为权重;同一目标节点的
* 记录连续且按 `source_node_ids` 升序(确定性)。
*
* @ingroup mesh
*/
struct InterfaceMap {
std::vector<int> target_node_ids; ///< 目标侧节点索引(0-based,每行重复出现)
std::vector<int> source_node_ids; ///< 源侧节点索引(0-based)
std::vector<double> weights; ///< 与上两者等长的插值权重
std::vector<int> source_patch_ids; ///< 与 source_node_ids 等长:源节点所属 patch(face tag)
std::vector<int> target_patch_ids; ///< 与 target_node_ids 等长:目标节点所属 patch
/// 参与映射的源表面积(共面三角对 = 精确重叠面积积分;非共面 = 采样贴合整片面积)
double source_area = 0.0;
/// 参与映射的目标表面积(口径同上)
double target_area = 0.0;
/**
* @brief 面积失配指标,0 = 完全贴合,1 = 完全失配
*
* 计算口径(含未匹配惩罚):
* [
* \frac{|A_s^{part}-A_t^{part}| + (A_s^{all}-A_s^{part}) +
* (A_t^{all}-A_t^{part})}{\max(A_s^{all}, A_t^{all})}
* ]
* 即参与映射面积的相对差 + 两侧未参与面积占比。> 0.02 视为可疑
* (交界面未贴合 / 网格错位)。
*/
double area_mismatch = 0.0;
int unmatched_source_faces = 0; ///< 未参与映射的源三角面片数
int unmatched_target_faces = 0; ///< 未参与映射的目标三角面片数
std::string diagnostic; ///< 退化/降级说明(空 = 正常)
};
/**
* @brief 建立交界面映射:target ← source(VDE-1243)
*
* 实现流程:
* 1. 从两侧 `FEAMesh` 提取表面三角片(含 patch id)与节点法向;
* 2. **共面三角对精确重叠**(R2):法向一致且平面距离 ≤ 容差的对,在公共
* 平面上用 Sutherland-Hodgman 裁剪求精确重叠面积/质心;权重按
* ∫ N_t·N_s dA(面积 × 质心处形函数值,线性形函数下精确)累加并逐行归一化
* → 常数场精确保持、面积加权守恒;
* 3. 非共面 / 曲面部分回退最近点投影:目标节点在源表面内匹配(距离 ≤ 容差、
* 法向同向),取最近 `max_neighbors` 个源三角面,用重心坐标分配权重;
* 4. 每行权重归一化(`normalize_conservative`),行级 `max_neighbors` 截断;
* 5. 参与面积:共面域用精确裁剪面积求和(含仅相切零面积 → 计未匹配、不回退
* 采样),非共面域回退「三角片采样点到对侧表面距离 ≤ 容差」判定。
*
* 退化输入(任一网格无有效三角片、无重叠、全退化三角形)返回
* `weights` 为空、`area_mismatch = 1`,不抛异常。
*
* @param source_surface 源侧表面网格(struct FEAMesh,使用 boundary_faces)
* @param target_surface 目标侧表面网格
* @param opts 选项
* @return InterfaceMap;反向映射用交换实参再调用一次,或使用
* build_bidirectional_interface_map()
*
* @ingroup mesh
*/
[[nodiscard]] InterfaceMap build_interface_map(
const FEAMesh& source_surface,
const FEAMesh& target_surface,
const InterfaceMapOptions& opts = {});
/**
* @brief 双向交界面映射(source→target 与 target→source 各一次)
* @ingroup mesh
*/
struct BidirectionalInterfaceMap {
InterfaceMap source_to_target; ///< target 节点 ← source 节点
InterfaceMap target_to_source; ///< source 节点 ← target 节点
};
/**
* @brief 双向建立交界面映射(VDE-1243)
*
* 两次调用共用同一套匹配口径,保证两个方向对称(几何匹配只取决于
* 两侧表面本身)。应用层做流固双向耦合时可直接使用。
*
* @ingroup mesh
*/
[[nodiscard]] BidirectionalInterfaceMap build_bidirectional_interface_map(
const FEAMesh& source_surface,
const FEAMesh& target_surface,
const InterfaceMapOptions& opts = {});
} // namespace vde::mesh