Files
hm 163d0c47e6 feat: P1.x 内核对齐 + P2-1 vde_cae + P2-2 插件扩展点 + VDE-1249 三阻塞修复(1.0.47)
### P1.x 内核对齐(P1 遗留收口)
- 原生 .vde 序列化(serializer/vde_format/vde_text)迁入内核 vde_brep;C API 序列化回迁 vde_kernel_capi;
  PMI/MBD 拆为内核数据模型(vde_brep)+ 3D-PDF 导出(vde_io/pmi_export.cpp),消除 kernel→io 反向依赖;
- make_geometry_host_services() 迁入内核 vde_brep,kernel-only 下 PluginManager+宿主服务可用;
- kernel-only 约 40 个测试 target + 4 个 examples 门控;六业务 OFF 的 2 个测试 target 门控;
- vde_version() 返回 0.5.0 既有缺陷修复;kernel SDK consumer 实测 1.0.47;

### P2-1 vde_cae 官方模块
- include/vde/cae/*、src/cae/*、tests/cae/*;旧路径转发头兼容;VDE_BUILD_CAE 开关;
- vde_io 移除 fea_mesh/fluid_domain;ctest 用例数保持(95 项 CAE 测试);CAE=OFF 构建 937/937;

### P2-2 插件 ABI 1.2:CAE solver / CAM strategy 扩展点
- VdeCaeSolverPlugin/VdeCamStrategyPlugin + Registration 尾部扩展(旧插件兼容);
- PluginManager cae_solvers()/cam_strategies()/solve_cae()/invoke_cam(),加载校验/失败隔离;
- plugins/sample_cae、sample_cam_post、abi11_compat、external/{runner,sample_stl_converter};
- docs/design/vde-service-protocol.md 进程外服务协议草案;test_plugin_extensions 9/9;

### VDE-1249 三阻塞修复
- fix1 共享边采样性能悬崖:sagitta 自适应段数 + 自由曲面证据触发 + fast planar loop 256 + IncrementalMesher 复用 mesh_face_diag;
  box+16 孔 legacy 3.3-3.6s→69.5ms、rebuild 4095→103ms;box+25 孔 5.1s→190.9ms;n42 链 ≤222ms;open=0/面积体积正确;
- fix2 fillet/blend 破损体护栏(fillet_edges_checked:watertight/dangling 护栏 + heal 重试 + 显式失败/诊断;
  静默 no-op success → 显式失败)+ delete_face_with_heal/fill_hole 边环重排(26 面盒 0/26→6/6,box 2/6→6/6);
- fix3 wireframe tight payload:WireframeOptions.include_segment_info + C API VdeWireframeOptions 尾扩展 +
  vde_body_to_wireframe_opt2(旧 ABI 安全);tight≈49-61% full(与 1.0.12 旧风格差 4B/段);

### 工程
- 修复 .gitignore `*.txt` 误伤:`!CMakeLists.txt`,把 plugins/**、tools/、tests/plugin、tests/cae 等漏入库的
  CMakeLists.txt 纳入版本库(保证干净 checkout 可构建);
- 版本 1.0.47(CMake/version.h/test_version/README/docs index/module-manual 同步);

验证:全量构建 0 error(334 targets);全量 ctest 7395 注册、7300/7300 PASS(0 failed,24 skipped,194.39s);
kernel-only(-DVDE_BUILD_IO=OFF + BUILD_TESTS=ON)全量构建 0 failed、plugin 30/12 + capi_split 7 全绿;
六业务 OFF 全量测试构建 0 failed;CAE 95/95;插件 ctest 61/61;VDE-1249 repro 前后数字见 CHANGELOG。
2026-10-28 16:32:01 +08:00

166 lines
6.9 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.
// 示例 CAE 求解器插件(VDE 微内核 P2 / 插件 ABI 1.2;纯 C ABI,不链接内核)。
//
// 演示 VdeCaeSolverPlugin 扩展点:输入 VDE 序列化模型 + 参数 JSON,输出结果 JSON。
// 求解是"演示级估算"(线弹性轴向刚度/变形/应力),不代表真实 FEA 精度;
// 目的是验证扩展点契约、宿主服务使用(body_from_serialized/body_query/body_bbox)
// 与跨 ABI 内存所有权(host->alloc 输出、宿 free_buffer 释放)。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include "vde/plugin/vde_plugin_api.h"
namespace {
int cae_fail(const VdePluginHost* host, int code, const char* message) {
if (host && host->set_error) host->set_error(message);
return code;
}
int validate_host(const VdePluginHost* host) {
if (!host) return VDE_PLUGIN_ERR_INVALID_ARG;
if (host->abi_major != VDE_PLUGIN_ABI_MAJOR)
return cae_fail(host, VDE_PLUGIN_ERR_ABI, "sample_cae: 宿主 ABI major 不兼容");
if (!host->alloc || !host->free || !host->set_error)
return cae_fail(host, VDE_PLUGIN_ERR_UNSUPPORTED,
"sample_cae: 宿主缺少 alloc/free/set_error");
if (!host->body_from_serialized || !host->body_query || !host->body_bbox ||
!host->body_destroy)
return cae_fail(host, VDE_PLUGIN_ERR_UNSUPPORTED,
"sample_cae: 宿主缺少 body_from_serialized/query/bbox/destroy");
return VDE_PLUGIN_OK;
}
/** 极简 JSON 数值字段提取:查找 "key" 后的 ':' 再 strtod;失败返回 fallback。 */
double json_number(const char* text, const char* key, double fallback) {
if (!text || !key) return fallback;
const std::string pattern = std::string("\"") + key + "\"";
const char* pos = std::strstr(text, pattern.c_str());
if (!pos) return fallback;
pos += pattern.size();
while (*pos == ' ' || *pos == '\t' || *pos == '\r' || *pos == '\n') ++pos;
if (*pos != ':') return fallback;
++pos;
char* end = nullptr;
const double value = std::strtod(pos, &end);
if (end == pos) return fallback;
return value;
}
int cae_solve(const VdePluginHost* host, const void* model_data, size_t model_size,
const char* params_json, VdeBuffer* result_json) {
if (result_json) {
result_json->data = nullptr;
result_json->size = 0;
}
if (!result_json) return cae_fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "sample_cae: result 为空");
const int host_rc = validate_host(host);
if (host_rc != VDE_PLUGIN_OK) return host_rc;
if (!model_data || model_size == 0)
return cae_fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "sample_cae: 模型数据为空");
VdeBody body = host->body_from_serialized(model_data, model_size);
if (!body)
return cae_fail(host, VDE_PLUGIN_ERR_PARSE,
"sample_cae: 无法反序列化模型(见宿主错误信息)");
VdeBodyInfo info{};
info.struct_size = static_cast<uint32_t>(sizeof(VdeBodyInfo));
int rc = host->body_query(body, &info);
if (rc != VDE_PLUGIN_OK) {
host->body_destroy(body);
return cae_fail(host, VDE_PLUGIN_ERR_INTERNAL, "sample_cae: body_query 失败");
}
double bmin[3] = {0.0, 0.0, 0.0};
double bmax[3] = {0.0, 0.0, 0.0};
rc = host->body_bbox(body, bmin, bmax);
if (rc != VDE_PLUGIN_OK) {
host->body_destroy(body);
return cae_fail(host, VDE_PLUGIN_ERR_INTERNAL, "sample_cae: body_bbox 失败");
}
host->body_destroy(body);
// 演示级线弹性估算:轴向刚度 k = E*A/L,变形 δ = F/k,应力 σ = F/A。
const double youngs = json_number(params_json, "youngs_modulus", 210.0e9);
const double load = json_number(params_json, "load", 1000.0);
const double extent_x = bmax[0] - bmin[0];
const double extent_y = bmax[1] - bmin[1];
const double length = bmax[2] - bmin[2];
const double area = (extent_x > 0.0 && extent_y > 0.0) ? extent_x * extent_y : 1.0;
const double l = (length > 1e-12) ? length : 1.0;
const double stiffness = (youngs > 0.0) ? youngs * area / l : 0.0;
const double deformation = (stiffness > 1e-30) ? load / stiffness : 0.0;
const double stress = load / area;
char text[1024];
const int written = std::snprintf(
text, sizeof(text),
"{\"solver_id\":\"fea.linear_static\",\"ok\":true,"
"\"volume\":%.10g,\"bbox\":[[%.10g,%.10g,%.10g],[%.10g,%.10g,%.10g]],"
"\"results\":{\"axial_stiffness\":%.10g,\"axial_deformation\":%.10g,"
"\"axial_stress\":%.10g},"
"\"params\":{\"youngs_modulus\":%.10g,\"load\":%.10g},"
"\"note\":\"demo-only estimate; not a validated FEA solver\"}",
info.volume, bmin[0], bmin[1], bmin[2], bmax[0], bmax[1], bmax[2], stiffness,
deformation, stress, youngs, load);
if (written <= 0) return cae_fail(host, VDE_PLUGIN_ERR_INTERNAL, "sample_cae: 结果 JSON 生成失败");
const std::size_t size = static_cast<std::size_t>(written);
void* buffer = host->alloc(size + 1);
if (!buffer) return cae_fail(host, VDE_PLUGIN_ERR_BUFFER, "sample_cae: 结果缓冲分配失败");
std::memcpy(buffer, text, size + 1);
result_json->data = buffer;
result_json->size = size;
return VDE_PLUGIN_OK;
}
const char* cae_describe() {
return "VDE sample CAE solver: demo linear-static axial estimate (ABI 1.2)";
}
const VdeCaeSolverPlugin kSolver = [] {
VdeCaeSolverPlugin solver{};
solver.struct_size = static_cast<uint32_t>(sizeof(VdeCaeSolverPlugin));
solver.solver_id = "fea.linear_static";
solver.capabilities_json =
"{\"fields\":[\"displacement\",\"stress\"],\"element_types\":[\"tet4\",\"hex8\"],"
"\"linear\":true,\"demo\":true}";
solver.solve = &cae_solve;
solver.describe = &cae_describe;
return solver;
}();
} // namespace
extern "C" {
VDE_PLUGIN_EXPORT int vde_plugin_query(uint32_t host_abi_major, VdePluginInfo* info) {
if (!info || info->struct_size < sizeof(VdePluginInfo)) return VDE_PLUGIN_ERR_ABI;
if (host_abi_major != VDE_PLUGIN_ABI_MAJOR) return VDE_PLUGIN_ERR_ABI;
info->id = "com.vde.sample.cae";
info->name = "VDE Sample CAE Linear Static Solver";
info->version = "0.1.0";
info->kind = VDE_PLUGIN_KIND_CAE_SOLVER;
info->abi_major = VDE_PLUGIN_ABI_MAJOR;
info->abi_minor = VDE_PLUGIN_ABI_MINOR;
info->capabilities = "cae_solver:fea.linear_static";
info->license = "Apache-2.0";
return VDE_PLUGIN_OK;
}
VDE_PLUGIN_EXPORT int vde_plugin_init(const VdePluginHost* host,
VdePluginRegistration* reg) {
if (!reg || reg->struct_size < sizeof(VdePluginRegistration))
return VDE_PLUGIN_ERR_ABI;
const int host_rc = validate_host(host);
if (host_rc != VDE_PLUGIN_OK) return host_rc;
reg->kind = VDE_PLUGIN_KIND_CAE_SOLVER;
reg->format = nullptr;
reg->cae_solver = &kSolver;
reg->cam_strategy = nullptr;
return VDE_PLUGIN_OK;
}
VDE_PLUGIN_EXPORT void vde_plugin_shutdown() {}
} // extern "C"