code wiki / (root) / nx_uv_cotangent_audit_t280.nx

nx_uv_cotangent_audit_t280.nx source

↩ module page · 32 lines · 1896 B

1import "nx_uv_cached_solver_candidate_t280.nx" 2import "nx_gate_verdict.nx" 3// Cotangent identity is exactly one for a nondegenerate Euclidean triangle. 4// Violations here are local coefficient evidence, not proof the assembled matrix is indefinite. 5func uvc_weight_metrics(s:*UvCachedSolve,out:*i64)->i64{ 6 if s==(0 as *UvCachedSolve){return UV_E_ARGS};if out==(0 as *i64){return UV_E_ARGS} 7 var j:i64=0;while j<5{out[j]=0;j=j+1} 8 if s.weights==(0 as *i64){return UV_E_STAGE} 9 var t:i64=0 10 while t<s.triangles{ 11 let a:i64=s.weights[t*3];let b:i64=s.weights[t*3+1];let c:i64=s.weights[t*3+2] 12 let err:i64=a*b+b*c+c*a-UV_W_Q*UV_W_Q 13 if err<0{out[0]=out[0]+1};if err==0{out[1]=out[1]+1};if err>0{out[2]=out[2]+1} 14 if vm_abs(err)>out[3]{out[3]=vm_abs(err)} 15 var atcap:i64=0;if vm_abs(a)==UV_COT_CLAMP*UV_W_Q{atcap=1};if vm_abs(b)==UV_COT_CLAMP*UV_W_Q{atcap=1};if vm_abs(c)==UV_COT_CLAMP*UV_W_Q{atcap=1} 16 out[4]=out[4]+atcap;t=t+1 17 };return UV_OK 18} 19func main(argc:i64,argv:*i64)->i64{ 20 if argc!=2{return 2};let len:*i64=sys_mmap_try(16) as *i64 21 let src:*u8=sys_read_file(argv[1] as *u8,len);if src==(0 as *u8){return 3} 22 let m:*i64=ncp_model_nxa(src,len[0]);if m==(0 as *i64){return 4};if uv_chart_build(m)!=UV_OK{return 5} 23 let out:*i64=sys_mmap_try(5*UV_I64) as *i64;var c:i64=0 24 while c<uv_chart_count(m){ 25 let st:*UvCachedSolve=uvc_begin(m,c);if st==(0 as *UvCachedSolve){return 6} 26 let rc:i64=uvc_weight_metrics(st,out) 27 gv_puts("UVCOT chart=");gv_num(c);gv_puts(" triangles=");gv_num(st.triangles);gv_puts(" result=");gv_num(rc) 28 gv_puts(" belowIdentity=");gv_num(out[0]);gv_puts(" exactIdentity=");gv_num(out[1]);gv_puts(" aboveIdentity=");gv_num(out[2]);gv_puts(" maxAbsErrorQ24=");gv_num(out[3]);gv_puts(" atCoefficientCap=");gv_num(out[4]);gv_puts("\n") 29 uvc_free(st);c=c+1 30 } 31 sys_munmap_direct(out as *u8,5*UV_I64);ncp_model_free(m);sys_munmap_direct(len as *u8,16);return 0 32}