00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include "globalt.h"
00004 #include "backupsolt.h"
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 void solvert_save (double *r,double *dr,double *fp,long ni,double time,double dt,timecontr &tc,long n)
00024 {
00025 switch (Tp->hdbcont.hdbfmts)
00026 {
00027 case text:
00028 solvert_save_text(r, dr, fp, ni, time, dt, tc, n);
00029 break;
00030 case binary:
00031 solvert_save_binary(r, dr, fp, ni, time, dt, tc, n);
00032 break;
00033 default:
00034 print_err("unknown type of backup file format is required", __FILE__, __LINE__, __func__);
00035 }
00036 }
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 void solvert_save_text (double *r,double *dr,double *fp,long ni,double time,double dt,timecontr &tc,long n)
00057 {
00058 switch (Tp->hdbcont.hdbtype)
00059 {
00060 case hdbs_single:
00061 case hdbrs_single:
00062 solvert_save_text_single(r, dr, fp, ni, time, dt, tc, n);
00063 break;
00064 case hdbs_multiple:
00065 case hdbrs_multiple:
00066 solvert_save_text_multiple(r, dr, fp, ni, time, dt, tc, n);
00067 break;
00068 default:
00069 print_err("unknown type of backup is required", __FILE__, __LINE__, __func__);
00070 }
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 void solvert_save_binary (double *r,double *dr,double *fp,long ni,double time,double dt,timecontr &tc,long n)
00092 {
00093 switch (Tp->hdbcont.hdbtype)
00094 {
00095 case hdbs_single:
00096 case hdbrs_single:
00097 solvert_save_binary_single(r, dr, fp, ni, time, dt, tc, n);
00098 break;
00099 case hdbs_multiple:
00100 case hdbrs_multiple:
00101 solvert_save_binary_multiple(r, dr, fp, ni, time, dt, tc, n);
00102 break;
00103 default:
00104 print_err("unknown type of backup is required", __FILE__, __LINE__, __func__);
00105 }
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 void solvert_save_text_single (double *r,double *dr,double *fp,long ni,double time,double dt,timecontr &tc,long n)
00127 {
00128 long i;
00129 FILE *aux;
00130 char name[FNAMELEN+20];
00131 char emsg[FNAMELEN+100];
00132 int prec = (int)Tp->hdbcont.prec;
00133
00134 sprintf(name, "%s.%ld.bac",Tp->hdbcont.hdbnames, ni);
00135 aux = fopen(name,"wt");
00136 if (aux==NULL)
00137 {
00138 sprintf(emsg, "cannot open backup file %s", name);
00139 print_err(emsg, __FILE__, __LINE__, __func__);
00140 abort();
00141 }
00142 fprintf (aux,"\n\n\n\n");
00143
00144
00145 tc.save_txt(aux, prec);
00146
00147 fprintf (aux,"%.*le\n",prec,time);
00148
00149 fprintf (aux,"%.*le\n",prec,dt);
00150
00151 fprintf (aux,"%ld\n",ni);
00152
00153 fprintf (aux,"%ld\n",n);
00154
00155
00156 for (i=0;i<n;i++){
00157 fprintf (aux,"%.*le\n",prec,r[i]);
00158 }
00159
00160 fprintf (aux,"\n");
00161
00162
00163 for (i=0;i<n;i++){
00164 fprintf (aux,"%.*le\n",prec,dr[i]);
00165 }
00166
00167 fprintf (aux,"\n");
00168
00169
00170 for (i=0;i<n;i++){
00171 fprintf (aux,"%.*le\n",prec,fp[i]);
00172 }
00173
00174
00175 fprintf (aux,"\n\n %ld\n",Tm->tnip);
00176
00177
00178 Tm->save_intpointst_txt (aux, Tp->hdbcont.selelems, Tp->hdbcont.selother_s);
00179
00180 fclose (aux);
00181
00182 if (Tp->hdbcont.rmold)
00183 {
00184 if (Tp->hdbcont.rmold_id>=0)
00185 {
00186 sprintf(name, "%s.%ld.bac",Tp->hdbcont.hdbnames,Tp->hdbcont.rmold_id);
00187 remove(name);
00188 }
00189 Tp->hdbcont.rmold_id = ni;
00190 }
00191 }
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 void solvert_save_text_multiple (double *r,double *dr,double *fp,long ni,double time,double dt,timecontr &tc,long n)
00223 {
00224 long i;
00225 FILE *aux;
00226 char name[FNAMELEN+20];
00227 char emsg[FNAMELEN+100];
00228 int prec = (int)Tp->hdbcont.prec;
00229
00230 sprintf(name, "%s.%ld.solver.bac",Tp->hdbcont.hdbnames, ni);
00231 aux = fopen(name,"wt");
00232 if (aux==NULL)
00233 {
00234 sprintf(emsg, "cannot open backup file %s", name);
00235 print_err(emsg, __FILE__, __LINE__, __func__);
00236 abort();
00237 }
00238
00239
00240 tc.save_txt(aux, prec);
00241
00242 fprintf (aux,"%.*le\n",prec,time);
00243
00244 fprintf (aux,"%.*le\n",prec,dt);
00245
00246 fprintf (aux,"%ld\n",ni);
00247
00248 fprintf (aux,"%ld\n",n);
00249
00250
00251 for (i=0;i<n;i++){
00252 fprintf (aux,"%.*le\n",prec,r[i]);
00253 }
00254
00255 fprintf (aux,"\n");
00256
00257
00258 for (i=0;i<n;i++){
00259 fprintf (aux,"%.*le\n",prec,dr[i]);
00260 }
00261
00262 fprintf (aux,"\n");
00263
00264
00265 for (i=0;i<n;i++){
00266 fprintf (aux,"%.*le\n",prec,fp[i]);
00267 }
00268
00269
00270 fprintf (aux,"\n\n %ld\n",Tm->tnip);
00271
00272 fclose (aux);
00273
00274
00275 Tm->save_intpointst_txt (ni, Tp->hdbcont.selelems, Tp->hdbcont.selother_s);
00276
00277 if (Tp->hdbcont.rmold)
00278 {
00279 if (Tp->hdbcont.rmold_id>=0)
00280 {
00281 sprintf(name, "%s.%ld.solver.bac",Tp->hdbcont.hdbnames,Tp->hdbcont.rmold_id);
00282 remove(name);
00283 sprintf(name, "%s.%ld.grad.bac",Tp->hdbcont.hdbnames,Tp->hdbcont.rmold_id);
00284 remove(name);
00285 sprintf(name, "%s.%ld.flux.bac",Tp->hdbcont.hdbnames,Tp->hdbcont.rmold_id);
00286 remove(name);
00287 sprintf(name, "%s.%ld.other.bac",Tp->hdbcont.hdbnames,Tp->hdbcont.rmold_id);
00288 remove(name);
00289 }
00290 Tp->hdbcont.rmold_id = ni;
00291 }
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 void solvert_save_binary_single (double *r,double *dr,double *fp,long ni,double time,double dt,timecontr &tc,long n)
00313 {
00314 FILE *aux;
00315 char name[FNAMELEN+30];
00316 char emsg[FNAMELEN+100];
00317
00318 sprintf(name, "%s.%ld.bac",Tp->hdbcont.hdbnames, ni);
00319 aux = fopen(name,"wb");
00320 if (aux==NULL)
00321 {
00322 sprintf(emsg, "cannot open backup file %s", name);
00323 print_err(emsg, __FILE__, __LINE__, __func__);
00324 abort();
00325 }
00326
00327
00328 tc.save_bin(aux);
00329
00330 fwrite (&time, sizeof(time), 1, aux);
00331
00332 fwrite (&dt, sizeof(dt), 1, aux);
00333
00334 fwrite (&ni, sizeof(ni), 1, aux);
00335
00336 fwrite (&n, sizeof(n), 1, aux);
00337
00338
00339 fwrite(r, sizeof(*r), n, aux);
00340
00341
00342 fwrite(dr, sizeof(*dr), n, aux);
00343
00344
00345 fwrite(fp, sizeof(*fp), n, aux);
00346
00347
00348 fwrite (&Tm->tnip, sizeof(Tm->tnip), 1, aux);
00349
00350
00351 Tm->save_intpointst_bin (aux, Tp->hdbcont.selelems, Tp->hdbcont.selother_s);
00352 fclose (aux);
00353
00354 if (Tp->hdbcont.rmold)
00355 {
00356 if (Tp->hdbcont.rmold_id>=0)
00357 {
00358 sprintf(name, "%s.%ld.bac",Tp->hdbcont.hdbnames,Tp->hdbcont.rmold_id);
00359 remove(name);
00360 }
00361 Tp->hdbcont.rmold_id = ni;
00362 }
00363 }
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394 void solvert_save_binary_multiple (double *r,double *dr,double *fp,long ni,double time,double dt,timecontr &tc,long n)
00395 {
00396 FILE *aux;
00397 char name[FNAMELEN+30];
00398 char emsg[FNAMELEN+100];
00399
00400 sprintf(name, "%s.%ld.solver.bac",Tp->hdbcont.hdbnames, ni);
00401 aux = fopen(name,"wb");
00402 if (aux==NULL)
00403 {
00404 sprintf(emsg, "cannot open backup file %s", name);
00405 print_err(emsg, __FILE__, __LINE__, __func__);
00406 abort();
00407 }
00408
00409
00410 tc.save_bin(aux);
00411
00412 fwrite (&time, sizeof(time), 1, aux);
00413
00414 fwrite (&dt, sizeof(dt), 1, aux);
00415
00416 fwrite (&ni, sizeof(ni), 1, aux);
00417
00418 fwrite (&n, sizeof(n), 1, aux);
00419
00420
00421 fwrite(r, sizeof(*r), n, aux);
00422
00423
00424 fwrite(dr, sizeof(*dr), n, aux);
00425
00426
00427 fwrite(fp, sizeof(*fp), n, aux);
00428
00429
00430 fwrite (&Tm->tnip, sizeof(Tm->tnip), 1, aux);
00431
00432 fclose (aux);
00433
00434
00435 Tm->save_intpointst_bin (ni, Tp->hdbcont.selelems, Tp->hdbcont.selother_s);
00436
00437 if (Tp->hdbcont.rmold)
00438 {
00439 if (Tp->hdbcont.rmold_id>=0)
00440 {
00441 sprintf(name, "%s.%ld.solver.bac",Tp->hdbcont.hdbnames,Tp->hdbcont.rmold_id);
00442 remove(name);
00443 sprintf(name, "%s.%ld.grad.bac",Tp->hdbcont.hdbnames,Tp->hdbcont.rmold_id);
00444 remove(name);
00445 sprintf(name, "%s.%ld.flux.bac",Tp->hdbcont.hdbnames,Tp->hdbcont.rmold_id);
00446 remove(name);
00447 sprintf(name, "%s.%ld.other.bac",Tp->hdbcont.hdbnames,Tp->hdbcont.rmold_id);
00448 remove(name);
00449 }
00450 Tp->hdbcont.rmold_id = ni;
00451 }
00452 }
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472 void solvert_restore (double *r,double *dr,double *fp,long &ni,double &time,double &dt,timecontr &tc,long &n)
00473 {
00474 switch (Tp->hdbcont.hdbfmtr)
00475 {
00476 case text:
00477 solvert_restore_text(r, dr, fp, ni, time, dt, tc, n);
00478 break;
00479 case binary:
00480 solvert_restore_binary(r, dr, fp, ni, time, dt, tc, n);
00481 break;
00482 default:
00483 print_err("unknown type of backup file format is required", __FILE__, __LINE__, __func__);
00484 }
00485 }
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505 void solvert_restore_text (double *r,double *dr,double *fp,long &ni,double &time,double &dt,timecontr &tc,long &n)
00506 {
00507 switch (Tp->hdbcont.hdbtype)
00508 {
00509 case hdbr_single:
00510 case hdbrs_single:
00511 solvert_restore_text_single(r, dr, fp, ni, time, dt, tc, n);
00512 break;
00513 case hdbr_multiple:
00514 case hdbrs_multiple:
00515 solvert_restore_text_multiple(r, dr, fp, ni, time, dt, tc, n);
00516 break;
00517 default:
00518 print_err("unknown type of backup is required", __FILE__, __LINE__, __func__);
00519 }
00520 }
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540 void solvert_restore_binary (double *r,double *dr,double *fp,long &ni,double &time,double &dt,timecontr &tc,long &n)
00541 {
00542 switch (Tp->hdbcont.hdbtype)
00543 {
00544 case hdbr_single:
00545 case hdbrs_single:
00546 solvert_restore_binary_single(r, dr, fp, ni, time, dt, tc, n);
00547 break;
00548 case hdbr_multiple:
00549 case hdbrs_multiple:
00550 solvert_restore_binary_multiple(r, dr, fp, ni, time, dt, tc, n);
00551 break;
00552 default:
00553 print_err("unknown type of backup is required", __FILE__, __LINE__, __func__);
00554 }
00555 }
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575 void solvert_restore_text_single (double *r,double *dr,double *fp,long &ni,double &time,double &dt,timecontr &tc,long &n)
00576 {
00577 long i;
00578 FILE *aux;
00579 char name[FNAMELEN+20];
00580 char emsg[FNAMELEN+100];
00581
00582 aux = fopen(Tp->hdbcont.hdbnamer,"rt");
00583 if (aux==NULL)
00584 {
00585 sprintf(emsg, "cannot open backup file %s", name);
00586 print_err(emsg, __FILE__, __LINE__, __func__);
00587 abort();
00588 }
00589
00590
00591 tc.restore_txt(aux);
00592
00593 fscanf (aux,"%le",&time);
00594
00595 fscanf (aux,"%le",&dt);
00596
00597 fscanf (aux,"%ld\n",&ni);
00598
00599 fscanf (aux,"%ld\n",&n);
00600
00601 if (n!=Ndoft){
00602 print_err("number of DOFs in backup file and in the actual problem is not same\n", __FILE__, __LINE__, __func__);
00603 abort();
00604 }
00605
00606
00607 for (i=0;i<n;i++){
00608 fscanf (aux,"%le",r+i);
00609 }
00610
00611 for (i=0;i<n;i++){
00612 fscanf (aux,"%le",dr+i);
00613 }
00614
00615 for (i=0;i<n;i++){
00616 fscanf (aux,"%le",fp+i);
00617 }
00618
00619
00620 fscanf (aux,"%ld",&i);
00621
00622 if (i!=Tm->tnip){
00623 print_err("number of integration points in backup file and in the actual problem is not same\n", __FILE__, __LINE__, __func__);
00624 abort();
00625 }
00626
00627
00628 Tm->restore_intpointst_txt (aux, Tp->hdbcont.selelemr, Tp->hdbcont.selother_r, Tp->hdbcont.selother_id);
00629
00630 fclose(aux);
00631 }
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662 void solvert_restore_text_multiple (double *r,double *dr,double *fp,long &ni,double &time,double &dt,timecontr &tc,long &n)
00663 {
00664 long i;
00665 FILE *aux;
00666 char name[FNAMELEN+20];
00667 char emsg[FNAMELEN+100];
00668
00669 sprintf(name, "%s.solver.bac",Tp->hdbcont.hdbnamer);
00670 aux = fopen(name,"rt");
00671 if (aux==NULL)
00672 {
00673 sprintf(emsg, "cannot open backup file %s", name);
00674 print_err(emsg, __FILE__, __LINE__, __func__);
00675 abort();
00676 }
00677
00678
00679 tc.restore_txt(aux);
00680
00681 fscanf (aux,"%le",&time);
00682
00683 fscanf (aux,"%le",&dt);
00684
00685 fscanf (aux,"%ld",&ni);
00686
00687 fscanf (aux,"%ld",&n);
00688
00689 if (n!=Ndoft){
00690 print_err("number of DOFs in backup file and in the actual problem is not same\n", __FILE__, __LINE__, __func__);
00691 abort();
00692 }
00693
00694
00695 for (i=0;i<n;i++){
00696 fscanf (aux,"%le",r+i);
00697 }
00698
00699
00700 for (i=0;i<n;i++){
00701 fscanf (aux,"%le",dr+i);
00702 }
00703
00704 for (i=0;i<n;i++){
00705 fscanf (aux,"%le",fp+i);
00706 }
00707
00708
00709 fscanf (aux,"%ld",&i);
00710
00711 if (i!=Tm->tnip){
00712 print_err("number of integration points in backup file and in the actual problem is not same\n", __FILE__, __LINE__, __func__);
00713 abort();
00714 }
00715
00716 fclose(aux);
00717
00718
00719 Tm->restore_intpointst_txt (Tp->hdbcont.selelemr, Tp->hdbcont.selother_r, Tp->hdbcont.selother_id);
00720 }
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740 void solvert_restore_binary_single (double *r,double *dr,double *fp,long &ni,double &time,double &dt,timecontr &tc,long &n)
00741 {
00742 FILE *aux;
00743 char name[FNAMELEN+30];
00744 char emsg[FNAMELEN+100];
00745
00746 aux = fopen(Tp->hdbcont.hdbnamer,"rb");
00747 if (aux==NULL)
00748 {
00749 sprintf(emsg, "cannot open backup file %s", name);
00750 print_err(emsg, __FILE__, __LINE__, __func__);
00751 abort();
00752 }
00753
00754
00755 tc.restore_bin(aux);
00756
00757 fread (&time, sizeof(time), 1, aux);
00758
00759 fread (&dt, sizeof(dt), 1, aux);
00760
00761 fread (&ni, sizeof(ni), 1, aux);
00762
00763 fread (&n, sizeof(n), 1, aux);
00764
00765
00766 fread(r, sizeof(*r), n, aux);
00767
00768
00769 fread(dr, sizeof(*dr), n, aux);
00770
00771
00772 fread(fp, sizeof(*fp), n, aux);
00773
00774
00775 fread (&Tm->tnip, sizeof(Tm->tnip), 1, aux);
00776
00777
00778 Tm->restore_intpointst_bin (aux, Tp->hdbcont.selelemr, Tp->hdbcont.selother_r, Tp->hdbcont.selother_id);
00779 fclose (aux);
00780 }
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812 void solvert_restore_binary_multiple (double *r,double *dr,double *fp,long &ni,double &time,double &dt,timecontr &tc,long &n)
00813 {
00814 FILE *aux;
00815 char name[FNAMELEN+30];
00816 char emsg[FNAMELEN+100];
00817
00818 sprintf(name, "%s.solver.bac",Tp->hdbcont.hdbnamer);
00819 aux = fopen(name,"rb");
00820 if (aux==NULL)
00821 {
00822 sprintf(emsg, "cannot open backup file %s", name);
00823 print_err(emsg, __FILE__, __LINE__, __func__);
00824 abort();
00825 }
00826
00827
00828 tc.restore_bin(aux);
00829
00830 fread (&time, sizeof(time), 1, aux);
00831
00832 fread (&dt, sizeof(dt), 1, aux);
00833
00834 fread (&ni, sizeof(ni), 1, aux);
00835
00836 fread (&n, sizeof(n), 1, aux);
00837
00838
00839 fread(r, sizeof(*r), n, aux);
00840
00841
00842 fread(dr, sizeof(*dr), n, aux);
00843
00844
00845 fread(fp, sizeof(*fp), n, aux);
00846
00847
00848 fread (&Tm->tnip, sizeof(Tm->tnip), 1, aux);
00849
00850 fclose (aux);
00851
00852
00853 Tm->restore_intpointst_bin (Tp->hdbcont.selelemr, Tp->hdbcont.selother_r, Tp->hdbcont.selother_id);
00854 }
00855
00856
00857