tadd grain volume and mass calculations - granular - granular dynamics simulati… | |
git clone git://src.adamsgaard.dk/granular | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 47f03a2170cd92c674ac784fb1cf73b1df90f9aa | |
parent 1dcf2dc7c9a6fa0c1782f141144002f84d90f4c6 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Thu, 18 Mar 2021 07:44:38 +0100 | |
add grain volume and mass calculations | |
Diffstat: | |
M grain.c | 17 +++++++++++++++-- | |
M grain.h | 1 + | |
2 files changed, 16 insertions(+), 2 deletions(-) | |
--- | |
diff --git a/grain.c b/grain.c | |
t@@ -1,4 +1,5 @@ | |
#include <stdio.h> | |
+#include <math.h> | |
#include "granular.h" | |
#include "util.h" | |
#include "grain.h" | |
t@@ -43,7 +44,7 @@ print_padded_nd_double(FILE *stream, const double *arr) | |
{ | |
size_t i; | |
- for (i = 0; i < 3; i++) | |
+ for (i = 0; i < ND; i++) | |
if (i < ND) | |
fprintf(stream, "%.17g\t", arr[i]); | |
else | |
t@@ -55,7 +56,7 @@ print_padded_nd_int(FILE *stream, const size_t *arr) | |
{ | |
size_t i; | |
- for (i = 0; i < 3; i++) | |
+ for (i = 0; i < ND; i++) | |
if (i < ND) | |
fprintf(stream, "%ld\t", arr[i]); | |
else | |
t@@ -147,3 +148,15 @@ check_grain_values(const struct grain *g) | |
return status; | |
} | |
+ | |
+double | |
+grain_volume(const struct grain *g) | |
+{ | |
+ return 4.0 / 3.0 * PI * pow(g->radius, 3); | |
+} | |
+ | |
+double | |
+grain_mass(const struct grain *g) | |
+{ | |
+ return grain_volume(g) * g->density; | |
+} | |
diff --git a/grain.h b/grain.h | |
t@@ -37,5 +37,6 @@ void init_grain(struct grain *g); | |
void print_grain(FILE *stream, const struct grain *g); | |
int check_grain_values(const struct grain *g); | |
double grain_volume(const struct grain *g); | |
+double grain_mass(const struct grain *g); | |
#endif |