tdefine simulation setup in separate file which is linked together with main objects - slidergrid - grid of elastic sliders on a frictional surface
(HTM) git clone git://src.adamsgaard.dk/slidergrid
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 24351f33993e14a88dd9cfb9787752bd4c912af2
(DIR) parent abf7d095f654ff0108832d8055a3ce72bf333920
(HTM) Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
Date: Wed, 16 Mar 2016 13:11:01 -0700
define simulation setup in separate file which is linked together with main objects
Diffstat:
M Makefile | 4 ++--
M main.c | 27 ++++-----------------------
M simulation.h | 2 ++
A test.c | 28 ++++++++++++++++++++++++++++
4 files changed, 36 insertions(+), 25 deletions(-)
---
(DIR) diff --git a/Makefile b/Makefile
t@@ -1,9 +1,9 @@
CC=gcc
CFLAGS=-Wall -O3 -g -pg
LDLIBS=-lm
-BIN=slidergrid
+ESSENTIALOBJS=main.o slider.o grid.o vector_math.o simulation.o
-$(BIN): main.o slider.o grid.o vector_math.o simulation.o
+test: test.o $(ESSENTIALOBJS)
$(CC) $(LDLIBS) $^ -o $@
profile: $(BIN)
(DIR) diff --git a/main.c b/main.c
t@@ -5,28 +5,6 @@
#include "simulation.h"
-simulation setup_simulation()
-{
- // create empty simulation structure
- simulation sim;
-
- // initialize grid of sliders
- int nx = 4;
- int ny = 4;
- int nz = 4;
- sim.N = nx*ny*nz;
- sim.sliders = create_regular_slider_grid(nx, ny, nz, 1.0, 1.0, 1.0);
-
- // set slider masses and moments of inertia
- int i;
- for (i=0; i<sim.N; i++) {
- sim.sliders[i].mass = 1.;
- sim.sliders[i].moment_of_inertia = 1.;
- }
-
- return sim;
-}
-
int main(int argc, char** argv)
{
int i;
t@@ -46,7 +24,10 @@ int main(int argc, char** argv)
// check simulation parameters for missing or wrong parameter values
if (check_simulation_values(sim)) {
- fprintf(stderr, "Error: Simulation configuration invalid.\n");
+ fprintf(stderr, "\nFatal error: The simulation configuration is "
+ "invalid.\nPlease check the setup_simulation() configuration, "
+ "which is verified in the function check_simulation_values "
+ "(simulation.c).\n");
return EXIT_FAILURE;
}
(DIR) diff --git a/simulation.h b/simulation.h
t@@ -1,6 +1,8 @@
#ifndef SIMULATION_H_
#define SIMULATION_H_
+#include "slider.h"
+
typedef struct {
slider* sliders;
int N;
(DIR) diff --git a/test.c b/test.c
t@@ -0,0 +1,28 @@
+#include "simulation.h"
+#include "grid.h"
+#include "slider.h"
+
+// test a regular, 2d, orthogonal grid of sliders
+simulation setup_simulation()
+{
+ // create empty simulation structure
+ simulation sim;
+
+ // initialize grid of sliders
+ int nx = 4;
+ int ny = 4;
+ int nz = 4;
+ sim.N = nx*ny*nz;
+ sim.sliders = create_regular_slider_grid(nx, ny, nz, 1.0, 1.0, 1.0);
+
+ sim.bond_length_limit = 1.5;
+
+ // set slider masses and moments of inertia
+ int i;
+ for (i=0; i<sim.N; i++) {
+ sim.sliders[i].mass = 1.;
+ sim.sliders[i].moment_of_inertia = 1.;
+ }
+
+ return sim;
+}