tfix dimensional constant usage - granular - granular dynamics simulation | |
git clone git://src.adamsgaard.dk/granular | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 47bb6a607f6621fef48a906e2fb2e44f02b2c979 | |
parent 126211efa113da8c8651ed99d5de9efa9f691b73 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Thu, 18 Mar 2021 07:35:56 +0100 | |
fix dimensional constant usage | |
Diffstat: | |
M grain.c | 13 ++++++------- | |
M util.c | 24 +++++++++++++----------- | |
2 files changed, 19 insertions(+), 18 deletions(-) | |
--- | |
diff --git a/grain.c b/grain.c | |
t@@ -1,16 +1,15 @@ | |
#include <stdio.h> | |
+#include "granular.h" | |
#include "util.h" | |
#include "grain.h" | |
-extern size_t nd; | |
- | |
void | |
grain_defaults(struct grain *g) | |
{ | |
size_t i; | |
g->radius = 1.0; | |
- for (i = 0; i < nd; i++) { | |
+ for (i = 0; i < ND; i++) { | |
g->pos[i] | |
= g->vel[i] | |
= g->acc[i] | |
t@@ -45,7 +44,7 @@ print_padded_nd_double(FILE *stream, const double *arr) | |
size_t i; | |
for (i = 0; i < 3; i++) | |
- if (i < nd) | |
+ if (i < ND) | |
fprintf(stream, "%.17g\t", arr[i]); | |
else | |
fprintf(stream, "0.0\t"); | |
t@@ -57,7 +56,7 @@ print_padded_nd_int(FILE *stream, const size_t *arr) | |
size_t i; | |
for (i = 0; i < 3; i++) | |
- if (i < nd) | |
+ if (i < ND) | |
fprintf(stream, "%ld\t", arr[i]); | |
else | |
fprintf(stream, "0.0\t"); | |
t@@ -102,7 +101,7 @@ check_grain_values(const struct grain *g) | |
check_float_positive("grain->radius", g->radius, &status); | |
- for (i = 0; i < nd; i++) { | |
+ for (i = 0; i < ND; i++) { | |
check_float("grain->pos", g->pos[i], &status); | |
check_float("grain->vel", g->vel[i], &status); | |
check_float("grain->acc", g->acc[i], &status); | |
t@@ -139,7 +138,7 @@ check_grain_values(const struct grain *g) | |
g->fracture_toughness, | |
&status); | |
- for (i = 0; i < nd; i++) | |
+ for (i = 0; i < ND; i++) | |
if (g->gridpos[i] > 1) | |
warn_parameter_value("grain->gridpos is not 0 or 1", | |
(double)g->gr… | |
diff --git a/util.c b/util.c | |
t@@ -1,4 +1,6 @@ | |
#include <stdio.h> | |
+#include <math.h> | |
+#include "granular.h" | |
void | |
warn_parameter_value(const char message[], | |
t@@ -14,15 +16,13 @@ warn_parameter_value(const char message[], | |
void | |
check_float(const char name[], const double value, int *status) | |
{ | |
- if (isnan(value)) { | |
- char message[100]; | |
+ char message[100]; | |
+ if (isnan(value)) { | |
snprintf(message, sizeof(message), "%s is NaN", name); | |
warn_parameter_value(message, value, status); | |
*status = 1; | |
} else if (isinf(value)) { | |
- char message[100]; | |
- | |
snprintf(message, sizeof(message), "%s is infinite", name); | |
warn_parameter_value(message, value, status); | |
*status = 1; | |
t@@ -34,7 +34,7 @@ check_float_non_negative(const char name[], const double val… | |
{ | |
char message[100]; | |
- check_float(*name, value, *status); | |
+ check_float(name, value, status); | |
if (value < 0.0) { | |
snprintf(message, sizeof(message), "%s is negative", name); | |
warn_parameter_value(message, value, status); | |
t@@ -47,7 +47,7 @@ check_float_positive(const char name[], const double value, … | |
{ | |
char message[100]; | |
- check_float(*name, value, *status); | |
+ check_float(name, value, status); | |
if (value <= 0.0) { | |
snprintf(message, sizeof(message), "%s is not positive", name); | |
warn_parameter_value(message, value, status); | |
t@@ -58,11 +58,13 @@ check_float_positive(const char name[], const double value… | |
void | |
check_bool(const char name[], const int value, int *status) | |
{ | |
- if (value < 0 || value > 1) | |
- warn_parameter_value("%s is not 0 or 1", | |
- (double)value, | |
- &status); | |
- *status = 1; | |
+ char message[100]; | |
+ | |
+ if (value < 0 || value > 1) { | |
+ snprintf(message, sizeof(message), "%s is not 0 or 1", name); | |
+ warn_parameter_value(message, (double)value, status); | |
+ *status = 1; | |
+ } | |
} | |
void |