Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
SWIFTsim
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
72
Issues
72
List
Boards
Labels
Milestones
Merge Requests
14
Merge Requests
14
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
SWIFT
SWIFTsim
Commits
ac2365c9
Commit
ac2365c9
authored
Apr 22, 2018
by
Matthieu Schaller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code formatting
parent
647eceac
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
254 additions
and
266 deletions
+254
-266
src/chemistry.c
src/chemistry.c
+4
-3
src/chemistry/EAGLE/chemistry.h
src/chemistry/EAGLE/chemistry.h
+6
-4
src/chemistry/gear/chemistry.h
src/chemistry/gear/chemistry.h
+6
-6
src/chemistry/gear/chemistry_io.h
src/chemistry/gear/chemistry_io.h
+10
-12
src/chemistry/none/chemistry.h
src/chemistry/none/chemistry.h
+6
-4
src/cooling/EAGLE/cooling.h
src/cooling/EAGLE/cooling.h
+0
-1
src/cooling/EAGLE/cooling_io.h
src/cooling/EAGLE/cooling_io.h
+2
-2
src/cooling/const_du/cooling.h
src/cooling/const_du/cooling.h
+1
-2
src/cooling/const_du/cooling_io.h
src/cooling/const_du/cooling_io.h
+2
-2
src/cooling/const_lambda/cooling.h
src/cooling/const_lambda/cooling.h
+0
-1
src/cooling/const_lambda/cooling_io.h
src/cooling/const_lambda/cooling_io.h
+2
-2
src/cooling/grackle/cooling.h
src/cooling/grackle/cooling.h
+127
-143
src/cooling/grackle/cooling_io.h
src/cooling/grackle/cooling_io.h
+44
-50
src/cooling/none/cooling.h
src/cooling/none/cooling.h
+2
-3
src/cooling/none/cooling_io.h
src/cooling/none/cooling_io.h
+2
-2
src/debug.c
src/debug.c
+3
-1
src/engine.c
src/engine.c
+14
-10
src/engine.h
src/engine.h
+12
-9
src/parallel_io.c
src/parallel_io.c
+3
-2
src/serial_io.c
src/serial_io.c
+3
-3
src/single_io.c
src/single_io.c
+3
-3
src/vector.h
src/vector.h
+2
-1
No files found.
src/chemistry.c
View file @
ac2365c9
...
...
@@ -46,7 +46,8 @@ void chemistry_init(const struct swift_params* parameter_file,
*
* Calls chemistry_print_backend for the chosen chemistry model.
*
* @brief The #chemistry_global_data containing information about the current model.
* @brief The #chemistry_global_data containing information about the current
* model.
*/
void
chemistry_print
(
const
struct
chemistry_global_data
*
data
)
{
chemistry_print_backend
(
data
);
...
...
@@ -60,8 +61,8 @@ void chemistry_print(const struct chemistry_global_data* data) {
*/
void
chemistry_struct_dump
(
const
struct
chemistry_global_data
*
chemistry
,
FILE
*
stream
)
{
restart_write_blocks
((
void
*
)
chemistry
,
sizeof
(
struct
chemistry_global_data
),
1
,
stream
,
"chemistry"
,
"chemistry function"
);
restart_write_blocks
((
void
*
)
chemistry
,
sizeof
(
struct
chemistry_global_data
),
1
,
stream
,
"chemistry"
,
"chemistry function"
);
}
/**
...
...
src/chemistry/EAGLE/chemistry.h
View file @
ac2365c9
...
...
@@ -90,8 +90,8 @@ __attribute__((always_inline)) INLINE static void chemistry_first_init_part(
const
struct
phys_const
*
restrict
phys_const
,
const
struct
unit_system
*
restrict
us
,
const
struct
cosmology
*
restrict
cosmo
,
const
struct
chemistry_global_data
*
data
,
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
)
{
const
struct
chemistry_global_data
*
data
,
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
)
{
p
->
chemistry_data
.
metal_mass_fraction_total
=
data
->
initial_metal_mass_fraction_total
;
...
...
@@ -136,9 +136,11 @@ static INLINE void chemistry_init_backend(
/**
* @brief Prints the properties of the chemistry model to stdout.
*
* @brief The #chemistry_global_data containing information about the current model.
* @brief The #chemistry_global_data containing information about the current
* model.
*/
static
INLINE
void
chemistry_print_backend
(
const
struct
chemistry_global_data
*
data
)
{
static
INLINE
void
chemistry_print_backend
(
const
struct
chemistry_global_data
*
data
)
{
message
(
"Chemistry model is 'EAGLE' tracking %d elements."
,
chemistry_element_count
);
...
...
src/chemistry/gear/chemistry.h
View file @
ac2365c9
...
...
@@ -38,7 +38,6 @@
#include "physical_constants.h"
#include "units.h"
/**
* @brief Compute the metal mass fraction
*
...
...
@@ -46,9 +45,10 @@
* @param xp Pointer to the extended particle data.
* @param data The global chemistry information.
*/
__attribute__
((
always_inline
))
INLINE
static
float
chemistry_metal_mass_fraction
(
const
struct
part
*
restrict
p
,
const
struct
xpart
*
restrict
xp
)
{
return
p
->
chemistry_data
.
Z
;
__attribute__
((
always_inline
))
INLINE
static
float
chemistry_metal_mass_fraction
(
const
struct
part
*
restrict
p
,
const
struct
xpart
*
restrict
xp
)
{
return
p
->
chemistry_data
.
Z
;
}
/**
...
...
@@ -136,8 +136,8 @@ __attribute__((always_inline)) INLINE static void chemistry_first_init_part(
const
struct
phys_const
*
restrict
phys_const
,
const
struct
unit_system
*
restrict
us
,
const
struct
cosmology
*
restrict
cosmo
,
const
struct
chemistry_global_data
*
data
,
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
)
{
const
struct
chemistry_global_data
*
data
,
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
)
{
p
->
chemistry_data
.
Z
=
data
->
initial_metallicity
;
chemistry_init_part
(
p
,
data
);
...
...
src/chemistry/gear/chemistry_io.h
View file @
ac2365c9
...
...
@@ -43,9 +43,11 @@ chemistry_get_element_name(enum chemistry_element elem) {
/**
* @brief Prints the properties of the chemistry model to stdout.
*
* @brief The #chemistry_global_data containing information about the current model.
* @brief The #chemistry_global_data containing information about the current
* model.
*/
static
INLINE
void
chemistry_print_backend
(
const
struct
chemistry_global_data
*
data
)
{
static
INLINE
void
chemistry_print_backend
(
const
struct
chemistry_global_data
*
data
)
{
message
(
"Chemistry function is 'Gear'."
);
}
...
...
@@ -65,9 +67,8 @@ __attribute__((always_inline)) INLINE static int chemistry_read_particles(
list
[
0
]
=
io_make_input_field
(
"ElementAbundance"
,
FLOAT
,
chemistry_element_count
,
OPTIONAL
,
UNIT_CONV_NO_UNITS
,
parts
,
chemistry_data
.
metal_mass_fraction
);
list
[
1
]
=
io_make_input_field
(
"Z"
,
FLOAT
,
1
,
OPTIONAL
,
UNIT_CONV_NO_UNITS
,
parts
,
chemistry_data
.
Z
);
list
[
1
]
=
io_make_input_field
(
"Z"
,
FLOAT
,
1
,
OPTIONAL
,
UNIT_CONV_NO_UNITS
,
parts
,
chemistry_data
.
Z
);
return
2
;
}
...
...
@@ -76,12 +77,10 @@ __attribute__((always_inline)) INLINE static void chemistry_read_parameters(
const
struct
swift_params
*
parameter_file
,
const
struct
unit_system
*
us
,
const
struct
phys_const
*
phys_const
,
struct
chemistry_global_data
*
data
)
{
data
->
initial_metallicity
=
parser_get_opt_param_float
(
parameter_file
,
"GearChemistry:InitialMetallicity"
,
-
1
);
data
->
initial_metallicity
=
parser_get_opt_param_float
(
parameter_file
,
"GearChemistry:InitialMetallicity"
,
-
1
);
}
/**
* @brief Specifies which particle fields to write to a dataset
*
...
...
@@ -97,8 +96,8 @@ __attribute__((always_inline)) INLINE static int chemistry_write_particles(
list
[
0
]
=
io_make_output_field
(
"SmoothedElementAbundance"
,
FLOAT
,
chemistry_element_count
,
UNIT_CONV_NO_UNITS
,
parts
,
chemistry_data
.
smoothed_metal_mass_fraction
);
list
[
1
]
=
io_make_output_field
(
"Z"
,
FLOAT
,
1
,
UNIT_CONV_NO_UNITS
,
parts
,
chemistry_data
.
Z
);
list
[
1
]
=
io_make_output_field
(
"Z"
,
FLOAT
,
1
,
UNIT_CONV_NO_UNITS
,
parts
,
chemistry_data
.
Z
);
list
[
2
]
=
io_make_output_field
(
"ElementAbundance"
,
FLOAT
,
chemistry_element_count
,
UNIT_CONV_NO_UNITS
,
...
...
@@ -126,5 +125,4 @@ __attribute__((always_inline)) INLINE static void chemistry_write_flavour(
}
#endif
#endif
/* SWIFT_CHEMISTRY_IO_GEAR_H */
src/chemistry/none/chemistry.h
View file @
ac2365c9
...
...
@@ -66,9 +66,11 @@ static INLINE void chemistry_init_backend(
/**
* @brief Prints the properties of the chemistry model to stdout.
*
* @brief The #chemistry_global_data containing information about the current model.
* @brief The #chemistry_global_data containing information about the current
* model.
*/
static
INLINE
void
chemistry_print_backend
(
const
struct
chemistry_global_data
*
data
)
{
static
INLINE
void
chemistry_print_backend
(
const
struct
chemistry_global_data
*
data
)
{
message
(
"Chemistry function is 'No chemistry'."
);
}
...
...
@@ -98,8 +100,8 @@ __attribute__((always_inline)) INLINE static void chemistry_first_init_part(
const
struct
phys_const
*
restrict
phys_const
,
const
struct
unit_system
*
restrict
us
,
const
struct
cosmology
*
restrict
cosmo
,
const
struct
chemistry_global_data
*
data
,
const
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
)
{}
const
struct
chemistry_global_data
*
data
,
const
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
)
{}
/**
* @brief Sets the chemistry properties of the (x-)particles to a valid start
...
...
src/cooling/EAGLE/cooling.h
View file @
ac2365c9
...
...
@@ -38,7 +38,6 @@
#include "physical_constants.h"
#include "units.h"
/**
* @brief Apply the cooling function to a particle.
*
...
...
src/cooling/EAGLE/cooling_io.h
View file @
ac2365c9
...
...
@@ -45,8 +45,8 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
*/
__attribute__
((
always_inline
))
INLINE
static
int
cooling_write_particles
(
const
struct
xpart
*
xparts
,
struct
io_props
*
list
,
const
struct
cooling_function_data
*
cooling
)
{
const
struct
cooling_function_data
*
cooling
)
{
return
0
;
}
#endif // SWIFT_COOLING_EAGLE_IO_H
#endif
// SWIFT_COOLING_EAGLE_IO_H
src/cooling/const_du/cooling.h
View file @
ac2365c9
...
...
@@ -45,7 +45,6 @@
#include "physical_constants.h"
#include "units.h"
/**
* @brief Apply the cooling function to a particle.
*
...
...
@@ -80,7 +79,7 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
float
cooling_du_dt
=
-
cooling
->
cooling_rate
;
/* Integrate cooling equation to enforce energy floor */
if
(
u_old
+
hydro_du_dt
*
dt
<
u_floor
)
{
if
(
u_old
+
hydro_du_dt
*
dt
<
u_floor
)
{
cooling_du_dt
=
0
.
f
;
}
else
if
(
u_old
+
(
hydro_du_dt
+
cooling_du_dt
)
*
dt
<
u_floor
)
{
cooling_du_dt
=
(
u_old
+
dt
*
hydro_du_dt
-
u_floor
)
/
dt
;
...
...
src/cooling/const_du/cooling_io.h
View file @
ac2365c9
...
...
@@ -47,8 +47,8 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
*/
__attribute__
((
always_inline
))
INLINE
static
int
cooling_write_particles
(
const
struct
xpart
*
xparts
,
struct
io_props
*
list
,
const
struct
cooling_function_data
*
cooling
)
{
const
struct
cooling_function_data
*
cooling
)
{
return
0
;
}
#endif // SWIFT_COOLING_CONST_DU_IO_H
#endif
// SWIFT_COOLING_CONST_DU_IO_H
src/cooling/const_lambda/cooling.h
View file @
ac2365c9
...
...
@@ -38,7 +38,6 @@
#include "physical_constants.h"
#include "units.h"
/**
* @brief Calculates du/dt in code units for a particle.
*
...
...
src/cooling/const_lambda/cooling_io.h
View file @
ac2365c9
...
...
@@ -49,8 +49,8 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
*/
__attribute__
((
always_inline
))
INLINE
static
int
cooling_write_particles
(
const
struct
xpart
*
xparts
,
struct
io_props
*
list
,
const
struct
cooling_function_data
*
cooling
)
{
const
struct
cooling_function_data
*
cooling
)
{
return
0
;
}
#endif // SWIFT_COOLING_CONST_LAMBDA_IO_H
#endif
// SWIFT_COOLING_CONST_LAMBDA_IO_H
src/cooling/grackle/cooling.h
View file @
ac2365c9
...
...
@@ -53,12 +53,12 @@ static gr_float cooling_time(
const
struct
cooling_function_data
*
restrict
cooling
,
const
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
);
static
double
cooling_rate
(
const
struct
phys_const
*
restrict
phys_const
,
const
struct
unit_system
*
restrict
us
,
const
struct
cosmology
*
restrict
cosmo
,
const
struct
cooling_function_data
*
restrict
cooling
,
const
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
,
double
dt
);
static
double
cooling_rate
(
const
struct
phys_const
*
restrict
phys_const
,
const
struct
unit_system
*
restrict
us
,
const
struct
cosmology
*
restrict
cosmo
,
const
struct
cooling_function_data
*
restrict
cooling
,
const
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
,
double
dt
);
/**
* @brief Print the chemical network
...
...
@@ -70,19 +70,17 @@ __attribute__((always_inline)) INLINE static void cooling_print_fractions(
const
struct
cooling_xpart_data
tmp
=
xp
->
cooling_data
;
#if COOLING_GRACKLE_MODE > 0
message
(
"HI %g, HII %g, HeI %g, HeII %g, HeIII %g, e %g"
,
tmp
.
HI_frac
,
tmp
.
HII_frac
,
tmp
.
He
I_frac
,
tmp
.
HeII_frac
,
tmp
.
HeIII_frac
,
tmp
.
e_frac
);
message
(
"HI %g, HII %g, HeI %g, HeII %g, HeIII %g, e %g"
,
tmp
.
HI_frac
,
tmp
.
HII_frac
,
tmp
.
HeI_frac
,
tmp
.
HeII_frac
,
tmp
.
HeII
I_frac
,
tmp
.
e_frac
);
#endif
#if COOLING_GRACKLE_MODE > 1
message
(
"HM %g, H2I %g, H2II %g"
,
tmp
.
HM_frac
,
tmp
.
H2I_frac
,
tmp
.
H2II_frac
);
message
(
"HM %g, H2I %g, H2II %g"
,
tmp
.
HM_frac
,
tmp
.
H2I_frac
,
tmp
.
H2II_frac
);
#endif
#if COOLING_GRACKLE_MODE > 2
message
(
"DI %g, DII %g, HDI %g"
,
tmp
.
DI_frac
,
tmp
.
DII_frac
,
tmp
.
HDI_frac
);
message
(
"DI %g, DII %g, HDI %g"
,
tmp
.
DI_frac
,
tmp
.
DII_frac
,
tmp
.
HDI_frac
);
#endif
message
(
"Metal: %g"
,
tmp
.
metal_frac
);
}
...
...
@@ -97,13 +95,12 @@ __attribute__((always_inline)) INLINE static void cooling_print_fractions(
*
* @return 0 if diff > limit
*/
#define cooling_check_field(xp, old, field, limit) \
({ \
float tmp = xp->cooling_data.field - old->cooling_data.field; \
tmp = fabs(tmp) / xp->cooling_data.field; \
if (tmp > limit) \
return 0; \
})
#define cooling_check_field(xp, old, field, limit) \
({ \
float tmp = xp->cooling_data.field - old->cooling_data.field; \
tmp = fabs(tmp) / xp->cooling_data.field; \
if (tmp > limit) return 0; \
})
/**
* @brief Check if difference between two particles is lower than a given value
...
...
@@ -113,8 +110,7 @@ __attribute__((always_inline)) INLINE static void cooling_print_fractions(
* @param limit The difference limit
*/
__attribute__
((
always_inline
))
INLINE
static
int
cooling_converged
(
const
struct
xpart
*
restrict
xp
,
const
struct
xpart
*
restrict
old
,
const
struct
xpart
*
restrict
xp
,
const
struct
xpart
*
restrict
old
,
const
float
limit
)
{
#if COOLING_GRACKLE_MODE > 0
...
...
@@ -152,8 +148,7 @@ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium(
const
struct
unit_system
*
restrict
us
,
const
struct
cosmology
*
restrict
cosmo
,
const
struct
cooling_function_data
*
restrict
cooling
,
const
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
)
{
const
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
)
{
/* get temporary data */
struct
part
p_tmp
=
*
p
;
...
...
@@ -164,9 +159,11 @@ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium(
/* compute time step */
const
double
alpha
=
0
.
01
;
double
dt
=
fabs
(
cooling_time
(
phys_const
,
us
,
cosmo
,
&
cooling_tmp
,
&
p_tmp
,
xp
));
double
dt
=
fabs
(
cooling_time
(
phys_const
,
us
,
cosmo
,
&
cooling_tmp
,
&
p_tmp
,
xp
));
cooling_rate
(
phys_const
,
us
,
cosmo
,
&
cooling_tmp
,
&
p_tmp
,
xp
,
dt
);
dt
=
alpha
*
fabs
(
cooling_time
(
phys_const
,
us
,
cosmo
,
&
cooling_tmp
,
&
p_tmp
,
xp
));
dt
=
alpha
*
fabs
(
cooling_time
(
phys_const
,
us
,
cosmo
,
&
cooling_tmp
,
&
p_tmp
,
xp
));
/* init simple variables */
int
step
=
0
;
...
...
@@ -184,9 +181,10 @@ __attribute__((always_inline)) INLINE static void cooling_compute_equilibrium(
}
while
(
step
<
max_step
&&
!
cooling_converged
(
xp
,
&
old
,
conv_limit
));
if
(
step
==
max_step
)
error
(
"A particle element fraction failed to converge."
"You can change 'GrackleCooling:MaxSteps' or "
"'GrackleCooling:ConvergenceLimit' to avoid this problem"
);
error
(
"A particle element fraction failed to converge."
"You can change 'GrackleCooling:MaxSteps' or "
"'GrackleCooling:ConvergenceLimit' to avoid this problem"
);
}
/**
...
...
@@ -201,8 +199,8 @@ __attribute__((always_inline)) INLINE static void cooling_first_init_part(
const
struct
phys_const
*
restrict
phys_const
,
const
struct
unit_system
*
restrict
us
,
const
struct
cosmology
*
restrict
cosmo
,
const
struct
cooling_function_data
*
cooling
,
const
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
)
{
const
struct
cooling_function_data
*
cooling
,
const
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
)
{
xp
->
cooling_data
.
radiated_energy
=
0
.
f
;
...
...
@@ -215,9 +213,9 @@ __attribute__((always_inline)) INLINE static void cooling_first_init_part(
xp
->
cooling_data
.
HeI_frac
=
1
.
-
grackle_data
->
HydrogenFractionByMass
;
xp
->
cooling_data
.
HeII_frac
=
zero
;
xp
->
cooling_data
.
HeIII_frac
=
zero
;
xp
->
cooling_data
.
e_frac
=
xp
->
cooling_data
.
HII_frac
\
+
0
.
25
*
xp
->
cooling_data
.
HeII_frac
\
+
0
.
5
*
xp
->
cooling_data
.
HeIII_frac
;
xp
->
cooling_data
.
e_frac
=
xp
->
cooling_data
.
HII_frac
+
0
.
25
*
xp
->
cooling_data
.
HeII_frac
+
0
.
5
*
xp
->
cooling_data
.
HeIII_frac
;
#endif // MODE >= 1
#if COOLING_GRACKLE_MODE >= 2
...
...
@@ -229,8 +227,8 @@ __attribute__((always_inline)) INLINE static void cooling_first_init_part(
#if COOLING_GRACKLE_MODE >= 3
/* primordial chemistry >= 3 */
xp
->
cooling_data
.
DI_frac
=
grackle_data
->
DeuteriumToHydrogenRatio
*
grackle_data
->
HydrogenFractionByMass
;
xp
->
cooling_data
.
DI_frac
=
grackle_data
->
DeuteriumToHydrogenRatio
*
grackle_data
->
HydrogenFractionByMass
;
xp
->
cooling_data
.
DII_frac
=
zero
;
xp
->
cooling_data
.
HDI_frac
=
zero
;
#endif // MODE >= 3
...
...
@@ -261,17 +259,16 @@ __attribute__((always_inline)) INLINE static void cooling_print_backend(
message
(
"Cooling function is 'Grackle'."
);
message
(
"Using Grackle = %i"
,
cooling
->
chemistry
.
use_grackle
);
message
(
"Chemical network = %i"
,
cooling
->
chemistry
.
primordial_chemistry
);
message
(
"Chemical network = %i"
,
cooling
->
chemistry
.
primordial_chemistry
);
message
(
"CloudyTable = %s"
,
cooling
->
cloudy_table
);
message
(
"Redshift = %g"
,
cooling
->
redshift
);
message
(
"UV background = %d"
,
cooling
->
with_uv_background
);
message
(
"Metal cooling = %i"
,
cooling
->
chemistry
.
metal_cooling
);
message
(
"Self Shielding = %i"
,
cooling
->
self_shielding_method
);
message
(
"Specific Heating Rates = %i"
,
cooling
->
provide_specific_heating_rates
);
cooling
->
provide_specific_heating_rates
);
message
(
"Volumetric Heating Rates = %i"
,
cooling
->
provide_volumetric_heating_rates
);
cooling
->
provide_volumetric_heating_rates
);
message
(
"Units:"
);
message
(
"
\t
Comoving = %i"
,
cooling
->
units
.
comoving_coordinates
);
message
(
"
\t
Length = %g"
,
cooling
->
units
.
length_units
);
...
...
@@ -282,54 +279,53 @@ __attribute__((always_inline)) INLINE static void cooling_print_backend(
/**
* @brief copy a single field from the grackle data to a #xpart
*
*
* @param data The #grackle_field_data
* @param xp The #xpart
* @param rho Particle density
* @param field The field to copy
*/
#define cooling_copy_field_from_grackle(data, xp, rho, field)
\
xp->cooling_data.field
## _frac = *data.field ##
_density / rho;
#define cooling_copy_field_from_grackle(data, xp, rho, field)
\
xp->cooling_data.field
##_frac = *data.field##
_density / rho;
/**
* @brief copy a single field from a #xpart to the grackle data
*
*
* @param data The #grackle_field_data
* @param xp The #xpart
* @param rho Particle density
* @param field The field to copy
*/
#define cooling_copy_field_to_grackle(data, xp, rho, field) \
gr_float grackle_ ## field = xp->cooling_data.field ## _frac * rho; \
data.field ## _density = &grackle_ ## field;
#define cooling_copy_field_to_grackle(data, xp, rho, field) \
gr_float grackle_##field = xp->cooling_data.field##_frac * rho; \
data.field##_density = &grackle_##field;
/**
* @brief copy a #xpart to the grackle data
*
* Warning this function creates some variable, therefore the grackle call
* should be in a block that still has the variables.
*
*
* @param data The #grackle_field_data
* @param p The #part
* @param xp The #xpart
* @param rho Particle density
*/
#if COOLING_GRACKLE_MODE > 0
#define cooling_copy_to_grackle1(data, p, xp, rho)
\
cooling_copy_field_to_grackle(data, xp, rho, HI);
\
cooling_copy_field_to_grackle(data, xp, rho, HII);
\
cooling_copy_field_to_grackle(data, xp, rho, HeI);
\
cooling_copy_field_to_grackle(data, xp, rho, HeII);
\
cooling_copy_field_to_grackle(data, xp, rho, HeIII);
\
#define cooling_copy_to_grackle1(data, p, xp, rho)
\
cooling_copy_field_to_grackle(data, xp, rho, HI);
\
cooling_copy_field_to_grackle(data, xp, rho, HII);
\
cooling_copy_field_to_grackle(data, xp, rho, HeI);
\
cooling_copy_field_to_grackle(data, xp, rho, HeII);
\
cooling_copy_field_to_grackle(data, xp, rho, HeIII);
\
cooling_copy_field_to_grackle(data, xp, rho, e);
#else
#define cooling_copy_to_grackle1(data, p, xp, rho)
\
data.HI_density = NULL;
\
data.HII_density = NULL;
\
data.HeI_density = NULL;
\
data.HeII_density = NULL;
\
data.HeIII_density = NULL;
\
#define cooling_copy_to_grackle1(data, p, xp, rho)
\
data.HI_density = NULL;
\
data.HII_density = NULL;
\
data.HeI_density = NULL;
\
data.HeII_density = NULL;
\
data.HeIII_density = NULL;
\
data.e_density = NULL;
#endif
...
...
@@ -338,21 +334,21 @@ __attribute__((always_inline)) INLINE static void cooling_print_backend(
*
* Warning this function creates some variable, therefore the grackle call
* should be in a block that still has the variables.
*
*
* @param data The #grackle_field_data
* @param p The #part
* @param xp The #xpart
* @param rho Particle density
*/
#if COOLING_GRACKLE_MODE > 1
#define cooling_copy_to_grackle2(data, p, xp, rho)
\
cooling_copy_field_to_grackle(data, xp, rho, HM);
\
cooling_copy_field_to_grackle(data, xp, rho, H2I);
\
#define cooling_copy_to_grackle2(data, p, xp, rho)
\
cooling_copy_field_to_grackle(data, xp, rho, HM);
\
cooling_copy_field_to_grackle(data, xp, rho, H2I);
\
cooling_copy_field_to_grackle(data, xp, rho, H2II);
#else
#define cooling_copy_to_grackle2(data, p, xp, rho)
\
data.HM_density = NULL;
\
data.H2I_density = NULL;
\
#define cooling_copy_to_grackle2(data, p, xp, rho)
\
data.HM_density = NULL;
\
data.H2I_density = NULL;
\
data.H2II_density = NULL;
#endif
...
...
@@ -361,39 +357,39 @@ __attribute__((always_inline)) INLINE static void cooling_print_backend(
*
* Warning this function creates some variable, therefore the grackle call
* should be in a block that still has the variables.
*
*
* @param data The #grackle_field_data
* @param p The #part
* @param xp The #xpart
* @param rho Particle density
*/
#if COOLING_GRACKLE_MODE > 2
#define cooling_copy_to_grackle3(data, p, xp, rho)
\
cooling_copy_field_to_grackle(data, xp, rho, DI);
\
cooling_copy_field_to_grackle(data, xp, rho, DII);
\
#define cooling_copy_to_grackle3(data, p, xp, rho)
\
cooling_copy_field_to_grackle(data, xp, rho, DI);
\
cooling_copy_field_to_grackle(data, xp, rho, DII);
\
cooling_copy_field_to_grackle(data, xp, rho, HDI);
#else
#define cooling_copy_to_grackle3(data, p, xp, rho)
\
data.DI_density = NULL;
\
data.DII_density = NULL;
\
#define cooling_copy_to_grackle3(data, p, xp, rho)
\
data.DI_density = NULL;
\
data.DII_density = NULL;
\
data.HDI_density = NULL;
#endif
/**
* @brief copy the grackle data to a #xpart
*
*
* @param data The #grackle_field_data
* @param p The #part
* @param xp The #xpart
* @param rho Particle density
*/
#if COOLING_GRACKLE_MODE > 0
#define cooling_copy_from_grackle1(data, p, xp, rho)
\
cooling_copy_field_from_grackle(data, xp, rho, HI);
\
cooling_copy_field_from_grackle(data, xp, rho, HII);
\
cooling_copy_field_from_grackle(data, xp, rho, HeI);
\
cooling_copy_field_from_grackle(data, xp, rho, HeII);
\
cooling_copy_field_from_grackle(data, xp, rho, HeIII);
\
#define cooling_copy_from_grackle1(data, p, xp, rho)
\
cooling_copy_field_from_grackle(data, xp, rho, HI);
\
cooling_copy_field_from_grackle(data, xp, rho, HII);
\
cooling_copy_field_from_grackle(data, xp, rho, HeI);
\
cooling_copy_field_from_grackle(data, xp, rho, HeII);
\
cooling_copy_field_from_grackle(data, xp, rho, HeIII);
\
cooling_copy_field_from_grackle(data, xp, rho, e);
#else
#define cooling_copy_from_grackle1(data, p, xp, rho)
...
...
@@ -401,16 +397,16 @@ __attribute__((always_inline)) INLINE static void cooling_print_backend(
/**
* @brief copy the grackle data to a #xpart
*
*
* @param data The #grackle_field_data
* @param p The #part
* @param xp The #xpart
* @param rho Particle density
*/
#if COOLING_GRACKLE_MODE > 1
#define cooling_copy_from_grackle2(data, p, xp, rho)
\
cooling_copy_field_from_grackle(data, xp, rho, HM);
\
cooling_copy_field_from_grackle(data, xp, rho, H2I);
\
#define cooling_copy_from_grackle2(data, p, xp, rho)
\
cooling_copy_field_from_grackle(data, xp, rho, HM);
\
cooling_copy_field_from_grackle(data, xp, rho, H2I);
\
cooling_copy_field_from_grackle(data, xp, rho, H2II);
#else
#define cooling_copy_from_grackle2(data, p, xp, rho)
...
...
@@ -418,45 +414,44 @@ __attribute__((always_inline)) INLINE static void cooling_print_backend(
/**
* @brief copy the grackle data to a #xpart
*
*
* @param data The #grackle_field_data
* @param p The #part
* @param xp The #xpart
* @param rho Particle density
*/
#if COOLING_GRACKLE_MODE > 2
#define cooling_copy_from_grackle3(data, p, xp, rho)
\
cooling_copy_field_from_grackle(data, xp, rho, DI);
\
cooling_copy_field_from_grackle(data, xp, rho, DII);
\
#define cooling_copy_from_grackle3(data, p, xp, rho)
\
cooling_copy_field_from_grackle(data, xp, rho, DI);
\
cooling_copy_field_from_grackle(data, xp, rho, DII);
\
cooling_copy_field_from_grackle(data, xp, rho, HDI);
#else
#define cooling_copy_from_grackle3(data, p, xp, rho)
#endif
/**
* @brief copy a #xpart to the grackle data
*
* Warning this function creates some variable, therefore the grackle call
* should be in a block that still has the variables.
*
*
* @param data The #grackle_field_data
* @param p The #part
* @param xp The #xpart
* @param rho Particle density
*/
#define cooling_copy_to_grackle(data, p, xp, rho)
\
cooling_copy_to_grackle1(data, p, xp, rho);
\
cooling_copy_to_grackle2(data, p, xp, rho);
\
cooling_copy_to_grackle3(data, p, xp, rho);
\
data.volumetric_heating_rate = NULL;
\
data.specific_heating_rate = NULL;
\
data.RT_heating_rate = NULL;
\
data.RT_HI_ionization_rate = NULL;
\
data.RT_HeI_ionization_rate = NULL;
\
data.RT_HeII_ionization_rate = NULL;
\
data.RT_H2_dissociation_rate = NULL;
\
gr_float metal_density = chemistry_metal_mass_fraction(p, xp) * rho;
\
#define cooling_copy_to_grackle(data, p, xp, rho)
\
cooling_copy_to_grackle1(data, p, xp, rho);
\
cooling_copy_to_grackle2(data, p, xp, rho);
\
cooling_copy_to_grackle3(data, p, xp, rho);
\
data.volumetric_heating_rate = NULL;
\
data.specific_heating_rate = NULL;
\
data.RT_heating_rate = NULL;
\
data.RT_HI_ionization_rate = NULL;
\
data.RT_HeI_ionization_rate = NULL;
\
data.RT_HeII_ionization_rate = NULL;
\
data.RT_H2_dissociation_rate = NULL;
\
gr_float metal_density = chemistry_metal_mass_fraction(p, xp) * rho;
\
data.metal_density = &metal_density;
/**
...
...
@@ -464,15 +459,15 @@ __attribute__((always_inline)) INLINE static void cooling_print_backend(
*
* Warning this function creates some variable, therefore the grackle call
* should be in a block that still has the variables.
*
*
* @param data The #grackle_field_data
* @param p The #part
* @param xp The #xpart
* @param rho Particle density
*/
#define cooling_copy_from_grackle(data, p, xp, rho)
\
cooling_copy_from_grackle1(data, p, xp, rho);
\
cooling_copy_from_grackle2(data, p, xp, rho);
\
#define cooling_copy_from_grackle(data, p, xp, rho)
\
cooling_copy_from_grackle1(data, p, xp, rho);
\
cooling_copy_from_grackle2(data, p, xp, rho);
\
cooling_copy_from_grackle3(data, p, xp, rho);
/**
...
...
@@ -538,25 +533,19 @@ __attribute__((always_inline)) INLINE static gr_float cooling_rate(
/* solve chemistry */
chemistry_data
chemistry_grackle
=
cooling
->
chemistry
;
chemistry_data_storage
my_rates
=
grackle_rates
;
int
error_code
=
_solve_chemistry
(
&
chemistry_grackle
,
&
my_rates
,
&
units
,
dt
,
data
.
grid_dx
,
data
.
grid_rank
,
data
.
grid_dimension
,
data
.
grid_start
,
data
.
grid_end
,
data
.
density
,
data
.
internal_energy
,
data
.
x_velocity
,
data
.
y_velocity
,
data
.
z_velocity
,
data
.
HI_density
,
data
.
HII_density
,
data
.
HM_density
,
data
.
HeI_density
,
data
.
HeII_density
,
data
.
HeIII_density
,
data
.
H2I_density
,
data
.
H2II_density
,
data
.
DI_density
,
data
.
DII_density
,
data
.
HDI_density
,
data
.
e_density
,
data
.
metal_density
,
data
.
volumetric_heating_rate
,
data
.
specific_heating_rate
,
data
.
RT_heating_rate
,
data
.
RT_HI_ionization_rate
,
data
.
RT_HeI_ionization_rate
,
data
.
RT_HeII_ionization_rate
,
data
.
RT_H2_dissociation_rate
,
NULL
);
if
(
error_code
==
0
)
error
(
"Error in solve_chemistry."
);
//if (solve_chemistry(&units, &data, dt) == 0) {
int
error_code
=
_solve_chemistry
(
&
chemistry_grackle
,
&
my_rates
,
&
units
,
dt
,
data
.
grid_dx
,
data
.
grid_rank
,
data
.
grid_dimension
,
data
.
grid_start
,
data
.
grid_end
,
data
.
density
,
data
.
internal_energy
,
data
.
x_velocity
,
data
.
y_velocity
,
data
.
z_velocity
,
data
.
HI_density
,
data
.
HII_density
,
data
.
HM_density
,
data
.
HeI_density
,
data
.
HeII_density
,
data
.
HeIII_density
,
data
.
H2I_density
,
data
.
H2II_density
,
data
.
DI_density
,
data
.
DII_density
,
data
.
HDI_density
,
data
.
e_density
,
data
.
metal_density
,
data
.
volumetric_heating_rate
,
data
.
specific_heating_rate
,
data
.
RT_heating_rate
,
data
.
RT_HI_ionization_rate
,
data
.
RT_HeI_ionization_rate
,
data
.
RT_HeII_ionization_rate
,
data
.
RT_H2_dissociation_rate
,
NULL
);
if
(
error_code
==
0
)
error
(
"Error in solve_chemistry."
);
// if (solve_chemistry(&units, &data, dt) == 0) {
// error("Error in solve_chemistry.");
//}
...
...
@@ -688,8 +677,6 @@ __attribute__((always_inline)) INLINE static float cooling_timestep(
return
FLT_MAX
;
}
/**
* @brief Initialises the cooling unit system.
*
...
...
@@ -697,8 +684,7 @@ __attribute__((always_inline)) INLINE static float cooling_timestep(
* @param cooling The cooling properties to initialize
*/
__attribute__
((
always_inline
))
INLINE
static
void
cooling_init_units
(
const
struct
unit_system
*
us
,
struct
cooling_function_data
*
cooling
)
{
const
struct
unit_system
*
us
,
struct
cooling_function_data
*
cooling
)
{
/* These are conversions from code units to cgs. */
...
...
@@ -727,7 +713,7 @@ __attribute__((always_inline)) INLINE static void cooling_init_units(
*/
__attribute__
((
always_inline
))
INLINE
static
void
cooling_init_grackle
(
struct
cooling_function_data
*
cooling
)
{
#ifdef SWIFT_DEBUG_CHECKS
/* enable verbose for grackle */