相较上一版 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 通过。
82 lines
3.6 KiB
C
82 lines
3.6 KiB
C
#ifndef NATIVE_RUNTIME_H
|
|
#define NATIVE_RUNTIME_H
|
|
#include "model.h"
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#ifndef NFRICTIONS
|
|
#define NFRICTIONS 0
|
|
#endif
|
|
#ifndef NCONTACTS
|
|
#define NCONTACTS 0
|
|
#endif
|
|
#define NATIVE_JACOBIAN_STATS_COUNT 3
|
|
typedef struct {
|
|
double start, stop, sample_step, max_step, rtol, timeout;
|
|
int bdf, record_samples;
|
|
const char *cancel_path;
|
|
} NativeOptions;
|
|
typedef struct {
|
|
int seen;
|
|
double first_time, first_temperature, extreme_time, extreme_temperature;
|
|
} NativePropertyWarning;
|
|
typedef struct {
|
|
NativeOptions options;
|
|
double *times, *states;
|
|
size_t count, capacity, sample_index;
|
|
/* Result history is a bounded buffer, independent of integrator memory. */
|
|
size_t buffered, committed, output_count;
|
|
FILE *sample_file, *output_file;
|
|
const char *sample_path, *output_blocks_path;
|
|
int storage_control, storage_failed;
|
|
double final_time, final_state[NSTATES];
|
|
double wall_start, cpu_start, solve_seconds, solve_cpu_seconds, last_progress;
|
|
double max_accepted_step;
|
|
unsigned long nfev, accepted, rejected, events, starts, njev, nlu;
|
|
/* Structure coloring is automatic; verification is diagnostic only. */
|
|
int jacobian_verify, jacobian_colored;
|
|
unsigned long jacobian_rhs, jacobian_colored_evals, jacobian_fallbacks;
|
|
unsigned long jacobian_checks, jacobian_mismatches, cvode_rhs, linear_rhs;
|
|
unsigned long jacobian_gas_evaluations, jacobian_gas_reuses;
|
|
/* PH, density, pipe. Keep runtime-only harnesses independent of kernels.h. */
|
|
unsigned long jacobian_scalar_evaluations[NATIVE_JACOBIAN_STATS_COUNT], jacobian_scalar_reuses[NATIVE_JACOBIAN_STATS_COUNT];
|
|
unsigned long same_time_returns, same_time_streak, max_same_time_streak;
|
|
int stagnating, cvode_flag;
|
|
double cvode_return_time, cvode_internal_time, cvode_last_step, cvode_next_step;
|
|
const char *failure_reason, *failure_operation;
|
|
char message_buffer[384];
|
|
int status; /* 0 completed, 1 cancelled, 2 failed */
|
|
const char *message;
|
|
/* Accepted-event latch only; never used by RHS or output force replay. */
|
|
#if NCONTACTS
|
|
double contact_last[2*NCONTACTS];
|
|
int contact_direction[2*NCONTACTS], contact_pending[2*NCONTACTS];
|
|
#endif
|
|
unsigned long contact_checks, contact_dense, contact_roots;
|
|
unsigned long contact_transitions, contact_clipping;
|
|
NativePropertyWarning property_warnings[6];
|
|
} NativeRun;
|
|
typedef int (*NativeDense)(void *context, double t, double *state);
|
|
double native_wall_time(void);
|
|
double native_cpu_time(void);
|
|
int native_poll(NativeRun *run, double time);
|
|
void native_property_warnings_json(NativeRun *run, FILE *file);
|
|
int native_fail(NativeRun *run, const char *reason, const char *operation, const char *message);
|
|
int native_rhs(NativeRun *run, double t, const double *y, double *dy);
|
|
int native_jacobian_rhs(NativeRun *run, double t, const double *y, double *dy);
|
|
int native_append(NativeRun *run, double t, const double *y);
|
|
int native_time_boundary_samples(NativeRun *run, double boundary, const double *state);
|
|
int native_accept(NativeRun *run, double t, double next, const double *old,
|
|
const double *trial, NativeDense dense, void *context,
|
|
double *accepted_time, double *accepted_state);
|
|
int native_rk45(NativeRun *run);
|
|
int native_bdf(NativeRun *run);
|
|
int native_solve(NativeRun *run);
|
|
void native_run_free(NativeRun *run);
|
|
int native_samples_append(NativeRun *run, double t, const double *state);
|
|
int native_samples_flush(NativeRun *run);
|
|
int native_samples_outputs(NativeRun *run);
|
|
int native_samples_json(NativeRun *run, FILE *file, size_t column);
|
|
int64_t native_file_tell(FILE *file);
|
|
#endif
|