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 1 commit
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
41 changes: 27 additions & 14 deletions src/semidiscretization/semidiscretization_euler_gravity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,22 +232,29 @@ 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 i in 1:n_elements
@views @. du_euler[2, .., i] -= u_euler[1, .., i] * u_gravity[2, .., i]
@views @. du_euler[3, .., i] -= u_euler[2, .., i] * u_gravity[2, .., i]
end
DanielDoehring marked this conversation as resolved.
Show resolved Hide resolved
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 i in 1:n_elements
@views @. du_euler[2, .., i] -= u_euler[1, .., i] * u_gravity[2, .., i]
@views @. du_euler[3, .., i] -= u_euler[1, .., i] * u_gravity[3, .., i]
@views @. du_euler[4, .., i] -= (u_euler[2, .., i] * u_gravity[2, .., i] +
u_euler[3, .., i] * u_gravity[3, .., i])
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 i in 1:n_elements
@views @. du_euler[2, .., i] -= u_euler[1, .., i] * u_gravity[2, .., i]
@views @. du_euler[3, .., i] -= u_euler[1, .., i] * u_gravity[3, .., i]
@views @. du_euler[4, .., i] -= u_euler[1, .., i] * u_gravity[4, .., i]
@views @. du_euler[5, .., i] -= (u_euler[2, .., i] * u_gravity[2, .., i] +
u_euler[3, .., i] * u_gravity[3, .., i] +
u_euler[4, .., i] * u_gravity[4, .., i])
end
else
error("Number of dimensions $(ndims(semi_euler)) not supported.")
end
Expand Down Expand Up @@ -335,7 +342,10 @@ 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 i in 1:n_elements
@views @. du_gravity[1, .., i] += grav_scale * (u_euler[1, .., i] - rho0)
end

a_stage = a[stage]
b_stage_dt = b[stage] * dt
Expand Down Expand Up @@ -390,7 +400,10 @@ 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 i in 1:n_elements
@views @. du_gravity[1, .., i] += grav_scale * (u_euler[1, .., i] - rho0)
end

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