Skip to content

Commit

Permalink
add more helpful warning message, modify elliptic grid solver default…
Browse files Browse the repository at this point in the history
… tolerance
  • Loading branch information
juddmehr committed Feb 8, 2025
1 parent cb43e3c commit ff797b1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/analysis/analyses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ function analyze(
if iszero(lu_decomp_flag)
@warn "Exiting. LU decomposition of the LHS matrix for the linear system failed. Please check your body geometry and ensure that there will be no panels lying directly atop eachother or other similar problematic geometry."
elseif !options.grid_solver_options.converged[1]
@warn "Exiting. Wake elliptic grid solve did not converge. Consider a looser convergence tolerance if the geometry looks good."
@warn begin "Exiting. Wake elliptic grid solve did not converge. Consider a looser convergence tolerance if the geometry looks good. \nConvergence Tolerance: $(options.grid_solver_options.atol)\nSolver terminated after $(options.grid_solver_options.iterations[1]) iterations with a residual of $(options.grid_solver_options.residual_value[1])"
end
end
end
#TODO: write a function that returns the same as outs below, but all zeros
Expand Down Expand Up @@ -280,7 +281,9 @@ function analyze(
if iszero(lu_decomp_flag)
@warn "Exiting. LU decomposition of the LHS matrix for the linear system failed. Please check your body geometry and ensure that there will be no panels lying directly atop eachother or other similar problematic geometry."
elseif !options.grid_solver_options.converged[1]
@warn "Exiting. Wake elliptic grid solve did not converge. Consider a looser convergence tolerance if the geometry looks good."
@warn begin "Exiting. Wake elliptic grid solve did not converge. Consider a looser convergence tolerance if the geometry looks good. \nConvergence Tolerance: $(options.grid_solver_options.atol)\nSolver terminated after $(options.grid_solver_options.iterations[1]) iterations with a residual of $(options.grid_solver_options.residual_value[1])"
end

end
end
#TODO: write a function that returns the same as outs below, but all zeros
Expand Down
6 changes: 5 additions & 1 deletion src/postprocess/boundary_layer_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function split_at_stagnation_point(
_, minvtid = findmin(Vtan_duct)
vtsp = Akima_smooth(s_tot, Vtan_duct)


if minvtid == length(Vtan_duct)
s_upper = nothing
s_lower = arc_lengths_from_panel_lengths(duct_panel_lengths[end:-1:1])
Expand All @@ -69,9 +70,12 @@ function split_at_stagnation_point(

return s_upper, s_lower, stag_ids, stag_point, split_ratio, dots
else
print("in past bug area that is hard to recreate. ")
print("min Vt index: ", minvtid)
println(" length s_tot: ", length(s_tot))
stag_point = Roots.find_zero(
x -> FLOWMath.derivative(vtsp, x),
(s_tot[max(minvtid - 1, 1)], s_tot[minvtid + 1]),
(s_tot[max(minvtid - 1, 1)], s_tot[min(minvtid + 1, length(s_tot))]),
Roots.Brent();
atol=eps(),
)
Expand Down
10 changes: 8 additions & 2 deletions src/preprocess/geometry/elliptic_grid_residuals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ function elliptic_grid_residual_dfdc!(r, y, x, p)
end

"""
solve_elliptic_grid!(x,p)
solve_elliptic_grid(x,p)
Solve for elliptic grid using a non-SLOR approach that is compatible with ImplicitAD
Expand Down Expand Up @@ -431,6 +431,8 @@ function solve_elliptic_grid(x, p)
)

p.converged[1] = NLsolve.converged(result)
p.iterations[1] = result.iterations
p.residual_value[1] = result.residual_norm

return result.zero
end
Expand All @@ -443,6 +445,7 @@ end
atol=1e-14,
iteration_limit=10,
converged=[false],
residual_value=[0.0],
verbose=false,
)
Expand All @@ -457,6 +460,7 @@ Solve for elliptic grid using a non-SLOR approach that is compatible with Implic
- `atol::Float=1e-10` : convergence tolerance, default = 1e-9
- `iteration_limit::Int=10` : maximum number of iterations to run, default=100
- `converged::Vector{Bool}=[false]` : convergence flag
- `residual_value::Vector{Float}=[0.0]` : final residual value
- `verbose::Bool=false` : flag to print verbose statements
"""
function solve_elliptic_grid!(
Expand All @@ -466,6 +470,8 @@ function solve_elliptic_grid!(
atol=1e-10,
iteration_limit=10,
converged=[false],
residual_value=[0.0],
iterations=[0],
verbose=false,
)

Expand All @@ -486,7 +492,7 @@ function solve_elliptic_grid!(
# - set up solve - #
itshape = (gridshape[2] - 1, gridshape[3] - 2)
constants = (;
x_caching, itshape, algorithm, autodiff, atol, iteration_limit, converged, verbose
x_caching, itshape, algorithm, autodiff, atol, iteration_limit, converged, residual_value, iterations, verbose
)

# non ImplicitAD version
Expand Down
2 changes: 2 additions & 0 deletions src/preprocess/geometry/wake_geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ function relax_grid!(
atol=grid_solver_options.atol,
iteration_limit=grid_solver_options.iteration_limit,
grid_solver_options.converged,
grid_solver_options.residual_value,
grid_solver_options.iterations,
verbose=verbose,
)

Expand Down
9 changes: 5 additions & 4 deletions src/utilities/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -644,20 +644,21 @@ end
Options for Newton elliptic grid solver.
# Fields
- `iteration_limit::Int = 10` : maximum number of iterations
- `atol::Float = 1e-14` : absolute convergence tolerance
- `iteration_limit::Int = 20` : maximum number of iterations
- `atol::Float = 3e-10` : absolute convergence tolerance
- `algorithm::Symbol = :newton` : algorithm to use in NLsolve.jl
- `autodiff::Symbol = :forward` : differentiation method to use in NLsolve.jl
- `converged::AbstractArray{Bool}` = [false]
- `iterations::AbstractArray{Int} = [0]` : iteration counter
"""
@kwdef struct GridSolverOptions{TB,TF,TI,TSym} <: GridSolverOptionsType
iteration_limit::TI = 10
atol::TF = 2e-10
iteration_limit::TI = 20
atol::TF = 3e-10
algorithm::TSym = :newton
autodiff::TSym = :forward
converged::AbstractArray{TB} = [false]
iterations::AbstractArray{TI} = [0]
residual_value::AbstractArray{TF} = [0.0]
end

#---------------------------------#
Expand Down

0 comments on commit ff797b1

Please sign in to comment.