Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-de-montserrat committed Nov 16, 2024
1 parent 60ec309 commit 4057277
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 36 deletions.
10 changes: 6 additions & 4 deletions src/JustRelax_CPU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import JustRelax:
AbstractFlowBoundaryConditions,
DisplacementBoundaryConditions,
VelocityBoundaryConditions,
apply_dirichlet, apply_dirichlet!

apply_dirichlet,
apply_dirichlet!

import JustPIC._2D: numphases, nphases

__init__() = @init_parallel_stencil(Threads, Float64, 2)
Expand Down Expand Up @@ -49,8 +50,9 @@ import JustRelax:
TemperatureBoundaryConditions,
AbstractFlowBoundaryConditions,
DisplacementBoundaryConditions,
VelocityBoundaryConditions,
apply_dirichlet, apply_dirichlet!
VelocityBoundaryConditions,
apply_dirichlet,
apply_dirichlet!

import JustPIC._3D: numphases, nphases

Expand Down
28 changes: 14 additions & 14 deletions src/boundaryconditions/Dirichlet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,49 +71,49 @@ function Base.getindex(
end

@inline function apply_dirichlet!(A::AbstractArray, bc::AbstractDirichletBoundaryCondition)
apply_mask!(A, bc.value, bc.mask)
return apply_mask!(A, bc.value, bc.mask)
end

@inline function apply_dirichlet!(
::AbstractArray, ::AbstractDirichletBoundaryCondition{Nothing,Nothing}
)
nothing
)
return nothing
end

@inline function apply_dirichlet!(
A::AbstractArray, bc::AbstractDirichletBoundaryCondition, inds::Vararg{Int,N}
) where {N}
apply_mask!(A, bc.value, bc.mask, inds...)
) where {N}
return apply_mask!(A, bc.value, bc.mask, inds...)
end

@inline function apply_dirichlet!(
::AbstractArray, ::AbstractDirichletBoundaryCondition{Nothing,Nothing}, ::Vararg{Int,N}
) where {N}
nothing
) where {N}
return nothing
end

@inline function apply_dirichlet(A::AbstractArray, bc::AbstractDirichletBoundaryCondition)
apply_mask(A, bc.value, bc.mask)
return apply_mask(A, bc.value, bc.mask)
end

@inline function apply_dirichlet(
A::AbstractArray, ::AbstractDirichletBoundaryCondition{Nothing,Nothing}
)
A
)
return A
end

@inline function apply_dirichlet(
A::AbstractArray, bc::AbstractDirichletBoundaryCondition, inds::Vararg{Int,N}
) where {N}
apply_mask(A, bc.value, bc.mask, inds...)
) where {N}
return apply_mask(A, bc.value, bc.mask, inds...)
end

@inline function apply_dirichlet(
A::AbstractArray,
::AbstractDirichletBoundaryCondition{Nothing,Nothing},
inds::Vararg{Int,N},
) where {N}
A[inds...]
) where {N}
return A[inds...]
end

@inline Dirichlet(x::NamedTuple) = Dirichlet(; x...)
Expand Down
2 changes: 1 addition & 1 deletion src/mask/constructors.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Mask(nx, ny, inds::Vararg{UnitRange, 2})
function Mask(nx, ny, inds::Vararg{UnitRange,2})
mask = @zeros(nx, ny)
@views mask[inds...] .= 1
return JustRelax.Mask(mask)
Expand Down
51 changes: 36 additions & 15 deletions src/thermal_diffusion/DiffusionPT_kernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ end
av(shear_heating)
) + T[I1...]
) / (one(_T) + av(dτ_ρ) * av(ρCp) * _dt)
apply_dirichlet!(T , dirichlet, I1...)
apply_dirichlet!(T, dirichlet, I1...)

return nothing
end

Expand Down Expand Up @@ -183,7 +183,7 @@ end
adiabatic[i, j, k] * T_ijk
) + T_ijk
) / (one(_T) + av(dτ_ρ) * ρCp * _dt)
apply_dirichlet!(T , dirichlet, I1...)
apply_dirichlet!(T, dirichlet, I1...)

return nothing
end
Expand Down Expand Up @@ -388,7 +388,18 @@ end
end

@parallel_indices (i, j) function update_T!(
T::AbstractArray{_T,2}, Told, qTx, qTy, H, shear_heating, ρCp, dτ_ρ, dirichlet, _dt, _dx, _dy
T::AbstractArray{_T,2},
Told,
qTx,
qTy,
H,
shear_heating,
ρCp,
dτ_ρ,
dirichlet,
_dt,
_dx,
_dy,
) where {_T}
nx, ny = size(ρCp)

Expand All @@ -405,7 +416,7 @@ end
end
#! format: on

I1 = i + 1, j + 1
I1 = i + 1, j + 1
T[I1...] =
(
av(dτ_ρ) * (
Expand All @@ -416,8 +427,8 @@ end
) + T[I1...]
) / (one(_T) + av(dτ_ρ) * av(ρCp) * _dt)

apply_dirichlet!(T , dirichlet, I1...)
apply_dirichlet!(T, dirichlet, I1...)

return nothing
end

Expand Down Expand Up @@ -460,7 +471,7 @@ end
compute_ρCp(rheology, getindex_phase(phase, i1, j1), args_ij)
) * 0.25

I1 = i + 1, j + 1
I1 = i + 1, j + 1
T[I1...] =
(
av(dτ_ρ) * (
Expand All @@ -471,14 +482,25 @@ end
adiabatic[i, j] * T[I1...]
) + T[I1...]
) / (one(_T) + av(dτ_ρ) * ρCp * _dt)
apply_dirichlet!(T , dirichlet, I1...)

apply_dirichlet!(T, dirichlet, I1...)

return nothing
end

@parallel_indices (i, j) function check_res!(
ResT::AbstractArray{_T,2}, T, Told, qTx2, qTy2, H, shear_heating, ρCp, dirichlet, _dt, _dx, _dy
ResT::AbstractArray{_T,2},
T,
Told,
qTx2,
qTy2,
H,
shear_heating,
ρCp,
dirichlet,
_dt,
_dx,
_dy,
) where {_T}
nx, ny = size(ρCp)

Expand All @@ -497,14 +519,13 @@ end

I1 = i + 1, j + 1
ResT[i, j] = if iszero(dirichlet.mask[I1...])
-av(ρCp) * (T[I1...] - Told[I1...]) * _dt -
(d_xa(qTx2) + d_ya(qTy2)) +
-av(ρCp) * (T[I1...] - Told[I1...]) * _dt - (d_xa(qTx2) + d_ya(qTy2)) +
av(H) +
av(shear_heating)
else
zero(_T)
end

return nothing
end

Expand Down Expand Up @@ -553,7 +574,7 @@ end
av(H) +
av(shear_heating) +
adiabatic[i, j] * T[I1...]
else
else
zero(_T)
end

Expand Down
24 changes: 22 additions & 2 deletions src/thermal_diffusion/DiffusionPT_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ function _heatdiffusion_PT!(
@parallel flux_range(ni...) compute_flux!(
@qT(thermal)..., @qT2(thermal)..., thermal.T, K, pt_thermal.θr_dτ, _di...
)
update_T(nothing, b_width, thermal, ρCp, pt_thermal, thermal_bc.dirichlet, _dt, _di, ni)
update_T(
nothing,
b_width,
thermal,
ρCp,
pt_thermal,
thermal_bc.dirichlet,
_dt,
_di,
ni,
)
thermal_bcs!(thermal, thermal_bc)
update_halo!(thermal.T)
end
Expand Down Expand Up @@ -160,7 +170,17 @@ function _heatdiffusion_PT!(
args,
)
update_T(
nothing, b_width, thermal, rheology, phases, pt_thermal, thermal_bc.dirichlet, _dt, _di, ni, args
nothing,
b_width,
thermal,
rheology,
phases,
pt_thermal,
thermal_bc.dirichlet,
_dt,
_di,
ni,
args,
)
thermal_bcs!(thermal, thermal_bc)
update_halo!(thermal.T)
Expand Down

0 comments on commit 4057277

Please sign in to comment.