tpass pointer to simulation structure - slidergrid - grid of elastic sliders on… | |
git clone git://src.adamsgaard.dk/slidergrid | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit f592a85d991ec58487fb39ba92a7eb3f32b39f75 | |
parent d45ab4c31a7de996f1785ca5d8fb7bc17c06c9dc | |
Author: Anders Damsgaard <[email protected]> | |
Date: Thu, 17 Mar 2016 16:56:12 -0700 | |
pass pointer to simulation structure | |
Diffstat: | |
M slidergrid/main.c | 2 +- | |
M slidergrid/simulation.c | 57 +++++++++++++++--------------… | |
M slidergrid/simulation.h | 4 ++-- | |
3 files changed, 31 insertions(+), 32 deletions(-) | |
--- | |
diff --git a/slidergrid/main.c b/slidergrid/main.c | |
t@@ -83,7 +83,7 @@ int main(int argc, char** argv) | |
sim.dt = find_time_step(sim.sliders, sim.N, 0.07); | |
// check simulation parameters for missing or wrong parameter values | |
- if (check_simulation_values(sim)) { | |
+ if (check_simulation_values(&sim)) { | |
fprintf(stderr, "\nFatal error: The simulation configuration is " | |
"invalid.\n\n" | |
"Please check the setup_simulation() configuration, " | |
diff --git a/slidergrid/simulation.c b/slidergrid/simulation.c | |
t@@ -19,67 +19,66 @@ simulation create_simulation() | |
return sim; | |
} | |
-int check_simulation_values(const simulation sim) | |
+int check_simulation_values(const simulation* sim) | |
{ | |
int return_status = 0; | |
// Slider-specific parameters | |
int i; | |
- for (i=0; i<sim.N; i++) { | |
+ for (i=0; i<sim->N; i++) { | |
- if (sim.sliders[i].mass <= 0.0) { | |
+ if (sim->sliders[i].mass <= 0.0) { | |
fprintf(stderr, "Error: Mass of slider %d is zero or negative " | |
- "(%f kg)\n", i, sim.sliders[i].mass); | |
+ "(%f kg)\n", i, sim->sliders[i].mass); | |
return_status = 1; | |
} | |
- if (sim.sliders[i].moment_of_inertia <= 0.0) { | |
+ if (sim->sliders[i].moment_of_inertia <= 0.0) { | |
fprintf(stderr, "Error: Moment of inertia of slider %d is " | |
"zero or negative (%f kg*m*m)\n", | |
- i, sim.sliders[i].moment_of_inertia); | |
+ i, sim->sliders[i].moment_of_inertia); | |
return_status = 1; | |
} | |
} | |
- | |
// General parameters | |
- if (sim.N <= 0) { | |
+ if (sim->N <= 0) { | |
fprintf(stderr, "Error: The number of sliders (N = %d) must be a " | |
- "positive number.\n", sim.N); | |
+ "positive number.\n", sim->N); | |
return_status = 1; | |
} | |
- if (sim.dt <= 0.0) { | |
+ if (sim->dt <= 0.0) { | |
fprintf(stderr, "Error: The numerical time step (dt = %f) must be a " | |
- "positive value.\n", sim.dt); | |
+ "positive value.\n", sim->dt); | |
return_status = 1; | |
} | |
- if (sim.dt > 1.0e9) { | |
+ if (sim->dt > 1.0e9) { | |
fprintf(stderr, "Error: The numerical time step (dt = %f) is " | |
- "invalid. Did you set bond_parallel_stiffness?\n", sim.dt); | |
+ "invalid. Did you set bond_parallel_stiffness?\n", sim->dt); | |
return_status = 1; | |
} | |
- if (sim.time > sim.time_end) { | |
+ if (sim->time > sim->time_end) { | |
fprintf(stderr, "Error: Current time (time = %f s) exceeds " | |
"total time (time_end = %f s)\n", | |
- sim.time, sim.time_end); | |
+ sim->time, sim->time_end); | |
return_status = 1; | |
} | |
- if (sim.bond_length_limit <= 0.0) { | |
+ if (sim->bond_length_limit <= 0.0) { | |
fprintf(stderr, "Error: The inter-slider bond length limit " | |
"(bond_length_limit = %f) must be a positive value.\n", | |
- sim.bond_length_limit); | |
+ sim->bond_length_limit); | |
return_status = 1; | |
} | |
- if (sim.file_interval < 0.0) { | |
+ if (sim->file_interval < 0.0) { | |
fprintf(stderr, "Error: The output file interval" | |
"(file_interval = %f) must be a zero or positive value.\n", | |
- sim.file_interval); | |
+ sim->file_interval); | |
return_status = 1; | |
} | |
t@@ -122,7 +121,7 @@ int save_slider_positions_to_file( | |
return 0; | |
} | |
-int save_general_state_to_file(const simulation sim, const char* filename) | |
+int save_general_state_to_file(const simulation* sim, const char* filename) | |
{ | |
FILE* f = fopen(filename, "w"); | |
if (f == NULL) { | |
t@@ -130,14 +129,14 @@ int save_general_state_to_file(const simulation sim, con… | |
return 1; | |
} | |
- fprintf(f, "id = %s\n", sim.id); | |
- fprintf(f, "N = %d\n", sim.N); | |
- fprintf(f, "time = %f\n", sim.time); | |
- fprintf(f, "time_end = %f\n", sim.time_end); | |
- fprintf(f, "dt = %f\n", sim.dt); | |
- fprintf(f, "file_interval = %f\n", sim.file_interval); | |
- fprintf(f, "iteration = %ld\n", sim.iteration); | |
- fprintf(f, "bond_length_limit = %f\n", sim.bond_length_limit); | |
+ fprintf(f, "id = %s\n", sim->id); | |
+ fprintf(f, "N = %d\n", sim->N); | |
+ fprintf(f, "time = %f\n", sim->time); | |
+ fprintf(f, "time_end = %f\n", sim->time_end); | |
+ fprintf(f, "dt = %f\n", sim->dt); | |
+ fprintf(f, "file_interval = %f\n", sim->file_interval); | |
+ fprintf(f, "iteration = %ld\n", sim->iteration); | |
+ fprintf(f, "bond_length_limit = %f\n", sim->bond_length_limit); | |
fclose(f); | |
return 0; | |
t@@ -314,7 +313,7 @@ int write_simulation_output(simulation* sim, char* output_… | |
// other parameters | |
sprintf(filename, "%s/%s.general.%06d.txt", | |
output_folder, sim->id, sim->file_number); | |
- if (save_general_state_to_file(*sim, filename)) { | |
+ if (save_general_state_to_file(sim, filename)) { | |
fprintf(stderr, "\nFatal error: Could not save to output file " | |
"'%s'.\n", filename); | |
return 1; | |
diff --git a/slidergrid/simulation.h b/slidergrid/simulation.h | |
t@@ -24,7 +24,7 @@ simulation create_simulation(); | |
Float find_time_step(const slider* sliders, const int N, const Float safety); | |
// check if simulation parameters have reasonable values | |
-int check_simulation_values(const simulation sim); | |
+int check_simulation_values(const simulation* sim); | |
// save slider positions to a file on the disk | |
int save_slider_positions_to_file( | |
t@@ -32,7 +32,7 @@ int save_slider_positions_to_file( | |
const int N, | |
const char* filename); | |
-int save_general_state_to_file(const simulation sim, const char* filename); | |
+int save_general_state_to_file(const simulation* sim, const char* filename); | |
int save_sliders_to_vtk_file( | |
const slider* sliders, |