From 08653d7aa879d647f547396e886ff8745b2e963c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20M=C3=B8yner?= Date: Fri, 1 Nov 2024 08:41:04 +0100 Subject: [PATCH 1/7] Fix to timing_breakdown for summarized stats --- src/utils.jl | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 3281c94d..056137d7 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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 From dbea5e780d55703950a4802879439c38105d5f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20M=C3=B8yner?= Date: Mon, 4 Nov 2024 15:37:37 +0100 Subject: [PATCH 2/7] Improve printing --- src/simulator/simulator.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/simulator/simulator.jl b/src/simulator/simulator.jl index 3da5a595..91bd2e4a 100644 --- a/src/simulator/simulator.jl +++ b/src/simulator/simulator.jl @@ -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 @@ -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) From cc96556ca26b1db7fd1e7563920620f163a2b303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20M=C3=B8yner?= Date: Wed, 6 Nov 2024 15:19:33 +0100 Subject: [PATCH 3/7] update_values!: Split into two parts for AD/Float64 --- src/ad/ad.jl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ad/ad.jl b/src/ad/ad.jl index 2151bcfc..b91866de 100644 --- a/src/ad/ad.jl +++ b/src/ad/ad.jl @@ -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 """ @@ -395,6 +399,14 @@ 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 + """ Take value of AD. """ From 1e471feaf2188392991eb2af0ea98b11f08805b1 Mon Sep 17 00:00:00 2001 From: Kai Bao Date: Thu, 7 Nov 2024 14:18:44 +0100 Subject: [PATCH 4/7] adding update_values for AbstractArray{<:ForwardDiff.Dual} --- src/ad/ad.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ad/ad.jl b/src/ad/ad.jl index b91866de..f905b44c 100644 --- a/src/ad/ad.jl +++ b/src/ad/ad.jl @@ -407,6 +407,10 @@ end return v end +function update_values!(v::AbstractArray{T}, next::AbstractArray{T}) where T<:ForwardDiff.Dual + @. v = next +end + """ Take value of AD. """ From 5cc750a3f822afacc211caea2eb11e480a1b0751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20M=C3=B8yner?= Date: Mon, 11 Nov 2024 15:52:49 +0100 Subject: [PATCH 5/7] HYPRE cleanup - put options in one place, support partial update --- ext/JutulHYPREExt/JutulHYPREExt.jl | 18 ++++++++++++++---- src/ext/hypre_ext.jl | 8 +++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ext/JutulHYPREExt/JutulHYPREExt.jl b/ext/JutulHYPREExt/JutulHYPREExt.jl index a3882305..d73cedb9 100644 --- a/ext/JutulHYPREExt/JutulHYPREExt.jl +++ b/ext/JutulHYPREExt/JutulHYPREExt.jl @@ -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 @@ -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 @@ -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) diff --git a/src/ext/hypre_ext.jl b/src/ext/hypre_ext.jl index ce591c52..b0af4e4c 100644 --- a/src/ext/hypre_ext.jl +++ b/src/ext/hypre_ext.jl @@ -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 @@ -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) From e6991b863c5d228cf4edf8941151e61d74b12729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20M=C3=B8yner?= Date: Tue, 12 Nov 2024 11:09:47 +0100 Subject: [PATCH 6/7] Bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index d89d6b3e..ea98be19 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Jutul" uuid = "2b460a1a-8a2b-45b2-b125-b5c536396eb9" authors = ["Olav Møyner "] -version = "0.2.41" +version = "0.2.42" [deps] AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c" From f64e510546932440a9ea8edc7633c0d14ceaaafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20M=C3=B8yner?= Date: Tue, 12 Nov 2024 14:19:34 +0100 Subject: [PATCH 7/7] Add MRSTWrapMesh neighborship function --- src/meshes/mrst.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/meshes/mrst.jl b/src/meshes/mrst.jl index 7b6b050d..96678731 100644 --- a/src/meshes/mrst.jl +++ b/src/meshes/mrst.jl @@ -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 [