tfix many grain inconsitencies - granular - granular dynamics simulation
 (HTM) git clone git://src.adamsgaard.dk/granular
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit a2970453f73bbaedddd1e48e427c1825b67fe990
 (DIR) parent eaad1100200c4187905bcab135b121fa10b9d75e
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Thu, 18 Mar 2021 07:20:01 +0100
       
       fix many grain inconsitencies
       
       Diffstat:
         M grain.c                             |      47 ++++++++++++++++---------------
         M grain.h                             |       2 ++
       
       2 files changed, 27 insertions(+), 22 deletions(-)
       ---
 (DIR) diff --git a/grain.c b/grain.c
       t@@ -32,13 +32,15 @@ grain_defaults(struct grain *g)
                g->poissons_ratio = 0.2;
                g->friction_coeff = 0.4;
                g->tensile_strength = 1e8;
       +        g->shear_strength = 1e8;
       +        g->fracture_toughness = 1e8;
                g->ncontacts = 0;
                g->thermal_energy = 0.0;
                g->color = 0;
        }
        
        static void
       -print_padded_nd_double(FILE *stream, double *arr)
       +print_padded_nd_double(FILE *stream, const double *arr)
        {
                size_t i;
                
       t@@ -50,13 +52,13 @@ print_padded_nd_double(FILE *stream, double *arr)
        }
        
        static void
       -print_padded_nd_int(FILE *stream, size_t *arr)
       +print_padded_nd_int(FILE *stream, const size_t *arr)
        {
                size_t i;
                
                for (i = 0; i < 3; i++)
                        if (i < nd)
       -                        fprintf(stream, "%d\t", arr[i]);
       +                        fprintf(stream, "%ld\t", arr[i]);
                        else
                                fprintf(stream, "0.0\t");
        }
       t@@ -64,9 +66,7 @@ print_padded_nd_int(FILE *stream, size_t *arr)
        void
        print_grain(FILE *stream, const struct grain *g)
        {
       -        size_t i;
       -
       -        fprintf(stream, "%d\t", g->radius);
       +        fprintf(stream, "%.17g\t", g->radius);
                print_padded_nd_double(stream, g->pos);
                print_padded_nd_double(stream, g->vel);
                print_padded_nd_double(stream, g->acc);
       t@@ -78,26 +78,26 @@ print_grain(FILE *stream, const struct grain *g)
                print_padded_nd_double(stream, g->disp);
                print_padded_nd_double(stream, g->forceext);
                fprintf(stream, "%.17g\t", g->density);
       -        fprintf(stream, "%d\t", g->fixed);
       -        fprintf(stream, "%d\t", g->rotating);
       -        fprintf(stream, "%d\t", g->enabled);
       +        fprintf(stream, "%ld\t", g->fixed);
       +        fprintf(stream, "%ld\t", g->rotating);
       +        fprintf(stream, "%ld\t", g->enabled);
                fprintf(stream, "%.17g\t", g->youngs_modulus);
                fprintf(stream, "%.17g\t", g->poissons_ratio);
       -        fprintf(stream, "%.17g\t", g->friction_coefficient);
       +        fprintf(stream, "%.17g\t", g->friction_coeff);
                fprintf(stream, "%.17g\t", g->tensile_strength);
                fprintf(stream, "%.17g\t", g->shear_strength);
                fprintf(stream, "%.17g\t", g->fracture_toughness);
       -        print_padded_nd_int(stream, g->grid_position);
       -        fprintf(stream, "%d\t", g->ncontacts);
       -        fprintf(stream, "%.17g\t", g->granular_stress);
       +        print_padded_nd_int(stream, g->gridpos);
       +        fprintf(stream, "%ld\t", g->ncontacts);
       +        print_padded_nd_double(stream, g->contact_stress);
                fprintf(stream, "%.17g\t", g->thermal_energy);
       -        fprintf(stream, "%d\n", g->color);
       +        fprintf(stream, "%ld\n", g->color);
        }
        
        int
        check_grain_values(const struct grain *g)
        {
       -        int i;
       +        size_t i;
                int status = 0;
        
                check_float_positive("grain->radius", g->radius, &status);
       t@@ -124,23 +124,26 @@ check_grain_values(const struct grain *g)
                                         g->youngs_modulus,
                                         &status);
                check_float_non_negative("grain->poissons_ratio",
       -                                 g->youngs_modulus,
       +                                 g->poissons_ratio,
                                         &status);
                check_float_non_negative("grain->friction_coeff",
       -                                 g->youngs_modulus,
       +                                 g->friction_coeff,
                                         &status);
                check_float_non_negative("grain->tensile_strength",
       -                                 g->youngs_modulus,
       +                                 g->tensile_strength,
       +                                 &status);
       +        check_float_non_negative("grain->shear_strength",
       +                                 g->shear_strength,
       +                                 &status);
       +        check_float_non_negative("grain->fracture_toughness",
       +                                 g->fracture_toughness,
                                         &status);
        
                for (i = 0; i < nd; i++)
       -                if (g->gridpos[i] < 0)
       +                if (g->gridpos[i] > 1)
                                warn_parameter_value("grain->gridpos is not 0 or 1",
                                                                         (double)g->gridpos[i], &status);
        
       -        if (g->ncontacts[i] < 0)
       -                warn_parameter_value("grain->ncontacts is not 0 or 1",
       -                                                         (double)g->ncontacts[i], &status);
                check_float_non_negative("grain->thermal_energy", g->thermal_energy, &status);
        
                return status;
 (DIR) diff --git a/grain.h b/grain.h
       t@@ -24,6 +24,8 @@ struct grain {
                double poissons_ratio;
                double friction_coeff;
                double tensile_strength;
       +        double shear_strength;
       +        double fracture_toughness;
                size_t gridpos[ND];
                size_t ncontacts;
                double contact_stress[ND];