-
Notifications
You must be signed in to change notification settings - Fork 9
/
io.cu
3099 lines (2742 loc) · 115 KB
/
io.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @author Christoph Schaefer cm.schaefer@gmail.com and Thomas I. Maindl
*
* @section LICENSE
* Copyright (c) 2019 Christoph Schaefer
*
* This file is part of miluphcuda.
*
* miluphcuda is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* miluphcuda is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with miluphcuda. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "io.h"
#include "miluph.h"
#include "timeintegration.h"
#include "config_parameter.h"
#include "pressure.h"
#include <libconfig.h>
#include <float.h>
#include "aneos.h"
#if HDF5IO
#include <hdf5.h>
#endif
int currentDiskIO = FALSE;
extern pthread_t fileIOthread;
extern double startTime;
extern double Smin;
extern double alphamin;
extern double emin;
extern double rhomin;
extern double damagemin;
extern double betamin;
extern double alpha_epspormin;
extern double epsilon_vmin;
extern __device__ volatile int maxNodeIndex;
File inputFile;
/*! \brief
Reading the material properties using libconfig.
\param pointer to config file
\return nothing
*/
void loadConfigFromFile(char *configFile)
{
config_init(¶m.config);
if (!config_read_file(¶m.config, configFile)) {
fprintf(stderr, "Error reading config file %s.\n", configFile);
config_destroy(¶m.config);
exit(1);
}
}
void set_integration_parameters()
{
FILE *f;
char line[1024];
char *name;
char *value;
char *fn = "pc_values.dat";
const char s[] = " = ";
int found = FALSE;
if ( (f = fopen(fn,"r")) == NULL) {
if (param.integrator_type == MONAGHAN_PC || param.integrator_type == EULER_PC) {
fprintf(stderr, "Can't open file %s!\n", fn);
exit(1);
}
} else {
found = TRUE;
}
Smin = rhomin = emin = alphamin = betamin = damagemin = alpha_epspormin = epsilon_vmin = 1e99;
if (found) {
while (fgets(line, sizeof(line), f)) {
/* comments start with # */
if (line[0] == '#') continue;
name = strtok(line, s);
value = strtok(NULL, s);
if (!strcmp(name, "Smin")) {
Smin = atof(value);
}
else if (!strcmp(name, "rhomin")) {
rhomin = atof(value);
}
else if (!strcmp(name, "emin")) {
emin = atof(value);
}
else if (!strcmp(name, "alphamin")) {
alphamin = atof(value);
}
else if (!strcmp(name, "betamin")) {
betamin = atof(value);
}
else if (!strcmp(name, "damagemin")) {
damagemin = atof(value);
}
else if (!strcmp(name, "alpha_epspormin")) {
alpha_epspormin = atof(value);
}
else if (!strcmp(name, "epsilon_vmin")) {
epsilon_vmin = atof(value);
}
}
fclose (f);
}
if (param.verbose && (param.integrator_type == MONAGHAN_PC || param.integrator_type == EULER_PC)) {
fprintf(stdout, "Using following values for the predictor corrector integrator:\n");
#if SOLID
fprintf(stdout, "Smin:\t\t\t %e\n", Smin);
#endif
#if INTEGRATE_ENERGY
fprintf(stdout, "emin:\t\t\t %e\n", emin);
#endif
#if INTEGRATE_DENSITY
fprintf(stdout, "rhomin:\t\t\t %e\n", rhomin);
#endif
#if FRAGMENTATION
fprintf(stdout, "damagemin:\t\t %e\n", damagemin);
#endif
#if PALPHA_POROSITY
fprintf(stdout, "alphamin:\t\t %e\n", alphamin);
#endif
#if INVISCID_SPH
fprintf(stdout, "betamin:\t\t %e\n", betamin);
#endif
#if EPSALPHA_POROSITY
fprintf(stdout, "alpha_epspormin:\t\t %e\n", alpha_epspormin);
fprintf(stdout, "epsilon_vmin:\t\t %e\n", epsilon_vmin);
#endif
fprintf(stdout, "These values (if not 1e99) are taken from file <pc_values.dat>.\n");
}
}
/* set some initial values */
void init_values(void)
{
int i;
int matId;
if (param.verbose)
fprintf(stdout, "\nReading/initialising material constants and copy them to the GPU...\n");
transferMaterialsToGPU();
for (i = 0; i < numberOfParticles; i++) {
matId = p_host.materialId[i];
#if MORE_OUTPUT
#if PALPHA_POROSITY
p_host.p_max[i] = p_host.p[i];
p_host.p_min[i] = p_host.p[i];
#else
p_host.p_max[i] = -DBL_MAX;
p_host.p_min[i] = DBL_MAX;
#endif
#if INTEGRATE_DENSITY
p_host.rho_max[i] = p_host.rho[i];
p_host.rho_min[i] = p_host.rho[i];
#else
p_host.rho_max[i] = -DBL_MAX;
p_host.rho_min[i] = DBL_MAX;
#endif
p_host.e_max[i] = p_host.e[i];
p_host.e_min[i] = p_host.e[i];
p_host.cs_max[i] = -DBL_MAX;
p_host.cs_min[i] = DBL_MAX;
#endif
#if PALPHA_POROSITY
p_host.cs[i] = cs_porous[matId];
#else
p_host.cs[i] = sqrt(bulk_modulus[matId]/till_rho_0[matId]);
#endif
#if !READ_INITIAL_SML_FROM_PARTICLE_FILE
if (!(p_host.h[i] > 0)) {
p_host.h[i] = sml[matId];
}
#endif
p_host.h0[i] = p_host.h[i];
}
}
// read in particles from start file
void read_particles_from_file(File inputFile)
{
int my_anop;
int i;
int d;
int c;
#if SOLID || NAVIER_STOKES
int e;
#endif
char h5filename[256];
char h5massfilename[256];
char massfilename[256];
FILE *massfile;
double h5time;
double *x;
int *ix;
#if HDF5IO
hid_t file_id;
hid_t x_id, v_id, m_id, mtype_id;
# if INTEGRATE_DENSITY
hid_t rho_id;
# endif
# if INTEGRATE_ENERGY
hid_t e_id;
# endif
hid_t time_id;
# if VARIABLE_SML || READ_INITIAL_SML_FROM_PARTICLE_FILE
hid_t sml_id;
# endif
hid_t dspace;
# if FRAGMENTATION
hid_t noaf_id, damage_id;
hid_t activation_thresholds_id;
hid_t maxnof_id;
int nofi;
int maxnof;
double *ax;
# endif
# if GRAVITATING_POINT_MASSES
hid_t rmin_id;
hid_t rmax_id;
hid_t flag_id;
# endif
# if JC_PLASTICITY
hid_t ep_id, T_id;
# endif
# if SOLID
hid_t S_id;
# endif
# if NAVIER_STOKES
hid_t Tshear_id;
# endif
# if PALPHA_POROSITY
hid_t p_id;
hid_t alpha_id;
# if SOLID
# if FRAGMENTATION
hid_t damage_porjutzi_id;
# endif
# endif
# endif
# if SIRONO_POROSITY
hid_t K_id;
hid_t rho_0prime_id;
hid_t rho_c_plus_id;
hid_t rho_c_minus_id;
hid_t compressive_strength_id;
hid_t tensile_strength_id;
hid_t flag_rho_0prime_id;
hid_t flag_plastic_id;
hid_t shear_strength_id;
# endif
# if EPSALPHA_POROSITY
hid_t alpha_epspor_id;
hid_t epsilon_v_id;
# endif
herr_t status;
/* filename extension is .h5 */
strcpy(massfilename, inputFile.name);
strcat(massfilename, ".mass");
strcpy(h5filename, inputFile.name);
strcpy(h5massfilename, inputFile.name);
strcat(h5filename, ".h5");
strcat(h5massfilename, ".mass.h5");
#endif // HDF5IO
// set start timestep from input filename
const char* ext;
ext = strrchr(inputFile.name, '.');
if (!ext) {
fprintf(stderr, "ERROR. Could not get start timestep from name of input file. Make sure to name the file *.1234 or something like this.\n");
exit(1);
} else {
sscanf(ext+1, "%04d", &startTimestep);
}
// START READING HDF5 INPUT FILE...
#if HDF5IO
if (param.hdf5input) {
fprintf(stdout, "Reading particle data from hdf5 file: %s.h5\n", inputFile.name);
# if GRAVITATING_POINT_MASSES
fprintf(stdout, "Reading pointmass data from hdf5 file: %s.mass.h5\n", inputFile.name);
# endif
file_id = H5Fopen (h5filename, H5F_ACC_RDONLY, H5P_DEFAULT);
if (file_id < 0) {
fprintf(stderr, "********************** Error opening file %s\n", h5filename);
exit(1);
} else {
fprintf(stdout, "Using hdf5 input file: %s\n", h5filename);
}
/* open the dataset for the positions */
x_id = H5Dopen(file_id, "/x", H5P_DEFAULT);
if (x_id < 0) {
fprintf(stderr, "Could not find locations in hdf5 file. Exiting...\n");
}
/* determine number of particles stored in hdf5 file */
dspace = H5Dget_space(x_id);
const int ndims = H5Sget_simple_extent_ndims(dspace);
hsize_t dims[ndims];
H5Sget_simple_extent_dims(dspace, dims, NULL);
my_anop = dims[0];
fprintf(stdout, "Reading data for %d particles...\n", my_anop);
/* allocate space for my_anop particles */
x = (double *) malloc(sizeof(double) * my_anop * DIM);
/* read positions */
status = H5Dread(x_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(x_id);
for (i = 0, d = 0; i < my_anop; i++, d += DIM) {
p_host.x[i] = x[d];
# if DIM > 1
p_host.y[i] = x[d+1];
# if DIM == 3
p_host.z[i] = x[d+2];
# endif
# endif
}
/* read velocities */
v_id = H5Dopen(file_id, "/v", H5P_DEFAULT);
if (v_id < 0) {
fprintf(stderr, "Could not find velocities in hdf5 file. Exiting...\n");
exit(1);
}
status = H5Dread(v_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(v_id);
for (i = 0, d = 0; i < my_anop; i++, d += DIM) {
p_host.vx[i] = x[d];
# if DIM > 1
p_host.vy[i] = x[d+1];
# if DIM == 3
p_host.vz[i] = x[d+2];
# endif
# endif
}
/* read accreted velocities */
v_id = H5Dopen(file_id, "/v_accreted", H5P_DEFAULT);
if (v_id < 0) {
fprintf(stdout, "Could not find accreted velocities in hdf5 file.\n");
}
else {
fprintf(stdout, "Found velocities of accreted particles and reading them.\n");
status = H5Dread(v_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(v_id);
for (i = 0, d = 0; i < my_anop; i++, d += DIM) {
p_host.vx0[i] = x[d];
# if DIM > 1
p_host.vy0[i] = x[d+1];
# if DIM == 3
p_host.vz0[i] = x[d+2];
# endif
# endif
}
}
free(x);
/* read simulation time */
time_id = H5Dopen(file_id, "/time", H5P_DEFAULT);
if (time_id < 0) {
fprintf(stderr, "Could not find time in hdf5 file. Exiting...\n");
exit(1);
}
status = H5Dread(time_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &h5time);
status = H5Dclose(time_id);
fprintf(stdout, "Current time: %g\n", h5time);
startTime = h5time;
/* read masses */
dims[0] = my_anop;
dims[1] = 1;
x = (double * ) malloc(sizeof(double) * my_anop);
m_id = H5Dopen(file_id, "/m", H5P_DEFAULT);
if (m_id < 0) {
fprintf(stderr, "Could not find mass information in hdf5 file. Exiting...\n");
exit(1);
}
status = H5Dread(m_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(m_id);
for (i = 0; i < my_anop; i++) {
p_host.m[i] = x[i];
}
free(x);
# if PALPHA_POROSITY
/* read alpha_jutzi */
dims[0] = my_anop;
dims[1] = 1;
alpha_id = H5Dopen(file_id, "/alpha_jutzi", H5P_DEFAULT);
if (alpha_id < 0) {
fprintf(stderr, "Could not find alpha_jutzi information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(alpha_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(alpha_id);
for (i = 0; i < my_anop; i++) {
p_host.alpha_jutzi[i] = x[i];
}
free(x);
/* read pressures */
p_id = H5Dopen(file_id, "/p", H5P_DEFAULT);
if (p_id < 0) {
fprintf(stderr, "Could not find pressure information in hdf5 file. Exiting...\n");
exit(1);
} else {
fprintf(stdout, "Reading actual pressure data to pressure_old on the device.\n");
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(p_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(p_id);
for (i = 0; i < my_anop; i++) {
p_host.pold[i] = x[i];
}
free(x);
# if FRAGMENTATION
/* read damage_porjutzi */
damage_porjutzi_id = H5Dopen(file_id, "/DIM_root_of_damage_porjutzi", H5P_DEFAULT);
if (damage_porjutzi_id < 0) {
fprintf(stderr, "Could not find damage_porjutzi information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(damage_porjutzi_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(damage_porjutzi_id);
for (i = 0; i < my_anop; i++) {
p_host.damage_porjutzi[i] = x[i];
}
free(x);
# endif
# endif
# if SIRONO_POROSITY
/* read rho_c_plus */
rho_c_plus_id = H5Dopen(file_id, "/rho_c_plus", H5P_DEFAULT);
if (rho_c_plus_id < 0) {
fprintf(stderr, "Could not find rho_c_plus information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(rho_c_plus_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(rho_c_plus_id);
for (i = 0; i < my_anop; i++) {
p_host.rho_c_plus[i] = x[i];
}
free(x);
/* read rho_c_minus */
rho_c_minus_id = H5Dopen(file_id, "/rho_c_minus", H5P_DEFAULT);
if (rho_c_minus_id < 0) {
fprintf(stderr, "Could not find rho_c_minus information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(rho_c_minus_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(rho_c_minus_id);
for (i = 0; i < my_anop; i++) {
p_host.rho_c_minus[i] = x[i];
}
free(x);
/* read bulk modulus */
K_id = H5Dopen(file_id, "/K", H5P_DEFAULT);
if (K_id < 0) {
fprintf(stderr, "Could not find bulk modulus information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(K_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(K_id);
for (i = 0; i < my_anop; i++) {
p_host.K[i] = x[i];
}
free(x);
/* read rho_0prime */
rho_0prime_id = H5Dopen(file_id, "/rho_0prime", H5P_DEFAULT);
if (rho_0prime_id < 0) {
fprintf(stderr, "Could not find rho_0prime information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(rho_0prime_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(rho_0prime_id);
for (i = 0; i < my_anop; i++) {
p_host.rho_0prime[i] = x[i];
}
free(x);
/* read compressive_strength */
compressive_strength_id = H5Dopen(file_id, "/compressive_strength", H5P_DEFAULT);
if (compressive_strength_id < 0) {
fprintf(stderr, "Could not find compressive_strength information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(compressive_strength_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(compressive_strength_id);
for (i = 0; i < my_anop; i++) {
p_host.compressive_strength[i] = x[i];
}
free(x);
/* read tensile_strength */
tensile_strength_id = H5Dopen(file_id, "/tensile_strength", H5P_DEFAULT);
if (tensile_strength_id < 0) {
fprintf(stderr, "Could not find tensile_strength information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(tensile_strength_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(tensile_strength_id);
for (i = 0; i < my_anop; i++) {
p_host.tensile_strength[i] = x[i];
}
free(x);
/* read shear_strength */
shear_strength_id = H5Dopen(file_id, "/shear_strength", H5P_DEFAULT);
if (shear_strength_id < 0) {
fprintf(stderr, "Could not find shear_strength information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(shear_strength_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(shear_strength_id);
for (i = 0; i < my_anop; i++) {
p_host.shear_strength[i] = x[i];
}
free(x);
/* read flag_rho_0prime */
flag_rho_0prime_id = H5Dopen(file_id, "/flag_rho_0prime", H5P_DEFAULT);
if (flag_rho_0prime_id < 0) {
fprintf(stderr, "Could not flag_rho_0prime information in hdf5 file. Exiting...\n");
exit(1);
}
ix = (int *) malloc(sizeof(int) * my_anop);
if (!(ix)) {
fprintf(stderr, "Cannot allocate enough memory.\n");
exit(1);
}
status = H5Dread(flag_rho_0prime_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ix);
status = H5Dclose(flag_rho_0prime_id);
for (i = 0; i < my_anop; i++) {
p_host.flag_rho_0prime[i] = ix[i];
}
free(ix);
/* read flag_plastic */
flag_plastic_id = H5Dopen(file_id, "/flag_plastic", H5P_DEFAULT);
if (flag_plastic_id < 0) {
fprintf(stderr, "Could not flag_plastic information in hdf5 file. Exiting...\n");
exit(1);
}
ix = (int *) malloc(sizeof(int) * my_anop);
status = H5Dread(flag_plastic_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ix);
status = H5Dclose(flag_plastic_id);
for (i = 0; i < my_anop; i++) {
p_host.flag_plastic[i] = ix[i];
}
free(ix);
# endif
# if EPSALPHA_POROSITY
/* read alpha_epspor */
alpha_epspor_id = H5Dopen(file_id, "/alpha_epspor", H5P_DEFAULT);
if (alpha_epspor_id < 0) {
fprintf(stderr, "Could not find alpha_epspor information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(alpha_epspor_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(alpha_epspor_id);
for (i = 0; i < my_anop; i++) {
p_host.alpha_epspor[i] = x[i];
}
free(x);
/* read epsilon_v */
epsilon_v_id = H5Dopen(file_id, "/epsilon_v", H5P_DEFAULT);
if (epsilon_v_id < 0) {
fprintf(stderr, "Could not find epsilon_v information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(epsilon_v_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(epsilon_v_id);
for (i = 0; i < my_anop; i++) {
p_host.epsilon_v[i] = x[i];
}
free(x);
# endif
# if VARIABLE_SML || READ_INITIAL_SML_FROM_PARTICLE_FILE
/* read sml */
sml_id = H5Dopen(file_id, "/sml", H5P_DEFAULT);
if (sml_id < 0) {
fprintf(stderr, "Could not find smoothing length information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(sml_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(sml_id);
for (i = 0; i < my_anop; i++) {
p_host.h[i] = x[i];
}
free(x);
# endif
# if READ_INITIAL_SML_FROM_PARTICLE_FILE
/* read sml0 */
sml_id = H5Dopen(file_id, "/sml_initial", H5P_DEFAULT);
if (sml_id < 0) {
fprintf(stderr, "Could not find initial smoothing length information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(sml_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(sml_id);
for (i = 0; i < my_anop; i++) {
p_host.h0[i] = x[i];
}
free(x);
# endif
# if INTEGRATE_DENSITY
/* read densities */
rho_id = H5Dopen(file_id, "/rho", H5P_DEFAULT);
if (rho_id < 0) {
fprintf(stderr, "Could not find density information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(rho_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(rho_id);
for (i = 0; i < my_anop; i++) {
p_host.rho[i] = x[i];
}
free(x);
# endif
# if INTEGRATE_ENERGY
/* read internal energies */
e_id = H5Dopen(file_id, "/e", H5P_DEFAULT);
if (e_id < 0) {
fprintf(stderr, "Could not find energy information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(e_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(e_id);
for (i = 0; i < my_anop; i++) {
p_host.e[i] = x[i];
}
free(x);
# endif
/* read material types */
mtype_id = H5Dopen(file_id, "/material_type", H5P_DEFAULT);
if (mtype_id < 0) {
fprintf(stderr, "Could not material type information in hdf5 file. Exiting...\n");
exit(1);
}
ix = (int *) malloc(sizeof(int) * my_anop);
if (!(ix)) {
fprintf(stderr, "Cannot allocate enough memory.\n");
exit(1);
}
status = H5Dread(mtype_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ix);
status = H5Dclose(mtype_id);
for (i = 0; i < my_anop; i++) {
p_host.materialId[i] = ix[i];
}
free(ix);
# if JC_PLASTICITY
/* read plastic strains */
ep_id = H5Dopen(file_id, "/ep", H5P_DEFAULT);
if (ep_id < 0) {
fprintf(stderr, "Could not find plastic strain information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(ep_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(ep_id);
for (i = 0; i < my_anop; i++) {
p_host.ep[i] = x[i];
}
free(x);
/* read temperatures */
T_id = H5Dopen(file_id, "/T", H5P_DEFAULT);
if (T_id < 0) {
fprintf(stderr, "Could not find temperature information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(T_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(T_id);
for (i = 0; i < my_anop; i++) {
p_host.T[i] = x[i];
}
free(x);
# endif
# if FRAGMENTATION
/* read number of activated flaws */
noaf_id = H5Dopen(file_id, "/number_of_activated_flaws", H5P_DEFAULT);
if (noaf_id < 0) {
fprintf(stderr, "Could not find number of activated flaws information in hdf5 file. Exiting...\n");
exit(1);
}
ix = (int *) malloc(sizeof(int) * my_anop);
status = H5Dread(noaf_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ix);
status = H5Dclose(noaf_id);
for (i = 0; i < my_anop; i++) {
p_host.numActiveFlaws[i] = ix[i];
}
free(ix);
/* read damage_tensile */
damage_id = H5Dopen(file_id, "/DIM_root_of_damage_tensile", H5P_DEFAULT);
if (damage_id < 0) {
fprintf(stderr, "Could not find tensile damage information in hdf5 file. Exiting...\n");
exit(1);
}
x = (double * ) malloc(sizeof(double) * my_anop);
status = H5Dread(damage_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(damage_id);
for (i = 0; i < my_anop; i++) {
p_host.d[i] = x[i];
}
free(x);
/* read max number of activation thresholds */
maxnof_id = H5Dopen(file_id, "/maximum_number_of_flaws", H5P_DEFAULT);
if (maxnof_id < 0) {
fprintf(stderr, "Could not find maximum number of flaws in hdf5 file. Exiting...\n");
exit(1);
}
status = H5Dread(maxnof_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &maxnof);
status = H5Dclose(maxnof_id);
fprintf(stdout, "Maximum number of activation thresholds for a particle in the data is %d.\n", maxnof);
/* read the activation thresholds (and set number-of-flaws accordingly) */
dims[0] = my_anop;
dims[1] = maxnof;
x = (double *) malloc(sizeof(double) * my_anop * maxnof);
if (!x) {
fprintf(stderr, "Cannot allocate enough memory.\n");
exit(1);
}
activation_thresholds_id = H5Dopen(file_id, "/activation_thresholds", H5P_DEFAULT);
if (activation_thresholds_id < 0) {
fprintf(stderr, "Could not find activation thresholds in hdf5 file. Exiting...\n");
exit(1);
}
status = H5Dread(activation_thresholds_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(activation_thresholds_id);
ax = (double *) malloc(sizeof(double) * maxnof);
for (i = 0; i < my_anop; i++) {
nofi = 0;
while (x[i*maxnof + nofi] > 0 && nofi < maxnof) {
ax[nofi] = x[i*maxnof + nofi];
nofi++;
}
p_host.numFlaws[i] = nofi;
for (d = 0; d < nofi; d++) {
p_host.flaws[i*MAX_NUM_FLAWS+d] = ax[d];
}
}
free(ax);
free(x);
# endif
# if NAVIER_STOKES
/* read deviatoric stresses */
x = (double *) malloc(sizeof(double) * my_anop * DIM * DIM);
dims[0] = my_anop;
dims[1] = DIM*DIM;
Tshear_id = H5Dopen(file_id, "/viscous_shear_stress", H5P_DEFAULT);
if (Tshear_id < 0) {
fprintf(stderr, "Could not find viscous_shear_stress information in hdf5 file. Exiting...\n");
exit(1);
}
status = H5Dread(Tshear_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(Tshear_id);
for (i = 0; i < my_anop; i++) {
for (d = 0; d < DIM; d++) {
for (e = 0; e < DIM; e++) {
p_host.Tshear[i*DIM*DIM+d*DIM+e] = x[i*DIM*DIM + d*DIM + e];
}
}
}
free(x);
# endif
# if SOLID
/* read deviatoric stresses */
x = (double *) malloc(sizeof(double) * my_anop * DIM * DIM);
dims[0] = my_anop;
dims[1] = DIM*DIM;
S_id = H5Dopen(file_id, "/deviatoric_stress", H5P_DEFAULT);
if (S_id < 0) {
fprintf(stderr, "Could not find stress information in hdf5 file. Exiting...\n");
exit(1);
}
status = H5Dread(S_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(S_id);
for (i = 0; i < my_anop; i++) {
for (d = 0; d < DIM; d++) {
for (e = 0; e < DIM; e++) {
p_host.S[i*DIM*DIM+d*DIM+e] = x[i*DIM*DIM + d*DIM + e];
}
}
}
free(x);
# endif
H5Fclose(file_id);
// START READING POINTMASSES INPUT FILE...
# if GRAVITATING_POINT_MASSES
file_id = H5Fopen (h5massfilename, H5F_ACC_RDONLY, H5P_DEFAULT);
if (file_id < 0) {
fprintf(stderr, "********************** Error opening file %s\n", h5massfilename);
exit(1);
} else {
fprintf(stdout, "Using hdf5 input file %s.\n", h5massfilename);
}
/* open the dataset for the positions */
x_id = H5Dopen(file_id, "/x", H5P_DEFAULT);
if (x_id < 0) {
fprintf(stderr, "Could not find locations in hdf5 file. Exiting...\n");
}
/* determine number of particles stored in hdf5 file */
dspace = H5Dget_space(x_id);
const int mndims = H5Sget_simple_extent_ndims(dspace);
hsize_t mdims[mndims];
H5Sget_simple_extent_dims(dspace, mdims, NULL);
my_anop = mdims[0];
fprintf(stdout, "Reading data for %d pointmasses.\n", my_anop);
/* allocate space for my_anop particles */
x = (double *) malloc(sizeof(double) * my_anop * DIM);
/* read positions */
status = H5Dread(x_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(x_id);
for (i = 0, d = 0; i < my_anop; i++, d += DIM) {
pointmass_host.x[i] = x[d];
# if DIM > 1
pointmass_host.y[i] = x[d+1];
# if DIM == 3
pointmass_host.z[i] = x[d+2];
# endif
# endif
}
/* read velocities */
v_id = H5Dopen(file_id, "/v", H5P_DEFAULT);
if (v_id < 0) {
fprintf(stderr, "Could not find velocities in hdf5 file. Exiting...\n");
exit(1);
}
status = H5Dread(v_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(v_id);
for (i = 0, d = 0; i < my_anop; i++, d += DIM) {
pointmass_host.vx[i] = x[d];
# if DIM > 1
pointmass_host.vy[i] = x[d+1];
# if DIM == 3
pointmass_host.vz[i] = x[d+2];
# endif
# endif
}
/* read masses */
dims[0] = my_anop;
dims[1] = 1;
free(x);
x = (double * ) malloc(sizeof(double) * my_anop);
m_id = H5Dopen(file_id, "/m", H5P_DEFAULT);
if (m_id < 0) {
fprintf(stderr, "Could not find mass information in hdf5 file. Exiting...\n");
exit(1);
}
status = H5Dread(m_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(m_id);
for (i = 0; i < my_anop; i++) {
pointmass_host.m[i] = x[i];
}
rmin_id = H5Dopen(file_id, "/rmin", H5P_DEFAULT);
if (rmin_id < 0) {
fprintf(stderr, "Could not find rmin information in hdf5 file. Exiting...\n");
exit(1);
}
status = H5Dread(rmin_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(rmin_id);
for (i = 0; i < my_anop; i++) {
pointmass_host.rmin[i] = x[i];
}
rmax_id = H5Dopen(file_id, "/rmax", H5P_DEFAULT);
if (rmax_id < 0) {
fprintf(stderr, "Could not find rmax information in hdf5 file. Exiting...\n");
exit(1);
}
status = H5Dread(rmax_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, x);
status = H5Dclose(rmax_id);
for (i = 0; i < my_anop; i++) {
pointmass_host.rmax[i] = x[i];
}
free(x);
// read feels_particles flag
ix = (int *) malloc(sizeof(int) * my_anop);
flag_id = H5Dopen(file_id, "/feels_particles", H5P_DEFAULT);
if (flag_id < 0) {
fprintf(stderr, "Could not find feels_particles flag information in hdf5 file. Exiting...\n");
exit(1);
}
status = H5Dread(flag_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ix);
status = H5Dclose(flag_id);