Wave 3 of the feedback implementation plan (3 parallel agents + integration); completes the "not implemented" list of docs/reference/feedback-audit-2026-11-19.md. VDE-1619 (P2): pair_periodic_nodes -- translational/rotational(Rodrigues)/mirror 1:1 pairing of boundary face nodes; greedy nearest with ambiguity rejection (whole request fails, no partial output), unmatched lists, no exceptions, deterministic; 8/8 tests. VDE-1621 (P2): beam_mesh -- B-Rep to centerlines (analytic cylinder axis -> faceted prism axis inference -> straight-edge fallback) -> Line2/Line3 elements with section assignment, junction/end nodes, local axes, Line3 midpoints; 9/9 tests. VDE-1620 (P3): edge_element_mesh -- global unique edge table, tetra_edges + tetra_edge_sign direction contract (v-u == sign*(b-a)), B-Rep edge tags, boundary face edges for PEC; Nedelec1 explicitly rejected (no silent degradation); 8/8 tests. Docs: api-reference-mesh +149 lines (3 API contracts), wave-3 parallel implementation report, remaining-gaps closed list + record, feedback-status batch entries, ticket appendices. Verification: full Release build exit 0; 23-suite integration 847 tests passed 0 failed; PR gate 930/930 (104.10 s).
143 lines
7.8 KiB
C++
143 lines
7.8 KiB
C++
#pragma once
|
||
/**
|
||
* @file cae/node_pairing.h
|
||
* @brief 周期/对称节点映射:主从节点 1:1 配对数据(VDE-1619)。
|
||
*
|
||
* 声学管道周期边界(入口面 ↔ 出口面)、旋转电机扇区(低角面 ↔ 高角面)、镜像
|
||
* 对称模型(对称面两侧)都需要「A 面节点 ↔ B 面节点」的 1:1 映射。本模块只输出
|
||
* 配对数据(保留自由度的主节点 / 被约束的从节点),**不生成约束方程、不消去
|
||
* 自由度**;主从约束由应用层装配(VDE-1187 口径)。
|
||
*
|
||
* 实现:src/cae/node_pairing.cpp;测试:tests/cae/test_vde1619_node_pairing.cpp。
|
||
*
|
||
* ## 语义口径
|
||
*
|
||
* 1. **取面节点**:master / slave 节点 = \c mesh.boundary_faces 中
|
||
* \c mesh.boundary_face_tags == 对应 tag 的所有多边形顶点并集(去重、升序)。
|
||
* 二次单元边界面(6 / 8 节点)的中节点同样计入(全部顶点并集,不做角点裁剪)。
|
||
* tag 不存在 / 该 tag 的边界面没有顶点 → valid=false,message 指明侧别与 tag。
|
||
* 2. **变换**(把 master 节点映射到 slave 侧目标位置):
|
||
* - TranslationalPeriodic:p' = p + vector;
|
||
* - RotationalPeriodic: p' = origin + R(axis, angle_rad) * (p - origin),
|
||
* axis 单位化、右手定则(Rodrigues 公式);
|
||
* - Mirror: p' = p - 2 * ((p - origin)·n) * n,n = normalize(axis)
|
||
* (axis = 镜像平面法向,origin = 镜像平面上一点)。
|
||
* 不做节点插值、不做投影补偿。
|
||
* 3. **配对(1:1 贪心)**:master 面节点按节点索引升序依次处理;对每个 master
|
||
* 在**尚未使用**的 slave 面节点中取容差内(距离 <= tolerance)最近点并绑定,
|
||
* 每个 slave 至多使用一次。平局时取 slave 节点索引最小者;tolerance > 0 时
|
||
* 等距平局必然被第 4 条歧义规则拒绝,实际绑定唯一。
|
||
* 4. **歧义(整单失败)**:设容差内最近距离为 dmin;若某候选距离 d 满足
|
||
* d - dmin < 0.1 * tolerance 且这样的候选 >= 2 个,视为歧义 → 立即
|
||
* valid=false,message 指明 master 节点索引与歧义候选数;此时 pairs /
|
||
* unmatched_master / unmatched_slave 均为空(不输出半成品,不得任选其一)。
|
||
* 5. **完整覆盖**:pairs.size() == master 面节点数 且 unmatched_master /
|
||
* unmatched_slave 均空 → valid=true(message 为空);否则 valid=false,
|
||
* pairs 保留已绑定的成功配对,两侧未匹配节点按节点索引升序给出(应用层据此
|
||
* 提示「两侧网格分布不一致,请重网格」)。
|
||
* 6. **确定性**:同一输入重复调用,pairs(master 节点升序)的顺序与内容、
|
||
* unmatched_*、message 逐位一致。
|
||
* 7. **参数非法**(不抛异常,valid=false + message):tolerance 为负 / NaN /
|
||
* 非有限;face tag < 0;平移 vector 为零或分量非有限;旋转 angle_rad 为 0 或
|
||
* 非有限、axis 为零或分量非有限;Mirror 法向 axis 为零或分量非有限;
|
||
* 旋转 / Mirror 的 origin 分量非有限;NodePairKind 值非法。
|
||
* tolerance == 0 表示自动取 1e-6 * 网格包围盒对角线(全部顶点);退化网格
|
||
* (包围盒对角线为 0)自动容差为 0,退化为精确匹配。
|
||
* 8. **健壮性**:只读、无全局状态、可并发调用;失败一律通过返回值表达,不抛
|
||
* 异常。结构非法(网格无顶点、boundary_face_tags 长度与 boundary_faces 不
|
||
* 一致、命中面的顶点索引越界、自动容差的包围盒对角线非有限)同样
|
||
* valid=false + message。master_face_tag / slave_face_tag 在返回值中原样回显。
|
||
*/
|
||
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
#include "vde/cae/fea_mesh.h"
|
||
|
||
namespace vde::mesh {
|
||
|
||
/**
|
||
* @brief 周期/对称变换类型(VDE-1619)。
|
||
* @ingroup cae
|
||
*/
|
||
enum class NodePairKind {
|
||
TranslationalPeriodic, ///< 沿 vector 平移(管道入口面 ↔ 出口面等)
|
||
RotationalPeriodic, ///< 绕 axis / origin 旋转 angle_rad(旋转电机扇区等)
|
||
Mirror, ///< 关于平面(过 origin、法向 axis)镜像(对称模型)
|
||
};
|
||
|
||
/**
|
||
* @brief 节点配对参数(VDE-1619)。
|
||
*
|
||
* 变换参数与容差口径见文件头「语义口径」。结构默认值只保证参数齐全,调用方
|
||
* 必须显式给出 kind / master_face_tag / slave_face_tag 与对应变换参数。
|
||
* @ingroup cae
|
||
*/
|
||
struct NodePairingParams {
|
||
NodePairKind kind = NodePairKind::TranslationalPeriodic; ///< 变换类型
|
||
int master_face_tag = -1; ///< master 边界面 B-Rep face 索引(boundary_face_tags 口径;须 >= 0)
|
||
int slave_face_tag = -1; ///< slave 边界面 B-Rep face 索引(同上)
|
||
core::Vector3D vector{0, 0, 0}; ///< 平移周期:master -> slave 的平移向量(长度单位)
|
||
core::Vector3D axis{0, 0, 1}; ///< 旋转周期:旋转轴;Mirror:镜像平面法向
|
||
core::Point3D origin{0, 0, 0}; ///< 旋转中心;Mirror:镜像平面上一点
|
||
double angle_rad = 0.0; ///< 旋转周期:扇区角(弧度,绕 axis 右手定则)
|
||
double tolerance = 1e-4; ///< 配对容差(绝对长度);0 = 1e-6 * 网格包围盒对角线
|
||
};
|
||
|
||
/**
|
||
* @brief 一对主从节点:slave 自由度约束到 master(保留 master)。
|
||
* @ingroup cae
|
||
*/
|
||
struct NodePair {
|
||
int master_node = -1; ///< 0-based 网格节点索引(保留自由度)
|
||
int slave_node = -1; ///< 0-based 网格节点索引(约束到 master)
|
||
};
|
||
|
||
/**
|
||
* @brief 节点配对结果(VDE-1619)。
|
||
*
|
||
* - valid=true:pairs.size() == master 面节点数,unmatched_* 均空,message 为空;
|
||
* - valid=false:message 说明原因;覆盖不足时 pairs 为已绑定的成功配对、
|
||
* unmatched_* 为两侧未匹配节点(升序);参数 / 面 tag / 歧义失败时三者均为空
|
||
* (见文件头「语义口径」第 4、5、7、8 条)。
|
||
* @ingroup cae
|
||
*/
|
||
struct NodePairMap {
|
||
bool valid = false; ///< true 仅当 1:1 完整覆盖
|
||
std::string message; ///< 空 = 成功;否则为失败原因
|
||
int master_face_tag = -1; ///< 原样回显 params.master_face_tag
|
||
int slave_face_tag = -1; ///< 原样回显 params.slave_face_tag
|
||
std::vector<NodePair> pairs; ///< 1:1 配对,按 master_node 升序
|
||
std::vector<int> unmatched_master; ///< 未找到 slave 的 master 节点(升序)
|
||
std::vector<int> unmatched_slave; ///< 未被使用的 slave 节点(升序)
|
||
};
|
||
|
||
/**
|
||
* @brief 周期/对称节点配对(VDE-1619)。
|
||
*
|
||
* 按 NodePairingParams 的变换把 master 面节点映射到 slave 侧,在容差内做 1:1
|
||
* 最近点配对;只输出数据,不生成约束方程、不消去自由度。
|
||
*
|
||
* @param mesh 有限元网格(只读,不修改;使用 vertices / boundary_faces /
|
||
* boundary_face_tags 三个字段)
|
||
* @param params 配对参数(见文件头「语义口径」)
|
||
* @return 配对结果;任何失败都通过 valid=false + message 表达,不抛异常
|
||
*
|
||
* @note 只读、无全局状态、可并发调用;确定性见文件头第 6 条。
|
||
* @code{.cpp}
|
||
* vde::mesh::NodePairingParams params;
|
||
* params.kind = vde::mesh::NodePairKind::TranslationalPeriodic;
|
||
* params.master_face_tag = inlet_face_id;
|
||
* params.slave_face_tag = outlet_face_id;
|
||
* params.vector = {0.0, 0.0, pipe_length};
|
||
* const vde::mesh::NodePairMap map =
|
||
* vde::mesh::pair_periodic_nodes(mesh, params);
|
||
* if (!map.valid) { // map.message 给出失败原因,map.unmatched_* 给出缺口 }
|
||
* @endcode
|
||
* @ingroup cae
|
||
*/
|
||
[[nodiscard]] NodePairMap pair_periodic_nodes(const FEAMesh& mesh,
|
||
const NodePairingParams& params);
|
||
|
||
} // namespace vde::mesh
|