pressure_floor.h 7.74 KB
Newer Older
Loic Hausammann's avatar
Loic Hausammann committed
1
2
/*******************************************************************************
 * This file is part of SWIFT.
3
 * Copyright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch)
Loic Hausammann's avatar
Loic Hausammann committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 *
 * 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/>.
 *
 ******************************************************************************/
#ifndef SWIFT_PRESSURE_FLOOR_GEAR_H
#define SWIFT_PRESSURE_FLOOR_GEAR_H

22
/* Forward declaration */
Loic Hausammann's avatar
Loic Hausammann committed
23
struct cosmology;
Loic Hausammann's avatar
Format    
Loic Hausammann committed
24
25
26
27
28
29
__attribute__((always_inline)) static INLINE float
pressure_floor_get_comoving_pressure(const struct part* p, const float pressure,
                                     const struct cosmology* cosmo);
__attribute__((always_inline)) static INLINE float
pressure_floor_get_physical_pressure(const struct part* p, const float pressure,
                                     const struct cosmology* cosmo);
30

Loic Hausammann's avatar
Loic Hausammann committed
31
32
#include "adiabatic_index.h"
#include "cosmology.h"
33
#include "dimension.h"
Loic Hausammann's avatar
Loic Hausammann committed
34
#include "equation_of_state.h"
35
#include "hydro.h"
Loic Hausammann's avatar
Loic Hausammann committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "hydro_properties.h"
#include "parser.h"
#include "part.h"
#include "units.h"

/**
 * @file src/pressure_floor/GEAR/pressure_floor.h
 * @brief Pressure floor used in the GEAR model
 */

/**
 * @brief Properties of the pressure floor in the GEAR model.
 */
struct pressure_floor_properties {

  /*! Jeans factor */
  float n_jeans;

  /*! The constants in internal units (4 G N_jeans^(2/3) / PI) */
  float constants;
};

/**
 * @brief Compute the physical pressure floor of a given #part.
 *
 * Note that the particle is not updated!!
 *
 * @param p The #part.
64
 * @param pressure_physical The physical pressure without any pressure floor.
65
66
67
68
 * @param cosmo The #cosmology model.
 *
 * @return The physical pressure with the floor.
 */
Loic Hausammann's avatar
Format    
Loic Hausammann committed
69
70
71
72
__attribute__((always_inline)) static INLINE float
pressure_floor_get_physical_pressure(const struct part* p,
                                     const float pressure_physical,
                                     const struct cosmology* cosmo) {
73

74
  const float H_phys = p->h * cosmo->a_inv * kernel_gamma;
75
76
77
  const float rho = hydro_get_physical_density(p, cosmo);

  /* Compute the pressure floor */
78
  float floor = H_phys * H_phys * rho * pressure_floor_props.constants -
Loic Hausammann's avatar
Format    
Loic Hausammann committed
79
                p->pressure_floor_data.sigma2;
80
81
  floor *= rho * hydro_one_over_gamma;

82
  return fmaxf(pressure_physical, floor);
83
84
85
86
87
88
89
90
}

/**
 * @brief Compute the comoving pressure floor of a given #part.
 *
 * Note that the particle is not updated!!
 *
 * @param p The #part.
91
 * @param pressure_comoving The comoving pressure without any pressure floor.
92
 * @param cosmo The #cosmology model.
Loic Hausammann's avatar
Loic Hausammann committed
93
94
95
 *
 * @return The physical or comoving pressure with the floor.
 */
Loic Hausammann's avatar
Format    
Loic Hausammann committed
96
97
98
99
__attribute__((always_inline)) static INLINE float
pressure_floor_get_comoving_pressure(const struct part* p,
                                     const float pressure_comoving,
                                     const struct cosmology* cosmo) {
Loic Hausammann's avatar
Loic Hausammann committed
100

101
102
  const float a_coef = pow_three_gamma_minus_one(cosmo->a);
  const float rho = hydro_get_comoving_density(p);
Loic Hausammann's avatar
Format    
Loic Hausammann committed
103

104
  /* Compute the pressure floor */
Loic Hausammann's avatar
Format    
Loic Hausammann committed
105
106
  float floor = kernel_gamma * kernel_gamma * p->h * p->h * rho *
                pressure_floor_props.constants;
107
  floor -= p->pressure_floor_data.sigma2 * cosmo->a * cosmo->a;
108
  floor *= a_coef * rho * hydro_one_over_gamma;
Loic Hausammann's avatar
Loic Hausammann committed
109

110
  return fmaxf(pressure_comoving, floor);
Loic Hausammann's avatar
Loic Hausammann committed
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
}

/**
 * @brief Initialise the pressure floor by reading the parameters and converting
 * to internal units.
 *
 * The input temperatures and number densities are converted to pressure and
 * density assuming a neutral gas of primoridal abundance.
 *
 * @param params The YAML parameter file.
 * @param us The system of units used internally.
 * @param phys_const The physical constants.
 * @param hydro_props The propoerties of the hydro scheme.
 * @param props The pressure floor properties to fill.
 */
126
__attribute__((always_inline)) static INLINE void pressure_floor_init(
Loic Hausammann's avatar
Format    
Loic Hausammann committed
127
128
129
    struct pressure_floor_properties* props,
    const struct phys_const* phys_const, const struct unit_system* us,
    const struct hydro_props* hydro_props, struct swift_params* params) {
Loic Hausammann's avatar
Loic Hausammann committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

  /* Read the Jeans factor */
  props->n_jeans =
      parser_get_param_float(params, "GEARPressureFloor:Jeans_factor");

  /* Compute the constants */
  props->constants =
      4.0 * M_1_PI * phys_const->const_newton_G * pow(props->n_jeans, 2. / 3.);
}

/**
 * @brief Print the properties of the pressure floor to stdout.
 *
 * @param props The pressure floor properties.
 */
145
__attribute__((always_inline)) static INLINE void pressure_floor_print(
Loic Hausammann's avatar
Format    
Loic Hausammann committed
146
    const struct pressure_floor_properties* props) {
Loic Hausammann's avatar
Loic Hausammann committed
147
148
149
150
151
152
153
154
155
156
157

  message("Pressure floor is 'GEAR' with:");
  message("Jeans factor: %g", props->n_jeans);
}

#ifdef HAVE_HDF5

/**
 * @brief Writes the current model of pressure floor to the file
 * @param h_grp The HDF5 group in which to write
 */
Loic Hausammann's avatar
Format    
Loic Hausammann committed
158
159
__attribute__((always_inline)) INLINE static void pressure_floor_print_snapshot(
    hid_t h_grp) {
Loic Hausammann's avatar
Loic Hausammann committed
160
161
162

  io_write_attribute_s(h_grp, "Pressure floor", "GEAR");
}
163

Loic Hausammann's avatar
Loic Hausammann committed
164
165
#endif

166
/**
Loic Hausammann's avatar
Loic Hausammann committed
167
 * @brief Finishes the density calculation for the pressure floor properties.
168
169
170
171
172
 *
 * @param p The particle to act upon
 * @param cosmo The current cosmological model.
 */
__attribute__((always_inline)) INLINE static void pressure_floor_end_density(
Loic Hausammann's avatar
Format    
Loic Hausammann committed
173
    struct part* restrict p, const struct cosmology* cosmo) {
174
175
176

  /* To finish the turbulence estimation we devide by the density */
  p->pressure_floor_data.sigma2 /=
177
      pow_dimension(p->h) * hydro_get_comoving_density(p);
178
179
180

  /* Add the cosmological term */
  p->pressure_floor_data.sigma2 *= cosmo->a2_inv;
181
182
183
}

/**
Loic Hausammann's avatar
Loic Hausammann committed
184
185
 * @brief Sets all the pressure floor fields to sensible values when the #part
 * has 0 ngbs.
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
 *
 * @param p The particle to act upon
 * @param xp The extended particle data to act upon
 * @param cosmo The current cosmological model.
 */
__attribute__((always_inline)) INLINE static void
pressure_floor_part_has_no_neighbours(struct part* restrict p,
                                      struct xpart* restrict xp,
                                      const struct cosmology* cosmo) {

  /* If part has 0 neighbours, the estimation of turbulence is 0 */
  p->pressure_floor_data.sigma2 = 0.f;
}

/**
 * @brief Sets the pressure_floor properties of the (x-)particles to a valid
 * start state.
 *
 * @param p Pointer to the particle data.
 * @param xp Pointer to the extended particle data.
 */
__attribute__((always_inline)) INLINE static void pressure_floor_init_part(
    struct part* restrict p, struct xpart* restrict xp) {
  p->pressure_floor_data.sigma2 = 0.f;
}

/**
 * @brief Sets the pressure_floor properties of the (x-)particles to a valid
 * start state.
 *
 * @param phys_const The physical constant in internal units.
 * @param us The unit system.
 * @param cosmo The current cosmological model.
 * @param p Pointer to the particle data.
 * @param xp Pointer to the extended particle data.
 */
Loic Hausammann's avatar
Format    
Loic Hausammann committed
222
223
224
225
226
227
__attribute__((always_inline)) INLINE static void
pressure_floor_first_init_part(const struct phys_const* restrict phys_const,
                               const struct unit_system* restrict us,
                               const struct cosmology* restrict cosmo,
                               struct part* restrict p,
                               struct xpart* restrict xp) {
228
229
230
231

  pressure_floor_init_part(p, xp);
}

Loic Hausammann's avatar
Loic Hausammann committed
232
#endif /* SWIFT_PRESSURE_FLOOR_GEAR_H */