From 55c2f97bfed04355691294eaa2745b33007df0ee Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" <p.w.draper@durham.ac.uk> Date: Wed, 17 Jan 2018 18:12:05 +0000 Subject: [PATCH] Dump engine physical constants --- src/engine.c | 5 ++--- src/physical_constants.c | 29 +++++++++++++++++++++++++++++ src/physical_constants.h | 4 ++++ src/restart.h | 4 ++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/engine.c b/src/engine.c index 330e626ae4..74459541ec 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5644,9 +5644,8 @@ void engine_struct_dump(struct engine *e, FILE *stream) { units_struct_dump(e->internal_units, stream); units_struct_dump(e->snapshotUnits, stream); partition_struct_dump(e->reparttype, stream); + phys_const_struct_dump(e->physical_constants, stream); - /* repartition */ - /* physical constants */ /* hydro props */ /* gravity props */ /* external potential props */ @@ -5689,8 +5688,8 @@ void engine_struct_restore(struct engine *e, FILE *stream) { units_struct_restore(e->internal_units, stream); units_struct_restore(e->snapshotUnits, stream); partition_struct_restore(e->reparttype, stream); + phys_const_struct_restore(e->physical_constants, stream); - /* physical constants */ /* hydro props */ /* gravity props */ /* external potential props */ diff --git a/src/physical_constants.c b/src/physical_constants.c index c851578c96..8d1460b67a 100644 --- a/src/physical_constants.c +++ b/src/physical_constants.c @@ -27,6 +27,7 @@ /* Local headers. */ #include "error.h" #include "physical_constants_cgs.h" +#include "restart.h" /** * @brief Converts physical constants to the internal unit system @@ -121,3 +122,31 @@ void phys_const_print(struct phys_const* internal_const) { message("%25s = %e", "Parsec", internal_const->const_parsec); message("%25s = %e", "Solar mass", internal_const->const_solar_mass); } + +/** + * @brief Write a phys_const struct to the given FILE as a stream of bytes. + * + * @param internal_const the struct + * @param stream the file stream + */ +void phys_const_struct_dump(const struct phys_const *internal_const, + FILE *stream) { + restart_write_blocks((void *) internal_const, sizeof(struct phys_const), + 1, stream, + "phys_const params"); +} + + +/** + * @brief Restore a phys_const struct from the given FILE as a stream of + * bytes. + * + * @param internal_const the struct + * @param stream the file stream + */ +void phys_const_struct_restore(const struct phys_const *internal_const, + FILE *stream) { + restart_read_blocks((void *)internal_const, sizeof(struct phys_const), + 1, stream, + "phys_const params"); +} diff --git a/src/physical_constants.h b/src/physical_constants.h index 3731c0ef56..79f341a8b8 100644 --- a/src/physical_constants.h +++ b/src/physical_constants.h @@ -82,4 +82,8 @@ void phys_const_init(struct unit_system* us, struct phys_const* internal_const); void phys_const_print(struct phys_const* internal_const); +/* Dump/restore. */ +void phys_const_struct_dump(const struct phys_const* internal_const, FILE *stream); +void phys_const_struct_restore(const struct phys_const* internal_const, FILE *stream); + #endif /* SWIFT_PHYSICAL_CONSTANTS_H */ diff --git a/src/restart.h b/src/restart.h index 579ca582c1..124c5f425f 100644 --- a/src/restart.h +++ b/src/restart.h @@ -19,6 +19,10 @@ #ifndef SWIFT_RESTART_H #define SWIFT_RESTART_H +#include <stdio.h> + +#include "engine.h" + void restart_write(struct engine *e, const char *filename); void restart_read(struct engine *e, const char *filename); -- GitLab