cooling.c 3.45 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
24
25
26
27
28
29
30
31
32
33
34
35
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
/*******************************************************************************
 * This file is part of SWIFT.
 * Copyright (c) 2016 Tom Theuns (tom.theuns@durham.ac.uk)
 *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk)
 *                    Richard Bower (r.g.bower@durham.ac.uk)
 *                    Stefan Arridge  (stefan.arridge@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/>.
 *
 ******************************************************************************/

/* Config parameters. */
#include "../config.h"

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

/**
 * @brief Initialises the cooling properties in the internal system
 * of units.
 *
 * @param parameter_file The parsed parameter file
 * @param us The current internal system of units
 * @param cooling  The cooling  properties to initialize
 */
void cooling_init(const struct swift_params* parameter_file,
                    struct UnitSystem* us,
                    struct cooling_data* cooling) {

#ifdef CONST_COOLING
  cooling->const_cooling.lambda = parser_get_param_double(parameter_file, "Cooling:lambda");
  cooling->const_cooling.min_energy = parser_get_param_double(parameter_file, "Cooling:min_energy");
  cooling->const_cooling.cooling_tstep_mult = parser_get_param_double(parameter_file, "Cooling:cooling_tstep_mult");
#endif /* CONST_COOLING */

}

/**
 * @brief Prints the properties of the cooling model to stdout.
 *
 * @param  cooling The cooling properties.
 */
void cooling_print(const struct cooling_data* cooling) {

#ifdef CONST_COOLING
  message(
      "Cooling properties are (lambda, min_energy, tstep multiplier) %g %g %g ",
      cooling->const_cooling.lambda,
      cooling->const_cooling.min_energy
      cooling->const_cooling.cooling_tstep_mult);
#endif /* CONST_COOLING */
}
Stefan Arridge's avatar
Stefan Arridge committed
64
65
66

void update_entropy(const struct cooling_data* cooling,
		   const struct phys_const* const phys_const, struct part* p, 
Stefan Arridge's avatar
Stefan Arridge committed
67
		   double dt){
68
69
70
71
72
73
74
75
76

  /*updates the entropy of a particle after integrating the cooling equation*/
  float u_old;
  float u_new;
  float new_entropy;
  float old_entropy = p->entropy;
  float rho = p->rho;

  u_old = old_entropy/(GAMMA_MINUS1) * pow(rho,GAMMA_MINUS1);
Stefan Arridge's avatar
Stefan Arridge committed
77
78
79
  u_new = calculate_new_thermal_energy(u_old,dt,cooling):
  new_entropy = u_new/pow(rho,GAMMA_MINUS1) * GAMMA_MINUS1;
  p->entropy = new_entropy
80
81
82
}


Stefan Arridge's avatar
Stefan Arridge committed
83
float calculate_new_thermal_energy(float u_old, double dt, const struct cooling_data* cooling){
Stefan Arridge's avatar
Stefan Arridge committed
84
#ifdef CONST_COOLING
85
86
87
88
89
  //This function integrates the cooling equation, given the initial thermal energy and the timestep dt.
  //Returns 0 if successful and 1 if not
  int status = 0;
  float du_dt = cooling->const_cooling.lambda;
  float u_floor = cooling->const_cooling.min_energy;
Stefan Arridge's avatar
Stefan Arridge committed
90
91
92
93
94
95
96
97
98
99
100
  float u_new;
  if (u_old - du_dt*dt > min_energy){
    u_new = u_old - du_dt*dt;
  }
  else{
    u_new = min_energy;
  }

  return u_new;
#endif /*CONST_COOLING*/ 
}
101
102
103
104
105