高温氦气物性补全;三通四通能量计算bug修正
This commit is contained in:
1 parent
6fc9afe41d
commit
2b07d996cf
133 files changed
+5230
-253310
No files matched your search
+78
-21
@@ -30,21 +30,34 @@ double native_cpu_time(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
int native_fail(NativeRun *r,const char *reason,const char *operation,const char *message) {
|
||||
if (!r->status) {
|
||||
r->status=2; r->failure_reason=reason; r->failure_operation=operation;
|
||||
snprintf(r->message_buffer,sizeof(r->message_buffer),"%s",message);
|
||||
r->message=r->message_buffer;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int native_poll(NativeRun *r, double t) {
|
||||
double now=native_wall_time();
|
||||
if (r->status) return 0;
|
||||
if (r->options.timeout > 0 && now-r->wall_start > r->options.timeout) {
|
||||
r->status=2; r->message="Native solve exceeded its time limit."; return 0;
|
||||
}
|
||||
if (now-r->last_progress >= 0.1) {
|
||||
r->last_progress=now;
|
||||
if (r->options.cancel_path) {
|
||||
FILE *f=fopen(r->options.cancel_path,"rb");
|
||||
if (f) { fclose(f); r->status=1; r->message="Simulation cancelled."; return 0; }
|
||||
if (f) {
|
||||
fclose(f); r->status=1; r->message="Simulation cancelled.";
|
||||
r->failure_reason="cancelled"; r->failure_operation="cancel-check"; return 0;
|
||||
}
|
||||
}
|
||||
fprintf(stderr,"{\"phase\":\"integrating\",\"time\":%.17g,\"nfev\":%lu,\"acceptedSteps\":%lu}\n",t,r->nfev,r->accepted);
|
||||
fflush(stderr);
|
||||
}
|
||||
if (r->options.timeout > 0 && now-r->wall_start > r->options.timeout)
|
||||
return native_fail(r,r->stagnating?"time-stagnation":"timeout","integration",
|
||||
r->stagnating?"Native solver kept returning without advancing time until the run time limit expired.":
|
||||
"Native solve exceeded its time limit.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -70,20 +83,55 @@ int native_jacobian_rhs(NativeRun *r, double t, const double *y, double *dy) {
|
||||
int native_append(NativeRun *r, double t, const double *y) {
|
||||
r->final_time=t; memcpy(r->final_state,y,NSTATES*sizeof(double));
|
||||
if (!r->options.record_samples) return 1;
|
||||
if (r->count && r->times[r->count-1] == t) r->count--;
|
||||
if (r->count == r->capacity) {
|
||||
size_t cap=r->capacity ? r->capacity*2 : 1024;
|
||||
if (cap > 2000000 || cap > 268435456u / NSTATES / sizeof(double)) return 0;
|
||||
double *times=realloc(r->times,cap*sizeof(double));
|
||||
if (!times) return 0;
|
||||
r->times=times;
|
||||
double *states=realloc(r->states,cap*NSTATES*sizeof(double));
|
||||
if (!states) return 0;
|
||||
r->states=states; r->capacity=cap;
|
||||
return native_samples_append(r,t,y);
|
||||
}
|
||||
|
||||
/* Amesim helium data domains: EOS, ideal Cp/h, viscosity. Warnings describe
|
||||
* the property use, not a component. Trial/Newton/Jacobian evaluations never
|
||||
* publish warnings; replay of output samples is also side-effect free. */
|
||||
static const double property_lower[3]={2.2,200,200};
|
||||
static const double property_upper[3]={1500,20000,15000};
|
||||
static const char *property_domain[3]={"equation-of-state","ideal-caloric","dynamic-viscosity"};
|
||||
static void property_warning_json(FILE *f,int slot,const NativePropertyWarning *w) {
|
||||
int domain=slot/2,upper=slot%2;
|
||||
fprintf(f,"{\"code\":\"helium-%s-%s\",\"medium\":\"helium\",\"property\":\"%s\","
|
||||
"\"direction\":\"%s\",\"limit\":%.17g,\"time\":%.17g,\"temperature\":%.17g,"
|
||||
"\"extremeTime\":%.17g,\"extremeTemperature\":%.17g}",
|
||||
property_domain[domain],upper?"high":"low",property_domain[domain],upper?"high":"low",
|
||||
upper?property_upper[domain]:property_lower[domain],w->first_time,w->first_temperature,
|
||||
w->extreme_time,w->extreme_temperature);
|
||||
}
|
||||
void native_property_warnings_json(NativeRun *r,FILE *f) {
|
||||
int comma=0;fputc('[',f);
|
||||
for(int i=0;i<6;i++)if(r->property_warnings[i].seen) {
|
||||
if(comma++)fputc(',',f);
|
||||
property_warning_json(f,i,&r->property_warnings[i]);
|
||||
}
|
||||
r->times[r->count]=t;
|
||||
memcpy(r->states+r->count*NSTATES,y,NSTATES*sizeof(double));
|
||||
r->count++; return 1;
|
||||
fputc(']',f);
|
||||
}
|
||||
static void check_property_temperatures(NativeRun *r,double t,const double *y) {
|
||||
#if defined(MODEL_PROPERTY_TEMPERATURES) && MODEL_PROPERTY_TEMPERATURES
|
||||
NativePropertyTemperatures temperatures={0};
|
||||
/* Additional diagnostic evaluation does not alter states or solver counters. */
|
||||
if(!model_property_temperatures(t,y,&temperatures))return;
|
||||
for(int d=0;d<3;d++)if(temperatures.seen&(1u<<d))for(int upper=0;upper<2;upper++) {
|
||||
double T=upper?temperatures.maximum[d]:temperatures.minimum[d];
|
||||
double limit=upper?property_upper[d]:property_lower[d];
|
||||
/* Ignore inversion roundoff at an exact domain endpoint. */
|
||||
double tolerance=1e-9*fmax(limit,1);
|
||||
if(upper ? T<=limit+tolerance : T>=limit-tolerance)continue;
|
||||
int slot=2*d+upper;NativePropertyWarning *w=&r->property_warnings[slot];
|
||||
if(!w->seen) {
|
||||
w->seen=1;w->first_time=w->extreme_time=t;w->first_temperature=w->extreme_temperature=T;
|
||||
fputs("{\"phase\":\"property-warning\",\"warning\":",stderr);
|
||||
property_warning_json(stderr,slot,w);fputs("}\n",stderr);fflush(stderr);
|
||||
} else if(upper ? T>w->extreme_temperature : T<w->extreme_temperature) {
|
||||
w->extreme_temperature=T;w->extreme_time=t;
|
||||
}
|
||||
}
|
||||
#else
|
||||
(void)r;(void)t;(void)y;
|
||||
#endif
|
||||
}
|
||||
|
||||
static double locate(int idx, double bound, int lower, double left, double right,
|
||||
@@ -213,6 +261,7 @@ int native_accept(NativeRun *r, double t, double next, const double *old,
|
||||
} else memcpy(accepted_state,trial,NSTATES*sizeof(double));
|
||||
*accepted_time=stop;
|
||||
r->final_time=stop; memcpy(r->final_state,accepted_state,NSTATES*sizeof(double));
|
||||
check_property_temperatures(r,stop,accepted_state);
|
||||
return count ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -229,16 +278,24 @@ int native_solve(NativeRun *r) {
|
||||
}
|
||||
#endif
|
||||
r->sample_index=1;
|
||||
if (!native_append(r,r->options.start,y)) { r->status=2; r->message="Cannot allocate samples."; return 0; }
|
||||
check_property_temperatures(r,r->options.start,y);
|
||||
if (!native_append(r,r->options.start,y)) return 0;
|
||||
r->wall_start=native_wall_time(); r->cpu_start=native_cpu_time();
|
||||
r->last_progress=r->wall_start-1;
|
||||
int ok=r->options.bdf ? native_bdf(r) : native_rk45(r);
|
||||
r->solve_seconds=native_wall_time()-r->wall_start;
|
||||
r->solve_cpu_seconds=native_cpu_time()-r->cpu_start;
|
||||
if (!ok && !r->status) { r->status=2; r->message="Native integration failed to advance."; }
|
||||
if (!native_append(r,r->final_time,r->final_state)) { r->status=2; r->message="Cannot save final state."; }
|
||||
if (!ok && !r->status) native_fail(r,"integration-failure","integration","Native integration failed.");
|
||||
if (ok && !r->status && r->final_time!=r->options.stop)
|
||||
native_fail(r,"incomplete-result","integration","Native solver returned before the requested stop time.");
|
||||
if (!r->storage_failed) native_append(r,r->final_time,r->final_state);
|
||||
native_samples_flush(r);
|
||||
if (!r->message) r->message=r->status ? "Native integration failed." : "Simulation completed.";
|
||||
return !r->status;
|
||||
}
|
||||
|
||||
void native_run_free(NativeRun *r) { free(r->times); free(r->states); }
|
||||
void native_run_free(NativeRun *r) {
|
||||
free(r->times); free(r->states);
|
||||
if(r->sample_file) fclose(r->sample_file);
|
||||
if(r->output_file) fclose(r->output_file);
|
||||
}
|
||||
Reference in new issue
Block a user