hydro_io.h 6.15 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*******************************************************************************
 * This file is part of SWIFT.
 * Coypright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 ******************************************************************************/
19
20
#ifndef SWIFT_GADGET2_HYDRO_IO_H
#define SWIFT_GADGET2_HYDRO_IO_H
21

22
#include "adiabatic_index.h"
23
#include "hydro.h"
24
25
26
#include "io_properties.h"
#include "kernel_hydro.h"

27
/**
28
 * @brief Specifies which particle fields to read from a dataset
29
 *
30
31
32
 * @param parts The particle array.
 * @param list The list of i/o properties to read.
 * @param num_fields The number of i/o fields to read.
33
 */
34
35
void hydro_read_particles(struct part* parts, struct io_props* list,
                          int* num_fields) {
36

37
  *num_fields = 8;
38
39
40
41
42
43
44
45
46
47
48

  /* List what we want to read */
  list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY,
                                UNIT_CONV_LENGTH, parts, x);
  list[1] = io_make_input_field("Velocities", FLOAT, 3, COMPULSORY,
                                UNIT_CONV_SPEED, parts, v);
  list[2] = io_make_input_field("Masses", FLOAT, 1, COMPULSORY, UNIT_CONV_MASS,
                                parts, mass);
  list[3] = io_make_input_field("SmoothingLength", FLOAT, 1, COMPULSORY,
                                UNIT_CONV_LENGTH, parts, h);
  list[4] = io_make_input_field("InternalEnergy", FLOAT, 1, COMPULSORY,
49
                                UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, entropy);
50
51
52
53
54
55
  list[5] = io_make_input_field("ParticleIDs", ULONGLONG, 1, COMPULSORY,
                                UNIT_CONV_NO_UNITS, parts, id);
  list[6] = io_make_input_field("Accelerations", FLOAT, 3, OPTIONAL,
                                UNIT_CONV_ACCELERATION, parts, a_hydro);
  list[7] = io_make_input_field("Density", FLOAT, 1, OPTIONAL,
                                UNIT_CONV_DENSITY, parts, rho);
56
57
}

58
void convert_u(const struct engine* e, const struct part* p, float* ret) {
59

60
  ret[0] = hydro_get_internal_energy(p);
61
62
}

63
void convert_P(const struct engine* e, const struct part* p, float* ret) {
64

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  ret[0] = hydro_get_pressure(p);
}

void convert_part_pos(const struct engine* e, const struct part* p,
                      double* ret) {

  if (e->s->periodic) {
    ret[0] = box_wrap(p->x[0], 0.0, e->s->dim[0]);
    ret[1] = box_wrap(p->x[1], 0.0, e->s->dim[1]);
    ret[2] = box_wrap(p->x[2], 0.0, e->s->dim[2]);
  } else {
    ret[0] = p->x[0];
    ret[1] = p->x[1];
    ret[2] = p->x[2];
  }
80
81
}

82
/**
83
 * @brief Specifies which particle fields to write to a dataset
84
 *
85
86
87
 * @param parts The particle array.
 * @param list The list of i/o properties to write.
 * @param num_fields The number of i/o fields to write.
88
 */
89
void hydro_write_particles(const struct part* parts, struct io_props* list,
90
91
                           int* num_fields) {

92
  *num_fields = 10;
93

94
#ifdef DEBUG_INTERACTIONS_SPH
95
  *num_fields += 4;
96
97
#endif

98
  /* List what we want to write */
99
100
  list[0] = io_make_output_field_convert_part(
      "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos);
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  list[1] =
      io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, v);
  list[2] =
      io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass);
  list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH,
                                 parts, h);
  list[4] = io_make_output_field(
      "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY_PER_UNIT_MASS, parts, entropy);
  list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1,
                                 UNIT_CONV_NO_UNITS, parts, id);
  list[6] = io_make_output_field("Acceleration", FLOAT, 3,
                                 UNIT_CONV_ACCELERATION, parts, a_hydro);
  list[7] =
      io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, rho);
115
116
  list[8] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1,
                                              UNIT_CONV_ENERGY_PER_UNIT_MASS,
117
                                              parts, convert_u);
118
  list[9] = io_make_output_field_convert_part(
119
      "Pressure", FLOAT, 1, UNIT_CONV_PRESSURE, parts, convert_P);
120
#ifdef DEBUG_INTERACTIONS_SPH
121
122
123
124
  list[10] = io_make_output_field("Num_ngb_density", INT, 1, UNIT_CONV_NO_UNITS,
                                 parts, num_ngb_density);
  list[11] = io_make_output_field("Num_ngb_force", INT, 1, UNIT_CONV_NO_UNITS,
                                 parts, num_ngb_force);
125
  list[12] = io_make_output_field("Ids_ngb_density", LONGLONG, MAX_NUM_OF_NEIGHBOURS,
126
                                 UNIT_CONV_NO_UNITS, parts, ids_ngbs_density);
127
  list[13] = io_make_output_field("Ids_ngb_force", LONGLONG, MAX_NUM_OF_NEIGHBOURS,
128
129
130
                                 UNIT_CONV_NO_UNITS, parts, ids_ngbs_force);
#endif

131
}
132
133
134
135
136
137
138
139

/**
 * @brief Writes the current model of SPH to the file
 * @param h_grpsph The HDF5 group in which to write
 */
void writeSPHflavour(hid_t h_grpsph) {

  /* Viscosity and thermal conduction */
140
141
142
  io_write_attribute_s(h_grpsph, "Thermal Conductivity Model",
                       "(No treatment) as in Springel (2005)");
  io_write_attribute_s(
143
144
      h_grpsph, "Viscosity Model",
      "as in Springel (2005), i.e. Monaghan (1992) with Balsara (1995) switch");
145
146
  io_write_attribute_f(h_grpsph, "Viscosity alpha", const_viscosity_alpha);
  io_write_attribute_f(h_grpsph, "Viscosity beta", 3.f);
147
}
148
149
150
151
152
153

/**
 * @brief Are we writing entropy in the internal energy field ?
 *
 * @return 1 if entropy is in 'internal energy', 0 otherwise.
 */
154
int writeEntropyFlag() { return 0; }
155
156

#endif /* SWIFT_GADGET2_HYDRO_IO_H */