高温氦气物性补全;三通四通能量计算bug修正
This commit is contained in:
1 parent
6fc9afe41d
commit
2b07d996cf
133 files changed
+5230
-253310
No files matched your search
+30
-24
@@ -31,13 +31,13 @@ static int probe(void) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static int write_result_index(const char *path, long series_start, long series_end,
|
||||
long result_bytes, size_t sample_count) {
|
||||
static int write_result_index(const char *path, int64_t series_start, int64_t series_end,
|
||||
int64_t result_bytes, size_t sample_count) {
|
||||
if(series_start<0 || series_end<series_start || result_bytes<series_end) return 0;
|
||||
FILE *index=fopen(path,"wb"); if(!index) return 0;
|
||||
int ok=fprintf(index,"{\"version\":1,\"seriesStart\":%ld,\"seriesEnd\":%ld,"
|
||||
"\"resultBytes\":%ld,\"sampleCount\":%zu}\n",
|
||||
series_start,series_end,result_bytes,sample_count)>=0;
|
||||
int ok=fprintf(index,"{\"version\":1,\"seriesStart\":%lld,\"seriesEnd\":%lld,"
|
||||
"\"resultBytes\":%lld,\"sampleCount\":%zu}\n",
|
||||
(long long)series_start,(long long)series_end,(long long)result_bytes,sample_count)>=0;
|
||||
if(ferror(index)) ok=0;
|
||||
if(fclose(index)) ok=0;
|
||||
return ok;
|
||||
@@ -46,19 +46,23 @@ static int write_result(NativeRun *r, const char *path, const char *index_path)
|
||||
if(index_path && !strcmp(path,index_path)) return 0;
|
||||
double dy[NSTATES], final[NOUTPUTS];
|
||||
int final_ok=model_eval(r->final_time,r->final_state,dy,final);
|
||||
size_t length=r->count*NOUTPUTS;
|
||||
if (length>268435456u/sizeof(double)) return 0;
|
||||
double *values=length?malloc(length*sizeof(double)):NULL;
|
||||
if (length && !values) return 0;
|
||||
for (size_t i=0;i<r->count;i++) {
|
||||
if (!model_eval(r->times[i],r->states+i*NSTATES,dy,values+i*NOUTPUTS)) {
|
||||
free(values); return 0;
|
||||
}
|
||||
}
|
||||
FILE *f=fopen(path,"wb"); if (!f) { free(values); return 0; }
|
||||
if (!native_samples_outputs(r)) return 0;
|
||||
FILE *f=fopen(path,"wb"); if (!f) return 0;
|
||||
fprintf(f,"{\"success\":%s,\"status\":",!r->status?"true":"false");
|
||||
json_string(f,r->status==0?"completed":r->status==1?"cancelled":"failed");
|
||||
fprintf(f,",\"message\":"); json_string(f,r->message);
|
||||
fprintf(f,",\"propertyWarnings\":"); native_property_warnings_json(r,f);
|
||||
fprintf(f,",\"solverControl\":{\"reason\":"); json_string(f,r->failure_reason?r->failure_reason:"");
|
||||
fprintf(f,",\"operation\":"); json_string(f,r->failure_operation?r->failure_operation:"");
|
||||
fprintf(f,",\"returnCode\":%d,\"sameTimeReturns\":%lu,\"maxSameTimeStreak\":%lu",
|
||||
r->cvode_flag,r->same_time_returns,r->max_same_time_streak);
|
||||
const char *names[]={"returnTime","internalTime","lastStep","nextStep"};
|
||||
double diagnostic[]={r->cvode_return_time,r->cvode_internal_time,r->cvode_last_step,r->cvode_next_step};
|
||||
for(int i=0;i<4;i++) {
|
||||
fprintf(f,",\"%s\":",names[i]);
|
||||
if(isfinite(diagnostic[i])) fprintf(f,"%.17g",diagnostic[i]); else fputs("null",f);
|
||||
}
|
||||
fputc('}',f);
|
||||
fprintf(f,",\"jacobianMode\":\"%s\",\"jacobianRhsCalls\":%lu,"
|
||||
"\"jacobianColoredEvals\":%lu,\"jacobianFallbacks\":%lu,"
|
||||
"\"jacobianChecks\":%lu,\"jacobianMismatches\":%lu,"
|
||||
@@ -75,22 +79,22 @@ static int write_result(NativeRun *r, const char *path, const char *index_path)
|
||||
r->events,r->starts,r->njev,r->nlu,r->max_accepted_step);
|
||||
/* Binary-mode positions delimit the complete series object, including
|
||||
both braces. The optional index avoids scanning or parsing its values. */
|
||||
long series_start=-1,series_end=-1,result_bytes=-1;
|
||||
int64_t series_start=-1,series_end=-1,result_bytes=-1;
|
||||
if(index_path) {
|
||||
series_start=ftell(f);
|
||||
series_start=native_file_tell(f);
|
||||
if(series_start>0) series_start--; else series_start=-1;
|
||||
}
|
||||
int output_ok=1;
|
||||
if (r->count) {
|
||||
fprintf(f,"\"time\":");
|
||||
output_ok=native_json_write_array(f,r->times,r->count,1);
|
||||
output_ok=native_samples_json(r,f,0);
|
||||
for (int j=0;j<NOUTPUTS && output_ok;j++) {
|
||||
fputc(',',f); json_string(f,model_output_keys[j]); fputc(':',f);
|
||||
output_ok=native_json_write_array(f,values+j,r->count,NOUTPUTS);
|
||||
output_ok=native_samples_json(r,f,(size_t)j+1);
|
||||
}
|
||||
}
|
||||
fputc('}',f);
|
||||
if(index_path) series_end=ftell(f);
|
||||
if(index_path) series_end=native_file_tell(f);
|
||||
fprintf(f,",\"final\":{");
|
||||
if (final_ok) for (int j=0;j<NOUTPUTS && output_ok;j++) {
|
||||
if (j) fputc(',',f);
|
||||
@@ -101,14 +105,14 @@ static int write_result(NativeRun *r, const char *path, const char *index_path)
|
||||
if (output_ok) output_ok=native_json_write_array(f,r->final_state,NSTATES,1);
|
||||
fprintf(f,"}\n"); int ok=output_ok && !ferror(f);
|
||||
if(index_path) {
|
||||
result_bytes=ftell(f);
|
||||
result_bytes=native_file_tell(f);
|
||||
if(series_start<0 || series_end<0 || result_bytes<0) ok=0;
|
||||
}
|
||||
if (fclose(f)) ok=0;
|
||||
/* Publish the index only after the complete result was successfully
|
||||
flushed and closed. An index I/O failure is a failed result write. */
|
||||
if(ok && index_path) ok=write_result_index(index_path,series_start,series_end,result_bytes,r->count);
|
||||
free(values); return ok;
|
||||
return ok;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@@ -122,11 +126,14 @@ int main(int argc, char **argv) {
|
||||
double y[NSTATES]; if (!model_init(y)) return 2;
|
||||
vector(stdout,y,NSTATES); fputc('\n',stdout); return 0;
|
||||
}
|
||||
if (!strcmp(arg,"--storage-control")) { r.storage_control=1; continue; }
|
||||
if (!strcmp(arg,"--solve-only")) { r.options.record_samples=0; continue; }
|
||||
if (!strcmp(arg,"--verify-jacobian")) { r.jacobian_verify=1; continue; }
|
||||
if (i+1==argc) return 64;
|
||||
const char *value=argv[++i];
|
||||
if (!strcmp(arg,"--output")) output=value;
|
||||
else if (!strcmp(arg,"--sample-file")) r.sample_path=value;
|
||||
else if (!strcmp(arg,"--output-block-file")) r.output_blocks_path=value;
|
||||
else if (!strcmp(arg,"--result-index")) index_path=value;
|
||||
else if (!strcmp(arg,"--cancel-file")) r.options.cancel_path=value;
|
||||
else if (!strcmp(arg,"--method")) {
|
||||
@@ -150,8 +157,7 @@ int main(int argc, char **argv) {
|
||||
r.options.start+r.options.max_step==r.options.start ||
|
||||
!isfinite(r.options.stop-r.options.start)) return 64;
|
||||
if (r.options.record_samples &&
|
||||
((r.options.stop-r.options.start)/r.options.sample_step>1000000 ||
|
||||
((r.options.stop-r.options.start)/r.options.sample_step+1024)*(NSTATES+NOUTPUTS)*sizeof(double)>268435456)) return 64;
|
||||
((r.options.stop-r.options.start)/r.options.sample_step>1000000)) return 64;
|
||||
native_solve(&r);
|
||||
int saved=write_result(&r,output,index_path);
|
||||
int code=saved?(r.status==2?2:0):3;
|
||||
|
||||
Reference in new issue
Block a user