Commit 80ec719d authored by lhausamm's avatar lhausamm

Rebasing corrections

parent f5d2a8bb
...@@ -124,7 +124,7 @@ int main(int argc, char *argv[]) { ...@@ -124,7 +124,7 @@ int main(int argc, char *argv[]) {
/* Structs used by the engine. Declare now to make sure these are always in /* Structs used by the engine. Declare now to make sure these are always in
* scope. */ * scope. */
struct chemistry_data chemistry; struct chemistry_global_data chemistry;
struct cooling_function_data cooling_func; struct cooling_function_data cooling_func;
struct cosmology cosmo; struct cosmology cosmo;
struct external_potential potential; struct external_potential potential;
......
...@@ -58,9 +58,9 @@ void chemistry_print(const struct chemistry_global_data* data) { ...@@ -58,9 +58,9 @@ void chemistry_print(const struct chemistry_global_data* data) {
* @param chemistry the struct * @param chemistry the struct
* @param stream the file stream * @param stream the file stream
*/ */
void chemistry_struct_dump(const struct chemistry_data* chemistry, void chemistry_struct_dump(const struct chemistry_global_data* chemistry,
FILE* stream) { FILE* stream) {
restart_write_blocks((void*)chemistry, sizeof(struct chemistry_data), 1, restart_write_blocks((void*)chemistry, sizeof(struct chemistry_global_data), 1,
stream, "chemistry", "chemistry function"); stream, "chemistry", "chemistry function");
} }
...@@ -71,8 +71,8 @@ void chemistry_struct_dump(const struct chemistry_data* chemistry, ...@@ -71,8 +71,8 @@ void chemistry_struct_dump(const struct chemistry_data* chemistry,
* @param chemistry the struct * @param chemistry the struct
* @param stream the file stream * @param stream the file stream
*/ */
void chemistry_struct_restore(const struct chemistry_data* chemistry, void chemistry_struct_restore(const struct chemistry_global_data* chemistry,
FILE* stream) { FILE* stream) {
restart_read_blocks((void*)chemistry, sizeof(struct chemistry_data), 1, restart_read_blocks((void*)chemistry, sizeof(struct chemistry_global_data), 1,
stream, NULL, "chemistry function"); stream, NULL, "chemistry function");
} }
...@@ -51,9 +51,9 @@ void chemistry_init(const struct swift_params* parameter_file, ...@@ -51,9 +51,9 @@ void chemistry_init(const struct swift_params* parameter_file,
void chemistry_print(const struct chemistry_global_data* data); void chemistry_print(const struct chemistry_global_data* data);
/* Dump/restore. */ /* Dump/restore. */
void chemistry_struct_dump(const struct chemistry_data* chemistry, void chemistry_struct_dump(const struct chemistry_global_data* chemistry,
FILE* stream); FILE* stream);
void chemistry_struct_restore(const struct chemistry_data* chemistry, void chemistry_struct_restore(const struct chemistry_global_data* chemistry,
FILE* stream); FILE* stream);
#endif /* SWIFT_CHEMISTRY_H */ #endif /* SWIFT_CHEMISTRY_H */
...@@ -38,18 +38,6 @@ ...@@ -38,18 +38,6 @@
#include "physical_constants.h" #include "physical_constants.h"
#include "units.h" #include "units.h"
/**
* @brief Return a string containing the name of a given #chemistry_element.
*/
__attribute__((always_inline)) INLINE static const char*
chemistry_get_element_name(enum chemistry_element elem) {
static const char* chemistry_element_names[chemistry_element_count] = {
"Oxygen", "Magnesium", "Sulfur", "Iron", "Zinc",
"Strontium", "Yttrium", "Barium", "Europium"};
return chemistry_element_names[elem];
}
/** /**
* @brief Compute the metal mass fraction * @brief Compute the metal mass fraction
...@@ -81,16 +69,6 @@ static INLINE void chemistry_init_backend( ...@@ -81,16 +69,6 @@ static INLINE void chemistry_init_backend(
chemistry_read_parameters(parameter_file, us, phys_const, data); chemistry_read_parameters(parameter_file, us, phys_const, data);
} }
/**
* @brief Prints the properties of the chemistry model to stdout.
*
* @brief The #chemistry_global_data containing information about the current model.
*/
static INLINE void chemistry_print_backend(const struct chemistry_global_data* data) {
message("Chemistry function is 'Gear'.");
}
/** /**
* @brief Prepares a particle for the smooth metal calculation. * @brief Prepares a particle for the smooth metal calculation.
* *
...@@ -155,8 +133,11 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density( ...@@ -155,8 +133,11 @@ __attribute__((always_inline)) INLINE static void chemistry_end_density(
* @param data The global chemistry information. * @param data The global chemistry information.
*/ */
__attribute__((always_inline)) INLINE static void chemistry_first_init_part( __attribute__((always_inline)) INLINE static void chemistry_first_init_part(
struct part* restrict p, struct xpart* restrict xp, const struct phys_const* restrict phys_const,
const struct chemistry_global_data* data) { const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct chemistry_global_data* data,
struct part* restrict p, struct xpart* restrict xp) {
p->chemistry_data.Z = data->initial_metallicity; p->chemistry_data.Z = data->initial_metallicity;
chemistry_init_part(p, data); chemistry_init_part(p, data);
......
...@@ -19,14 +19,37 @@ ...@@ -19,14 +19,37 @@
#ifndef SWIFT_CHEMISTRY_IO_GEAR_H #ifndef SWIFT_CHEMISTRY_IO_GEAR_H
#define SWIFT_CHEMISTRY_IO_GEAR_H #define SWIFT_CHEMISTRY_IO_GEAR_H
#include "chemistry.h"
#include "chemistry_struct.h" #include "chemistry_struct.h"
#include "error.h"
#include "io_properties.h" #include "io_properties.h"
#include "parser.h" #include "parser.h"
#include "part.h" #include "part.h"
#include "physical_constants.h" #include "physical_constants.h"
#include "units.h" #include "units.h"
/**
* @brief Return a string containing the name of a given #chemistry_element.
*/
__attribute__((always_inline)) INLINE static const char*
chemistry_get_element_name(enum chemistry_element elem) {
static const char* chemistry_element_names[chemistry_element_count] = {
"Oxygen", "Magnesium", "Sulfur", "Iron", "Zinc",
"Strontium", "Yttrium", "Barium", "Europium"};
return chemistry_element_names[elem];
}
/**
* @brief Prints the properties of the chemistry model to stdout.
*
* @brief The #chemistry_global_data containing information about the current model.
*/
static INLINE void chemistry_print_backend(const struct chemistry_global_data* data) {
message("Chemistry function is 'Gear'.");
}
/** /**
* @brief Specifies which particle fields to read from a dataset * @brief Specifies which particle fields to read from a dataset
* *
...@@ -91,7 +114,7 @@ __attribute__((always_inline)) INLINE static int chemistry_write_particles( ...@@ -91,7 +114,7 @@ __attribute__((always_inline)) INLINE static int chemistry_write_particles(
* @param h_grp The HDF5 group in which to write * @param h_grp The HDF5 group in which to write
*/ */
__attribute__((always_inline)) INLINE static void chemistry_write_flavour( __attribute__((always_inline)) INLINE static void chemistry_write_flavour(
hid_t h_grpsph) { hid_t h_grp) {
io_write_attribute_s(h_grp, "Chemistry Model", "GEAR"); io_write_attribute_s(h_grp, "Chemistry Model", "GEAR");
for (enum chemistry_element i = chemistry_element_O; for (enum chemistry_element i = chemistry_element_O;
......
...@@ -47,12 +47,16 @@ ...@@ -47,12 +47,16 @@
/* prototypes */ /* prototypes */
static gr_float cooling_time( static gr_float cooling_time(
const struct phys_const* restrict phys_const,
const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* restrict cooling, const struct cooling_function_data* restrict cooling,
const struct part* restrict p, struct xpart* restrict xp); const struct part* restrict p, struct xpart* restrict xp);
static double cooling_rate( static double cooling_rate(
const struct phys_const* restrict phys_const, const struct phys_const* restrict phys_const,
const struct unit_system* restrict us, const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* restrict cooling, const struct cooling_function_data* restrict cooling,
const struct part* restrict p, struct xpart* restrict xp, double dt); const struct part* restrict p, struct xpart* restrict xp, double dt);
...@@ -144,9 +148,12 @@ __attribute__((always_inline)) INLINE static int cooling_converged( ...@@ -144,9 +148,12 @@ __attribute__((always_inline)) INLINE static int cooling_converged(
* @param cooling The properties of the cooling function. * @param cooling The properties of the cooling function.
*/ */
__attribute__((always_inline)) INLINE static void cooling_compute_equilibrium( __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium(
const struct phys_const* restrict phys_const,
const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* restrict cooling,
const struct part* restrict p, const struct part* restrict p,
struct xpart* restrict xp, struct xpart* restrict xp) {
const struct cooling_function_data* cooling) {
/* get temporary data */ /* get temporary data */
struct part p_tmp = *p; struct part p_tmp = *p;
...@@ -157,9 +164,9 @@ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium( ...@@ -157,9 +164,9 @@ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium(
/* compute time step */ /* compute time step */
const double alpha = 0.01; const double alpha = 0.01;
double dt = fabs(cooling_time(&cooling_tmp, &p_tmp, xp)); double dt = fabs(cooling_time(phys_const, us, cosmo, &cooling_tmp, &p_tmp, xp));
cooling_rate(NULL, NULL, &cooling_tmp, &p_tmp, xp, dt); cooling_rate(phys_const, us, cosmo, &cooling_tmp, &p_tmp, xp, dt);
dt = alpha * fabs(cooling_time(&cooling_tmp, &p_tmp, xp)); dt = alpha * fabs(cooling_time(phys_const, us, cosmo, &cooling_tmp, &p_tmp, xp));
/* init simple variables */ /* init simple variables */
int step = 0; int step = 0;
...@@ -173,7 +180,7 @@ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium( ...@@ -173,7 +180,7 @@ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium(
old = *xp; old = *xp;
/* update chemistry */ /* update chemistry */
cooling_rate(NULL, NULL, &cooling_tmp, &p_tmp, xp, dt); cooling_rate(phys_const, us, cosmo, &cooling_tmp, &p_tmp, xp, dt);
} while (step < max_step && !cooling_converged(xp, &old, conv_limit)); } while (step < max_step && !cooling_converged(xp, &old, conv_limit));
if (step == max_step) if (step == max_step)
...@@ -191,8 +198,11 @@ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium( ...@@ -191,8 +198,11 @@ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium(
* @param cooling The properties of the cooling function. * @param cooling The properties of the cooling function.
*/ */
__attribute__((always_inline)) INLINE static void cooling_first_init_part( __attribute__((always_inline)) INLINE static void cooling_first_init_part(
const struct part* restrict p, struct xpart* restrict xp, const struct phys_const* restrict phys_const,
const struct cooling_function_data* cooling) { const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* cooling,
const struct part* restrict p, struct xpart* restrict xp) {
xp->cooling_data.radiated_energy = 0.f; xp->cooling_data.radiated_energy = 0.f;
...@@ -226,7 +236,7 @@ __attribute__((always_inline)) INLINE static void cooling_first_init_part( ...@@ -226,7 +236,7 @@ __attribute__((always_inline)) INLINE static void cooling_first_init_part(
#endif // MODE >= 3 #endif // MODE >= 3
#if COOLING_GRACKLE_MODE > 0 #if COOLING_GRACKLE_MODE > 0
cooling_compute_equilibrium(p, xp, cooling); cooling_compute_equilibrium(phys_const, us, cosmo, p, xp, cooling);
#endif #endif
} }
...@@ -567,6 +577,9 @@ __attribute__((always_inline)) INLINE static gr_float cooling_rate( ...@@ -567,6 +577,9 @@ __attribute__((always_inline)) INLINE static gr_float cooling_rate(
* @return cooling time * @return cooling time
*/ */
__attribute__((always_inline)) INLINE static gr_float cooling_time( __attribute__((always_inline)) INLINE static gr_float cooling_time(
const struct phys_const* restrict phys_const,
const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* restrict cooling, const struct cooling_function_data* restrict cooling,
const struct part* restrict p, struct xpart* restrict xp) { const struct part* restrict p, struct xpart* restrict xp) {
...@@ -592,8 +605,8 @@ __attribute__((always_inline)) INLINE static gr_float cooling_time( ...@@ -592,8 +605,8 @@ __attribute__((always_inline)) INLINE static gr_float cooling_time(
data.grid_end = grid_end; data.grid_end = grid_end;
/* general particle data */ /* general particle data */
const gr_float energy_before = hydro_get_internal_energy(p); const gr_float energy_before = hydro_get_physical_internal_energy(p, cosmo);
gr_float density = hydro_get_density(p); gr_float density = hydro_get_physical_density(p, cosmo);
gr_float energy = energy_before; gr_float energy = energy_before;
/* initialize density */ /* initialize density */
...@@ -646,7 +659,7 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part( ...@@ -646,7 +659,7 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
const float hydro_du_dt = hydro_get_internal_energy_dt(p); const float hydro_du_dt = hydro_get_internal_energy_dt(p);
/* compute cooling rate */ /* compute cooling rate */
const float du_dt = cooling_rate(phys_const, us, cosmo, cooling, p, dt); const float du_dt = cooling_rate(phys_const, us, cosmo, cooling, p, xp, dt);
/* record energy lost */ /* record energy lost */
xp->cooling_data.radiated_energy += -du_dt * dt * hydro_get_mass(p); xp->cooling_data.radiated_energy += -du_dt * dt * hydro_get_mass(p);
......
...@@ -5965,8 +5965,8 @@ void engine_struct_restore(struct engine *e, FILE *stream) { ...@@ -5965,8 +5965,8 @@ void engine_struct_restore(struct engine *e, FILE *stream) {
cooling_struct_restore(cooling_func, stream); cooling_struct_restore(cooling_func, stream);
e->cooling_func = cooling_func; e->cooling_func = cooling_func;
struct chemistry_data *chemistry = struct chemistry_global_data *chemistry =
(struct chemistry_data *)malloc(sizeof(struct chemistry_data)); (struct chemistry_global_data *)malloc(sizeof(struct chemistry_global_data));
chemistry_struct_restore(chemistry, stream); chemistry_struct_restore(chemistry, stream);
e->chemistry = chemistry; e->chemistry = chemistry;
......
...@@ -656,7 +656,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { ...@@ -656,7 +656,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) {
const struct space *s = e->s; const struct space *s = e->s;
const struct hydro_space *hs = &s->hs; const struct hydro_space *hs = &s->hs;
const struct cosmology *cosmo = e->cosmology; const struct cosmology *cosmo = e->cosmology;
const struct chemistry_data *chemistry = e->chemistry; const struct chemistry_global_data *chemistry = e->chemistry;
const float hydro_h_max = e->hydro_properties->h_max; const float hydro_h_max = e->hydro_properties->h_max;
const float eps = e->hydro_properties->h_tolerance; const float eps = e->hydro_properties->h_tolerance;
const float hydro_eta_dim = const float hydro_eta_dim =
......
...@@ -2648,6 +2648,8 @@ void space_first_init_parts(struct space *s, ...@@ -2648,6 +2648,8 @@ void space_first_init_parts(struct space *s,
struct xpart *restrict xp = s->xparts; struct xpart *restrict xp = s->xparts;
const struct cosmology *cosmo = s->e->cosmology; const struct cosmology *cosmo = s->e->cosmology;
const struct phys_const *phys_const = s->e->physical_constants;
const struct unit_system *us = s->e->internal_units;
const float a_factor_vel = cosmo->a * cosmo->a; const float a_factor_vel = cosmo->a * cosmo->a;
const struct hydro_props *hydro_props = s->e->hydro_properties; const struct hydro_props *hydro_props = s->e->hydro_properties;
...@@ -2678,10 +2680,10 @@ void space_first_init_parts(struct space *s, ...@@ -2678,10 +2680,10 @@ void space_first_init_parts(struct space *s,
if (u_min > 0.f) hydro_set_init_internal_energy(&p[i], u_min); if (u_min > 0.f) hydro_set_init_internal_energy(&p[i], u_min);
/* Also initialise the chemistry */ /* Also initialise the chemistry */
chemistry_first_init_part(&p[i], &xp[i], chemistry); chemistry_first_init_part(phys_const, us, cosmo, chemistry, &p[i], &xp[i]);
/* And the cooling */ /* And the cooling */
cooling_first_init_part(&p[i], &xp[i], cool_func); cooling_first_init_part(phys_const, us, cosmo, cool_func, &p[i], &xp[i]);
#ifdef SWIFT_DEBUG_CHECKS #ifdef SWIFT_DEBUG_CHECKS
p[i].ti_drift = 0; p[i].ti_drift = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment