Skip to content

Commit

Permalink
Merge pull request #104 from sintefmath/dev
Browse files Browse the repository at this point in the history
Minor improvements
  • Loading branch information
moyner authored Nov 12, 2024
2 parents 2ad93bc + f64e510 commit 1bfe36b
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Jutul"
uuid = "2b460a1a-8a2b-45b2-b125-b5c536396eb9"
authors = ["Olav Møyner <[email protected]>"]
version = "0.2.41"
version = "0.2.42"

[deps]
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
Expand Down
18 changes: 14 additions & 4 deletions ext/JutulHYPREExt/JutulHYPREExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module JutulHYPREExt
function Jutul.setup_hypre_precond(type = :boomeramg; kwarg...)
@assert type == :boomeramg
HYPRE.Init()
prec = HYPRE.BoomerAMG(; PrintLevel = 0, Tol = 0.0, MaxIter = 1, kwarg...)
prec = HYPRE.BoomerAMG(; kwarg...)
return prec
end

Expand Down Expand Up @@ -42,8 +42,17 @@ module JutulHYPREExt
end

function Jutul.update_preconditioner!(preconditioner::BoomerAMGPreconditioner, J, r, ctx, executor)
D = preconditioner.data
update_boomeramg!(preconditioner, J, r, ctx, executor, do_setup = true)
return preconditioner
end

function Jutul.partial_update_preconditioner!(preconditioner::BoomerAMGPreconditioner, J, r, ctx, executor)
update_boomeramg!(preconditioner, J, r, ctx, executor, do_setup = false)
return preconditioner
end

function update_boomeramg!(preconditioner::BoomerAMGPreconditioner, J, r, ctx, executor; do_setup = true)
D = preconditioner.data
if !haskey(D, :assembly_helper)
D[:assembly_helper] = Jutul.generate_hypre_assembly_helper(J, executor)
end
Expand All @@ -61,8 +70,9 @@ module JutulHYPREExt
J_h = transfer_matrix_to_hypre(J, D, executor)
end
D[:hypre_system] = (J_h, r_h, x_h)
HYPRE.@check HYPRE.HYPRE_BoomerAMGSetup(preconditioner.prec, J_h, r_h, x_h)
return preconditioner
if do_setup
HYPRE.@check HYPRE.HYPRE_BoomerAMGSetup(preconditioner.prec, J_h, r_h, x_h)
end
end

function transfer_vector_to_hypre(r, D, executor)
Expand Down
20 changes: 18 additions & 2 deletions src/ad/ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,13 @@ end
Replace values of `x` in-place by `y`, leaving `x` with the values of y and the partials of `x`.
"""
@inline function update_values!(v::AbstractArray{<:Real}, next::AbstractArray{<:Real})
@inline function update_values!(v::AbstractArray{<:ForwardDiff.Dual}, next::AbstractArray{<:Real})
# The ForwardDiff type is immutable, so to preserve the derivatives we do this little trick:
@. v = v - value(v) + value(next)
@inbounds for i in eachindex(v, next)
val = v[i]
v[i] = val - value(val) + value(next[i])
end
return v
end

"""
Expand All @@ -395,6 +399,18 @@ Replace values (for non-Real types, direct assignment)
@. v = next
end

@inline function update_values!(v::AbstractArray{<:Any}, next::AbstractArray{<:ForwardDiff.Dual})
@inbounds for i in eachindex(v, next)
next_val = next[i]
v[i] = value(next_val)
end
return v
end

function update_values!(v::AbstractArray{T}, next::AbstractArray{T}) where T<:ForwardDiff.Dual
@. v = next
end

"""
Take value of AD.
"""
Expand Down
8 changes: 7 additions & 1 deletion src/ext/hypre_ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ function BoomerAMGPreconditioner(;
AggNumLevels = 1, # Aggressive coarsening for first levels
AggTruncFactor = 0.3, # Remove weak connections
InterpType = 6, # ext+i
PrintLevel = 0,
Tol = 0.0,
MaxIter = 1,
kwarg...
)
# Default settings inspired by
Expand All @@ -29,8 +32,11 @@ function BoomerAMGPreconditioner(;
AggNumLevels = AggNumLevels,
AggTruncFactor = AggTruncFactor,
InterpType = InterpType,
Tol = Tol,
MaxIter = MaxIter,
PrintLevel = PrintLevel,
kwarg...
)
)
catch e
@error "Unable to initialize HYPRE preconditioner. Is HYPRE.jl loaded and Julia at least 1.9?"
rethrow(e)
Expand Down
4 changes: 4 additions & 0 deletions src/meshes/mrst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function cell_ijk(g::MRSTWrapMesh, base_index::Integer)
return (x, y, z)
end

function get_neighborship(g::MRSTWrapMesh; internal = true)
# TODO: Make this more elegant.
return get_neighborship(UnstructuredMesh(g); internal = internal)
end

function declare_entities(g::MRSTWrapMesh)
return [
Expand Down
5 changes: 4 additions & 1 deletion src/simulator/simulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ function solve_timestep!(sim, dT, forces, max_its, config;
# We store the report even if it is a failure.
push!(ministep_reports, s)
nextstep_local!(rec, dt, ok)
n_so_far = length(ministep_reports)
if ok
if 2 > info_level > 1
jutul_message("Convergence", "Ministep #$n_so_far of $(get_tstr(dt, 1)) ($(round(100.0*dt/dT, digits=1))% of report step) converged.", color = :green)
end
t_local += dt
if t_local >= dT
# Onto the next one
Expand Down Expand Up @@ -312,7 +316,6 @@ function solve_timestep!(sim, dT, forces, max_its, config;
inner_msg = " Reducing mini-step."
c = :yellow
end
n_so_far = length(ministep_reports)
jutul_message("Convergence", "Report step $step_no, mini-step #$n_so_far ($(get_tstr(dt_old, 2))) failed to converge.$inner_msg", color = c)
end
if isnan(dt)
Expand Down
26 changes: 17 additions & 9 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -895,16 +895,24 @@ function timing_breakdown_ministep(ministep)
t_local = 0.0
its = 0
asm = 0
for step in ministep[:steps]
asm += 1
t_asm += step[:secondary_time] + step[:equations_time] + step[:linear_system_time]
if haskey(step, :linear_solve_time)
its += 1
t_solve += step[:linear_solve_time]
end
if haskey(step, :time_subdomains)
t_local += step[:time_subdomains]
if haskey(ministep, :steps)
for step in ministep[:steps]
asm += 1
t_asm += step[:secondary_time] + step[:equations_time] + step[:linear_system_time]
if haskey(step, :linear_solve_time)
its += 1
t_solve += step[:linear_solve_time]
end
if haskey(step, :time_subdomains)
t_local += step[:time_subdomains]
end
end
else
s = ministep[:stats]
asm += s.linearizations
its += s.newtons
t_asm += s.equations + s.secondary + s.linear_system
t_solve += s.linear_solve + s.linear_solve_precond
end
return (assembly = t_asm, solve = t_solve, subdomains = t_local, its = its, no_asm = asm)
end
Expand Down

2 comments on commit 1bfe36b

@moyner
Copy link
Member Author

@moyner moyner commented on 1bfe36b Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/119253

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.42 -m "<description of version>" 1bfe36b1d4739ba5bfc8b101fe9d78e838bdeb71
git push origin v0.2.42

Please sign in to comment.