hydro_properties.c 3.87 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
37
#define hydro_props_default_max_iterations 30
#define hydro_props_default_volume_change 2.0f

38
39
40
41
42
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");
43
  p->target_neighbours = pow_dimension(p->eta_neighbours) * kernel_norm;
44
45
46
  p->delta_neighbours = parser_get_param_float(params, "SPH:delta_neighbours");

  /* Ghost stuff */
47
48
  p->max_smoothing_iterations = parser_get_opt_param_int(
      params, "SPH:max_ghost_iterations", hydro_props_default_max_iterations);
49
50
51

  /* Time integration properties */
  p->CFL_condition = parser_get_param_float(params, "SPH:CFL_condition");
52
53
  const float max_volume_change = parser_get_opt_param_float(
      params, "SPH:max_volume_change", hydro_props_default_volume_change);
54
  p->log_max_h_change = logf(powf(max_volume_change, hydro_dimension_inv));
55
56
57
58
}

void hydro_props_print(const struct hydro_props *p) {

59
  message("Adiabatic index gamma: %f.", hydro_gamma);
60
61
62
63

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

64
65
66
  message("Hydrodynamic kernel: %s with %.2f +/- %.2f neighbours (eta=%f).",
          kernel_name, p->target_neighbours, p->delta_neighbours,
          p->eta_neighbours);
67

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

70
  message(
Matthieu Schaller's avatar
Matthieu Schaller committed
71
72
      "Hydrodynamic integration: Max change of volume: %.2f "
      "(max|dlog(h)/dt|=%f).",
73
      powf(expf(p->log_max_h_change), hydro_dimension), p->log_max_h_change);
74
75
76
77

  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);
78
}
79
80
81
82
83

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

  writeAttribute_f(h_grpsph, "Adiabatic index", hydro_gamma);
84
  writeAttribute_i(h_grpsph, "Dimension", (int)hydro_dimension);
85
86
87
88
89
90
91
92
93
94
95
96
97
  writeAttribute_s(h_grpsph, "Scheme", SPH_IMPLEMENTATION);
  writeAttribute_s(h_grpsph, "Kernel function", kernel_name);
  writeAttribute_f(h_grpsph, "Kernel target N_ngb", p->target_neighbours);
  writeAttribute_f(h_grpsph, "Kernel delta N_ngb", p->delta_neighbours);
  writeAttribute_f(h_grpsph, "Kernel eta", p->eta_neighbours);
  writeAttribute_f(h_grpsph, "CFL parameter", p->CFL_condition);
  writeAttribute_f(h_grpsph, "Volume log(max(delta h))", p->log_max_h_change);
  writeAttribute_f(h_grpsph, "Volume max change time-step",
                   powf(expf(p->log_max_h_change), 3.f));
  writeAttribute_f(h_grpsph, "Max ghost iterations",
                   p->max_smoothing_iterations);
}
#endif