tgrain.c: add grain reading function - granular - granular dynamics simulation | |
git clone git://src.adamsgaard.dk/granular | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit a501b9c908adc5dbd1ca45be5f20bed5c8d04e4c | |
parent 828052591c1463144a4df91161a1c9a1749eefbe | |
Author: Anders Damsgaard <[email protected]> | |
Date: Thu, 18 Mar 2021 11:17:35 +0100 | |
grain.c: add grain reading function | |
Diffstat: | |
M grain.c | 65 +++++++++++++++++++++++++++--… | |
1 file changed, 58 insertions(+), 7 deletions(-) | |
--- | |
diff --git a/grain.c b/grain.c | |
t@@ -71,7 +71,7 @@ print_padded_nd_int(FILE *stream, const size_t *arr) | |
for (i = 0; i < ND; i++) | |
if (i < ND) | |
- fprintf(stream, "%ld\t", arr[i]); | |
+ fprintf(stream, "%zu\t", arr[i]); | |
else | |
fprintf(stream, "0.0\t"); | |
} | |
t@@ -91,9 +91,9 @@ grain_print(FILE *stream, const struct grain *g) | |
print_padded_nd_double(stream, g->disp); | |
print_padded_nd_double(stream, g->forceext); | |
fprintf(stream, "%.*g\t", FLOATPREC, g->density); | |
- fprintf(stream, "%ld\t", g->fixed); | |
- fprintf(stream, "%ld\t", g->rotating); | |
- fprintf(stream, "%ld\t", g->enabled); | |
+ fprintf(stream, "%zu\t", g->fixed); | |
+ fprintf(stream, "%zu\t", g->rotating); | |
+ fprintf(stream, "%zu\t", g->enabled); | |
fprintf(stream, "%.*g\t", FLOATPREC, g->youngs_modulus); | |
fprintf(stream, "%.*g\t", FLOATPREC, g->poissons_ratio); | |
fprintf(stream, "%.*g\t", FLOATPREC, g->friction_coeff); | |
t@@ -101,10 +101,10 @@ grain_print(FILE *stream, const struct grain *g) | |
fprintf(stream, "%.*g\t", FLOATPREC, g->shear_strength); | |
fprintf(stream, "%.*g\t", FLOATPREC, g->fracture_toughness); | |
print_padded_nd_int(stream, g->gridpos); | |
- fprintf(stream, "%ld\t", g->ncontacts); | |
+ fprintf(stream, "%zu\t", g->ncontacts); | |
print_padded_nd_double(stream, g->contact_stress); | |
fprintf(stream, "%.*g\t", FLOATPREC, g->thermal_energy); | |
- fprintf(stream, "%ld\n", g->color); | |
+ fprintf(stream, "%zu\n", g->color); | |
} | |
struct grain * | |
t@@ -112,7 +112,58 @@ grain_read(char *line) | |
{ | |
struct grain *g = malloc(sizeof(*g)); | |
- if (sscanf(line, "%lg\t", &g->radius) != 1) | |
+ if (sscanf(line, "%lg\t" /* radius */ | |
+ "%lg\t%lg\t%lg\t" /* pos */ | |
+ "%lg\t%lg\t%lg\t" /* vel */ | |
+ "%lg\t%lg\t%lg\t" /* acc */ | |
+ "%lg\t%lg\t%lg\t" /* force */ | |
+ "%lg\t%lg\t%lg\t" /* angpos */ | |
+ "%lg\t%lg\t%lg\t" /* angvel */ | |
+ "%lg\t%lg\t%lg\t" /* angacc */ | |
+ "%lg\t%lg\t%lg\t" /* torque */ | |
+ "%lg\t%lg\t%lg\t" /* disp */ | |
+ "%lg\t%lg\t%lg\t" /* forceext */ | |
+ "%lg\t" /* density */ | |
+ "%zu\t" /* fixed */ | |
+ "%zu\t" /* rotating */ | |
+ "%zu\t" /* enabled */ | |
+ "%lg\t" /* youngs_modulus */ | |
+ "%lg\t" /* poissons_ratio */ | |
+ "%lg\t" /* friction_coeff */ | |
+ "%lg\t" /* tensile_strength */ | |
+ "%lg\t" /* shear_strength */ | |
+ "%lg\t" /* fracture_toughness */ | |
+ "%zu\t%zu\t%zu\t" /* gridpos */ | |
+ "%zu\t" /* ncontacts */ | |
+ "%lg\t%lg\t%lg\t" /* contact_stress */ | |
+ "%lg\t" /* thermal_energy */ | |
+ "%zu\n", /* color */ | |
+ &g->radius, | |
+ &g->pos[0], &g->pos[1], &g->pos[2], | |
+ &g->vel[0], &g->vel[1], &g->vel[2], | |
+ &g->acc[0], &g->acc[1], &g->acc[2], | |
+ &g->force[0], &g->force[1], &g->force… | |
+ &g->angpos[0], &g->angpos[1], &g->ang… | |
+ &g->angvel[0], &g->angvel[1], &g->ang… | |
+ &g->angacc[0], &g->angacc[1], &g->ang… | |
+ &g->torque[0], &g->torque[1], &g->tor… | |
+ &g->disp[0], &g->disp[1], &g->disp[2]… | |
+ &g->forceext[0], &g->forceext[1], &g-… | |
+ &g->density, | |
+ &g->fixed, | |
+ &g->rotating, | |
+ &g->enabled, | |
+ &g->youngs_modulus, | |
+ &g->poissons_ratio, | |
+ &g->friction_coeff, | |
+ &g->tensile_strength, | |
+ &g->shear_strength, | |
+ &g->fracture_toughness, | |
+ &g->gridpos[0], &g->gridpos[1], &g->g… | |
+ &g->ncontacts, | |
+ &g->contact_stress[0], &g->contact_st… | |
+ &g->thermal_energy, | |
+ &g->color) != 52) | |
errx(1, "%s: could not read line: %s", __func__, line); | |
if (grain_check_values(g)) |