Skip to content

Commit

Permalink
Norm for faster performance
Browse files Browse the repository at this point in the history
  • Loading branch information
axla-io committed Sep 19, 2023
1 parent 6c30879 commit 06a3953
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/dfsane.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::DFSane,
fuₙ₋₁ = f(uₙ₋₁)
end

f₍ₙₒᵣₘ₎ₙ₋₁ = sum(abs2, fuₙ₋₁)
f₍ₙₒᵣₘ₎ₙ₋₁ ^= (nₑₓₚ / 2)
f₍ₙₒᵣₘ₎ₙ₋₁ = norm(fuₙ₋₁)^nₑₓₚ
f₍ₙₒᵣₘ₎₀ = f₍ₙₒᵣₘ₎ₙ₋₁

= fill(f₍ₙₒᵣₘ₎ₙ₋₁, M)
Expand Down Expand Up @@ -152,8 +151,7 @@ function perform_step!(cache::DFSaneCache{true})
@. cache.uₙ = cache.uₙ₋₁ + α₊ * cache.𝒹

f(cache.fuₙ, cache.uₙ)
f₍ₙₒᵣₘ₎ₙ = sum(abs2, cache.fuₙ)
f₍ₙₒᵣₘ₎ₙ ^= (nₑₓₚ / 2)
f₍ₙₒᵣₘ₎ₙ = norm(cache.fuₙ)^nₑₓₚ
for _ in 1:(cache.alg.max_inner_iterations)
𝒸 =+ η - γ * α₊^2 * f₍ₙₒᵣₘ₎ₙ₋₁

Expand All @@ -166,8 +164,7 @@ function perform_step!(cache::DFSaneCache{true})
@. cache.uₙ = cache.uₙ₋₁ - α₋ * cache.𝒹

f(cache.fuₙ, cache.uₙ)
f₍ₙₒᵣₘ₎ₙ = sum(abs2, cache.fuₙ)
f₍ₙₒᵣₘ₎ₙ ^= (nₑₓₚ / 2)
f₍ₙₒᵣₘ₎ₙ = norm(cache.fuₙ)^nₑₓₚ

f₍ₙₒᵣₘ₎ₙ .≤ 𝒸 && break

Expand All @@ -177,8 +174,7 @@ function perform_step!(cache::DFSaneCache{true})

@. cache.uₙ = cache.uₙ₋₁ + α₊ * cache.𝒹
f(cache.fuₙ, cache.uₙ)
f₍ₙₒᵣₘ₎ₙ = sum(abs2, cache.fuₙ)
f₍ₙₒᵣₘ₎ₙ ^= (nₑₓₚ / 2)
f₍ₙₒᵣₘ₎ₙ = norm(cache.fuₙ)^nₑₓₚ
end

if cache.internalnorm(cache.fuₙ) < cache.abstol
Expand All @@ -194,7 +190,6 @@ function perform_step!(cache::DFSaneCache{true})
α₋ = sum(cache.uₙ₋₁)
cache.σₙ = α₊ / α₋


# Spectral parameter bounds check
if abs(cache.σₙ) > σₘₐₓ || abs(cache.σₙ) < σₘᵢₙ
test_norm = sqrt(sum(abs2, cache.fuₙ₋₁))
Expand Down Expand Up @@ -239,8 +234,7 @@ function perform_step!(cache::DFSaneCache{false})
@. cache.uₙ = cache.uₙ₋₁ + α₊ * cache.𝒹

@. cache.fuₙ = f(cache.uₙ)
f₍ₙₒᵣₘ₎ₙ = sum(abs2, cache.fuₙ)
f₍ₙₒᵣₘ₎ₙ ^= (nₑₓₚ / 2)
f₍ₙₒᵣₘ₎ₙ = norm(cache.fuₙ)^nₑₓₚ

for _ in 1:(cache.alg.max_inner_iterations)
𝒸 =+ η - γ * α₊^2 * f₍ₙₒᵣₘ₎ₙ₋₁
Expand All @@ -254,8 +248,7 @@ function perform_step!(cache::DFSaneCache{false})
@. cache.uₙ = cache.uₙ₋₁ - α₋ * cache.𝒹 # correct order?

@. cache.fuₙ = f(cache.uₙ)
f₍ₙₒᵣₘ₎ₙ = sum(abs2, cache.fuₙ)
f₍ₙₒᵣₘ₎ₙ ^= (nₑₓₚ / 2)
f₍ₙₒᵣₘ₎ₙ = norm(cache.fuₙ)^nₑₓₚ

(f₍ₙₒᵣₘ₎ₙ .≤ 𝒸) && break

Expand All @@ -265,8 +258,7 @@ function perform_step!(cache::DFSaneCache{false})

@. cache.uₙ = cache.uₙ₋₁ + α₊ * cache.𝒹 # correct order?
@. cache.fuₙ = f(cache.uₙ)
f₍ₙₒᵣₘ₎ₙ = sum(abs2, cache.fuₙ)
f₍ₙₒᵣₘ₎ₙ ^= (nₑₓₚ / 2)
f₍ₙₒᵣₘ₎ₙ = norm(cache.fuₙ)^nₑₓₚ
end

if cache.internalnorm(cache.fuₙ) < cache.abstol
Expand Down

0 comments on commit 06a3953

Please sign in to comment.