hydro_io.h 7.13 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
#include "hydro.h"
22
#include "hydro_flux_limiters.h"
23
24
#include "hydro_gradients.h"
#include "hydro_slope_limiters.h"
25
#include "io_properties.h"
26
#include "riemann.h"
27

28
29
30
31
32
33
34
/* Set the description of the particle movement. */
#if defined(GIZMO_FIX_PARTICLES)
#define GIZMO_PARTICLE_MOVEMENT "Fixed particles."
#else
#define GIZMO_PARTICLE_MOVEMENT "Particles move with flow velocity."
#endif

35
/**
36
 * @brief Specifies which particle fields to read from a dataset
37
 *
38
39
40
 * @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.
41
 */
42
43
44
45
void hydro_read_particles(struct part* parts, struct io_props* list,
                          int* num_fields) {

  *num_fields = 8;
46

47
48
49
50
51
52
  /* 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,
53
                                parts, conserved.mass);
54
55
  list[3] = io_make_input_field("SmoothingLength", FLOAT, 1, COMPULSORY,
                                UNIT_CONV_LENGTH, parts, h);
56
57
58
  list[4] = io_make_input_field("InternalEnergy", FLOAT, 1, COMPULSORY,
                                UNIT_CONV_ENERGY_PER_UNIT_MASS, parts,
                                conserved.energy);
59
60
61
62
63
64
65
66
  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);
}

67
68
69
70
71
/**
 * @brief Get the internal energy of a particle
 *
 * @param e #engine.
 * @param p Particle.
72
 * @param ret (return) Internal energy of the particle
73
 */
74
75
76
void convert_u(const struct engine* e, const struct part* p, float* ret) {

  ret[0] = hydro_get_internal_energy(p);
77
78
}

79
80
81
82
83
/**
 * @brief Get the entropic function of a particle
 *
 * @param e #engine.
 * @param p Particle.
84
 * @param ret (return) Entropic function of the particle
85
 */
86
87
void convert_A(const struct engine* e, const struct part* p, float* ret) {
  ret[0] = hydro_get_entropy(p);
88
89
}

90
91
92
93
94
95
96
/**
 * @brief Get the total energy of a particle
 *
 * @param e #engine.
 * @param p Particle.
 * @return Total energy of the particle
 */
97
void convert_Etot(const struct engine* e, const struct part* p, float* ret) {
98
#ifdef GIZMO_TOTAL_ENERGY
99
  ret[0] = p->conserved.energy;
100
#else
101
102
103
104
105
106
  float momentum2;

  momentum2 = p->conserved.momentum[0] * p->conserved.momentum[0] +
              p->conserved.momentum[1] * p->conserved.momentum[1] +
              p->conserved.momentum[2] * p->conserved.momentum[2];

107
  ret[0] = p->conserved.energy + 0.5f * momentum2 / p->conserved.mass;
108
#endif
109
110
}

111
112
113
114
115
116
117
118
119
120
121
122
123
124
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];
  }
}

125
/**
126
 * @brief Specifies which particle fields to write to a dataset
127
 *
128
129
130
 * @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.
131
 */
132
133
void hydro_write_particles(struct part* parts, struct io_props* list,
                           int* num_fields) {
134

135
  *num_fields = 10;
136
137

  /* List what we want to write */
138
139
  list[0] = io_make_output_field_convert_part(
      "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, parts, convert_part_pos);
140
141
142
143
144
145
146
147
  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,
148
                                              parts, convert_u);
149
150
  list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1,
                                 UNIT_CONV_NO_UNITS, parts, id);
151
  list[6] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts,
152
                                 primitives.rho);
153
  list[7] = io_make_output_field_convert_part(
154
      "Entropy", FLOAT, 1, UNIT_CONV_ENTROPY, parts, convert_A);
155
156
  list[8] = io_make_output_field("Pressure", FLOAT, 1, UNIT_CONV_PRESSURE,
                                 parts, primitives.P);
157
158
  list[9] = io_make_output_field_convert_part(
      "TotEnergy", FLOAT, 1, UNIT_CONV_ENERGY, parts, convert_Etot);
159
160
161
162
163
164
}

/**
 * @brief Writes the current model of SPH to the file
 * @param h_grpsph The HDF5 group in which to write
 */
165
166
void writeSPHflavour(hid_t h_grpsph) {
  /* Gradient information */
167
168
  io_write_attribute_s(h_grpsph, "Gradient reconstruction model",
                       HYDRO_GRADIENT_IMPLEMENTATION);
169
170

  /* Slope limiter information */
171
172
173
174
  io_write_attribute_s(h_grpsph, "Cell wide slope limiter model",
                       HYDRO_SLOPE_LIMITER_CELL_IMPLEMENTATION);
  io_write_attribute_s(h_grpsph, "Piecewise slope limiter model",
                       HYDRO_SLOPE_LIMITER_FACE_IMPLEMENTATION);
175

176
177
178
179
  /* Flux limiter information */
  io_write_attribute_s(h_grpsph, "Flux limiter model",
                       HYDRO_FLUX_LIMITER_IMPLEMENTATION);

180
  /* Riemann solver information */
181
182
  io_write_attribute_s(h_grpsph, "Riemann solver type",
                       RIEMANN_SOLVER_IMPLEMENTATION);
183
184
185

  /* Particle movement information */
  io_write_attribute_s(h_grpsph, "Particle movement", GIZMO_PARTICLE_MOVEMENT);
186
}
187
188
189
190
191
192
193

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