tsave initial conditions, add function to write all output files - slidergrid -… | |
git clone git://src.adamsgaard.dk/slidergrid | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 695b94d0b8c81fbbcfca476c06eda313facaf72c | |
parent 153343f86817343c65a421adafecbb2769977911 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Thu, 17 Mar 2016 16:41:37 -0700 | |
save initial conditions, add function to write all output files | |
Diffstat: | |
M Makefile | 5 +++-- | |
M slidergrid/main.c | 38 ++++++++---------------------… | |
M slidergrid/simulation.c | 34 +++++++++++++++++++++++++++++… | |
M slidergrid/simulation.h | 2 ++ | |
4 files changed, 49 insertions(+), 30 deletions(-) | |
--- | |
diff --git a/Makefile b/Makefile | |
t@@ -14,8 +14,8 @@ default: run-test | |
run-test: test | |
./$< | |
- #python postprocessing.py --plot-sliders $<-output | |
- | |
+ @#python postprocessing.py --plot-sliders $<-output | |
+ @#rsync -rav test-output /var/www/html/ | |
test: test.o $(ESSENTIALOBJS) | |
$(CC) $(LDLIBS) $^ -o $@ | |
t@@ -29,5 +29,6 @@ debug: $(BIN) | |
clean: | |
@$(RM) $(BIN) | |
+ @$(RM) -r $(BIN)-output | |
@$(RM) *.o | |
@$(RM) $(SRCFOLDER)*.o | |
diff --git a/slidergrid/main.c b/slidergrid/main.c | |
t@@ -112,11 +112,17 @@ int main(int argc, char** argv) | |
} | |
} | |
+ // save initial conditions to output files | |
+ if (write_simulation_output(sim, output_folder)) { | |
+ fprintf(stderr, "\nFatal error: Could not write one or more " | |
+ "output files.\n"); | |
+ return EXIT_FAILURE; | |
+ } | |
+ | |
// main temporal loop | |
sim.iteration = 0; | |
Float time_since_status = 0.0; | |
Float time_since_file = 0.0; | |
- char filename[1000]; | |
for (sim.time = 0.0; | |
sim.time <= sim.time_end; | |
sim.time += sim.dt) { | |
t@@ -136,36 +142,12 @@ int main(int argc, char** argv) | |
} | |
if (time_since_file >= sim.file_interval) { | |
- | |
- // slider parameters | |
- sprintf(filename, "%s/%s.sliders.%06d.txt", | |
- output_folder, sim.id, sim.file_number); | |
- if (save_slider_positions_to_file(sim.sliders, sim.N, filename)) { | |
- fprintf(stderr, "\nFatal error: Could not save to output file " | |
- "'%s'.\n", filename); | |
+ if (write_simulation_output(sim, output_folder)) { | |
+ fprintf(stderr, "\nFatal error: Could not write one or more " | |
+ "output files.\n"); | |
return EXIT_FAILURE; | |
} | |
- | |
- // other parameters | |
- sprintf(filename, "%s/%s.general.%06d.txt", | |
- output_folder, sim.id, sim.file_number); | |
- if (save_general_state_to_file(sim, filename)) { | |
- fprintf(stderr, "\nFatal error: Could not save to output file " | |
- "'%s'.\n", filename); | |
- return EXIT_FAILURE; | |
- } | |
- | |
- // sliders to VTK file | |
- sprintf(filename, "%s/%s.sliders.%06d.vtu", | |
- output_folder, sim.id, sim.file_number); | |
- if (save_sliders_to_vtk_file(sim.sliders, sim.N, filename)) { | |
- fprintf(stderr, "\nFatal error: Could not save to output file " | |
- "'%s'.\n", filename); | |
- return EXIT_FAILURE; | |
- } | |
- | |
time_since_file = 0.0; | |
- sim.file_number++; | |
} | |
if (verbose) { | |
diff --git a/slidergrid/simulation.c b/slidergrid/simulation.c | |
t@@ -298,3 +298,37 @@ int save_sliders_to_vtk_file( | |
return 0; | |
} | |
+int write_simulation_output(simulation sim, char* output_folder) | |
+{ | |
+ char filename[1000]; | |
+ | |
+ // slider parameters | |
+ sprintf(filename, "%s/%s.sliders.%06d.txt", | |
+ output_folder, sim.id, sim.file_number); | |
+ if (save_slider_positions_to_file(sim.sliders, sim.N, filename)) { | |
+ fprintf(stderr, "\nFatal error: Could not save to output file " | |
+ "'%s'.\n", filename); | |
+ return 1; | |
+ } | |
+ | |
+ // other parameters | |
+ sprintf(filename, "%s/%s.general.%06d.txt", | |
+ output_folder, sim.id, sim.file_number); | |
+ if (save_general_state_to_file(sim, filename)) { | |
+ fprintf(stderr, "\nFatal error: Could not save to output file " | |
+ "'%s'.\n", filename); | |
+ return 1; | |
+ } | |
+ | |
+ // sliders to VTK file | |
+ sprintf(filename, "%s/%s.sliders.%06d.vtu", | |
+ output_folder, sim.id, sim.file_number); | |
+ if (save_sliders_to_vtk_file(sim.sliders, sim.N, filename)) { | |
+ fprintf(stderr, "\nFatal error: Could not save to output file " | |
+ "'%s'.\n", filename); | |
+ return 1; | |
+ } | |
+ | |
+ sim.file_number++; | |
+ return 0; | |
+} | |
diff --git a/slidergrid/simulation.h b/slidergrid/simulation.h | |
t@@ -39,6 +39,8 @@ int save_sliders_to_vtk_file( | |
const int N, | |
const char* filename); | |
+int write_simulation_output(simulation sim, char* output_folder); | |
+ | |
// user-defined function which sets up the simulation | |
simulation setup_simulation(); | |