前端进度条性能优化、仿真结束后后处理优化;后端C代码生成流程优化:先识别来源,再按照已知未知量需求排序,最后局部求解

This commit is contained in:
ljz committed 2026-09-11 11:27:54 +08:00
1 parent 0dcb465d84
commit 91bd9fb252
77 files changed
+11223 -551

No files matched your search

+33 -14
View File
@@ -202,7 +202,9 @@ double native_temperature_ph(const NativeMedium *m, double p, double h) {
return m->real_helium ? temperature_ph(p,h) : ideal_temperature(m,h,m->cp);
}
double native_viscosity(const NativeMedium *m, double T, int diagnostic) {
if (diagnostic && m->real_helium)
/* Retain the ABI argument; flow and diagnostics use the same property. */
(void)diagnostic;
if (m->real_helium)
return 1e-7*exp(.7501594*log(T)+35.76324/T-2212.129/(T*T)+.9212635);
return m->mu*pow(T/m->muT,1.5)*(m->muT+m->S)/(T+m->S);
}
@@ -236,44 +238,61 @@ int native_medium_orifice(const NativeMedium *m, double p1, double p2, double h1
*v*=fabs(opening)<=1e-12?0:sign;
return isfinite(*q) && isfinite(*cm) && isfinite(*v);
}
static double pipe_friction(double re, double rr) {
static double pipe_rough_limit(double rr) {
return rr>0 ? 1/pow(-2*log10(rr/3.7),2) : 0;
}
static double pipe_friction_prepared(double re, double rr, double rough_limit) {
if(re<=0) return 64000000;
double lam=64/re;
if(re<=89.96829989) return lam;
double smooth=1/pow(-1.8*log10(6.9/re),2),turb=smooth;
if(rr>0) { double r=re*rr,weight=r*r/(r*r+180*180);turb+=weight*(1/pow(-2*log10(rr/3.7),2)-smooth); }
if(rr>0) { double r=re*rr,weight=r*r/(r*r+180*180);turb+=weight*(rough_limit-smooth); }
double trans=pow((re-89.96829989)/2741.96700831,8.37293695);
return lam+trans/(1+trans)*(turb-lam);
}
static double pipe_friction(double re, double rr) {
return pipe_friction_prepared(re,rr,pipe_rough_limit(rr));
}
double native_pipe_flow(const NativeMedium *m, double p1, double p2, double T,
double d, double length, double rr, int kind) {
if(fabs(p1-p2)<=1e-8) return 0;
double p=fmax(fmax(p1,p2),1),pd=fmin(p1,p2),sign=p1>p2?1:-1;
T=fmax(T,1);
double area=PI*d*d/4,mu=native_viscosity(m,T,0),den=PI*d*mu;
if(kind==3) { /* PNL0003: Darcy loss between two stored states. */
double rho=fmax(native_density(m,p,T),1e-12),dp=fabs(p1-p2),lo=0,hi=1e-9;
while(pipe_friction(4*hi/den,rr)*(length/d)*hi*hi/(2*rho*area*area)<dp) {
hi*=10; if(hi>=1000) return sign*1000;
}
for(int i=0;i<48;i++) { double q=.5*(lo+hi);
if(pipe_friction(4*q/den,rr)*(length/d)*q*q/(2*rho*area*area)<dp) lo=q;else hi=q;
}
return sign*.5*(lo+hi);
}
/* PNL0001/2/3 share compressible flow and its near-equilibrium smoothing.
PNL0003 differs in storage placement, not in the resistance law. */
double cm,vel;medium_valve(m,p,pd,T,&cm,&vel);
if(kind==0) {
double lam=pow(area*p*cm,2)/(16*PI*mu*length*T);
if(4*lam/den<=1000) return sign*lam;
}
double rough_limit=pipe_rough_limit(rr);
double base=area*p*cm/sqrt(T),q=sqrt(d/(length*.02))*base;
for(int i=0;i<(kind==0?64:16);i++) {
double next=sqrt(d/(length*pipe_friction(4*fabs(q)/den,rr)))*base;
double next=sqrt(d/(length*pipe_friction_prepared(4*fabs(q)/den,rr,rough_limit)))*base;
if(fabs(next-q)<=fmax(1e-12,fabs(q)*1e-9)) return sign*next;
q=.5*(q+next);
}
return sign*q;
}
double native_pipe_flow_cached(NativePipeCache *cache, const NativeMedium *m,
double p1, double p2, double T, double d,
double length, double rr, int kind) {
if(cache->valid && cache->p1==p1 && cache->p2==p2 && cache->T==T &&
cache->diameter==d && cache->length==length && cache->roughness==rr && cache->kind==kind &&
cache->medium.real_helium==m->real_helium && cache->medium.R==m->R &&
cache->medium.cp==m->cp && cache->medium.Tref==m->Tref && cache->medium.slope==m->slope &&
cache->medium.mu==m->mu && cache->medium.muT==m->muT && cache->medium.S==m->S)
return cache->flow;
double result=native_pipe_flow(m,p1,p2,T,d,length,rr,kind);
cache->valid=0;
if(isfinite(result)) {
cache->medium=*m;cache->p1=p1;cache->p2=p2;cache->T=T;
cache->diameter=d;cache->length=length;cache->roughness=rr;cache->kind=kind;
cache->flow=result;cache->valid=1;
}
return result;
}
void native_pipe_diagnostics(const NativeMedium *m, double q, double p, double T,
double d, double length, double rr, int diagnostic, double *r) {
double area=PI*d*d/4,re=4*fabs(q)/(PI*d*native_viscosity(m,T,0)),ff=pipe_friction(re,rr);