Commit 441c1f58 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Code formatting and missing new header in the Makefile.am

parent 3aa48a5e
......@@ -47,7 +47,7 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \
sourceterms.h sourceterms_struct.h statistics.h memswap.h cache.h runner_doiact_vec.h profiler.h \
dump.h logger.h active.h timeline.h xmf.h gravity_properties.h gravity_derivatives.h \
gravity_softened_derivatives.h vector_power.h collectgroup.h hydro_space.h sort_part.h \
chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h space_getsid.h
chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h space_getsid.h utilities.h
# Common source files
AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \
......
......@@ -1086,45 +1086,45 @@ __attribute__((always_inline)) INLINE static void eos_init(
// and convert to internal units
// Tillotson
if (parser_get_opt_param_int(params, "EoS:planetary_use_Til", 0)) {
set_Til_iron(&e->Til_iron, eos_planetary_id_Til_iron);
set_Til_granite(&e->Til_granite, eos_planetary_id_Til_granite);
set_Til_water(&e->Til_water, eos_planetary_id_Til_water);
set_Til_iron(&e->Til_iron, eos_planetary_id_Til_iron);
set_Til_granite(&e->Til_granite, eos_planetary_id_Til_granite);
set_Til_water(&e->Til_water, eos_planetary_id_Til_water);
convert_units_Til(&e->Til_iron, us);
convert_units_Til(&e->Til_granite, us);
convert_units_Til(&e->Til_water, us);
convert_units_Til(&e->Til_iron, us);
convert_units_Til(&e->Til_granite, us);
convert_units_Til(&e->Til_water, us);
}
// Hubbard & MacFarlane (1980)
if (parser_get_opt_param_int(params, "EoS:planetary_use_HM80", 0)) {
set_HM80_HHe(&e->HM80_HHe, eos_planetary_id_HM80_HHe);
set_HM80_ice(&e->HM80_ice, eos_planetary_id_HM80_ice);
set_HM80_rock(&e->HM80_rock, eos_planetary_id_HM80_rock);
parser_get_param_string(params, "EoS:planetary_HM80_HHe_table_file",
HM80_HHe_table_file);
parser_get_param_string(params, "EoS:planetary_HM80_ice_table_file",
HM80_ice_table_file);
parser_get_param_string(params, "EoS:planetary_HM80_rock_table_file",
HM80_rock_table_file);
load_HM80_table(&e->HM80_HHe, HM80_HHe_table_file);
load_HM80_table(&e->HM80_ice, HM80_ice_table_file);
load_HM80_table(&e->HM80_rock, HM80_rock_table_file);
convert_units_HM80(&e->HM80_HHe, us);
convert_units_HM80(&e->HM80_ice, us);
convert_units_HM80(&e->HM80_rock, us);
set_HM80_HHe(&e->HM80_HHe, eos_planetary_id_HM80_HHe);
set_HM80_ice(&e->HM80_ice, eos_planetary_id_HM80_ice);
set_HM80_rock(&e->HM80_rock, eos_planetary_id_HM80_rock);
parser_get_param_string(params, "EoS:planetary_HM80_HHe_table_file",
HM80_HHe_table_file);
parser_get_param_string(params, "EoS:planetary_HM80_ice_table_file",
HM80_ice_table_file);
parser_get_param_string(params, "EoS:planetary_HM80_rock_table_file",
HM80_rock_table_file);
load_HM80_table(&e->HM80_HHe, HM80_HHe_table_file);
load_HM80_table(&e->HM80_ice, HM80_ice_table_file);
load_HM80_table(&e->HM80_rock, HM80_rock_table_file);
convert_units_HM80(&e->HM80_HHe, us);
convert_units_HM80(&e->HM80_ice, us);
convert_units_HM80(&e->HM80_rock, us);
}
// ANEOS
if (parser_get_opt_param_int(params, "EoS:planetary_use_ANEOS", 0)) {
set_ANEOS_iron(&e->ANEOS_iron, eos_planetary_id_ANEOS_iron);
set_MANEOS_forsterite(&e->MANEOS_forsterite,
eos_planetary_id_MANEOS_forsterite);
set_ANEOS_iron(&e->ANEOS_iron, eos_planetary_id_ANEOS_iron);
set_MANEOS_forsterite(&e->MANEOS_forsterite,
eos_planetary_id_MANEOS_forsterite);
convert_units_ANEOS(&e->ANEOS_iron, us);
convert_units_ANEOS(&e->MANEOS_forsterite, us);
convert_units_ANEOS(&e->ANEOS_iron, us);
convert_units_ANEOS(&e->MANEOS_forsterite, us);
}
// SESAME
......
......@@ -101,15 +101,15 @@ INLINE static void set_HM80_rock(struct HM80_params *mat,
// Read the table from file
INLINE static void load_HM80_table(struct HM80_params *mat, char *table_file) {
// Allocate table memory
mat->table_P_rho_u = (float *)malloc(mat->num_rho * mat->num_u *
sizeof(float *));
mat->table_P_rho_u =
(float *)malloc(mat->num_rho * mat->num_u * sizeof(float *));
// Load table contents from file
FILE *f = fopen(table_file, "r");
int c;
for (int i = 0; i < mat->num_rho; i++) {
for (int j = 0; j < mat->num_u; j++) {
c = fscanf(f, "%f", &mat->table_P_rho_u[i*mat->num_rho + j]);
c = fscanf(f, "%f", &mat->table_P_rho_u[i * mat->num_rho + j]);
if (c != 1) {
error("Failed to read EOS table");
}
......@@ -139,7 +139,7 @@ INLINE static void convert_units_HM80(struct HM80_params *mat,
// Table Pressures in Mbar
for (int i = 0; i < mat->num_rho; i++) {
for (int j = 0; j < mat->num_u; j++) {
mat->table_P_rho_u[i*mat->num_rho + j] *=
mat->table_P_rho_u[i * mat->num_rho + j] *=
Mbar_to_Ba / units_cgs_conversion_factor(us, UNIT_CONV_PRESSURE);
}
}
......@@ -229,20 +229,23 @@ INLINE static float HM80_pressure_from_internal_energy(
// Return an edge value if above the table maximum/a
else if (rho_idx >= mat->num_rho - 1) { // Too-high rho
if (u_idx >= mat->num_u - 1) { // and too-high u
P = mat->table_P_rho_u[(mat->num_rho - 1)*mat->num_u + mat->num_u - 1];
P = mat->table_P_rho_u[(mat->num_rho - 1) * mat->num_u + mat->num_u - 1];
} else {
P = mat->table_P_rho_u[(mat->num_rho - 1)*mat->num_u + u_idx];
P = mat->table_P_rho_u[(mat->num_rho - 1) * mat->num_u + u_idx];
}
} else if (u_idx >= mat->num_u - 1) { // Too-high u
P = mat->table_P_rho_u[rho_idx*mat->num_u + mat->num_u - 1];
P = mat->table_P_rho_u[rho_idx * mat->num_u + mat->num_u - 1];
}
// Normal interpolation within the table
else {
P = (1.f - intp_rho) *
((1.f - intp_u) * mat->table_P_rho_u[rho_idx*mat->num_u + u_idx] +
intp_u * mat->table_P_rho_u[rho_idx*mat->num_u + u_idx + 1]) +
intp_rho * ((1 - intp_u) * mat->table_P_rho_u[(rho_idx + 1)*mat->num_u + u_idx] +
intp_u * mat->table_P_rho_u[(rho_idx + 1)*mat->num_u + u_idx + 1]);
((1.f - intp_u) * mat->table_P_rho_u[rho_idx * mat->num_u + u_idx] +
intp_u * mat->table_P_rho_u[rho_idx * mat->num_u + u_idx + 1]) +
intp_rho *
((1 - intp_u) *
mat->table_P_rho_u[(rho_idx + 1) * mat->num_u + u_idx] +
intp_u *
mat->table_P_rho_u[(rho_idx + 1) * mat->num_u + u_idx + 1]);
}
return P;
......
......@@ -171,8 +171,8 @@ void hydro_write_particles(const struct part* parts, const struct xpart* xparts,
list[6] =
io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho);
list[7] = io_make_output_field_convert_part("Entropy", FLOAT, 1,
UNIT_CONV_ENTROPY_PER_UNIT_MASS,
parts, xparts, convert_S);
UNIT_CONV_ENTROPY_PER_UNIT_MASS,
parts, xparts, convert_S);
list[8] = io_make_output_field("MaterialID", INT, 1, UNIT_CONV_NO_UNITS,
parts, mat_id);
list[9] = io_make_output_field_convert_part(
......
......@@ -30,29 +30,30 @@
*
* Return -1 and n for x below and above the array edge values respectively.
*/
INLINE static int find_value_in_monot_incr_array(
const float x, const float *array, const int n) {
INLINE static int find_value_in_monot_incr_array(const float x,
const float *array,
const int n) {
int index_mid, index_low = 0, index_high = n;
int index_mid, index_low = 0, index_high = n;
// Until array[index_low] < x < array[index_high=index_low+1]
while (index_high - index_low > 1) {
index_mid = (index_high + index_low) / 2; // Middle index
// Until array[index_low] < x < array[index_high=index_low+1]
while (index_high - index_low > 1) {
index_mid = (index_high + index_low) / 2; // Middle index
// Replace the low or high index with the middle
if (array[index_mid] <= x)
index_low = index_mid;
else
index_high = index_mid;
}
// Set index with the found index_low or an error value if outside the array
if (x < array[0])
return -1;
else if (array[n-1] <= x)
return n;
// Replace the low or high index with the middle
if (array[index_mid] <= x)
index_low = index_mid;
else
return index_low;
index_high = index_mid;
}
// Set index with the found index_low or an error value if outside the array
if (x < array[0])
return -1;
else if (array[n - 1] <= x)
return n;
else
return index_low;
}
#endif /* SWIFT_UTILITIES_H */
......@@ -24,52 +24,52 @@
* @brief Test generic utility functions
*/
int main() {
/// Test find_value_in_monot_incr_array()
int n = 100;
float array[n];
int index;
float x;
/// Test find_value_in_monot_incr_array()
int n = 100;
float array[n];
int index;
float x;
// Initialise test array
for (int j = 0; j < n; j++) {
array[j] = j;
}
// Initialise test array
for (int j = 0; j < n; j++) {
array[j] = j;
}
// Typical value
x = 42.42f;
index = find_value_in_monot_incr_array(x, array, n);
if (index != 42) {
error("Failed with a typical value ");
}
// Typical value
x = 42.42f;
index = find_value_in_monot_incr_array(x, array, n);
if (index != 42) {
error("Failed with a typical value ");
}
// Value on array element
x = 33.f;
index = find_value_in_monot_incr_array(x, array, n);
if (index != 33) {
error("Failed with an array element ");
}
// Value on array element
x = 33.f;
index = find_value_in_monot_incr_array(x, array, n);
if (index != 33) {
error("Failed with an array element ");
}
// Value below array
x = -123.f;
index = find_value_in_monot_incr_array(x, array, n);
if (index != -1) {
error("Failed with a value below the array ");
}
// Value below array
x = -123.f;
index = find_value_in_monot_incr_array(x, array, n);
if (index != -1) {
error("Failed with a value below the array ");
}
// Value above array
x = 123.f;
index = find_value_in_monot_incr_array(x, array, n);
if (index != n) {
error("Failed with a value above the array ");
}
// Value above array
x = 123.f;
index = find_value_in_monot_incr_array(x, array, n);
if (index != n) {
error("Failed with a value above the array ");
}
// Array slice with typical value
x = 9.81f;
n = 10;
index = find_value_in_monot_incr_array(x, array + 5, n);
if (index != 4) {
error("Failed with an array slice ");
}
// Array slice with typical value
x = 9.81f;
n = 10;
index = find_value_in_monot_incr_array(x, array + 5, n);
if (index != 4) {
error("Failed with an array slice ");
}
return 0;
return 0;
}
Supports Markdown
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