diff --git a/src/engine.c b/src/engine.c index d6fb46f9c096c64ecd2f5dac456b1a3dbccd03db..ac43011499aa924c74bf004084b9387774bed2d4 100644 --- a/src/engine.c +++ b/src/engine.c @@ -6295,6 +6295,7 @@ void engine_struct_dump(struct engine *e, FILE *stream) { phys_const_struct_dump(e->physical_constants, stream); hydro_props_struct_dump(e->hydro_properties, stream); gravity_props_struct_dump(e->gravity_properties, stream); + pm_mesh_struct_dump(e->mesh, stream); potential_struct_dump(e->external_potential, stream); cooling_struct_dump(e->cooling_func, stream); chemistry_struct_dump(e->chemistry, stream); @@ -6364,6 +6365,10 @@ void engine_struct_restore(struct engine *e, FILE *stream) { gravity_props_struct_restore(gravity_properties, stream); e->gravity_properties = gravity_properties; + struct pm_mesh *mesh = (struct pm_mesh *)malloc(sizeof(struct pm_mesh)); + pm_mesh_struct_restore(mesh, stream); + e->mesh = mesh; + struct external_potential *external_potential = (struct external_potential *)malloc(sizeof(struct external_potential)); potential_struct_restore(external_potential, stream); diff --git a/src/gravity_properties.c b/src/gravity_properties.c index 5e0fa238a8434740cf35b98e1b83cbd59588f08f..84ce90f7270d1651f4ef33b9b716772125e71ab0 100644 --- a/src/gravity_properties.c +++ b/src/gravity_properties.c @@ -190,7 +190,7 @@ void gravity_props_struct_dump(const struct gravity_props *p, FILE *stream) { * @param p the struct * @param stream the file stream */ -void gravity_props_struct_restore(const struct gravity_props *p, FILE *stream) { +void gravity_props_struct_restore(struct gravity_props *p, FILE *stream) { restart_read_blocks((void *)p, sizeof(struct gravity_props), 1, stream, NULL, "gravity props"); } diff --git a/src/gravity_properties.h b/src/gravity_properties.h index 59491eca21d8bc4e8dc3a75f99226e700106c671..1d230b8c372a1503acc42515f8fbeb06445247db 100644 --- a/src/gravity_properties.h +++ b/src/gravity_properties.h @@ -27,10 +27,12 @@ #endif /* Local includes. */ -#include "cosmology.h" -#include "parser.h" #include "restart.h" +/* Forward declarations */ +struct cosmology; +struct swift_params; + /** * @brief Contains all the constants and parameters of the self-gravity scheme */ @@ -96,6 +98,6 @@ void gravity_props_print_snapshot(hid_t h_grpsph, /* Dump/restore. */ void gravity_props_struct_dump(const struct gravity_props *p, FILE *stream); -void gravity_props_struct_restore(const struct gravity_props *p, FILE *stream); +void gravity_props_struct_restore(struct gravity_props *p, FILE *stream); #endif /* SWIFT_GRAVITY_PROPERTIES */ diff --git a/src/mesh_gravity.c b/src/mesh_gravity.c index 4f5ff463543a0484229cde131de17cbc6a98405b..be38c00cb8379baea4f7de31efd18cefacc1562b 100644 --- a/src/mesh_gravity.c +++ b/src/mesh_gravity.c @@ -509,3 +509,39 @@ void pm_mesh_clean(struct pm_mesh* mesh) { if (mesh->potential) free(mesh->potential); mesh->potential = 0; } + +/** + * @brief Write a #pm_mesh struct to the given FILE as a stream of bytes. + * + * @param p the struct + * @param stream the file stream + */ +void pm_mesh_struct_dump(const struct pm_mesh* mesh, FILE* stream) { + restart_write_blocks((void*)mesh, sizeof(struct pm_mesh), 1, stream, + "gravity", "gravity props"); +} + +/** + * @brief Restore a #pm_mesh struct from the given FILE as a stream of + * bytes. + * + * @param p the struct + * @param stream the file stream + */ +void pm_mesh_struct_restore(struct pm_mesh* mesh, FILE* stream) { + + restart_read_blocks((void*)mesh, sizeof(struct pm_mesh), 1, stream, NULL, + "gravity props"); + + const int N = mesh->N; + + /* Allocate the memory for the combined density and potential array */ + mesh->potential = (double*)fftw_malloc(sizeof(double) * N * N * N); + if (mesh->potential == NULL) + error("Error allocating memory for the long-range gravity mesh."); + +#ifdef HAVE_FFTW +#else + error("No FFTW library found. Cannot compute periodic long-range forces."); +#endif +} diff --git a/src/mesh_gravity.h b/src/mesh_gravity.h index d04ab26e6d4c730b9f1e8fa6492b09a445719f0b..8cc4cd753ccfb24f80f997dd389f2e5569c7dce1 100644 --- a/src/mesh_gravity.h +++ b/src/mesh_gravity.h @@ -24,6 +24,7 @@ /* Local headers */ #include "gravity_properties.h" +#include "restart.h" /* Forward declarations */ struct engine; @@ -71,4 +72,8 @@ void pm_mesh_interpolate_forces(const struct pm_mesh *mesh, int gcount); void pm_mesh_clean(struct pm_mesh *mesh); +/* Dump/restore. */ +void pm_mesh_struct_dump(const struct pm_mesh *p, FILE *stream); +void pm_mesh_struct_restore(struct pm_mesh *p, FILE *stream); + #endif /* SWIFT_MESH_GRAVITY_H */