tmove grain read from stdin to simulation.c and clean up includes - granular - … | |
git clone git://src.adamsgaard.dk/granular | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 40ba40a9674ffd919a157cab8d4ea0089e0f5fe2 | |
parent ef24a161a54a064dd7afc2b6c6425e3bca3748dd | |
Author: Anders Damsgaard <[email protected]> | |
Date: Thu, 25 Mar 2021 22:03:32 +0100 | |
move grain read from stdin to simulation.c and clean up includes | |
Diffstat: | |
M Makefile | 1 + | |
M granular.c | 42 +++++------------------------… | |
M granular2vtu.c | 18 +----------------- | |
M simulation.c | 17 +++++++++++++++++ | |
M simulation.h | 1 + | |
5 files changed, 26 insertions(+), 53 deletions(-) | |
--- | |
diff --git a/Makefile b/Makefile | |
t@@ -9,6 +9,7 @@ MANPREFIX = ${PREFIX}/share/man | |
DOCPREFIX = ${PREFIX}/share/doc/${NAME} | |
BIN = \ | |
+ granular\ | |
granular2vtu\ | |
granularpacking | |
SCRIPTS = \ | |
diff --git a/granular.c b/granular.c | |
t@@ -1,50 +1,20 @@ | |
-#include <stdio.h> | |
#include <stdlib.h> | |
-#include <math.h> | |
-#include <string.h> | |
-#include <time.h> | |
-#include <unistd.h> | |
-#include <err.h> | |
- | |
-#include "grain.h" | |
- | |
-#include "arg.h" | |
- | |
-/* relative tolerance criteria for the solvers */ | |
-#define RTOL 1e-5 | |
-#define MAX_ITER_1D_FD_SIMPLE_SHEAR 100000 | |
- | |
-/* uncomment to print time spent per time step to stdout */ | |
-/* #define BENCHMARK_PERFORMANCE */ | |
- | |
-char *argv0; | |
- | |
-static void | |
-usage(void) | |
-{ | |
- errx(1, "usage: %s " | |
- "[name]\n", argv0); | |
-} | |
+#include "simulation.h" | |
int | |
main(int argc, char *argv[]) | |
{ | |
- /* struct simulation sim; */ | |
+ struct simulation sim = sim_new(); | |
#ifdef __OpenBSD__ | |
if (pledge("stdio wpath cpath", NULL) == -1) | |
err(2, "pledge failed"); | |
#endif | |
- ARGBEGIN { | |
- default: | |
- usage(); | |
- } ARGEND; | |
- | |
- /*if (argc == 1 && argv[0]) | |
- snprintf(sim.name, sizeof(sim.name), "%s", argv[0]); | |
- else */if (argc > 1) | |
- usage(); | |
+ sim_defaults(&sim); | |
+ sim_read_grains(&sim, stdin); | |
+ sim_print_grains_vtk(stdout, &sim); | |
+ sim_free(&sim); | |
return 0; | |
} | |
diff --git a/granular2vtu.c b/granular2vtu.c | |
t@@ -1,21 +1,9 @@ | |
-#ifndef __OpenBSD__ | |
-#define _POSIX_C_SOURCE 200809L | |
-#endif | |
-#include <unistd.h> | |
-#include <stdio.h> | |
#include <stdlib.h> | |
-#include <err.h> | |
-#include "grain.h" | |
#include "simulation.h" | |
-#include "arrays.h" | |
-#include "util.h" | |
int | |
main(void) | |
{ | |
- char *line = NULL; | |
- size_t linesize = 0; | |
- ssize_t linelen; | |
struct simulation sim = sim_new(); | |
#ifdef __OpenBSD__ | |
t@@ -23,13 +11,9 @@ main(void) | |
err(2, "pledge failed"); | |
#endif | |
- while ((linelen = getline(&line, &linesize, stdin)) > 0) | |
- sim_add_grain(&sim, grain_read(line)); | |
- | |
+ sim_read_grains(&sim, stdin); | |
sim_print_grains_vtk(stdout, &sim); | |
- | |
sim_free(&sim); | |
- free(line); | |
return 0; | |
} | |
diff --git a/simulation.c b/simulation.c | |
t@@ -1,3 +1,7 @@ | |
+#ifndef __OpenBSD__ | |
+#define _POSIX_C_SOURCE 200809L | |
+#endif | |
+#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <err.h> | |
t@@ -74,6 +78,19 @@ sim_add_grain(struct simulation *sim, struct grain *g) | |
} | |
void | |
+sim_read_grains(struct simulation *sim, FILE *stream) | |
+{ | |
+ char *line = NULL; | |
+ size_t linesize = 0; | |
+ ssize_t linelen; | |
+ | |
+ while ((linelen = getline(&line, &linesize, stream)) > 0) | |
+ sim_add_grain(sim, grain_read(line)); | |
+ | |
+ free(line); | |
+} | |
+ | |
+void | |
print_grains(FILE *stream, const struct grain *grains, size_t n) | |
{ | |
size_t i; | |
diff --git a/simulation.h b/simulation.h | |
t@@ -37,6 +37,7 @@ void sim_defaults(struct simulation *sim); | |
void sim_free(struct simulation *sim); | |
void sim_add_grain(struct simulation *sim, struct grain *g); | |
+void sim_read_grains(struct simulation *sim, FILE *stream); | |
void print_grains(FILE *stream, const struct grain *grains, size_t n); | |
void sim_print_grains(FILE *stream, const struct simulation *sim); |