Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
e32d8a9f
Commit
e32d8a9f
authored
Jan 25, 2018
by
lhausamm
Browse files
Change grackle cooling from densities to fraction
parent
a9261d20
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/cooling/grackle/cooling.h
View file @
e32d8a9f
...
...
@@ -72,24 +72,25 @@ __attribute__((always_inline)) INLINE static void cooling_first_init_part(
#if COOLING_GRACKLE_MODE >= 1
/* primordial chemistry >= 1 */
xp
->
cooling_data
.
HI_
density
=
0
.
f
;
xp
->
cooling_data
.
HII_
density
=
0
.
f
;
xp
->
cooling_data
.
HeI_
density
=
0
.
f
;
xp
->
cooling_data
.
HeII_
density
=
0
.
f
;
xp
->
cooling_data
.
HeIII_
density
=
0
.
f
;
xp
->
cooling_data
.
e_
density
=
0
.
f
;
xp
->
cooling_data
.
HI_
frac
=
grackle_data
->
HydrogenFractionByMass
;
xp
->
cooling_data
.
HII_
frac
=
0
.
f
;
xp
->
cooling_data
.
HeI_
frac
=
1
.
-
grackle_data
->
HydrogenFractionByMass
;
xp
->
cooling_data
.
HeII_
frac
=
0
.
f
;
xp
->
cooling_data
.
HeIII_
frac
=
0
.
f
;
xp
->
cooling_data
.
e_
frac
=
0
.
f
;
#if COOLING_GRACKLE_MODE >= 2
/* primordial chemistry >= 2 */
xp
->
cooling_data
.
HM_
density
=
0
.
f
;
xp
->
cooling_data
.
H2I_
density
=
0
.
f
;
xp
->
cooling_data
.
H2II_
density
=
0
.
f
;
xp
->
cooling_data
.
HM_
frac
=
0
.
f
;
xp
->
cooling_data
.
H2I_
frac
=
0
.
f
;
xp
->
cooling_data
.
H2II_
frac
=
0
.
f
;
#if COOLING_GRACKLE_MODE >= 3
/* primordial chemistry >= 3 */
xp
->
cooling_data
.
DI_density
=
0
.
f
;
xp
->
cooling_data
.
DII_density
=
0
.
f
;
xp
->
cooling_data
.
HDI_density
=
0
.
f
;
static
const
float
DeuteriumFractionByMass
=
3.4e-5
;
xp
->
cooling_data
.
DI_frac
=
2
.
0
*
DeuteriumFractionByMass
;
xp
->
cooling_data
.
DII_frac
=
0
.
f
;
xp
->
cooling_data
.
HDI_frac
=
0
.
f
;
#endif // MODE >= 3
#endif // MODE >= 2
...
...
@@ -97,7 +98,81 @@ __attribute__((always_inline)) INLINE static void cooling_first_init_part(
#endif // MODE >= 1
/* metal cooling = 1 */
xp
->
cooling_data
.
metal_density
=
0
.
f
;
xp
->
cooling_data
.
metal_frac
=
0
.
f
;
}
/**
* @brief update particle with densities.
*
* @param xp The extended particle data
*/
__attribute__
((
always_inline
))
INLINE
static
void
cooling_compute_density
(
struct
xpart
*
restrict
xp
,
const
float
rho
)
{
#if COOLING_GRACKLE_MODE >= 1
/* primordial chemistry >= 1 */
xp
->
cooling_data
.
HI_frac
*=
rho
;
xp
->
cooling_data
.
HII_frac
*=
rho
;
xp
->
cooling_data
.
HeI_frac
*=
rho
;
xp
->
cooling_data
.
HeII_frac
*=
rho
;
xp
->
cooling_data
.
HeIII_frac
*=
rho
;
xp
->
cooling_data
.
e_frac
*=
rho
;
#if COOLING_GRACKLE_MODE >= 2
/* primordial chemistry >= 2 */
xp
->
cooling_data
.
HM_frac
*=
rho
;
xp
->
cooling_data
.
H2I_frac
*=
rho
;
xp
->
cooling_data
.
H2II_frac
*=
rho
;
#if COOLING_GRACKLE_MODE >= 3
/* primordial chemistry >= 3 */
xp
->
cooling_data
.
DI_frac
*=
rho
;
xp
->
cooling_data
.
DII_frac
*=
rho
;
xp
->
cooling_data
.
HDI_frac
*=
rho
;
#endif // MODE >= 3
#endif // MODE >= 2
#endif // MODE >= 1
xp
->
cooling_data
.
metal_frac
*=
rho
;
}
/**
* @brief update particle with fraction.
*
* @param xp The extended particle data
*/
__attribute__
((
always_inline
))
INLINE
static
void
cooling_compute_fraction
(
struct
xpart
*
restrict
xp
,
const
float
rho
)
{
#if COOLING_GRACKLE_MODE >= 1
/* primordial chemistry >= 1 */
xp
->
cooling_data
.
HI_frac
/=
rho
;
xp
->
cooling_data
.
HII_frac
/=
rho
;
xp
->
cooling_data
.
HeI_frac
/=
rho
;
xp
->
cooling_data
.
HeII_frac
/=
rho
;
xp
->
cooling_data
.
HeIII_frac
/=
rho
;
xp
->
cooling_data
.
e_frac
/=
rho
;
#if COOLING_GRACKLE_MODE >= 2
/* primordial chemistry >= 2 */
xp
->
cooling_data
.
HM_frac
/=
rho
;
xp
->
cooling_data
.
H2I_frac
/=
rho
;
xp
->
cooling_data
.
H2II_frac
/=
rho
;
#if COOLING_GRACKLE_MODE >= 3
/* primordial chemistry >= 3 */
xp
->
cooling_data
.
DI_frac
/=
rho
;
xp
->
cooling_data
.
DII_frac
/=
rho
;
xp
->
cooling_data
.
HDI_frac
/=
rho
;
#endif // MODE >= 3
#endif // MODE >= 2
#endif // MODE >= 1
xp
->
cooling_data
.
metal_frac
/=
rho
;
}
/**
...
...
@@ -184,6 +259,7 @@ __attribute__((always_inline)) INLINE static double cooling_rate(
gr_float
density
=
hydro_get_physical_density
(
p
,
cosmo
);
const
double
energy_before
=
hydro_get_physical_internal_energy
(
p
,
cosmo
);
gr_float
energy
=
energy_before
;
/* v is useless with grackle 3.0 */
gr_float
vx
=
0
;
gr_float
vy
=
0
;
...
...
@@ -195,26 +271,29 @@ __attribute__((always_inline)) INLINE static double cooling_rate(
data
.
y_velocity
=
&
vy
;
data
.
z_velocity
=
&
vz
;
/* transform gas fraction to densities */
cooling_compute_density
(
xp
,
p
->
rho
);
#if COOLING_GRACKLE_MODE >= 1
/* primordial chemistry >= 1 */
data
.
HI_density
=
&
xp
->
cooling_data
.
HI_
density
;
data
.
HII_density
=
&
xp
->
cooling_data
.
HII_
density
;
data
.
HeI_density
=
&
xp
->
cooling_data
.
HeI_
density
;
data
.
HeII_density
=
&
xp
->
cooling_data
.
HeII_
density
;
data
.
HeIII_density
=
&
xp
->
cooling_data
.
HeIII_
density
;
data
.
e_density
=
&
xp
->
cooling_data
.
e_
density
;
data
.
HI_density
=
&
xp
->
cooling_data
.
HI_
frac
;
data
.
HII_density
=
&
xp
->
cooling_data
.
HII_
frac
;
data
.
HeI_density
=
&
xp
->
cooling_data
.
HeI_
frac
;
data
.
HeII_density
=
&
xp
->
cooling_data
.
HeII_
frac
;
data
.
HeIII_density
=
&
xp
->
cooling_data
.
HeIII_
frac
;
data
.
e_density
=
&
xp
->
cooling_data
.
e_
frac
;
#if COOLING_GRACKLE_MODE >= 2
/* primordial chemistry >= 2 */
data
.
HM_density
=
&
xp
->
cooling_data
.
HM_
density
;
data
.
H2I_density
=
&
xp
->
cooling_data
.
H2I_
density
;
data
.
H2II_density
=
&
xp
->
cooling_data
.
H2II_
density
;
data
.
HM_density
=
&
xp
->
cooling_data
.
HM_
frac
;
data
.
H2I_density
=
&
xp
->
cooling_data
.
H2I_
frac
;
data
.
H2II_density
=
&
xp
->
cooling_data
.
H2II_
frac
;
#if COOLING_GRACKLE_MODE >= 3
/* primordial chemistry >= 3 */
data
.
DI_density
=
&
xp
->
cooling_data
.
DI_
density
;
data
.
DII_density
=
&
xp
->
cooling_data
.
DII_
density
;
data
.
HDI_density
=
&
xp
->
cooling_data
.
HDI_
density
;
data
.
DI_density
=
&
xp
->
cooling_data
.
DI_
frac
;
data
.
DII_density
=
&
xp
->
cooling_data
.
DII_
frac
;
data
.
HDI_density
=
&
xp
->
cooling_data
.
HDI_
frac
;
#endif // MODE >= 3
#endif // MODE >= 2
...
...
@@ -222,23 +301,27 @@ __attribute__((always_inline)) INLINE static double cooling_rate(
#endif // MODE >= 1
/* metal cooling = 1 */
data
.
metal_density
=
&
xp
->
cooling_data
.
metal_
density
;
data
.
metal_density
=
&
xp
->
cooling_data
.
metal_
frac
;
/* /\* volumetric heating rate *\/ */
/* gr_float volumetric_heating_rate = 0.; */
/* data.volumetric_heating_rate = &volumetric_heating_rate; */
gr_float
volumetric_heating_rate
=
0
.;
data
.
volumetric_heating_rate
=
&
volumetric_heating_rate
;
/* /\* specific heating rate *\/ */
/* gr_float specific_heating_rate = 0.; */
/* data.specific_heating_rate = &specific_heating_rate; */
gr_float
specific_heating_rate
=
0
.;
data
.
specific_heating_rate
=
&
specific_heating_rate
;
/* solve chemistry with table */
if
(
solve_chemistry
(
&
units
,
&
data
,
dt
)
==
0
)
{
error
(
"Error in solve_chemistry."
);
}
/* transform densities to gas fraction */
cooling_compute_fraction
(
xp
,
p
->
rho
);
cooling_print_backend
(
cooling
);
printf
(
"Energy: %g, before: %g, density: %g
\n
"
,
energy
,
energy_before
,
density
);
exit
(
1
);
return
(
energy
-
energy_before
)
/
dt
;
}
...
...
@@ -357,7 +440,7 @@ __attribute__((always_inline)) INLINE static void cooling_init_backend(
/* molecular network with H, He, D
From Cloudy table */
chemistry
->
primordial_chemistry
=
COOLING_GRACKLE_MODE
;
chemistry
->
metal_cooling
=
1
;
// metal cooling on
chemistry
->
metal_cooling
=
1
;
chemistry
->
UVbackground
=
cooling
->
uv_background
;
chemistry
->
grackle_data_file
=
cooling
->
cloudy_table
;
chemistry
->
use_radiative_transfer
=
0
;
...
...
src/cooling/grackle/cooling_struct.h
View file @
e32d8a9f
...
...
@@ -63,24 +63,24 @@ struct cooling_xpart_data {
#if COOLING_GRACKLE_MODE >= 1
/* primordial chemistry >= 1 */
gr_float
HI_
density
;
gr_float
HII_
density
;
gr_float
HeI_
density
;
gr_float
HeII_
density
;
gr_float
HeIII_
density
;
gr_float
e_
density
;
gr_float
HI_
frac
;
gr_float
HII_
frac
;
gr_float
HeI_
frac
;
gr_float
HeII_
frac
;
gr_float
HeIII_
frac
;
gr_float
e_
frac
;
#if COOLING_GRACKLE_MODE >= 2
/* primordial chemistry >= 2 */
gr_float
HM_
density
;
gr_float
H2I_
density
;
gr_float
H2II_
density
;
gr_float
HM_
frac
;
gr_float
H2I_
frac
;
gr_float
H2II_
frac
;
#if COOLING_GRACKLE_MODE >= 3
/* primordial chemistry >= 3 */
gr_float
DI_
density
;
gr_float
DII_
density
;
gr_float
HDI_
density
;
gr_float
DI_
frac
;
gr_float
DII_
frac
;
gr_float
HDI_
frac
;
#endif // MODE >= 3
#endif // MODE >= 2
...
...
@@ -88,7 +88,7 @@ struct cooling_xpart_data {
#endif // MODE >= 1
/* metal cooling = 1 */
gr_float
metal_
density
;
gr_float
metal_
frac
;
};
#endif
/* SWIFT_COOLING_STRUCT_NONE_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment