hydro_properties.c 4.75 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*******************************************************************************
 * This file is part of SWIFT.
 * Copyright (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/>.
 *
 ******************************************************************************/

/* This object's header. */
#include "hydro_properties.h"

/* Standard headers */
24
#include <float.h>
25
26
27
#include <math.h>

/* Local headers. */
28
#include "adiabatic_index.h"
29
#include "common_io.h"
30
#include "dimension.h"
31
32
#include "error.h"
#include "hydro.h"
33
#include "kernel_hydro.h"
34

35
36
#define hydro_props_default_max_iterations 30
#define hydro_props_default_volume_change 2.0f
37
#define hydro_props_default_h_max FLT_MAX
38

39
40
41
42
43
void hydro_props_init(struct hydro_props *p,
                      const struct swift_params *params) {

  /* Kernel properties */
  p->eta_neighbours = parser_get_param_float(params, "SPH:resolution_eta");
44
  p->target_neighbours = pow_dimension(p->eta_neighbours) * kernel_norm;
45
46
  p->delta_neighbours = parser_get_param_float(params, "SPH:delta_neighbours");

47
48
49
50
51
52
#ifdef SHADOWFAX_SPH
  /* change the meaning of target_neighbours and delta_neighbours */
  p->target_neighbours = 1.0f;
  p->delta_neighbours = 0.0f;
#endif

53
54
55
56
57
  /* Maximal smoothing length */
  p->h_max = parser_get_opt_param_float(params, "SPH:h_max",
                                        hydro_props_default_h_max);

  /* Number of iterations to converge h */
58
59
  p->max_smoothing_iterations = parser_get_opt_param_int(
      params, "SPH:max_ghost_iterations", hydro_props_default_max_iterations);
60
61
62

  /* Time integration properties */
  p->CFL_condition = parser_get_param_float(params, "SPH:CFL_condition");
63
64
  const float max_volume_change = parser_get_opt_param_float(
      params, "SPH:max_volume_change", hydro_props_default_volume_change);
65
  p->log_max_h_change = logf(powf(max_volume_change, hydro_dimension_inv));
66
67
68
69
}

void hydro_props_print(const struct hydro_props *p) {

70
71
72
73
74
75
76
77
78
#if defined(EOS_IDEAL_GAS)
  message("Equation of state: Ideal gas.");
#elif defined(EOS_ISOTHERMAL_GAS)
  message(
      "Equation of state: Isothermal with internal energy "
      "per unit mass set to %f.",
      const_isothermal_internal_energy);
#endif

79
  message("Adiabatic index gamma: %f.", hydro_gamma);
80
81
82
83

  message("Hydrodynamic scheme: %s in %dD.", SPH_IMPLEMENTATION,
          (int)hydro_dimension);

84
85
86
  message("Hydrodynamic kernel: %s with %.2f +/- %.2f neighbours (eta=%f).",
          kernel_name, p->target_neighbours, p->delta_neighbours,
          p->eta_neighbours);
87

Peter W. Draper's avatar
Peter W. Draper committed
88
  message("Hydrodynamic integration: CFL parameter: %.4f.", p->CFL_condition);
89

90
  message(
Matthieu Schaller's avatar
Matthieu Schaller committed
91
92
      "Hydrodynamic integration: Max change of volume: %.2f "
      "(max|dlog(h)/dt|=%f).",
93
      pow_dimension(expf(p->log_max_h_change)), p->log_max_h_change);
94

95
96
97
  if (p->h_max != hydro_props_default_h_max)
    message("Maximal smoothing length allowed: %.4f", p->h_max);

98
99
100
  if (p->max_smoothing_iterations != hydro_props_default_max_iterations)
    message("Maximal iterations in ghost task set to %d (default is %d)",
            p->max_smoothing_iterations, hydro_props_default_max_iterations);
101
}
102
103
104
105

#if defined(HAVE_HDF5)
void hydro_props_print_snapshot(hid_t h_grpsph, const struct hydro_props *p) {

106
107
108
109
110
111
112
  io_write_attribute_f(h_grpsph, "Adiabatic index", hydro_gamma);
  io_write_attribute_i(h_grpsph, "Dimension", (int)hydro_dimension);
  io_write_attribute_s(h_grpsph, "Scheme", SPH_IMPLEMENTATION);
  io_write_attribute_s(h_grpsph, "Kernel function", kernel_name);
  io_write_attribute_f(h_grpsph, "Kernel target N_ngb", p->target_neighbours);
  io_write_attribute_f(h_grpsph, "Kernel delta N_ngb", p->delta_neighbours);
  io_write_attribute_f(h_grpsph, "Kernel eta", p->eta_neighbours);
113
  io_write_attribute_f(h_grpsph, "Maximal smoothing length", p->h_max);
114
115
116
117
118
119
120
  io_write_attribute_f(h_grpsph, "CFL parameter", p->CFL_condition);
  io_write_attribute_f(h_grpsph, "Volume log(max(delta h))",
                       p->log_max_h_change);
  io_write_attribute_f(h_grpsph, "Volume max change time-step",
                       pow_dimension(expf(p->log_max_h_change)));
  io_write_attribute_i(h_grpsph, "Max ghost iterations",
                       p->max_smoothing_iterations);
121
122
}
#endif