Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread-parallelize src term addition Euler Gravity #2102

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 41 additions & 14 deletions src/semidiscretization/semidiscretization_euler_gravity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,22 +232,41 @@ function rhs!(du_ode, u_ode, semi::SemidiscretizationEulerGravity, t)
# compute gravitational potential and forces
@trixi_timeit timer() "gravity solver" update_gravity!(semi, u_ode)

n_elements = size(u_euler)[end]
# add gravitational source source_terms to the Euler part
if ndims(semi_euler) == 1
@views @. du_euler[2, .., :] -= u_euler[1, .., :] * u_gravity[2, .., :]
@views @. du_euler[3, .., :] -= u_euler[2, .., :] * u_gravity[2, .., :]
@threaded for element in 1:n_elements
@views @. du_euler[2, .., element] -= u_euler[1, .., element] *
u_gravity[2, .., element]
@views @. du_euler[3, .., element] -= u_euler[2, .., element] *
u_gravity[2, .., element]
end
elseif ndims(semi_euler) == 2
@views @. du_euler[2, .., :] -= u_euler[1, .., :] * u_gravity[2, .., :]
@views @. du_euler[3, .., :] -= u_euler[1, .., :] * u_gravity[3, .., :]
@views @. du_euler[4, .., :] -= (u_euler[2, .., :] * u_gravity[2, .., :] +
u_euler[3, .., :] * u_gravity[3, .., :])
@threaded for element in 1:n_elements
@views @. du_euler[2, .., element] -= u_euler[1, .., element] *
u_gravity[2, .., element]
@views @. du_euler[3, .., element] -= u_euler[1, .., element] *
u_gravity[3, .., element]
@views @. du_euler[4, .., element] -= (u_euler[2, .., element] *
u_gravity[2, .., element] +
u_euler[3, .., element] *
u_gravity[3, .., element])
end
elseif ndims(semi_euler) == 3
@views @. du_euler[2, .., :] -= u_euler[1, .., :] * u_gravity[2, .., :]
@views @. du_euler[3, .., :] -= u_euler[1, .., :] * u_gravity[3, .., :]
@views @. du_euler[4, .., :] -= u_euler[1, .., :] * u_gravity[4, .., :]
@views @. du_euler[5, .., :] -= (u_euler[2, .., :] * u_gravity[2, .., :] +
u_euler[3, .., :] * u_gravity[3, .., :] +
u_euler[4, .., :] * u_gravity[4, .., :])
@threaded for element in 1:n_elements
@views @. du_euler[2, .., element] -= u_euler[1, .., element] *
u_gravity[2, .., element]
@views @. du_euler[3, .., element] -= u_euler[1, .., element] *
u_gravity[3, .., element]
@views @. du_euler[4, .., element] -= u_euler[1, .., element] *
u_gravity[4, .., element]
@views @. du_euler[5, .., element] -= (u_euler[2, .., element] *
u_gravity[2, .., element] +
u_euler[3, .., element] *
u_gravity[3, .., element] +
u_euler[4, .., element] *
u_gravity[4, .., element])
end
else
error("Number of dimensions $(ndims(semi_euler)) not supported.")
end
Expand Down Expand Up @@ -335,7 +354,11 @@ function timestep_gravity_2N!(cache, u_euler, t, dt, gravity_parameters, semi_gr
# Source term: Jeans instability OR coupling convergence test OR blast wave
# put in gravity source term proportional to Euler density
# OBS! subtract off the background density ρ_0 (spatial mean value)
@views @. du_gravity[1, .., :] += grav_scale * (u_euler[1, .., :] - rho0)
n_elements = size(u_euler)[end]
@threaded for element in 1:n_elements
@views @. du_gravity[1, .., element] += grav_scale *
(u_euler[1, .., element] - rho0)
end

a_stage = a[stage]
b_stage_dt = b[stage] * dt
Expand Down Expand Up @@ -390,7 +413,11 @@ function timestep_gravity_3Sstar!(cache, u_euler, t, dt, gravity_parameters,
# Source term: Jeans instability OR coupling convergence test OR blast wave
# put in gravity source term proportional to Euler density
# OBS! subtract off the background density ρ_0 around which the Jeans instability is perturbed
@views @. du_gravity[1, .., :] += grav_scale * (u_euler[1, .., :] - rho0)
n_elements = size(u_euler)[end]
@threaded for element in 1:n_elements
@views @. du_gravity[1, .., element] += grav_scale *
(u_euler[1, .., element] - rho0)
end

delta_stage = delta[stage]
gamma1_stage = gamma1[stage]
Expand Down
Loading