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

Improve stability of heat diffusion solver #219

Merged
merged 9 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
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
49 changes: 49 additions & 0 deletions src/ext/AMDGPU/2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,55 @@ function JR2D.PTThermalCoeffs(
return PTThermalCoeffs(rheology, args, dt, ni, di, li; ϵ=ϵ, CFL=CFL)
end

function JR2D.update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs{T,<:ROCArray}, rheology, phase_ratios, args, dt
) where {T}
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
phase_ratios.center,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

function JR2D.update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs{T,<:ROCArray}, rheology, args, dt
) where {T}
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

function JR2D.update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs{T,<:ROCArray}, rheology, ::Nothing, args, dt
) where {T}
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

# Boundary conditions
function JR2D.flow_bcs!(
::AMDGPUBackendTrait, stokes::JustRelax.StokesArrays, bcs::VelocityBoundaryConditions
Expand Down
49 changes: 49 additions & 0 deletions src/ext/AMDGPU/3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,55 @@ function JR3D.PTThermalCoeffs(
return PTThermalCoeffs(rheology, args, dt, ni, di, li; ϵ=ϵ, CFL=CFL)
end

function JR3D.update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs{T,<:ROCArray}, rheology, phase_ratios, args, dt
) where {T}
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
phase_ratios.center,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

function JR3D.update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs{T,<:ROCArray}, rheology, args, dt
) where {T}
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

function JR3D.update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs{T,<:ROCArray}, rheology, ::Nothing, args, dt
) where {T}
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

# Boundary conditions
function JR3D.flow_bcs!(
::AMDGPUBackendTrait, stokes::JustRelax.StokesArrays, bcs::VelocityBoundaryConditions
Expand Down
49 changes: 49 additions & 0 deletions src/ext/CUDA/2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,55 @@ function JR2D.PTThermalCoeffs(
return PTThermalCoeffs(rheology, args, dt, ni, di, li; ϵ=ϵ, CFL=CFL)
end

function JR2D.update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs{T,<:CuArray}, rheology, phase_ratios, args, dt
) where {T}
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
phase_ratios.center,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

function JR2D.update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs{T,<:CuArray}, rheology, args, dt
) where {T}
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

function JR2D.update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs{T,<:CuArray}, rheology, ::Nothing, args, dt
) where {T}
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

# Boundary conditions
function JR2D.flow_bcs!(
::CUDABackendTrait, stokes::JustRelax.StokesArrays, bcs::VelocityBoundaryConditions
Expand Down
49 changes: 49 additions & 0 deletions src/ext/CUDA/3D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,55 @@ function JR3D.update_pt_thermal_arrays!(
return nothing
end

function JR3D.update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs{T,<:CuArray}, rheology, phase_ratios, args, dt
) where {T}
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
phase_ratios.center,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

function JR3D.update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs{T,<:CuArray}, rheology, args, dt
) where {T}
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

function JR3D.update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs{T,<:CuArray}, rheology, ::Nothing, args, dt
) where {T}
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

# Boundary conditions
function JR3D.flow_bcs!(
::CUDABackendTrait, stokes::JustRelax.StokesArrays, bcs::VelocityBoundaryConditions
Expand Down
47 changes: 47 additions & 0 deletions src/thermal_diffusion/DiffusionPT_coefficients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,50 @@ function _compute_pt_thermal_arrays!(

return nothing
end

function update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs, rheology, phase_ratios, args, dt
)
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
phase_ratios.center,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

function update_thermal_coeffs!(pt_thermal::JustRelax.PTThermalCoeffs, rheology, args, dt)
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end

function update_thermal_coeffs!(
pt_thermal::JustRelax.PTThermalCoeffs, rheology, ::Nothing, args, dt
)
ni = size(pt_thermal.dτ_ρ)
@parallel (@idx ni) compute_pt_thermal_arrays!(
pt_thermal.θr_dτ,
pt_thermal.dτ_ρ,
rheology,
args,
pt_thermal.max_lxyz,
pt_thermal.Vpdτ,
inv(dt),
)
return nothing
end
70 changes: 40 additions & 30 deletions src/thermal_diffusion/DiffusionPT_kernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,15 @@ end
d_za(A) = _d_za(A, I..., _dz)

I1 = I .+ 1
T[I1...] +=
av(dτ_ρ) * (
(-(d_xa(qTx) + d_ya(qTy) + d_za(qTz))) -
av(ρCp) * (T[I1...] - Told[I1...]) * _dt
) +
av(H) +
av(shear_heating)

T[I1...] =
(
av(dτ_ρ) * (
-(d_xa(qTx) + d_ya(qTy) + d_za(qTz)) +
Told[I1...] * av(ρCp) * _dt +
av(H) +
av(shear_heating)
) + T[I1...]
) / (one(_T) + av(dτ_ρ) * av(ρCp) * _dt)
return nothing
end

Expand Down Expand Up @@ -166,16 +167,18 @@ end
T_ijk = T[I...]
args_ijk = (; T=T_ijk, P=av(args.P))
phase_ijk = getindex_phase(phase, i, j, k)
ρCp = compute_ρCp(rheology, phase_ijk, args_ijk)

T[I...] =
T_ijk +
av(dτ_ρ) * (
(-(d_xa(qTx) + d_ya(qTy) + d_za(qTz))) -
compute_ρCp(rheology, phase_ijk, args_ijk) * (T_ijk - Told[I...]) * _dt +
av(H) +
av(shear_heating) +
adiabatic[i, j, k] * T_ijk
)
(
av(dτ_ρ) * (
-(d_xa(qTx) + d_ya(qTy) + d_za(qTz)) +
Told[I...] * ρCp * _dt +
av(H) +
av(shear_heating) +
adiabatic[i, j] * T_ijk
) + T_ijk
) / (one(_T) + av(dτ_ρ) * ρCp * _dt)
return nothing
end

Expand Down Expand Up @@ -389,13 +392,16 @@ end
end
#! format: on

T[i + 1, j + 1] +=
av(dτ_ρ) * (
(-(d_xa(qTx) + d_ya(qTy))) -
av(ρCp) * (T[i + 1, j + 1] - Told[i + 1, j + 1]) * _dt +
av(H) +
av(shear_heating)
)
T[i + 1, j + 1] =
(
av(dτ_ρ) * (
-(d_xa(qTx) + d_ya(qTy)) +
Told[i + 1, j + 1] * av(ρCp) * _dt +
av(H) +
av(shear_heating)
) + T[i + 1, j + 1]
) / (one(_T) + av(dτ_ρ) * av(ρCp) * _dt)

return nothing
end

Expand Down Expand Up @@ -437,13 +443,17 @@ end
compute_ρCp(rheology, getindex_phase(phase, i1, j1), args_ij)
) * 0.25

T[i + 1, j + 1] +=
av(dτ_ρ) * (
(-(d_xa(qTx) + d_ya(qTy))) - ρCp * (T_ij - Told[i + 1, j + 1]) * _dt +
av(H) +
av(shear_heating) +
adiabatic[i, j] * T[i + 1, j + 1]
)
T[i + 1, j + 1] =
(
av(dτ_ρ) * (
-(d_xa(qTx) + d_ya(qTy)) +
Told[i + 1, j + 1] * ρCp * _dt +
av(H) +
av(shear_heating) +
adiabatic[i, j] * T[i + 1, j + 1]
) + T[i + 1, j + 1]
) / (one(_T) + av(dτ_ρ) * ρCp * _dt)

return nothing
end

Expand Down
1 change: 1 addition & 0 deletions src/thermal_diffusion/DiffusionPT_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function _heatdiffusion_PT!(

while err > ϵ && iter < iterMax
wtime0 += @elapsed begin
update_thermal_coeffs!(pt_thermal, rheology, phase, args, dt)
@parallel flux_range(ni...) compute_flux!(
@qT(thermal)...,
@qT2(thermal)...,
Expand Down
Loading