Files
SystemSimulationApp/tests/manual/valve_tail_diag.h
T
ljz 7611f13208 修复循环信号与事件采样并接入 LSTP 接触定位,补充八路验证及复用实验
相较上一版 Jacobian 确定性复用更新,本次补齐事件边界一致性、结果两侧采样及接触事件定位;保留已有物性复用和组件力学公式。

- 统一 UD00 信号求值与下一事件查询的绝对时间边界,修复循环边界浮点舍入导致的阶段错位、重复或漏报,并覆盖零时长、多阶段及长周期场景。
- 引入原生输出语义 v2:保留规则网格真实时间,补充内部时间事件和状态事件的左邻及事件后采样,按保存时间、状态和离散模式重放结果。
- 两条代码生成路径均发出 LSTP 接触描述,默认定位间隙过零及非负力模式的力截断;仅在接受事件时更新防重复记录,增加 contactEvents 诊断计数。
- 补充 MASS/LSTP 独立事件实验、八路全曲线与驱动阶段配对评估,以及 Amesim 不连续点输出对照和力差定位报告;MASS 新增释放机制仍保留为独立实验。
- 保存局部 probe、context 访问与回退、shadow replay、R288 real skip/typed replay 及阀门数值尾部诊断工具和报告;未证明净收益的实验不启用为生产默认优化。
- 更新原生运行说明和元件建模规范,补充信号边界、输出语义、接触事件和实验依赖回归测试。

验证:五组专项回归共 34 项全部通过;37 个待提交 Python 文件语法检查通过;git diff --cached --check 通过。
2026-09-17 23:50:13 +08:00

36 lines
1.9 KiB
C

#ifndef VALVE_TAIL_DIAG_H
#define VALVE_TAIL_DIAG_H
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif
#include "local_probe.h"
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <xmmintrin.h>
#ifndef KD_TRACE
#define KD_TRACE 1
#endif
typedef struct {unsigned mxcsr;unsigned short cw,sw;int err;} KdEnv;
typedef struct {uint64_t key[5];double cm,vel;KdEnv env;int ready;} KdMemo;
typedef struct {uint64_t jac;int group,hit;uint64_t key[5];double cm,vel;KdEnv before,after;uint64_t tail,lookup,capture;int executed,pad;} KdRecord;
extern int kd_scope;
extern uint64_t kd_jac;
extern KdMemo kd_memo;
static inline uint64_t kd_clock(void){unsigned lo,hi;__asm__ __volatile__("lfence\n\trdtsc\n\tlfence":"=a"(lo),"=d"(hi)::"memory");return ((uint64_t)hi<<32)|lo;}
static inline KdEnv kd_env(void){KdEnv e;__asm__ __volatile__("stmxcsr %0;fnstcw %1;fnstsw %2":"=m"(e.mxcsr),"=m"(e.cw),"=m"(e.sw)::"memory");e.err=errno;return e;}
static inline int kd_env_equal(KdEnv a,KdEnv b){return a.mxcsr==b.mxcsr && a.cw==b.cw && a.sw==b.sw && a.err==b.err;}
static inline int kd_finite(const uint64_t *key){for(int i=0;i<5;i++)if((key[i]&UINT64_C(0x7ff0000000000000))==UINT64_C(0x7ff0000000000000))return 0;return 1;}
/* Diagnostic-only lookup: its answer NEVER bypasses the original tail.
* Only a baseline entry is considered. Probe misses never populate the slot. */
static inline int kd_lookup(const uint64_t *key,KdEnv e,double *cm,double *vel){
if(!kd_memo.ready || !kd_env_equal(e,kd_memo.env) || memcmp(key,kd_memo.key,40))return 0;
*cm=kd_memo.cm;*vel=kd_memo.vel;return 1;
}
void kd_start(void);void kd_finish(void);void kd_new_jac(void);
void kd_before(KdRecord*,double,double,double,double,double);
void kd_after(KdRecord*,double,double,uint64_t,int);
void kd_matrix(double,const double*,const double*);
void kd_eval_exit(double,const double*,const double*,const double*,int,NativePropertyCache*,NativePipeCache*,ModelJacobianWorkspace*);
#endif