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
83787596
Commit
83787596
authored
Feb 04, 2016
by
Matthieu Schaller
Browse files
Gadget-2 force loop now correct
parent
6bfdc639
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/engine.c
View file @
83787596
...
...
@@ -1818,7 +1818,6 @@ if ( e->nodeID == 0 )
printParticle
(
e
->
s
->
parts
,
1000
,
e
->
s
->
nr_parts
);
printParticle
(
e
->
s
->
parts
,
515050
,
e
->
s
->
nr_parts
);
exit
(
0
);
/* Move forward in time */
e
->
timeOld
=
e
->
time
;
...
...
src/hydro/Gadget2/hydro.h
View file @
83787596
...
...
@@ -174,7 +174,10 @@ __attribute__((always_inline)) INLINE static void hydro_reset_acceleration(struc
p
->
a
[
2
]
=
0
.
0
f
;
/* Reset the time derivatives. */
p
->
v_sig
=
0
.
0
f
;
p
->
entropy_dt
=
0
.
0
f
;
/* Reset minimal signal velocity */
p
->
v_sig
=
FLT_MAX
;
}
...
...
@@ -212,6 +215,8 @@ __attribute__((always_inline)) INLINE static void hydro_predict_extra(struct par
*/
__attribute__
((
always_inline
))
INLINE
static
void
hydro_end_force
(
struct
part
*
p
)
{
p
->
entropy_dt
*=
(
const_hydro_gamma
-
1
.
f
)
*
powf
(
p
->
rho
,
-
(
const_hydro_gamma
-
1
.
f
));
}
/**
...
...
src/hydro/Gadget2/hydro_iact.h
View file @
83787596
...
...
@@ -200,80 +200,82 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_density(
__attribute__
((
always_inline
))
INLINE
static
void
runner_iact_force
(
float
r2
,
float
*
dx
,
float
hi
,
float
hj
,
struct
part
*
pi
,
struct
part
*
pj
)
{
/* float r = sqrtf(r2), ri = 1.0f / r; */
/* float xi, xj; */
/* float hi_inv, hi2_inv; */
/* float hj_inv, hj2_inv; */
/* float wi, wj, wi_dx, wj_dx, wi_dr, wj_dr, w, dvdr; */
/* float mi, mj, POrho2i, POrho2j, rhoi, rhoj; */
/* float v_sig, omega_ij, Pi_ij; */
/* float f; */
/* int k; */
/* /\* Get some values in local variables. *\/ */
/* mi = pi->mass; */
/* mj = pj->mass; */
/* rhoi = pi->rho; */
/* rhoj = pj->rho; */
/* //POrho2i = pi->force.POrho2; */
/* //POrho2j = pj->force.POrho2; */
/* /\* Get the kernel for hi. *\/ */
/* hi_inv = 1.0f / hi; */
/* hi2_inv = hi_inv * hi_inv; */
/* xi = r * hi_inv; */
/* kernel_deval(xi, &wi, &wi_dx); */
/* wi_dr = hi2_inv * hi2_inv * wi_dx; */
/* /\* Get the kernel for hj. *\/ */
/* hj_inv = 1.0f / hj; */
/* hj2_inv = hj_inv * hj_inv; */
/* xj = r * hj_inv; */
/* kernel_deval(xj, &wj, &wj_dx); */
/* wj_dr = hj2_inv * hj2_inv * wj_dx; */
/* /\* Compute dv dot r. *\/ */
/* dvdr = (pi->v[0] - pj->v[0]) * dx[0] + (pi->v[1] - pj->v[1]) * dx[1] + */
/* (pi->v[2] - pj->v[2]) * dx[2]; */
/* dvdr *= ri; */
/* /\* Compute the relative velocity. (This is 0 if the particles move away from */
/* * each other and negative otherwise) *\/ */
/* omega_ij = fminf(dvdr, 0.f); */
/* /\* Compute signal velocity *\/ */
/* v_sig = pi->force.c + pj->force.c - 3.0f * omega_ij; */
/* /\* Compute viscosity tensor *\/ */
/* Pi_ij = -const_viscosity_alpha * v_sig * omega_ij / (rhoi + rhoj); */
/* /\* Apply balsara switch *\/ */
/* Pi_ij *= (pi->force.balsara + pj->force.balsara); */
/* /\* Get the common factor out. *\/ */
/* w = ri * */
/* ((POrho2i * wi_dr + POrho2j * wj_dr) + 0.25f * Pi_ij * (wi_dr + wj_dr)); */
/* /\* Use the force, Luke! *\/ */
/* for (k = 0; k < 3; k++) { */
/* f = dx[k] * w; */
/* pi->a[k] -= mj * f; */
/* pj->a[k] += mi * f; */
/* } */
/* /\* Get the time derivative for u. *\/ */
/* pi->force.u_dt += */
/* mj * dvdr * (POrho2i * wi_dr + 0.125f * Pi_ij * (wi_dr + wj_dr)); */
/* pj->force.u_dt += */
/* mi * dvdr * (POrho2j * wj_dr + 0.125f * Pi_ij * (wi_dr + wj_dr)); */
/* /\* Get the time derivative for h. *\/ */
/* pi->force.h_dt -= mj * dvdr / rhoj * wi_dr; */
/* pj->force.h_dt -= mi * dvdr / rhoi * wj_dr; */
/* /\* Update the signal velocity. *\/ */
/* pi->force.v_sig = fmaxf(pi->force.v_sig, v_sig); */
/* pj->force.v_sig = fmaxf(pj->force.v_sig, v_sig); */
float
wi
,
wj
,
wi_dx
,
wj_dx
;
const
float
fac_mu
=
1
.
f
;
/* Will change with cosmological integration */
const
float
r
=
sqrtf
(
r2
);
const
float
r_inv
=
1
.
0
f
/
r
;
/* Get some values in local variables. */
//const float mi = pi->mass;
const
float
mj
=
pj
->
mass
;
const
float
rhoi
=
pi
->
rho
;
const
float
rhoj
=
pj
->
rho
;
const
float
pressurei
=
pi
->
pressure
;
const
float
pressurej
=
pj
->
pressure
;
/* Get the kernel for hi. */
const
float
hi_inv
=
1
.
0
f
/
hi
;
const
float
hi2_inv
=
hi_inv
*
hi_inv
;
const
float
ui
=
r
*
hi_inv
;
kernel_deval
(
ui
,
&
wi
,
&
wi_dx
);
const
float
wi_dr
=
hi2_inv
*
hi2_inv
*
wi_dx
;
/* Get the kernel for hj. */
const
float
hj_inv
=
1
.
0
f
/
hj
;
const
float
hj2_inv
=
hj_inv
*
hj_inv
;
const
float
xj
=
r
*
hj_inv
;
kernel_deval
(
xj
,
&
wj
,
&
wj_dx
);
const
float
wj_dr
=
hj2_inv
*
hj2_inv
*
wj_dx
;
/* Compute gradient terms */
const
float
P_over_rho_i
=
pressurei
/
(
rhoi
*
rhoi
)
*
pi
->
rho_dh
;
const
float
P_over_rho_j
=
pressurej
/
(
rhoj
*
rhoj
)
*
pj
->
rho_dh
;
/* Compute sound speeds */
const
float
ci
=
sqrtf
(
const_hydro_gamma
*
pressurei
/
rhoi
);
const
float
cj
=
sqrtf
(
const_hydro_gamma
*
pressurej
/
rhoj
);
float
v_sig
=
ci
+
cj
;
/* Compute dv dot r. */
const
float
dvdr
=
(
pi
->
v
[
0
]
-
pj
->
v
[
0
])
*
dx
[
0
]
+
(
pi
->
v
[
1
]
-
pj
->
v
[
1
])
*
dx
[
1
]
+
(
pi
->
v
[
2
]
-
pj
->
v
[
2
])
*
dx
[
2
];
/* Artificial viscosity term */
float
visc
=
0
.
f
;
if
(
dvdr
<
0
.
f
)
{
const
float
mu_ij
=
fac_mu
*
dvdr
*
r_inv
;
v_sig
-=
3
.
f
*
mu_ij
;
const
float
rho_ij
=
0
.
5
f
*
(
rhoi
+
rhoj
);
const
float
balsara_i
=
fabsf
(
pi
->
div_v
)
/
(
fabsf
(
pi
->
div_v
)
+
pi
->
curl_v
+
0
.
0001
*
ci
/
fac_mu
/
hi
);
const
float
balsara_j
=
fabsf
(
pj
->
div_v
)
/
(
fabsf
(
pj
->
div_v
)
+
pj
->
curl_v
+
0
.
0001
*
cj
/
fac_mu
/
hj
);
visc
=
-
0
.
25
f
*
const_viscosity_alpha
*
v_sig
*
mu_ij
/
rho_ij
*
(
balsara_i
+
balsara_j
);
}
/* Now, convolve with the kernel */
const
float
visc_term
=
0
.
5
f
*
mj
*
visc
*
(
wi_dr
+
wj_dr
)
*
r_inv
;
const
float
sph_term
=
mj
*
(
P_over_rho_i
*
wi_dr
+
P_over_rho_j
*
wj_dr
)
*
r_inv
;
/* Eventually got the acceleration */
const
float
acc
=
visc_term
+
sph_term
;
/* Use the force Luke ! */
pi
->
a
[
0
]
-=
acc
*
dx
[
0
];
pi
->
a
[
1
]
-=
acc
*
dx
[
1
];
pi
->
a
[
2
]
-=
acc
*
dx
[
2
];
pj
->
a
[
0
]
+=
acc
*
dx
[
0
];
pj
->
a
[
1
]
+=
acc
*
dx
[
1
];
pj
->
a
[
2
]
+=
acc
*
dx
[
2
];
/* Update the signal velocity. */
pi
->
v_sig
=
fmaxf
(
pi
->
v_sig
,
v_sig
)
;
pj
->
v_sig
=
fmaxf
(
pj
->
v_sig
,
v_sig
)
;
/* Change in entropy */
pi
->
entropy_dt
+=
0
.
5
f
*
visc_term
*
dvdr
;
pj
->
entropy_dt
-=
0
.
5
f
*
visc_term
*
dvdr
;
}
...
...
@@ -284,76 +286,76 @@ __attribute__((always_inline)) INLINE static void runner_iact_force(
__attribute__
((
always_inline
))
INLINE
static
void
runner_iact_nonsym_force
(
float
r2
,
float
*
dx
,
float
hi
,
float
hj
,
struct
part
*
pi
,
struct
part
*
pj
)
{
/*
float
r = sqrtf(r2), ri = 1.0f / r; */
/* float xi, xj; */
/*
float
hi_inv, hi2_inv;
*/
/* float hj_inv, hj2_inv; */
/*
float
wi, wj, wi_dx, wj_dx, wi_dr, wj_dr, w, dvdr; */
/*
float
/\*mi,*\/ mj, POrho2i, POrho2j, rhoi, rhoj; */
/* float v_sig, omega_ij, Pi_ij; */
/*
float f;
*/
/
* int k; */
/* /\* Get some values in local variables. *\/ */
/* // mi
= p
i
->
mass; */
/* mj
= p
j
->
mass; */
/* rhoi
= p
i
->
rho; */
/* rhoj = pj->rho; */
/*
POrho2i = pi->force.POrho2;
*/
/* POrho2j = pj->force.POrho2; */
/* /\* Get the kernel for hi. *\/ */
/* hi_inv = 1.0f / hi; */
/* hi2_inv
= hi_inv * hi_inv
;
*
/
/* xi = r * hi_inv; */
/*
kernel_deval(xi, &wi, &wi_dx);
*/
/* wi_dr = hi2_inv * hi2_inv * wi_dx; */
/* /\* Get the kernel for hj. *\/ */
/* hj_inv = 1.0f / hj; */
/* hj2_inv
= hj_inv * hj_inv
;
*
/
/* xj = r * hj_inv; */
/*
kernel_deval(xj, &wj, &wj_dx);
*/
/* wj_dr = hj2_inv * hj2_inv * wj_dx; */
/* /\* Compute dv dot r. *\/ */
/*
dvdr = (pi->v[0] - pj->v[0]) * dx[0] + (pi->v[1] - pj->v[1]) * dx[1] +
*/
/* (pi->v[2] - pj->v[2]) * dx[2]; */
/* dvdr *= ri; */
/* /\* Compute the relative velocity. (This is 0 if the particles move away from */
/*
* each other and negative otherwise) *\/
*/
/* omega_ij = fminf(dvdr, 0.f); */
/* /\* Compute signal velocity *\/ */
/*
v_sig = pi->force.c + pj->force.c - 3.0f * omega_ij;
*/
/* /\* Compute viscosity tensor *\/ */
/* Pi_ij = -const_viscosity_alpha * v_sig * omega_ij / (rhoi + rhoj); */
/* /\* Apply balsara switch *\/ */
/* Pi_ij *= (pi->force.balsara
+ p
j
->
force.balsara); */
/* /\* Get the common factor out. *\/ */
/* w = ri * */
/* ((POrho2i * wi_dr + POrho2j * wj_dr) + 0.25f * Pi_ij * (wi_dr + wj_dr)); */
/* /\* Use the force, Luke! *\/ */
/* for (k = 0; k < 3; k++) { */
/* f = dx[k] * w; */
/*
pi->a[k] -= mj * f;
*/
/* } */
/*
/\* Get the time derivative for u. *\/
*/
/*
pi->
force.u_dt += */
/* mj * dvdr * (POrho2i * wi_dr + 0.125f * Pi_ij * (wi_dr + wj_dr)); */
/* /\* Get the time derivative for h. *\/ */
/*
pi->force.h_dt -= mj * dvdr / rhoj * wi_dr;
*/
/* /\* Update the signal velocity. *\/ */
/*
pi->force.v_sig = fmaxf(pi->force.v_sig, v_sig);
*/
/* pj->force.v_sig = fmaxf(pj->force.v_sig, v_sig); */
float
wi
,
wj
,
wi_dx
,
wj_dx
;
const
float
fac_mu
=
1
.
f
;
/* Will change with cosmological integration
*/
const
float
r
=
sqrtf
(
r2
);
const
float
r_inv
=
1
.
0
f
/
r
;
/*
Get some values in local variables.
*/
/
/const float mi = pi->mass;
const
float
mj
=
pj
->
mass
;
const
float
rhoi
=
pi
->
rho
;
const
float
rhoj
=
p
j
->
rho
;
const
float
pressurei
=
p
i
->
pressure
;
const
float
pressurej
=
p
j
->
pressure
;
/*
Get the kernel for hi.
*/
const
float
hi_inv
=
1
.
0
f
/
hi
;
const
float
hi2_inv
=
hi_inv
*
hi_inv
;
const
float
ui
=
r
*
hi_inv
;
kernel_deval
(
ui
,
&
wi
,
&
wi_dx
);
const
float
wi_dr
=
hi
2
_inv
*
hi
2
_inv
*
wi_dx
;
/*
Get the kernel for hj.
*/
const
float
hj_inv
=
1
.
0
f
/
hj
;
const
float
hj2_inv
=
hj_inv
*
hj_inv
;
const
float
xj
=
r
*
hj_inv
;
kernel_deval
(
xj
,
&
wj
,
&
wj_dx
);
const
float
wj_dr
=
hj
2
_inv
*
hj
2
_inv
*
wj_dx
;
/*
Compute gradient terms
*/
const
float
P_over_rho_i
=
pressurei
/
(
rhoi
*
rhoi
)
*
pi
->
rho_dh
;
const
float
P_over_rho_j
=
pressurej
/
(
rhoj
*
rhoj
)
*
pj
->
rho_dh
;
/*
Compute sound speeds
*/
const
float
ci
=
sqrtf
(
const_hydro_gamma
*
pressurei
/
rhoi
);
const
float
cj
=
sqrtf
(
const_hydro_gamma
*
pressurej
/
rhoj
);
float
v_sig
=
ci
+
cj
;
/*
Compute dv dot r.
*/
const
float
dvdr
=
(
pi
->
v
[
0
]
-
pj
->
v
[
0
])
*
dx
[
0
]
+
(
pi
->
v
[
1
]
-
pj
->
v
[
1
])
*
dx
[
1
]
+
(
pi
->
v
[
2
]
-
pj
->
v
[
2
])
*
dx
[
2
];
/*
Artificial viscosity term
*/
float
visc
=
0
.
f
;
if
(
dvdr
<
0
.
f
)
{
const
float
mu_ij
=
fac_mu
*
dvdr
*
r_inv
;
v_sig
-=
3
.
f
*
mu_ij
;
const
float
rho_ij
=
0
.
5
f
*
(
rhoi
+
rhoj
);
const
float
balsara_i
=
fabsf
(
pi
->
div_v
)
/
(
fabsf
(
pi
->
div_v
)
+
p
i
->
curl_v
+
0
.
0001
*
ci
/
fac_mu
/
hi
);
const
float
balsara_j
=
fabsf
(
pj
->
div_v
)
/
(
fabsf
(
pj
->
div_v
)
+
pj
->
curl_v
+
0
.
0001
*
cj
/
fac_mu
/
hj
);
visc
=
-
0
.
25
f
*
const_viscosity_alpha
*
v_sig
*
mu_ij
/
rho_ij
*
(
balsara_i
+
balsara_j
);
}
/* Now, convolve with the kernel */
const
float
visc_term
=
0
.
5
f
*
mj
*
visc
*
(
wi_dr
+
wj_dr
)
*
r_inv
;
const
float
sph_term
=
mj
*
(
P_over_rho_i
*
wi_dr
+
P_over_rho_j
*
wj_dr
)
*
r_inv
;
/*
Eventually got the acceleration
*/
const
float
acc
=
visc_term
+
sph_term
;
/*
Use the force Luke !
*/
pi
->
a
[
0
]
-=
acc
*
dx
[
0
];
pi
->
a
[
1
]
-=
acc
*
dx
[
1
];
pi
->
a
[
2
]
-=
acc
*
dx
[
2
];
/*
Update the signal velocity.
*/
pi
->
v_sig
=
fmaxf
(
pi
->
v_sig
,
v_sig
)
;
/*
Change in entropy
*/
pi
->
entropy_dt
+=
0
.
5
f
*
visc_term
*
dvdr
;
}
...
...
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