Skip to content
Snippets Groups Projects
Commit 8d9c9727 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Better way of dealing with the chemistry i/o. The i/o routines directly call...

Better way of dealing with the chemistry i/o. The i/o routines directly call the list construction, lowering the burden on the hydro scheme mainteners.
parent 18f77b9e
No related branches found
No related tags found
1 merge request!486Add chemistry in part
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
void hydro_read_particles(struct part* parts, struct io_props* list, void hydro_read_particles(struct part* parts, struct io_props* list,
int* num_fields) { int* num_fields) {
*num_fields = 8;
/* List what we want to read */ /* List what we want to read */
list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY, list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY,
UNIT_CONV_LENGTH, parts, x); UNIT_CONV_LENGTH, parts, x);
...@@ -49,13 +51,6 @@ void hydro_read_particles(struct part* parts, struct io_props* list, ...@@ -49,13 +51,6 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
UNIT_CONV_ACCELERATION, parts, a_hydro); UNIT_CONV_ACCELERATION, parts, a_hydro);
list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL, list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL,
UNIT_CONV_DENSITY, parts, rho); UNIT_CONV_DENSITY, parts, rho);
*num_fields = 8;
list += *num_fields;
/* Read in chemistry information */
const int num_chem_fields = chemistry_read_particles(parts, list);
*num_fields += num_chem_fields;
list += num_chem_fields;
} }
void convert_part_pos(const struct engine* e, const struct part* p, void convert_part_pos(const struct engine* e, const struct part* p,
...@@ -82,6 +77,8 @@ void convert_part_pos(const struct engine* e, const struct part* p, ...@@ -82,6 +77,8 @@ void convert_part_pos(const struct engine* e, const struct part* p,
void hydro_write_particles(struct part* parts, struct io_props* list, void hydro_write_particles(struct part* parts, struct io_props* list,
int* num_fields) { int* num_fields) {
*num_fields = 8;
/* List what we want to write */ /* List what we want to write */
list[0] = io_make_output_field_convert_part( list[0] = io_make_output_field_convert_part(
"Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos); "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos);
...@@ -99,14 +96,6 @@ void hydro_write_particles(struct part* parts, struct io_props* list, ...@@ -99,14 +96,6 @@ void hydro_write_particles(struct part* parts, struct io_props* list,
UNIT_CONV_ACCELERATION, parts, a_hydro); UNIT_CONV_ACCELERATION, parts, a_hydro);
list[7] = list[7] =
io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho); io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho);
*num_fields = 8;
list += *num_fields;
/* Write some chemistry information */
const int num_chem_fields = chemistry_write_particles(parts, list);
*num_fields += num_chem_fields;
list += num_chem_fields;
} }
/** /**
... ...
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
void hydro_read_particles(struct part* parts, struct io_props* list, void hydro_read_particles(struct part* parts, struct io_props* list,
int* num_fields) { int* num_fields) {
*num_fields = 8;
/* List what we want to read */ /* List what we want to read */
list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY, list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY,
UNIT_CONV_LENGTH, parts, x); UNIT_CONV_LENGTH, parts, x);
...@@ -53,14 +55,6 @@ void hydro_read_particles(struct part* parts, struct io_props* list, ...@@ -53,14 +55,6 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
UNIT_CONV_ACCELERATION, parts, a_hydro); UNIT_CONV_ACCELERATION, parts, a_hydro);
list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL, list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL,
UNIT_CONV_DENSITY, parts, rho); UNIT_CONV_DENSITY, parts, rho);
*num_fields = 8;
list += *num_fields;
/* Read in chemistry information */
const int num_chem_fields = chemistry_read_particles(parts, list);
*num_fields += num_chem_fields;
list += num_chem_fields;
} }
void convert_u(const struct engine* e, const struct part* p, float* ret) { void convert_u(const struct engine* e, const struct part* p, float* ret) {
...@@ -97,6 +91,8 @@ void convert_part_pos(const struct engine* e, const struct part* p, ...@@ -97,6 +91,8 @@ void convert_part_pos(const struct engine* e, const struct part* p,
void hydro_write_particles(const struct part* parts, struct io_props* list, void hydro_write_particles(const struct part* parts, struct io_props* list,
int* num_fields) { int* num_fields) {
*num_fields = 10;
/* List what we want to write */ /* List what we want to write */
list[0] = io_make_output_field_convert_part( list[0] = io_make_output_field_convert_part(
"Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos); "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos);
...@@ -120,16 +116,11 @@ void hydro_write_particles(const struct part* parts, struct io_props* list, ...@@ -120,16 +116,11 @@ void hydro_write_particles(const struct part* parts, struct io_props* list,
list[9] = io_make_output_field_convert_part( list[9] = io_make_output_field_convert_part(
"Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, convert_P); "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, convert_P);
*num_fields = 10;
list += *num_fields;
/* Write some chemistry information */
const int num_chem_fields = chemistry_write_particles(parts, list);
*num_fields += num_chem_fields;
list += num_chem_fields;
#ifdef DEBUG_INTERACTIONS_SPH #ifdef DEBUG_INTERACTIONS_SPH
list += *num_fields;
*num_fields += 4;
list[0] = io_make_output_field("Num_ngb_density", INT, 1, UNIT_CONV_NO_UNITS, list[0] = io_make_output_field("Num_ngb_density", INT, 1, UNIT_CONV_NO_UNITS,
parts, num_ngb_density); parts, num_ngb_density);
list[1] = io_make_output_field("Num_ngb_force", INT, 1, UNIT_CONV_NO_UNITS, list[1] = io_make_output_field("Num_ngb_force", INT, 1, UNIT_CONV_NO_UNITS,
...@@ -141,8 +132,6 @@ void hydro_write_particles(const struct part* parts, struct io_props* list, ...@@ -141,8 +132,6 @@ void hydro_write_particles(const struct part* parts, struct io_props* list,
io_make_output_field("Ids_ngb_force", LONGLONG, MAX_NUM_OF_NEIGHBOURS, io_make_output_field("Ids_ngb_force", LONGLONG, MAX_NUM_OF_NEIGHBOURS,
UNIT_CONV_NO_UNITS, parts, ids_ngbs_force); UNIT_CONV_NO_UNITS, parts, ids_ngbs_force);
*num_fields += 4;
list += 4;
#endif #endif
} }
... ...
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
void hydro_read_particles(struct part* parts, struct io_props* list, void hydro_read_particles(struct part* parts, struct io_props* list,
int* num_fields) { int* num_fields) {
*num_fields = 8;
/* List what we want to read */ /* List what we want to read */
list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY, list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY,
UNIT_CONV_LENGTH, parts, x); UNIT_CONV_LENGTH, parts, x);
...@@ -59,14 +61,6 @@ void hydro_read_particles(struct part* parts, struct io_props* list, ...@@ -59,14 +61,6 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
UNIT_CONV_ACCELERATION, parts, a_hydro); UNIT_CONV_ACCELERATION, parts, a_hydro);
list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL, list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL,
UNIT_CONV_DENSITY, parts, primitives.rho); UNIT_CONV_DENSITY, parts, primitives.rho);
*num_fields = 8;
list += *num_fields;
/* Read in chemistry information */
const int num_chem_fields = chemistry_read_particles(parts, list);
*num_fields += num_chem_fields;
list += num_chem_fields;
} }
/** /**
...@@ -137,6 +131,8 @@ void convert_part_pos(const struct engine* e, const struct part* p, ...@@ -137,6 +131,8 @@ void convert_part_pos(const struct engine* e, const struct part* p,
void hydro_write_particles(struct part* parts, struct io_props* list, void hydro_write_particles(struct part* parts, struct io_props* list,
int* num_fields) { int* num_fields) {
*num_fields = 10;
/* List what we want to write */ /* List what we want to write */
list[0] = io_make_output_field_convert_part( list[0] = io_make_output_field_convert_part(
"Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos); "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos);
...@@ -159,14 +155,6 @@ void hydro_write_particles(struct part* parts, struct io_props* list, ...@@ -159,14 +155,6 @@ void hydro_write_particles(struct part* parts, struct io_props* list,
parts, primitives.P); parts, primitives.P);
list[9] = io_make_output_field_convert_part( list[9] = io_make_output_field_convert_part(
"TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY, parts, convert_Etot); "TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY, parts, convert_Etot);
*num_fields = 10;
list += *num_fields;
/* Write some chemistry information */
const int num_chem_fields = chemistry_write_particles(parts, list);
*num_fields += num_chem_fields;
list += num_chem_fields;
} }
/** /**
... ...
......
...@@ -48,6 +48,8 @@ ...@@ -48,6 +48,8 @@
void hydro_read_particles(struct part* parts, struct io_props* list, void hydro_read_particles(struct part* parts, struct io_props* list,
int* num_fields) { int* num_fields) {
*num_fields = 8;
/* List what we want to read */ /* List what we want to read */
list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY, list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY,
UNIT_CONV_LENGTH, parts, x); UNIT_CONV_LENGTH, parts, x);
...@@ -65,13 +67,6 @@ void hydro_read_particles(struct part* parts, struct io_props* list, ...@@ -65,13 +67,6 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
UNIT_CONV_ACCELERATION, parts, a_hydro); UNIT_CONV_ACCELERATION, parts, a_hydro);
list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL, list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL,
UNIT_CONV_DENSITY, parts, rho); UNIT_CONV_DENSITY, parts, rho);
*num_fields = 8;
list += *num_fields;
/* Read in chemistry information */
const int num_chem_fields = chemistry_read_particles(parts, list);
*num_fields += num_chem_fields;
list += num_chem_fields;
} }
void convert_S(const struct engine* e, const struct part* p, float* ret) { void convert_S(const struct engine* e, const struct part* p, float* ret) {
...@@ -108,6 +103,8 @@ void convert_part_pos(const struct engine* e, const struct part* p, ...@@ -108,6 +103,8 @@ void convert_part_pos(const struct engine* e, const struct part* p,
void hydro_write_particles(struct part* parts, struct io_props* list, void hydro_write_particles(struct part* parts, struct io_props* list,
int* num_fields) { int* num_fields) {
*num_fields = 10;
/* List what we want to write */ /* List what we want to write */
list[0] = io_make_output_field_convert_part( list[0] = io_make_output_field_convert_part(
"Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos); "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos);
...@@ -129,14 +126,6 @@ void hydro_write_particles(struct part* parts, struct io_props* list, ...@@ -129,14 +126,6 @@ void hydro_write_particles(struct part* parts, struct io_props* list,
"Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, convert_S); "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, convert_S);
list[9] = io_make_output_field_convert_part( list[9] = io_make_output_field_convert_part(
"Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, convert_P); "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, convert_P);
*num_fields = 10;
list += *num_fields;
/* Write some chemistry information */
const int num_chem_fields = chemistry_write_particles(parts, list);
*num_fields += num_chem_fields;
list += num_chem_fields;
} }
/** /**
... ...
......
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
void hydro_read_particles(struct part* parts, struct io_props* list, void hydro_read_particles(struct part* parts, struct io_props* list,
int* num_fields) { int* num_fields) {
*num_fields = 8;
/* List what we want to read */ /* List what we want to read */
list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY, list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY,
UNIT_CONV_LENGTH, parts, x); UNIT_CONV_LENGTH, parts, x);
...@@ -63,14 +65,6 @@ void hydro_read_particles(struct part* parts, struct io_props* list, ...@@ -63,14 +65,6 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
UNIT_CONV_ACCELERATION, parts, a_hydro); UNIT_CONV_ACCELERATION, parts, a_hydro);
list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL, list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL,
UNIT_CONV_DENSITY, parts, rho); UNIT_CONV_DENSITY, parts, rho);
*num_fields = 8;
list += *num_fields;
/* Read in chemistry information */
const int num_chem_fields = chemistry_read_particles(parts, list);
*num_fields += num_chem_fields;
list += num_chem_fields;
} }
void convert_u(const struct engine* e, const struct part* p, float* ret) { void convert_u(const struct engine* e, const struct part* p, float* ret) {
...@@ -107,6 +101,8 @@ void convert_part_pos(const struct engine* e, const struct part* p, ...@@ -107,6 +101,8 @@ void convert_part_pos(const struct engine* e, const struct part* p,
void hydro_write_particles(struct part* parts, struct io_props* list, void hydro_write_particles(struct part* parts, struct io_props* list,
int* num_fields) { int* num_fields) {
*num_fields = 11;
/* List what we want to write */ /* List what we want to write */
list[0] = io_make_output_field_convert_part( list[0] = io_make_output_field_convert_part(
"Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos); "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos);
...@@ -131,14 +127,6 @@ void hydro_write_particles(struct part* parts, struct io_props* list, ...@@ -131,14 +127,6 @@ void hydro_write_particles(struct part* parts, struct io_props* list,
"Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, convert_P); "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, convert_P);
list[10] = io_make_output_field("WeightedDensity", FLOAT, 1, list[10] = io_make_output_field("WeightedDensity", FLOAT, 1,
UNIT_CONV_DENSITY, parts, rho_bar); UNIT_CONV_DENSITY, parts, rho_bar);
*num_fields = 11;
list += *num_fields;
/* Write some chemistry information */
const int num_chem_fields = chemistry_write_particles(parts, list);
*num_fields += num_chem_fields;
list += num_chem_fields;
} }
/** /**
... ...
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
void hydro_read_particles(struct part* parts, struct io_props* list, void hydro_read_particles(struct part* parts, struct io_props* list,
int* num_fields) { int* num_fields) {
*num_fields = 8;
/* List what we want to read */ /* List what we want to read */
list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY, list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY,
UNIT_CONV_LENGTH, parts, x); UNIT_CONV_LENGTH, parts, x);
...@@ -53,13 +55,6 @@ void hydro_read_particles(struct part* parts, struct io_props* list, ...@@ -53,13 +55,6 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
UNIT_CONV_ACCELERATION, parts, a_hydro); UNIT_CONV_ACCELERATION, parts, a_hydro);
list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL, list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL,
UNIT_CONV_DENSITY, parts, primitives.rho); UNIT_CONV_DENSITY, parts, primitives.rho);
*num_fields = 8;
list += *num_fields;
/* Read in chemistry information */
const int num_chem_fields = chemistry_read_particles(parts, list);
*num_fields += num_chem_fields;
list += num_chem_fields;
} }
/** /**
...@@ -133,6 +128,8 @@ void convert_part_pos(const struct engine* e, const struct part* p, ...@@ -133,6 +128,8 @@ void convert_part_pos(const struct engine* e, const struct part* p,
void hydro_write_particles(struct part* parts, struct io_props* list, void hydro_write_particles(struct part* parts, struct io_props* list,
int* num_fields) { int* num_fields) {
*num_fields = 13;
/* List what we want to write */ /* List what we want to write */
list[0] = io_make_output_field_convert_part( list[0] = io_make_output_field_convert_part(
"Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos); "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos);
...@@ -161,14 +158,6 @@ void hydro_write_particles(struct part* parts, struct io_props* list, ...@@ -161,14 +158,6 @@ void hydro_write_particles(struct part* parts, struct io_props* list,
parts, primitives.P); parts, primitives.P);
list[12] = io_make_output_field_convert_part( list[12] = io_make_output_field_convert_part(
"TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY, parts, convert_Etot); "TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY, parts, convert_Etot);
*num_fields = 13;
list += *num_fields;
/* Write some chemistry information */
const int num_chem_fields = chemistry_write_particles(parts, list);
*num_fields += num_chem_fields;
list += num_chem_fields;
} }
/** /**
... ...
......
...@@ -727,6 +727,7 @@ void read_ic_parallel(char* fileName, const struct unit_system* internal_units, ...@@ -727,6 +727,7 @@ void read_ic_parallel(char* fileName, const struct unit_system* internal_units,
if (with_hydro) { if (with_hydro) {
Nparticles = *Ngas; Nparticles = *Ngas;
hydro_read_particles(*parts, list, &num_fields); hydro_read_particles(*parts, list, &num_fields);
num_fields += chemistry_read_particles(*parts, list + num_fields);
} }
break; break;
...@@ -1056,6 +1057,7 @@ void write_output_parallel(struct engine* e, const char* baseName, ...@@ -1056,6 +1057,7 @@ void write_output_parallel(struct engine* e, const char* baseName,
case swift_type_gas: case swift_type_gas:
Nparticles = Ngas; Nparticles = Ngas;
hydro_write_particles(parts, list, &num_fields); hydro_write_particles(parts, list, &num_fields);
num_fields += chemistry_write_particles(parts, list + num_fields);
break; break;
case swift_type_dark_matter: case swift_type_dark_matter:
... ...
......
...@@ -607,6 +607,7 @@ void read_ic_serial(char* fileName, const struct unit_system* internal_units, ...@@ -607,6 +607,7 @@ void read_ic_serial(char* fileName, const struct unit_system* internal_units,
if (with_hydro) { if (with_hydro) {
Nparticles = *Ngas; Nparticles = *Ngas;
hydro_read_particles(*parts, list, &num_fields); hydro_read_particles(*parts, list, &num_fields);
num_fields += chemistry_read_particles(*parts, list + num_fields);
} }
break; break;
...@@ -943,6 +944,7 @@ void write_output_serial(struct engine* e, const char* baseName, ...@@ -943,6 +944,7 @@ void write_output_serial(struct engine* e, const char* baseName,
case swift_type_gas: case swift_type_gas:
Nparticles = Ngas; Nparticles = Ngas;
hydro_write_particles(parts, list, &num_fields); hydro_write_particles(parts, list, &num_fields);
num_fields += chemistry_write_particles(parts, list + num_fields);
break; break;
case swift_type_dark_matter: case swift_type_dark_matter:
... ...
......
...@@ -485,6 +485,7 @@ void read_ic_single(char* fileName, const struct unit_system* internal_units, ...@@ -485,6 +485,7 @@ void read_ic_single(char* fileName, const struct unit_system* internal_units,
if (with_hydro) { if (with_hydro) {
Nparticles = *Ngas; Nparticles = *Ngas;
hydro_read_particles(*parts, list, &num_fields); hydro_read_particles(*parts, list, &num_fields);
num_fields += chemistry_read_particles(*parts, list + num_fields);
} }
break; break;
...@@ -758,6 +759,7 @@ void write_output_single(struct engine* e, const char* baseName, ...@@ -758,6 +759,7 @@ void write_output_single(struct engine* e, const char* baseName,
case swift_type_gas: case swift_type_gas:
N = Ngas; N = Ngas;
hydro_write_particles(parts, list, &num_fields); hydro_write_particles(parts, list, &num_fields);
num_fields += chemistry_write_particles(parts, list + num_fields);
break; break;
case swift_type_dark_matter: case swift_type_dark_matter:
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment