Skip to content
GitLab
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
3c31b2e2
Commit
3c31b2e2
authored
Jan 27, 2017
by
Stefan Arridge
Browse files
Changed implementation of energy floor. Made some changes to the cooling halo example
parent
7894d3b5
Changes
7
Hide whitespace changes
Inline
Side-by-side
examples/CoolingHaloWithSpin/cooling_halo.yml
View file @
3c31b2e2
...
...
@@ -40,7 +40,7 @@ IsothermalPotential:
position_z
:
0.
vrot
:
200.
# Rotation speed of isothermal potential in internal units
timestep_mult
:
0.03
# Controls time step
epsilon
:
1.0
# Softening for the isothermal potential
epsilon
:
0.1
# Softening for the isothermal potential
# Cooling parameters
LambdaCooling
:
...
...
@@ -48,4 +48,4 @@ LambdaCooling:
minimum_temperature
:
1.0e4
# Minimal temperature (Kelvin)
mean_molecular_weight
:
0.59
# Mean molecular weight
hydrogen_mass_abundance
:
0.75
# Hydrogen mass abundance (dimensionless)
cooling_tstep_mult
:
1.0
# Dimensionless pre-factor for the time-step condition
cooling_tstep_mult
:
0.1
# Dimensionless pre-factor for the time-step condition
examples/CoolingHaloWithSpin/density_profile.py
View file @
3c31b2e2
...
...
@@ -28,7 +28,7 @@ unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
unit_length_cgs
=
float
(
params
.
attrs
[
"InternalUnitSystem:UnitLength_in_cgs"
])
unit_velocity_cgs
=
float
(
params
.
attrs
[
"InternalUnitSystem:UnitVelocity_in_cgs"
])
unit_time_cgs
=
unit_length_cgs
/
unit_velocity_cgs
v_c
=
float
(
params
.
attrs
[
"
Softened
IsothermalPotential:vrot"
])
v_c
=
float
(
params
.
attrs
[
"IsothermalPotential:vrot"
])
v_c_cgs
=
v_c
*
unit_velocity_cgs
lambda_cgs
=
float
(
params
.
attrs
[
"LambdaCooling:lambda_cgs"
])
X_H
=
float
(
params
.
attrs
[
"LambdaCooling:hydrogen_mass_abundance"
])
...
...
@@ -101,18 +101,18 @@ for i in range(n_snaps):
rho_0
=
density
[
0
]
rho_analytic_init
=
rho_0
*
(
radial_bin_mids
/
r_0
)
**
(
-
2
)
plt
.
plot
(
radial_bin_mids
,
density
/
rho_analytic_init
,
'ko'
,
label
=
"Average density of shell"
)
#
plt.plot(
t
,rho_analytic,label = "Initial analytic density profile"
plt
.
plot
(
radial_bin_mids
,
density
,
'ko'
,
label
=
"Average density of shell"
)
plt
.
plot
(
radial_bin_mids
,
rho_analytic
_init
,
label
=
"Initial analytic density profile"
)
plt
.
xlabel
(
r
"$r / r_{vir}$"
)
plt
.
ylabel
(
r
"$\rho / \rho_{init})$"
)
plt
.
ylabel
(
r
"$
(
\rho / \rho_{init})$"
)
plt
.
title
(
r
"$\mathrm{Time}= %.3g \, s \, , \, %d \, \, \mathrm{particles} \,,\, v_c = %.1f \, \mathrm{km / s}$"
%
(
snap_time_cgs
,
N
,
v_c
))
#plt.ylim((1.e-2,1.e1))
plt
.
plot
((
r_cool_over_r_vir
,
r_cool_over_r_vir
),(
0
,
20
),
'r'
,
label
=
"Cooling radius"
)
plt
.
plot
((
r_cool_over_r_vir
,
r_cool_over_r_vir
),(
1.0e-4
,
1.0e4
),
'r'
,
label
=
"Cooling radius"
)
plt
.
xlim
((
radial_bin_mids
[
0
],
max_r
))
plt
.
ylim
((
0
,
20
))
plt
.
plot
((
0
,
max_r
),(
1
,
1
))
plt
.
ylim
((
1.0e-4
,
1.0e4
))
#
plt.plot((0,max_r),(1,1))
#plt.xscale('log')
#
plt.yscale('log')
plt
.
yscale
(
'log'
)
plt
.
legend
(
loc
=
"upper right"
)
plot_filename
=
"density_profile_%03d.png"
%
i
plt
.
savefig
(
plot_filename
,
format
=
"png"
)
...
...
examples/CoolingHaloWithSpin/internal_energy_profile.py
View file @
3c31b2e2
...
...
@@ -46,7 +46,7 @@ unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
unit_length_cgs
=
float
(
params
.
attrs
[
"InternalUnitSystem:UnitLength_in_cgs"
])
unit_velocity_cgs
=
float
(
params
.
attrs
[
"InternalUnitSystem:UnitVelocity_in_cgs"
])
unit_time_cgs
=
unit_length_cgs
/
unit_velocity_cgs
v_c
=
float
(
params
.
attrs
[
"
Softened
IsothermalPotential:vrot"
])
v_c
=
float
(
params
.
attrs
[
"IsothermalPotential:vrot"
])
v_c_cgs
=
v_c
*
unit_velocity_cgs
lambda_cgs
=
float
(
params
.
attrs
[
"LambdaCooling:lambda_cgs"
])
X_H
=
float
(
params
.
attrs
[
"LambdaCooling:hydrogen_mass_abundance"
])
...
...
examples/CoolingHaloWithSpin/makeIC.py
View file @
3c31b2e2
...
...
@@ -36,6 +36,7 @@ h = 0.67777 # hubble parameter
gamma
=
5.
/
3.
eta
=
1.2349
spin_lambda
=
0.05
#spin parameter
f_b
=
0.2
#baryon fraction
# First set unit velocity and then the circular velocity parameter for the isothermal potential
const_unit_velocity_in_cgs
=
1.e5
#kms^-1
...
...
@@ -99,6 +100,8 @@ grp.attrs["PeriodicBoundariesOn"] = periodic
# set seed for random number
np
.
random
.
seed
(
1234
)
gas_mass
=
f_b
*
np
.
sqrt
(
3.
)
/
2.
#virial mass of halo is 1, virial radius is 1, enclosed mass scales with r
gas_particle_mass
=
gas_mass
/
float
(
N
)
# Positions
# r^(-2) distribution corresponds to uniform distribution in radius
...
...
@@ -164,12 +167,12 @@ N = x_coords.size
print
"Number of particles in the box = "
,
N
#make the coords and radius arrays again
coords
_2
=
np
.
zeros
((
N
,
3
))
coords
_2
[:,
0
]
=
x_coords
coords
_2
[:,
1
]
=
y_coords
coords
_2
[:,
2
]
=
z_coords
coords
=
np
.
zeros
((
N
,
3
))
coords
[:,
0
]
=
x_coords
coords
[:,
1
]
=
y_coords
coords
[:,
2
]
=
z_coords
radius
=
np
.
sqrt
((
coords
_2
[:,
0
]
-
boxSize
/
2.
)
**
2
+
(
coords
_2
[:,
1
]
-
boxSize
/
2.
)
**
2
+
(
coords
_2
[:,
2
]
-
boxSize
/
2.
)
**
2
)
radius
=
np
.
sqrt
((
coords
[:,
0
]
-
boxSize
/
2.
)
**
2
+
(
coords
[:,
1
]
-
boxSize
/
2.
)
**
2
+
(
coords
[:,
2
]
-
boxSize
/
2.
)
**
2
)
#now give particle's velocities
v
=
np
.
zeros
((
N
,
3
))
...
...
@@ -184,7 +187,7 @@ print "J =", J
omega
=
np
.
zeros
((
N
,
3
))
for
i
in
range
(
N
):
omega
[
i
,
2
]
=
3.
*
J
/
radius
[
i
]
v
[
i
,:]
=
np
.
cross
(
omega
[
i
,:],(
coords
_2
[
i
,:]
-
boxSize
/
2.
))
v
[
i
,:]
=
np
.
cross
(
omega
[
i
,:],(
coords
[
i
,:]
-
boxSize
/
2.
))
# Header
grp
=
file
.
create_group
(
"/Header"
)
...
...
@@ -202,16 +205,15 @@ grp.attrs["Dimension"] = 3
grp
=
file
.
create_group
(
"/PartType0"
)
ds
=
grp
.
create_dataset
(
'Coordinates'
,
(
N
,
3
),
'd'
)
ds
[()]
=
coords
_2
coords
_2
=
np
.
zeros
(
1
)
ds
[()]
=
coords
coords
=
np
.
zeros
(
1
)
ds
=
grp
.
create_dataset
(
'Velocities'
,
(
N
,
3
),
'f'
)
ds
[()]
=
v
v
=
np
.
zeros
(
1
)
# All particles of equal mass
mass
=
1.
/
N
m
=
np
.
full
((
N
,),
mass
)
m
=
np
.
full
((
N
,),
gas_particle_mass
)
ds
=
grp
.
create_dataset
(
'Masses'
,
(
N
,
),
'f'
)
ds
[()]
=
m
m
=
np
.
zeros
(
1
)
...
...
examples/CoolingHaloWithSpin/velocity_profile.py
View file @
3c31b2e2
...
...
@@ -46,7 +46,7 @@ unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
unit_length_cgs
=
float
(
params
.
attrs
[
"InternalUnitSystem:UnitLength_in_cgs"
])
unit_velocity_cgs
=
float
(
params
.
attrs
[
"InternalUnitSystem:UnitVelocity_in_cgs"
])
unit_time_cgs
=
unit_length_cgs
/
unit_velocity_cgs
v_c
=
float
(
params
.
attrs
[
"
Softened
IsothermalPotential:vrot"
])
v_c
=
float
(
params
.
attrs
[
"IsothermalPotential:vrot"
])
v_c_cgs
=
v_c
*
unit_velocity_cgs
header
=
f
[
"Header"
]
N
=
header
.
attrs
[
"NumPart_Total"
][
0
]
...
...
src/cooling/const_lambda/cooling.h
View file @
3c31b2e2
...
...
@@ -89,8 +89,9 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
float
cooling_du_dt
=
cooling_rate
(
phys_const
,
us
,
cooling
,
p
);
/* Integrate cooling equation to enforce energy floor */
if
(
u_old
+
(
hydro_du_dt
+
cooling_du_dt
)
*
dt
<
u_floor
)
{
cooling_du_dt
=
-
(
u_old
+
dt
*
hydro_du_dt
-
u_floor
)
/
dt
;
/* Factor of 1.5 included since timestep could potentially double */
if
(
u_old
+
(
hydro_du_dt
+
cooling_du_dt
)
*
1
.
5
f
*
dt
<
u_floor
)
{
cooling_du_dt
=
-
(
u_old
+
1
.
5
f
*
dt
*
hydro_du_dt
-
u_floor
)
/
(
1
.
5
f
*
dt
);
}
/* Update the internal energy time derivative */
...
...
src/hydro/Gadget2/hydro.h
View file @
3c31b2e2
...
...
@@ -332,11 +332,8 @@ __attribute__((always_inline)) INLINE static void hydro_predict_extra(
else
p
->
rho
*=
expf
(
w2
);
if
(
p
->
entropy
+
p
->
entropy_dt
*
dt
<
0
.
0
)
printf
(
"Negative entropy: Old entropy = %g, New entropy = %g "
,
p
->
entropy
,
p
->
entropy
+
p
->
entropy_dt
*
dt
);
/* Predict the entropy */
p
->
entropy
+=
p
->
entropy_dt
*
dt
;
/* Re-compute the pressure */
const
float
pressure
=
gas_pressure_from_entropy
(
p
->
rho
,
p
->
entropy
);
...
...
@@ -379,7 +376,12 @@ __attribute__((always_inline)) INLINE static void hydro_kick_extra(
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
,
float
dt
)
{
/* Do not decrease the entropy by more than a factor of 2 */
p
->
entropy_dt
=
max
(
-
0
.
5
f
*
xp
->
entropy_full
/
dt
,
p
->
entropy_dt
);
if
(
p
->
entropy_dt
<
-
0
.
5
f
*
xp
->
entropy_full
/
dt
){
message
(
"Warning! Limiting entropy_dt. Possible cooling error.
\n
entropy_full = %g
\n
entropy_dt * dt =%g
\n
"
,
xp
->
entropy_full
,
p
->
entropy_dt
*
dt
);
p
->
entropy_dt
=
-
0
.
5
f
*
xp
->
entropy_full
/
dt
;
}
xp
->
entropy_full
+=
p
->
entropy_dt
*
dt
;
/* Compute the pressure */
...
...
@@ -409,7 +411,6 @@ __attribute__((always_inline)) INLINE static void hydro_convert_quantities(
/* We read u in the entropy field. We now get S from u */
xp
->
entropy_full
=
gas_entropy_from_internal_energy
(
p
->
rho
,
p
->
entropy
);
p
->
entropy
=
xp
->
entropy_full
;
/* Compute the pressure */
const
float
pressure
=
gas_pressure_from_entropy
(
p
->
rho
,
p
->
entropy
);
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment