hydro_io.h 4.23 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*******************************************************************************
 * 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/>.
 *
 ******************************************************************************/

20
21
22
23
24
25
/**
 * @brief Reads the different particles to the HDF5 file
 *
 * @param h_grp The HDF5 group in which to read the arrays.
 * @param N The number of particles on that MPI rank.
 * @param N_total The total number of particles (only used in MPI mode)
Matthieu Schaller's avatar
Matthieu Schaller committed
26
27
 * @param offset The offset of the particles for this MPI rank (only used in MPI
 *mode)
28
29
30
 * @param parts The particle array
 *
 */
Matthieu Schaller's avatar
Matthieu Schaller committed
31
32
33
__attribute__((always_inline)) INLINE static void hydro_read_particles(
    hid_t h_grp, int N, long long N_total, long long offset,
    struct part* parts) {
34
35

  /* Read arrays */
Matthieu Schaller's avatar
Matthieu Schaller committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  readArray(h_grp, "Coordinates", DOUBLE, N, 3, parts, N_total, offset, x,
            COMPULSORY);
  readArray(h_grp, "Velocities", FLOAT, N, 3, parts, N_total, offset, v,
            COMPULSORY);
  readArray(h_grp, "Masses", FLOAT, N, 1, parts, N_total, offset, mass,
            COMPULSORY);
  readArray(h_grp, "SmoothingLength", FLOAT, N, 1, parts, N_total, offset, h,
            COMPULSORY);
  readArray(h_grp, "InternalEnergy", FLOAT, N, 1, parts, N_total, offset,
            entropy, COMPULSORY);
  readArray(h_grp, "ParticleIDs", ULONGLONG, N, 1, parts, N_total, offset, id,
            COMPULSORY);
  readArray(h_grp, "Acceleration", FLOAT, N, 3, parts, N_total, offset, a,
            OPTIONAL);
  readArray(h_grp, "Density", FLOAT, N, 1, parts, N_total, offset, rho,
            OPTIONAL);
52
53
}

54
55
56
57
58
59
60
61
62
/**
 * @brief Writes the different particles to the HDF5 file
 *
 * @param h_grp The HDF5 group in which to write the arrays.
 * @param fileName The name of the file (unsued in MPI mode).
 * @param xmfFile The XMF file to write to (unused in MPI mode).
 * @param N The number of particles on that MPI rank.
 * @param N_total The total number of particles (only used in MPI mode)
 * @param mpi_rank The MPI rank of this node (only used in MPI mode)
Matthieu Schaller's avatar
Matthieu Schaller committed
63
64
 * @param offset The offset of the particles for this MPI rank (only used in MPI
 *mode)
65
66
67
68
 * @param parts The particle array
 * @param us The unit system to use
 *
 */
Matthieu Schaller's avatar
Matthieu Schaller committed
69
70
71
__attribute__((always_inline)) INLINE static void hydro_write_particles(
    hid_t h_grp, char* fileName, FILE* xmfFile, int N, long long N_total,
    int mpi_rank, long long offset, struct part* parts, struct UnitSystem* us) {
72
73

  /* Write arrays */
74
75
76
  writeArray(h_grp, fileName, xmfFile, "Coordinates", DOUBLE, N, 3, parts,
             N_total, mpi_rank, offset, x, us, UNIT_CONV_LENGTH);
  writeArray(h_grp, fileName, xmfFile, "Velocities", FLOAT, N, 3, parts,
Matthieu Schaller's avatar
Matthieu Schaller committed
77
78
79
             N_total, mpi_rank, offset, v, us, UNIT_CONV_SPEED);
  writeArray(h_grp, fileName, xmfFile, "Masses", FLOAT, N, 1, parts, N_total,
             mpi_rank, offset, mass, us, UNIT_CONV_MASS);
80
81
  writeArray(h_grp, fileName, xmfFile, "SmoothingLength", FLOAT, N, 1, parts,
             N_total, mpi_rank, offset, h, us, UNIT_CONV_LENGTH);
82
  writeArray(h_grp, fileName, xmfFile, "InternalEnergy", FLOAT, N, 1, parts,
Matthieu Schaller's avatar
Matthieu Schaller committed
83
84
             N_total, mpi_rank, offset, entropy, us,
             UNIT_CONV_ENTROPY_PER_UNIT_MASS);
85
  writeArray(h_grp, fileName, xmfFile, "ParticleIDs", ULONGLONG, N, 1, parts,
86
87
88
             N_total, mpi_rank, offset, id, us, UNIT_CONV_NO_UNITS);
  writeArray(h_grp, fileName, xmfFile, "Acceleration", FLOAT, N, 3, parts,
             N_total, mpi_rank, offset, a, us, UNIT_CONV_ACCELERATION);
Matthieu Schaller's avatar
Matthieu Schaller committed
89
90
  writeArray(h_grp, fileName, xmfFile, "Density", FLOAT, N, 1, parts, N_total,
             mpi_rank, offset, rho, us, UNIT_CONV_DENSITY);
91
}