Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
05c67513
Commit
05c67513
authored
7 years ago
by
lhausamm
Browse files
Options
Downloads
Patches
Plain Diff
Code works and seems to give good results
parent
ffb02e38
No related branches found
No related tags found
1 merge request
!469
Update cooling grackle
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/cooling/grackle/cooling.h
+38
-32
38 additions, 32 deletions
src/cooling/grackle/cooling.h
src/cooling/grackle/cooling_struct.h
+7
-0
7 additions, 0 deletions
src/cooling/grackle/cooling_struct.h
src/cooling/grackle/grackle_wrapper.c
+2
-20
2 additions, 20 deletions
src/cooling/grackle/grackle_wrapper.c
with
47 additions
and
52 deletions
src/cooling/grackle/cooling.h
+
38
−
32
View file @
05c67513
...
...
@@ -39,24 +39,44 @@
/* include the grackle wrapper */
#include
"grackle_wrapper.h"
/*! This function computes the new entropy due to the cooling,
* between step t0 and t1.
/**
* @brief Compute the cooling rate
*
* We do nothing.
*
* @param phys_const The physical constants in internal units.
* @param us The internal system of units.
* @param cooling The #cooling_function_data used in the run.
* @param p Pointer to the particle data.
* @param dt The time-step of this particle.
*/
__attribute__
((
always_inline
))
INLINE
static
double
cooling_rate
(
const
struct
phys_const
*
restrict
phys_const
,
const
struct
unit_system
*
restrict
us
,
const
struct
cooling_function_data
*
restrict
cooling
,
struct
part
*
restrict
p
,
float
dt
)
{
static
INLINE
double
do_cooling_grackle
(
double
energy
,
double
density
,
double
dtime
,
double
*
ne
,
double
Z
,
double
a_now
)
{
if
(
cooling
->
GrackleRedshift
==
-
1
)
error
(
"TODO time dependant redshift"
);
/*********************************************************************
call to the main chemistry solver
*********************************************************************/
/* Get current internal energy (dt=0) */
double
u_old
=
hydro_get_internal_energy
(
p
);
/* Get current density */
const
float
rho
=
hydro_get_density
(
p
);
/* Actual scaling fractor */
const
float
a_now
=
1
.
/
(
1
.
+
cooling
->
GrackleRedshift
);
if
(
wrap_do_cooling
(
density
,
&
energy
,
dtime
,
Z
,
a_now
)
==
0
)
{
/* 0.02041 (= 1 Zsun in Grackle v2.0, but = 1.5761 Zsun in
Grackle v2.1) */
double
Z
=
0
.
02041
;
if
(
wrap_do_cooling
(
rho
,
&
u_old
,
dt
,
Z
,
a_now
)
==
0
)
{
error
(
"Error in do_cooling.
\n
"
);
return
0
;
}
return
energy
;
return
u_old
;
}
/**
...
...
@@ -76,32 +96,18 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
const
struct
cooling_function_data
*
restrict
cooling
,
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
,
float
dt
)
{
if
(
dt
==
0
.)
return
;
/* Get current internal energy (dt=0) */
const
float
u_old
=
hydro_get_internal_energy
(
p
);
/* Get current density */
const
float
rho
=
hydro_get_density
(
p
);
/* Actual scaling fractor */
if
(
cooling
->
GrackleRedshift
==
-
1
)
error
(
"TODO time dependant redshift"
);
const
float
a_now
=
1
.
/
(
1
.
+
cooling
->
GrackleRedshift
);
;
/* must be chaged !!! */
double
ne
,
Z
;
Z
=
0
.
02041
;
/* 0.02041 (= 1 Zsun in Grackle v2.0, but = 1.5761 Zsun in
Grackle v2.1) */
ne
=
0
.
0
;
/* mass fraction of eletron */
/* useless for GRACKLE_CHEMISTRY = 0 */
/* Current du_dt */
const
float
hydro_du_dt
=
hydro_get_internal_energy_dt
(
p
);
float
u_new
;
float
delta_u
;
u_new
=
do_cooling_grackle
(
u_old
,
rho
,
dt
,
&
ne
,
Z
,
a_now
);
// u_new = u_old * 0.99;
// if (u_new < 0)
// if (p->id==50356)
// printf("WARNING !!! ID=%llu u_old=%g u_new=%g rho=%g dt=%g ne=%g Z=%g
// a_now=%g\n",p->id,u_old,u_new,rho,dt,ne,Z,a_now);
u_new
=
cooling_rate
(
phys_const
,
us
,
cooling
,
p
,
dt
);
delta_u
=
u_new
-
u_old
;
...
...
@@ -109,7 +115,7 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
xp
->
cooling_data
.
radiated_energy
+=
-
delta_u
*
hydro_get_mass
(
p
);
/* Update the internal energy */
hydro_set_internal_energy_dt
(
p
,
delta_u
/
dt
);
hydro_set_internal_energy_dt
(
p
,
hydro_du_dt
+
delta_u
/
dt
);
}
/**
...
...
@@ -200,7 +206,7 @@ static INLINE void cooling_init_backend(
cooling
->
GrackleCloudyTable
);
message
(
"UVbackground = %d"
,
UVbackground
);
message
(
"GrackleRedshift = %g"
,
cooling
->
GrackleRedshift
);
message
(
"GrackleHSShieldingDensityThreshold = %g atom/c
c
"
,
threshold
);
message
(
"GrackleHSShieldingDensityThreshold = %g atom/c
m3
"
,
threshold
);
#endif
if
(
wrap_init_cooling
(
cooling
->
GrackleCloudyTable
,
UVbackground
,
...
...
This diff is collapsed.
Click to expand it.
src/cooling/grackle/cooling_struct.h
+
7
−
0
View file @
05c67513
...
...
@@ -29,9 +29,16 @@
*/
struct
cooling_function_data
{
/* Filename of the Cloudy Table */
char
GrackleCloudyTable
[
200
];
/* Enable/Disable UV backgroud */
int
UVbackground
;
/* Redshift to use for the UV backgroud (-1 to use cosmological one) */
double
GrackleRedshift
;
/* Density Threshold for the shielding */
double
GrackleHSShieldingDensityThreshold
;
};
...
...
This diff is collapsed.
Click to expand it.
src/cooling/grackle/grackle_wrapper.c
+
2
−
20
View file @
05c67513
...
...
@@ -117,17 +117,6 @@ int wrap_get_cooling_time(double rho, double u, double Z, double a_now,
error
(
"field_size must currently be set to 1."
);
}
// passed density and energy are proper
/*
if(my_units.comoving_coordinates){
den_factor = pow(a_now, 3);
u_factor = pow(a_now, 0);
} else {
den_factor = 1.0;
u_factor = 1.0;
}
*/
if
(
calculate_cooling_time_table
(
&
my_units
,
a_now
,
grid_rank
,
grid_dimension
,
grid_start
,
grid_end
,
density
,
energy
,
x_velocity
,
y_velocity
,
z_velocity
,
...
...
@@ -137,7 +126,7 @@ int wrap_get_cooling_time(double rho, double u, double Z, double a_now,
// return updated chemistry and energy
for
(
int
i
=
0
;
i
<
FIELD_SIZE
;
i
++
)
{
*
coolingtime
=
cooling_time
[
i
];
coolingtime
[
i
]
=
cooling_time
[
i
];
}
return
1
;
...
...
@@ -162,10 +151,6 @@ int wrap_do_cooling(double rho, double *u, double dt, double Z, double a_now) {
GRACKLE_ASSERT
(
FIELD_SIZE
==
1
);
#ifdef SWIFT_DEBUG_CHECKS
double
old_value
=
energy
[
0
];
#endif
message
(
"dt = %f"
,
dt
);
if
(
solve_chemistry_table
(
&
my_units
,
a_now
,
dt
,
grid_rank
,
grid_dimension
,
grid_start
,
grid_end
,
density
,
energy
,
x_velocity
,
y_velocity
,
z_velocity
,
metal_density
)
==
0
)
{
...
...
@@ -173,13 +158,10 @@ int wrap_do_cooling(double rho, double *u, double dt, double Z, double a_now) {
return
0
;
}
#ifdef SWIFT_DEBUG_CHECKS
GRACKLE_ASSERT
(
old_value
!=
energy
[
0
]);
#endif
// return updated chemistry and energy
for
(
int
i
=
0
;
i
<
FIELD_SIZE
;
i
++
)
{
*
u
=
energy
[
i
]
/
u_factor
;
u
[
i
]
=
energy
[
i
]
/
u_factor
;
}
return
1
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment