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
fa504958
Commit
fa504958
authored
Jul 21, 2016
by
James Willis
Browse files
Merge branch 'gadget2-part-update' into intrinsic-vectorisation
parents
77444460
46ea1a8b
Changes
18
Hide whitespace changes
Inline
Side-by-side
src/cell.c
View file @
fa504958
...
...
@@ -638,11 +638,11 @@ void cell_split(struct cell *c, ptrdiff_t parts_offset) {
*/
void
cell_init_parts
(
struct
cell
*
c
,
void
*
data
)
{
struct
part
*
p
=
c
->
parts
;
struct
xpart
*
xp
=
c
->
xparts
;
const
in
t
count
=
c
->
count
;
struct
part
*
restrict
p
=
c
->
parts
;
struct
xpart
*
restrict
xp
=
c
->
xparts
;
const
size_
t
count
=
c
->
count
;
for
(
in
t
i
=
0
;
i
<
count
;
++
i
)
{
for
(
size_
t
i
=
0
;
i
<
count
;
++
i
)
{
p
[
i
].
ti_begin
=
0
;
p
[
i
].
ti_end
=
0
;
xp
[
i
].
v_full
[
0
]
=
p
[
i
].
v
[
0
];
...
...
@@ -665,13 +665,14 @@ void cell_init_parts(struct cell *c, void *data) {
*/
void
cell_init_gparts
(
struct
cell
*
c
,
void
*
data
)
{
struct
gpart
*
gp
=
c
->
gparts
;
const
in
t
gcount
=
c
->
gcount
;
struct
gpart
*
restrict
gp
=
c
->
gparts
;
const
size_
t
gcount
=
c
->
gcount
;
for
(
in
t
i
=
0
;
i
<
gcount
;
++
i
)
{
for
(
size_
t
i
=
0
;
i
<
gcount
;
++
i
)
{
gp
[
i
].
ti_begin
=
0
;
gp
[
i
].
ti_end
=
0
;
gravity_first_init_gpart
(
&
gp
[
i
]);
gravity_init_gpart
(
&
gp
[
i
]);
}
c
->
ti_end_min
=
0
;
c
->
ti_end_max
=
0
;
...
...
src/gravity/Default/gravity.h
View file @
fa504958
...
...
@@ -82,7 +82,7 @@ __attribute__((always_inline)) INLINE static void gravity_first_init_gpart(
*
* @param gp The particle to act upon
*/
__attribute__
((
always_inline
))
INLINE
static
void
gravity_init_part
(
__attribute__
((
always_inline
))
INLINE
static
void
gravity_init_
g
part
(
struct
gpart
*
gp
)
{
/* Zero the acceleration */
...
...
src/hydro/Default/hydro.h
View file @
fa504958
...
...
@@ -136,15 +136,12 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force(
/* Some smoothing length multiples. */
const
float
h
=
p
->
h
;
const
float
ih
=
1
.
0
f
/
h
;
const
float
ih2
=
ih
*
ih
;
const
float
ih4
=
ih2
*
ih2
;
/* Pre-compute some stuff for the balsara switch. */
const
float
normDiv_v
=
fabs
(
p
->
density
.
div_v
/
p
->
rho
*
ih4
);
const
float
normDiv_v
=
fabs
(
p
->
density
.
div_v
);
const
float
normRot_v
=
sqrtf
(
p
->
density
.
rot_v
[
0
]
*
p
->
density
.
rot_v
[
0
]
+
p
->
density
.
rot_v
[
1
]
*
p
->
density
.
rot_v
[
1
]
+
p
->
density
.
rot_v
[
2
]
*
p
->
density
.
rot_v
[
2
])
/
p
->
rho
*
ih4
;
p
->
density
.
rot_v
[
2
]
*
p
->
density
.
rot_v
[
2
]);
/* Compute this particle's sound speed. */
const
float
u
=
p
->
u
;
...
...
src/hydro/Default/hydro_io.h
View file @
fa504958
...
...
@@ -42,7 +42,7 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
list
[
3
]
=
io_make_input_field
(
"SmoothingLength"
,
FLOAT
,
1
,
COMPULSORY
,
UNIT_CONV_LENGTH
,
parts
,
h
);
list
[
4
]
=
io_make_input_field
(
"InternalEnergy"
,
FLOAT
,
1
,
COMPULSORY
,
UNIT_CONV_ENERGY
,
parts
,
u
);
UNIT_CONV_ENERGY
_PER_UNIT_MASS
,
parts
,
u
);
list
[
5
]
=
io_make_input_field
(
"ParticleIDs"
,
ULONGLONG
,
1
,
COMPULSORY
,
UNIT_CONV_NO_UNITS
,
parts
,
id
);
list
[
6
]
=
io_make_input_field
(
"Accelerations"
,
FLOAT
,
3
,
OPTIONAL
,
...
...
@@ -72,7 +72,7 @@ void hydro_write_particles(struct part* parts, struct io_props* list,
io_make_output_field
(
"Masses"
,
FLOAT
,
1
,
UNIT_CONV_MASS
,
parts
,
mass
);
list
[
3
]
=
io_make_output_field
(
"SmoothingLength"
,
FLOAT
,
1
,
UNIT_CONV_LENGTH
,
parts
,
h
);
list
[
4
]
=
io_make_output_field
(
"
Entrop
y"
,
FLOAT
,
1
,
list
[
4
]
=
io_make_output_field
(
"
InternalEnerg
y"
,
FLOAT
,
1
,
UNIT_CONV_ENERGY_PER_UNIT_MASS
,
parts
,
u
);
list
[
5
]
=
io_make_output_field
(
"ParticleIDs"
,
ULONGLONG
,
1
,
UNIT_CONV_NO_UNITS
,
parts
,
id
);
...
...
src/hydro/Default/hydro_part.h
View file @
fa504958
...
...
@@ -69,43 +69,43 @@ struct part {
float
alpha
;
/* Store density/force specific stuff. */
//
union {
union
{
struct
{
struct
{
/* Particle velocity divergence. */
float
div_v
;
/* Particle velocity divergence. */
float
div_v
;
/* Derivative of particle number density. */
float
wcount_dh
;
/* Derivative of particle number density. */
float
wcount_dh
;
/* Particle velocity curl. */
float
rot_v
[
3
];
/* Particle velocity curl. */
float
rot_v
[
3
];
/* Particle number density. */
float
wcount
;
/* Particle number density. */
float
wcount
;
}
density
;
}
density
;
struct
{
struct
{
/* Balsara switch */
float
balsara
;
/* Balsara switch */
float
balsara
;
/* Aggregate quantities. */
float
POrho2
;
/* Aggregate quantities. */
float
POrho2
;
/* Change in particle energy over time. */
float
u_dt
;
/* Change in particle energy over time. */
float
u_dt
;
/* Signal velocity */
float
v_sig
;
/* Signal velocity */
float
v_sig
;
/* Sound speed */
float
c
;
/* Sound speed */
float
c
;
}
force
;
//
};
}
force
;
};
/* Particle mass. */
float
mass
;
...
...
src/hydro/Gadget2/hydro.h
View file @
fa504958
...
...
@@ -65,7 +65,7 @@ __attribute__((always_inline)) INLINE static void hydro_init_part(
p
->
density
.
wcount_dh
=
0
.
f
;
p
->
rho
=
0
.
f
;
p
->
rho_dh
=
0
.
f
;
p
->
div_v
=
0
.
f
;
p
->
density
.
div_v
=
0
.
f
;
p
->
density
.
rot_v
[
0
]
=
0
.
f
;
p
->
density
.
rot_v
[
1
]
=
0
.
f
;
p
->
density
.
rot_v
[
2
]
=
0
.
f
;
...
...
@@ -111,7 +111,7 @@ __attribute__((always_inline)) INLINE static void hydro_end_density(
p
->
density
.
rot_v
[
2
]
*=
ih4
*
irho
;
/* Finish calculation of the velocity divergence */
p
->
div_v
*=
ih4
*
irho
;
p
->
density
.
div_v
*=
ih4
*
irho
;
}
/**
...
...
@@ -128,17 +128,31 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force(
struct
part
*
restrict
p
,
struct
xpart
*
restrict
xp
,
int
ti_current
,
double
timeBase
)
{
const
float
fac_mu
=
1
.
f
;
/* Will change with cosmological integration */
/* Compute the norm of the curl */
p
->
force
.
curl_v
=
sqrtf
(
p
->
density
.
rot_v
[
0
]
*
p
->
density
.
rot_v
[
0
]
+
p
->
density
.
rot_v
[
1
]
*
p
->
density
.
rot_v
[
1
]
+
p
->
density
.
rot_v
[
2
]
*
p
->
density
.
rot_v
[
2
]);
const
float
curl_v
=
sqrtf
(
p
->
density
.
rot_v
[
0
]
*
p
->
density
.
rot_v
[
0
]
+
p
->
density
.
rot_v
[
1
]
*
p
->
density
.
rot_v
[
1
]
+
p
->
density
.
rot_v
[
2
]
*
p
->
density
.
rot_v
[
2
]);
/* Compute the pressure */
const
float
dt
=
(
ti_current
-
(
p
->
ti_begin
+
p
->
ti_end
)
/
2
)
*
timeBase
;
p
->
force
.
pressure
=
(
p
->
entropy
+
p
->
entropy_dt
*
dt
)
*
pow_gamma
(
p
->
rho
);
const
float
dt
=
(
ti_current
-
(
p
->
ti_begin
+
p
->
ti_end
)
*
0
.
5
f
)
*
timeBase
;
const
float
pressure
=
(
p
->
entropy
+
p
->
force
.
entropy_dt
*
dt
)
*
pow_gamma
(
p
->
rho
);
/* Divide the pressure by the density and density gradient */
const
float
P_over_rho
=
pressure
/
(
p
->
rho
*
p
->
rho
)
*
p
->
rho_dh
;
/* Compute the sound speed */
p
->
force
.
soundspeed
=
sqrtf
(
hydro_gamma
*
p
->
force
.
pressure
/
p
->
rho
);
const
float
soundspeed
=
sqrtf
(
hydro_gamma
*
pressure
/
p
->
rho
);
/* Compute the Balsara switch */
float
balsara
=
fabsf
(
p
->
density
.
div_v
)
/
(
fabsf
(
p
->
density
.
div_v
)
+
curl_v
+
0
.
0001
f
*
p
->
force
.
soundspeed
/
fac_mu
/
p
->
h
);
/* Update variables. */
p
->
force
.
P_over_rho
=
P_over_rho
;
p
->
force
.
soundspeed
=
soundspeed
;
p
->
force
.
balsara
=
balsara
;
}
/**
...
...
@@ -160,7 +174,7 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration(
p
->
h_dt
=
0
.
0
f
;
/* Reset the time derivatives. */
p
->
entropy_dt
=
0
.
0
f
;
p
->
force
.
entropy_dt
=
0
.
0
f
;
/* Reset maximal signal velocity */
p
->
force
.
v_sig
=
0
.
0
f
;
...
...
@@ -181,11 +195,18 @@ __attribute__((always_inline)) INLINE static void hydro_predict_extra(
/* Drift the pressure */
const
float
dt_entr
=
(
t1
-
(
p
->
ti_begin
+
p
->
ti_end
)
/
2
)
*
timeBase
;
p
->
force
.
pressure
=
(
p
->
entropy
+
p
->
entropy_dt
*
dt_entr
)
*
pow_gamma
(
p
->
rho
);
const
float
pressure
=
(
p
->
entropy
+
p
->
force
.
entropy_dt
*
dt_entr
)
*
pow_gamma
(
p
->
rho
);
/* Divide the pressure by the density and density gradient */
const
float
P_over_rho
=
pressure
/
(
p
->
rho
*
p
->
rho
)
*
p
->
rho_dh
;
/* Compute the new sound speed */
p
->
force
.
soundspeed
=
sqrtf
(
hydro_gamma
*
p
->
force
.
pressure
/
p
->
rho
);
const
float
soundspeed
=
sqrtf
(
hydro_gamma
*
pressure
/
p
->
rho
);
/* Update variables */
p
->
force
.
P_over_rho
=
P_over_rho
;
p
->
force
.
soundspeed
=
soundspeed
;
}
/**
...
...
@@ -198,7 +219,7 @@ __attribute__((always_inline)) INLINE static void hydro_predict_extra(
__attribute__
((
always_inline
))
INLINE
static
void
hydro_end_force
(
struct
part
*
restrict
p
)
{
p
->
entropy_dt
*=
hydro_gamma_minus_one
*
pow_minus_gamma_minus_one
(
p
->
rho
);
p
->
force
.
entropy_dt
*=
hydro_gamma_minus_one
*
pow_minus_gamma_minus_one
(
p
->
rho
);
}
/**
...
...
@@ -214,15 +235,15 @@ __attribute__((always_inline)) INLINE static void hydro_kick_extra(
float
half_dt
)
{
/* Do not decrease the entropy (temperature) by more than a factor of 2*/
const
float
entropy_change
=
p
->
entropy_dt
*
dt
;
const
float
entropy_change
=
p
->
force
.
entropy_dt
*
dt
;
if
(
entropy_change
>
-
0
.
5
f
*
p
->
entropy
)
p
->
entropy
+=
entropy_change
;
else
p
->
entropy
*=
0
.
5
f
;
/* Do not 'overcool' when timestep increases */
if
(
p
->
entropy
+
0
.
5
f
*
p
->
entropy_dt
*
dt
<
0
.
5
f
*
p
->
entropy
)
p
->
entropy_dt
=
-
0
.
5
f
*
p
->
entropy
/
dt
;
if
(
p
->
entropy
+
0
.
5
f
*
p
->
force
.
entropy_dt
*
dt
<
0
.
5
f
*
p
->
entropy
)
p
->
force
.
entropy_dt
=
-
0
.
5
f
*
p
->
entropy
/
dt
;
}
/**
...
...
@@ -248,7 +269,7 @@ __attribute__((always_inline)) INLINE static void hydro_convert_quantities(
__attribute__
((
always_inline
))
INLINE
static
float
hydro_get_internal_energy
(
const
struct
part
*
restrict
p
,
float
dt
)
{
const
float
entropy
=
p
->
entropy
+
p
->
entropy_dt
*
dt
;
const
float
entropy
=
p
->
entropy
+
p
->
force
.
entropy_dt
*
dt
;
return
entropy
*
pow_gamma_minus_one
(
p
->
rho
)
*
hydro_one_over_gamma_minus_one
;
}
src/hydro/Gadget2/hydro_debug.h
View file @
fa504958
...
...
@@ -23,15 +23,15 @@ __attribute__((always_inline)) INLINE static void hydro_debug_particle(
"x=[%.3e,%.3e,%.3e], "
"v=[%.3e,%.3e,%.3e],v_full=[%.3e,%.3e,%.3e]
\n
a=[%.3e,%.3e,%.3e],
\n
"
"h=%.3e, "
"wcount=%d, wcount_dh=%.3e, m=%.3e, dh_drho=%.3e, rho=%.3e, P=%.3e, "
"wcount=%d, wcount_dh=%.3e, m=%.3e, dh_drho=%.3e, rho=%.3e, P
_over_rho
=%.3e, "
"S=%.3e, "
"dS/dt=%.3e, c=%.3e
\n
"
"divV=%.3e,
curlV=%.3e,
rotV=[%.3e,%.3e,%.3e]
\n
"
"divV=%.3e, rotV=[%.3e,%.3e,%.3e]
, balsara=%.3e
\n
"
"v_sig=%e dh/dt=%.3e t_begin=%d, t_end=%d
\n
"
,
p
->
x
[
0
],
p
->
x
[
1
],
p
->
x
[
2
],
p
->
v
[
0
],
p
->
v
[
1
],
p
->
v
[
2
],
xp
->
v_full
[
0
],
xp
->
v_full
[
1
],
xp
->
v_full
[
2
],
p
->
a_hydro
[
0
],
p
->
a_hydro
[
1
],
p
->
a_hydro
[
2
],
p
->
h
,
(
int
)
p
->
density
.
wcount
,
p
->
density
.
wcount_dh
,
p
->
mass
,
p
->
rho_dh
,
p
->
rho
,
p
->
force
.
pressure
,
p
->
entropy
,
p
->
entropy_dt
,
p
->
force
.
soundspeed
,
p
->
d
iv_v
,
p
->
force
.
curl
_v
,
p
->
density
.
rot_v
[
0
],
p
->
density
.
rot_v
[
1
],
p
->
density
.
rot_v
[
2
],
p
->
force
.
v_sig
,
p
->
h_dt
,
p
->
ti_begin
,
p
->
ti_end
);
p
->
rho
,
p
->
force
.
P_over_rho
,
p
->
entropy
,
p
->
force
.
entropy_dt
,
p
->
force
.
soundspeed
,
p
->
d
ensity
.
div
_v
,
p
->
density
.
rot_v
[
0
],
p
->
density
.
rot_v
[
1
],
p
->
density
.
rot_v
[
2
],
p
->
force
.
balsara
,
p
->
force
.
v_sig
,
p
->
h_dt
,
p
->
ti_begin
,
p
->
ti_end
);
}
src/hydro/Gadget2/hydro_iact.h
View file @
fa504958
...
...
@@ -86,8 +86,8 @@ __attribute__((always_inline)) INLINE static void runner_iact_density(
dv
[
2
]
=
pi
->
v
[
2
]
-
pj
->
v
[
2
];
const
float
dvdr
=
dv
[
0
]
*
dx
[
0
]
+
dv
[
1
]
*
dx
[
1
]
+
dv
[
2
]
*
dx
[
2
];
pi
->
div_v
-=
faci
*
dvdr
;
pj
->
div_v
-=
facj
*
dvdr
;
pi
->
density
.
div_v
-=
faci
*
dvdr
;
pj
->
density
.
div_v
-=
facj
*
dvdr
;
/* Compute dv cross r */
curlvr
[
0
]
=
dv
[
1
]
*
dx
[
2
]
-
dv
[
2
]
*
dx
[
1
];
...
...
@@ -209,13 +209,13 @@ __attribute__((always_inline)) INLINE static void runner_iact_vec_density(
pi
[
k
]
->
rho_dh
-=
rhoi_dh
.
f
[
k
];
pi
[
k
]
->
density
.
wcount
+=
wcounti
.
f
[
k
];
pi
[
k
]
->
density
.
wcount_dh
-=
wcounti_dh
.
f
[
k
];
pi
[
k
]
->
div_v
-=
div_vi
.
f
[
k
];
pi
[
k
]
->
density
.
div_v
-=
div_vi
.
f
[
k
];
for
(
j
=
0
;
j
<
3
;
j
++
)
pi
[
k
]
->
density
.
rot_v
[
j
]
+=
curl_vi
[
j
].
f
[
k
];
pj
[
k
]
->
rho
+=
rhoj
.
f
[
k
];
pj
[
k
]
->
rho_dh
-=
rhoj_dh
.
f
[
k
];
pj
[
k
]
->
density
.
wcount
+=
wcountj
.
f
[
k
];
pj
[
k
]
->
density
.
wcount_dh
-=
wcountj_dh
.
f
[
k
];
pj
[
k
]
->
div_v
-=
div_vj
.
f
[
k
];
pj
[
k
]
->
density
.
div_v
-=
div_vj
.
f
[
k
];
for
(
j
=
0
;
j
<
3
;
j
++
)
pj
[
k
]
->
density
.
rot_v
[
j
]
+=
curl_vj
[
j
].
f
[
k
];
}
...
...
@@ -263,7 +263,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_density(
dv
[
1
]
=
pi
->
v
[
1
]
-
pj
->
v
[
1
];
dv
[
2
]
=
pi
->
v
[
2
]
-
pj
->
v
[
2
];
const
float
dvdr
=
dv
[
0
]
*
dx
[
0
]
+
dv
[
1
]
*
dx
[
1
]
+
dv
[
2
]
*
dx
[
2
];
pi
->
div_v
-=
fac
*
dvdr
;
pi
->
density
.
div_v
-=
fac
*
dvdr
;
/* Compute dv cross r */
curlvr
[
0
]
=
dv
[
1
]
*
dx
[
2
]
-
dv
[
2
]
*
dx
[
1
];
...
...
@@ -363,7 +363,7 @@ runner_iact_nonsym_vec_density(float *R2, float *Dx, float *Hi, float *Hj,
pi
[
k
]
->
rho_dh
-=
rhoi_dh
.
f
[
k
];
pi
[
k
]
->
density
.
wcount
+=
wcounti
.
f
[
k
];
pi
[
k
]
->
density
.
wcount_dh
-=
wcounti_dh
.
f
[
k
];
pi
[
k
]
->
div_v
-=
div_vi
.
f
[
k
];
pi
[
k
]
->
density
.
div_v
-=
div_vi
.
f
[
k
];
for
(
j
=
0
;
j
<
3
;
j
++
)
pi
[
k
]
->
density
.
rot_v
[
j
]
+=
curl_vi
[
j
].
f
[
k
];
}
...
...
@@ -393,8 +393,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_force(
const
float
mj
=
pj
->
mass
;
const
float
rhoi
=
pi
->
rho
;
const
float
rhoj
=
pj
->
rho
;
const
float
pressurei
=
pi
->
force
.
pressure
;
const
float
pressurej
=
pj
->
force
.
pressure
;
/* Get the kernel for hi. */
const
float
hi_inv
=
1
.
0
f
/
hi
;
...
...
@@ -411,8 +409,8 @@ __attribute__((always_inline)) INLINE static void runner_iact_force(
const
float
wj_dr
=
hj2_inv
*
hj2_inv
*
wj_dx
;
/* Compute gradient terms */
const
float
P_over_rho_i
=
p
ressurei
/
(
rhoi
*
rhoi
)
*
pi
->
rho_dh
;
const
float
P_over_rho_j
=
p
ressurej
/
(
rhoj
*
rhoj
)
*
pj
->
rho_dh
;
const
float
P_over_rho_i
=
p
i
->
force
.
P_over_rho
;
const
float
P_over_rho_j
=
p
j
->
force
.
P_over_rho
;
/* Compute sound speeds */
const
float
ci
=
pi
->
force
.
soundspeed
;
...
...
@@ -424,13 +422,9 @@ __attribute__((always_inline)) INLINE static void runner_iact_force(
(
pi
->
v
[
2
]
-
pj
->
v
[
2
])
*
dx
[
2
];
/* Balsara term */
const
float
balsara_i
=
fabsf
(
pi
->
div_v
)
/
(
fabsf
(
pi
->
div_v
)
+
pi
->
force
.
curl_v
+
0
.
0001
f
*
ci
/
fac_mu
/
hi
);
const
float
balsara_j
=
fabsf
(
pj
->
div_v
)
/
(
fabsf
(
pj
->
div_v
)
+
pj
->
force
.
curl_v
+
0
.
0001
f
*
cj
/
fac_mu
/
hj
);
const
float
balsara_i
=
pi
->
force
.
balsara
;
const
float
balsara_j
=
pj
->
force
.
balsara
;
/* Are the particles moving towards each others ? */
const
float
omega_ij
=
fminf
(
dvdr
,
0
.
f
);
const
float
mu_ij
=
fac_mu
*
r_inv
*
omega_ij
;
/* This is 0 or negative */
...
...
@@ -468,8 +462,8 @@ __attribute__((always_inline)) INLINE static void runner_iact_force(
pj
->
force
.
v_sig
=
fmaxf
(
pj
->
force
.
v_sig
,
v_sig
);
/* Change in entropy */
pi
->
entropy_dt
+=
0
.
5
f
*
mj
*
visc_term
*
dvdr
;
pj
->
entropy_dt
-=
0
.
5
f
*
mi
*
visc_term
*
dvdr
;
pi
->
force
.
entropy_dt
+=
0
.
5
f
*
mj
*
visc_term
*
dvdr
;
pj
->
force
.
entropy_dt
-=
0
.
5
f
*
mi
*
visc_term
*
dvdr
;
}
/**
...
...
@@ -501,8 +495,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
const
float
mj
=
pj
->
mass
;
const
float
rhoi
=
pi
->
rho
;
const
float
rhoj
=
pj
->
rho
;
const
float
pressurei
=
pi
->
force
.
pressure
;
const
float
pressurej
=
pj
->
force
.
pressure
;
/* Get the kernel for hi. */
const
float
hi_inv
=
1
.
0
f
/
hi
;
...
...
@@ -519,8 +511,8 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
const
float
wj_dr
=
hj2_inv
*
hj2_inv
*
wj_dx
;
/* Compute gradient terms */
const
float
P_over_rho_i
=
p
ressurei
/
(
rhoi
*
rhoi
)
*
pi
->
rho_dh
;
const
float
P_over_rho_j
=
p
ressurej
/
(
rhoj
*
rhoj
)
*
pj
->
rho_dh
;
const
float
P_over_rho_i
=
p
i
->
force
.
P_over_rho
;
const
float
P_over_rho_j
=
p
j
->
force
.
P_over_rho
;
/* Compute sound speeds */
const
float
ci
=
pi
->
force
.
soundspeed
;
...
...
@@ -532,12 +524,8 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
(
pi
->
v
[
2
]
-
pj
->
v
[
2
])
*
dx
[
2
];
/* Balsara term */
const
float
balsara_i
=
fabsf
(
pi
->
div_v
)
/
(
fabsf
(
pi
->
div_v
)
+
pi
->
force
.
curl_v
+
0
.
0001
f
*
ci
/
fac_mu
/
hi
);
const
float
balsara_j
=
fabsf
(
pj
->
div_v
)
/
(
fabsf
(
pj
->
div_v
)
+
pj
->
force
.
curl_v
+
0
.
0001
f
*
cj
/
fac_mu
/
hj
);
const
float
balsara_i
=
pi
->
force
.
balsara
;
const
float
balsara_j
=
pj
->
force
.
balsara
;
/* Are the particles moving towards each others ? */
const
float
omega_ij
=
fminf
(
dvdr
,
0
.
f
);
...
...
@@ -570,7 +558,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
pi
->
force
.
v_sig
=
fmaxf
(
pi
->
force
.
v_sig
,
v_sig
);
/* Change in entropy */
pi
->
entropy_dt
+=
0
.
5
f
*
mj
*
visc_term
*
dvdr
;
pi
->
force
.
entropy_dt
+=
0
.
5
f
*
mj
*
visc_term
*
dvdr
;
}
/**
...
...
src/hydro/Gadget2/hydro_io.h
View file @
fa504958
...
...
@@ -17,6 +17,7 @@
*
******************************************************************************/
#include
"adiabatic_index.h"
#include
"io_properties.h"
#include
"kernel_hydro.h"
...
...
@@ -42,7 +43,7 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
list
[
3
]
=
io_make_input_field
(
"SmoothingLength"
,
FLOAT
,
1
,
COMPULSORY
,
UNIT_CONV_LENGTH
,
parts
,
h
);
list
[
4
]
=
io_make_input_field
(
"InternalEnergy"
,
FLOAT
,
1
,
COMPULSORY
,
UNIT_CONV_ENERGY
,
parts
,
entropy
);
UNIT_CONV_ENERGY
_PER_UNIT_MASS
,
parts
,
entropy
);
list
[
5
]
=
io_make_input_field
(
"ParticleIDs"
,
ULONGLONG
,
1
,
COMPULSORY
,
UNIT_CONV_NO_UNITS
,
parts
,
id
);
list
[
6
]
=
io_make_input_field
(
"Accelerations"
,
FLOAT
,
3
,
OPTIONAL
,
...
...
@@ -51,6 +52,12 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
UNIT_CONV_DENSITY
,
parts
,
rho
);
}
float
convert_u
(
struct
engine
*
e
,
struct
part
*
p
)
{
return
p
->
entropy
*
pow_gamma_minus_one
(
p
->
rho
)
*
hydro_one_over_gamma_minus_one
;
}
/**
* @brief Specifies which particle fields to write to a dataset
*
...
...
@@ -61,7 +68,7 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
void
hydro_write_particles
(
struct
part
*
parts
,
struct
io_props
*
list
,
int
*
num_fields
)
{
*
num_fields
=
8
;
*
num_fields
=
9
;
/* List what we want to write */
list
[
0
]
=
io_make_output_field
(
"Coordinates"
,
DOUBLE
,
3
,
UNIT_CONV_LENGTH
,
...
...
@@ -80,6 +87,9 @@ void hydro_write_particles(struct part* parts, struct io_props* list,
UNIT_CONV_ACCELERATION
,
parts
,
a_hydro
);
list
[
7
]
=
io_make_output_field
(
"Density"
,
FLOAT
,
1
,
UNIT_CONV_DENSITY
,
parts
,
rho
);
list
[
8
]
=
io_make_output_field_convert_part
(
"InternalEnergy"
,
FLOAT
,
1
,
UNIT_CONV_ENERGY_PER_UNIT_MASS
,
parts
,
rho
,
convert_u
);
}
/**
...
...
@@ -102,4 +112,4 @@ void writeSPHflavour(hid_t h_grpsph) {
*
* @return 1 if entropy is in 'internal energy', 0 otherwise.
*/
int
writeEntropyFlag
()
{
return
1
;
}
int
writeEntropyFlag
()
{
return
0
;
}
src/hydro/Gadget2/hydro_part.h
View file @
fa504958
...
...
@@ -25,6 +25,8 @@ struct xpart {
/* Velocity at the last full step. */
float
v_full
[
3
];
}
__attribute__
((
aligned
(
xpart_align
)));
...
...
@@ -55,15 +57,12 @@ struct part {
/* Particle density. */
float
rho
;
/* Derivative of the density with respect to this particle's smoothing length.
*/
float
rho_dh
;
/* Particle entropy. */
float
entropy
;
/* Entropy time derivative */
float
entropy_dt
;
/* Derivative of the density with respect to this particle's smoothing length.
*/
float
rho_dh
;
/* Particle mass. */
float
mass
;
...
...
@@ -72,37 +71,40 @@ struct part {
struct
{
/* Number of neighbours */
/* Number of neighbours
.
*/
float
wcount
;
/* Number of neighbours spatial derivative */
/* Number of neighbours spatial derivative
.
*/
float
wcount_dh
;
/*
V
elocity curl
components
*/
/*
Particle v
elocity curl
.
*/
float
rot_v
[
3
];
/* Particle velocity divergence. */
float
div_v
;
}
density
;
struct
{
/*
Velocity curl norm
*/
float
curl_v
;
/*
Balsara switch
*/
float
balsara
;
/* Signal velocity */
/* Signal velocity
.
*/
float
v_sig
;
/* P
article pressure
*/
float
pressure
;
/* P
ressure over density
*/
float
P_over_rho
;
/* Particle sound speed */
/* Particle sound speed
.
*/
float
soundspeed
;
/* Entropy time derivative */
float
entropy_dt
;
}
force
;
};
/* Velocity divergence */
float
div_v
;
/* Particle ID. */
long
long
id
;
...
...
src/hydro/Minimal/hydro_io.h
View file @
fa504958
...
...
@@ -42,7 +42,7 @@ void hydro_read_particles(struct part* parts, struct io_props* list,
list
[
3
]
=
io_make_input_field
(
"SmoothingLength"
,
FLOAT
,
1
,
COMPULSORY
,
UNIT_CONV_LENGTH
,
parts
,
h
);
list
[
4
]
=
io_make_input_field
(
"InternalEnergy"
,
FLOAT
,
1
,
COMPULSORY
,
UNIT_CONV_ENERGY
,
parts
,
u
);
UNIT_CONV_ENERGY
_PER_UNIT_MASS
,
parts
,
u
);
list
[
5
]
=
io_make_input_field
(
"ParticleIDs"
,
ULONGLONG
,
1
,
COMPULSORY
,
UNIT_CONV_NO_UNITS
,
parts
,
id
);
list
[
6
]
=
io_make_input_field
(
"Accelerations"
,
FLOAT
,
3
,
OPTIONAL
,
...
...
@@ -72,7 +72,7 @@ void hydro_write_particles(struct part* parts, struct io_props* list,
io_make_output_field
(
"Masses"
,
FLOAT
,
1
,
UNIT_CONV_MASS
,
parts
,
mass
);
list
[
3
]
=
io_make_output_field
(
"SmoothingLength"
,
FLOAT
,
1
,
UNIT_CONV_LENGTH
,
parts
,
h
);
list
[
4
]
=
io_make_output_field
(
"
Entrop
y"
,
FLOAT
,
1
,
list
[
4
]
=
io_make_output_field
(
"
InternalEnerg
y"
,
FLOAT
,
1
,
UNIT_CONV_ENERGY_PER_UNIT_MASS
,
parts
,
u
);
list
[
5
]
=
io_make_output_field
(
"ParticleIDs"
,
ULONGLONG
,
1
,
UNIT_CONV_NO_UNITS
,
parts
,
id
);
...
...
src/io_properties.h
View file @
fa504958
...
...
@@ -54,6 +54,16 @@ struct io_props {
/* The size of the particles */
size_t
partSize
;
/* The particle arrays */
struct
part
*
parts
;
struct
gpart
*
gparts
;
/* Conversion function for part */
float
(
*
convert_part
)(
struct
engine
*
,
struct
part
*
);
/* Conversion function for gpart */
float
(
*
convert_gpart
)(
struct
engine
*
,
struct
gpart
*
);
};
/**
...
...
@@ -68,7 +78,7 @@ struct io_props {
*
* @param name Name of the field to read
* @param type The type of the data
* @param dimension Dataset dimension (
!
D, 3D, ...)