hydro_io.h 5.71 KB
Newer Older
1
2
/*******************************************************************************
 * This file is part of SWIFT.
3
 * Coypright (c) 2016 Bert Vandenbroucke (bert.vandenbroucke@gmail.com)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * 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/>.
 *
 ******************************************************************************/

20
#include "adiabatic_index.h"
21
22
#include "hydro_gradients.h"
#include "hydro_slope_limiters.h"
23
#include "io_properties.h"
24
#include "riemann.h"
25

26
/**
27
 * @brief Specifies which particle fields to read from a dataset
28
 *
29
30
31
 * @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.
32
 */
33
34
35
36
void hydro_read_particles(struct part* parts, struct io_props* list,
                          int* num_fields) {

  *num_fields = 8;
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  /* 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,
                          UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, primitives.P);
  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, primitives.rho);
}

float convert_u(struct engine* e, struct part* p) {
  return p->primitives.P / hydro_gamma_minus_one / p->primitives.rho;
60
61
}

62
63
64
65
float convert_A(struct engine* e, struct part* p) {
  return p->primitives.P / pow_gamma(p->primitives.rho);
}

66
/**
67
 * @brief Specifies which particle fields to write to a dataset
68
 *
69
70
71
 * @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.
72
 */
73
74
void hydro_write_particles(struct part* parts, struct io_props* list,
                           int* num_fields) {
75

Bert Vandenbroucke's avatar
Bert Vandenbroucke committed
76
  *num_fields = 13;
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

  /* List what we want to write */
  list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH,
                                 parts, x);
  list[1] = io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts,
                                 primitives.v);
  list[2] = io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts,
                                 conserved.mass);
  list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH,
                                 parts, h);
  list[4] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1,
                                              UNIT_CONV_ENERGY_PER_UNIT_MASS,
                                              parts, primitives.P, convert_u);
  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,
                                 primitives.rho);
96
97
  list[8] = io_make_output_field("Volume", FLOAT, 1, UNIT_CONV_VOLUME, parts,
                                 geometry.volume);
98
99
  list[9] = io_make_output_field("GradDensity", FLOAT, 3, UNIT_CONV_DENSITY,
                                 parts, primitives.gradients.rho);
100
101
102
103
  list[10] = io_make_output_field_convert_part(
      "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY, parts, primitives.P, convert_A);
  list[11] = io_make_output_field("Pressure", FLOAT, 1, UNIT_CONV_PRESSURE,
                                  parts, primitives.P);
Bert Vandenbroucke's avatar
Bert Vandenbroucke committed
104
105
  list[12] = io_make_output_field("TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY,
                                  parts, conserved.energy);
106
107
108
109
110
111
}

/**
 * @brief Writes the current model of SPH to the file
 * @param h_grpsph The HDF5 group in which to write
 */
112
113
114
115
116
117
118
119
120
121
void writeSPHflavour(hid_t h_grpsph) {
  /* Gradient information */
  writeAttribute_s(h_grpsph, "Gradient reconstruction model",
                   HYDRO_GRADIENT_IMPLEMENTATION);

  /* Slope limiter information */
  writeAttribute_s(h_grpsph, "Cell wide slope limiter model",
                   HYDRO_SLOPE_LIMITER_CELL_IMPLEMENTATION);
  writeAttribute_s(h_grpsph, "Piecewise slope limiter model",
                   HYDRO_SLOPE_LIMITER_FACE_IMPLEMENTATION);
122
123
124

  /* Riemann solver information */
  writeAttribute_s(h_grpsph, "Riemann solver type", RIEMANN_SOLVER_IMPLEMENTATION);
125
}
126
127
128
129
130
131
132

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