diff --git a/examples/main.c b/examples/main.c index d7a6dd3d47a874d92fa5ed162ee1d67d5a56f2e0..995231789915fb26574dbccfc2696f8449a1e679 100644 --- a/examples/main.c +++ b/examples/main.c @@ -604,26 +604,6 @@ int main(int argc, char *argv[]) { if (with_cosmology) cosmology_init(params, &us, &prog_const, &cosmo); if (with_cosmology) cosmology_print(&cosmo); - // MATTHIEU START - struct engine ee; - ee.ti_current = 0; - ee.timeBase = (log(cosmo.a_end) - log(cosmo.a_begin)) / max_nr_timesteps; - cosmology_update(&cosmo, &ee); - - for (int i = 0; i <= 16; ++i) { - - ee.ti_current = (max_nr_timesteps / 16) * i; - - cosmology_update(&cosmo, &ee); - - message("z=%e H(z)=%e w=%f t=%e [yrs] t_l=%e [yrs]", cosmo.z, cosmo.H, - cosmo.w, cosmo.time / prog_const.const_year, - cosmo.lookback_time / prog_const.const_year); - } - - return 0; - // MATTHIEU END - /* Initialise the hydro properties */ if (with_hydro) hydro_props_init(&hydro_properties, params); if (with_hydro) eos_init(&eos, params); diff --git a/src/chemistry.c b/src/chemistry.c index 35a30d8301d92120498da3aa358c1cc3d617eee4..091a0b363d16507894f3dcbba2ca79860f3cbaa9 100644 --- a/src/chemistry.c +++ b/src/chemistry.c @@ -51,3 +51,28 @@ void chemistry_init(const struct swift_params* parameter_file, void chemistry_print(const struct chemistry_data* data) { chemistry_print_backend(data); } + +/** + * @brief Write a chemistry struct to the given FILE as a stream of bytes. + * + * @param chemistry the struct + * @param stream the file stream + */ +void chemistry_struct_dump(const struct chemistry_data* chemistry, + FILE* stream) { + restart_write_blocks((void*)chemistry, sizeof(struct chemistry_data), 1, + stream, "chemistry", "chemistry function"); +} + +/** + * @brief Restore a hydro_props struct from the given FILE as a stream of + * bytes. + * + * @param chemistry the struct + * @param stream the file stream + */ +void chemistry_struct_restore(const struct chemistry_data* chemistry, + FILE* stream) { + restart_read_blocks((void*)chemistry, sizeof(struct chemistry_data), 1, + stream, NULL, "chemistry function"); +} diff --git a/src/chemistry.h b/src/chemistry.h index b7a17bdb313f3b5ddc2416cdc7a729e4f8916ffe..b4571e61e80004bdb64e088394f409219c18ea5c 100644 --- a/src/chemistry.h +++ b/src/chemistry.h @@ -47,4 +47,10 @@ void chemistry_init(const struct swift_params* parameter_file, void chemistry_print(const struct chemistry_data* data); +/* Dump/restore. */ +void chemistry_struct_dump(const struct chemistry_data* chemistry, + FILE* stream); +void chemistry_struct_restore(const struct chemistry_data* chemistry, + FILE* stream); + #endif /* SWIFT_CHEMISTRY_H */ diff --git a/src/cooling.c b/src/cooling.c index 89a04b30f8ce3f106d90a6db1364a3caadba6deb..57d1928a5d59ac2ff46c6cd20a45d69dec25ec60 100644 --- a/src/cooling.c +++ b/src/cooling.c @@ -55,7 +55,7 @@ void cooling_print(const struct cooling_function_data* cooling) { } /** - * @brief Write a hydro_props struct to the given FILE as a stream of bytes. + * @brief Write a cooling struct to the given FILE as a stream of bytes. * * @param cooling the struct * @param stream the file stream diff --git a/src/cosmology.c b/src/cosmology.c index 44c1f493c386c4ef25b1c2690d9d8d77cbdf9524..fcfe75b4ca5111c0f38067c10077a60759a0c39d 100644 --- a/src/cosmology.c +++ b/src/cosmology.c @@ -31,6 +31,7 @@ /* Local headers */ #include "adiabatic_index.h" #include "inline.h" +#include "restart.h" #ifdef HAVE_LIBGSL #include <gsl/gsl_integration.h> @@ -417,22 +418,6 @@ void cosmology_init(const struct swift_params *params, c->time_interp_table_offset = 0.; cosmology_init_tables(c); } - -/** - * @brief Prints the #cosmology model to stdout. - */ -void cosmology_print(const struct cosmology *c) { - - message( - "Density parameters: [O_m, O_l, O_b, O_k, O_r] = [%f, %f, %f, %f, %f]", - c->Omega_m, c->Omega_lambda, c->Omega_b, c->Omega_k, c->Omega_r); - message("Dark energy equation of state: w_0=%f w_a=%f", c->w_0, c->w_a); - message("Hubble constant: h = %f, H_0 = %e U_t^(-1)", c->h, c->H0); - message("Hubble time: 1/H0 = %e U_t", c->Hubble_time); - message("Universe age at present day: %e U_t", - c->universe_age_at_present_day); -} - /** * @brief Computes the cosmology factor that enters the drift operator. * @@ -531,3 +516,41 @@ double cosmology_get_delta_time(const struct cosmology *c, double a1, return t2 - t1; } + +/** + * @brief Prints the #cosmology model to stdout. + */ +void cosmology_print(const struct cosmology *c) { + + message( + "Density parameters: [O_m, O_l, O_b, O_k, O_r] = [%f, %f, %f, %f, %f]", + c->Omega_m, c->Omega_lambda, c->Omega_b, c->Omega_k, c->Omega_r); + message("Dark energy equation of state: w_0=%f w_a=%f", c->w_0, c->w_a); + message("Hubble constant: h = %f, H_0 = %e U_t^(-1)", c->h, c->H0); + message("Hubble time: 1/H0 = %e U_t", c->Hubble_time); + message("Universe age at present day: %e U_t", + c->universe_age_at_present_day); +} + +/** + * @brief Write a cosmology struct to the given FILE as a stream of bytes. + * + * @param cosmology the struct + * @param stream the file stream + */ +void cosmology_struct_dump(const struct cosmology *cosmology, FILE *stream) { + restart_write_blocks((void *)cosmology, sizeof(struct cosmology), 1, stream, + "cosmology", "cosmology function"); +} + +/** + * @brief Restore a cosmology struct from the given FILE as a stream of + * bytes. + * + * @param cosmology the struct + * @param stream the file stream + */ +void cosmology_struct_restore(const struct cosmology *cosmology, FILE *stream) { + restart_read_blocks((void *)cosmology, sizeof(struct cosmology), 1, stream, + NULL, "cosmology function"); +} diff --git a/src/cosmology.h b/src/cosmology.h index 3a096225914a97b457d4699b2febeaa0e3bc35bf..eae0f8c8e52504fa9e7bbbca1e6bd627cb7ebdc9 100644 --- a/src/cosmology.h +++ b/src/cosmology.h @@ -141,4 +141,8 @@ void cosmology_init(const struct swift_params *params, void cosmology_print(const struct cosmology *c); +/* Dump/restore. */ +void cosmology_struct_dump(const struct cosmology *cosmology, FILE *stream); +void cosmology_struct_restore(const struct cosmology *cosmology, FILE *stream); + #endif /* SWIFT_COSMOLOGY_H */ diff --git a/src/engine.c b/src/engine.c index 7967bdf01aa726655326998eb020a0ed0492ba31..69c5a5d49ff5841df1bcaced94a18742eb6c3e3c 100644 --- a/src/engine.c +++ b/src/engine.c @@ -51,8 +51,10 @@ #include "active.h" #include "atomic.h" #include "cell.h" +#include "chemistry.h" #include "clocks.h" #include "cooling.h" +#include "cosmology.h" #include "cycle.h" #include "debug.h" #include "error.h" @@ -5806,6 +5808,7 @@ void engine_struct_dump(struct engine *e, FILE *stream) { space_struct_dump(e->s, stream); units_struct_dump(e->internal_units, stream); units_struct_dump(e->snapshotUnits, stream); + cosmology_struct_dump(e->cosmology, stream); #ifdef WITH_MPI /* Save the partition for restoration. */ @@ -5818,6 +5821,7 @@ void engine_struct_dump(struct engine *e, FILE *stream) { gravity_props_struct_dump(e->gravity_properties, stream); potential_struct_dump(e->external_potential, stream); cooling_struct_dump(e->cooling_func, stream); + chemistry_struct_dump(e->chemistry, stream); sourceterms_struct_dump(e->sourceterms, stream); parser_struct_dump(e->parameter_file, stream); } @@ -5856,6 +5860,10 @@ void engine_struct_restore(struct engine *e, FILE *stream) { units_struct_restore(us, stream); e->snapshotUnits = us; + struct cosmology *cosmo = malloc(sizeof(struct cosmology)); + cosmology_struct_restore(cosmo, stream); + e->cosmology = cosmo; + #ifdef WITH_MPI struct repartition *reparttype = malloc(sizeof(struct repartition)); partition_struct_restore(reparttype, stream); @@ -5885,6 +5893,10 @@ void engine_struct_restore(struct engine *e, FILE *stream) { cooling_struct_restore(cooling_func, stream); e->cooling_func = cooling_func; + struct chemistry_data *chemistry = malloc(sizeof(struct chemistry_data)); + chemistry_struct_restore(chemistry, stream); + e->chemistry = chemistry; + struct sourceterms *sourceterms = malloc(sizeof(struct sourceterms)); sourceterms_struct_restore(sourceterms, stream); e->sourceterms = sourceterms;