Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ DifferentiationInterface = "0.7"
Distributions = "0.25.87"
ExplicitImports = "1.14.0"
FastGaussQuadrature = "0.5,1"
FastTanhSinhQuadrature = "1, 2.1"
FastTanhSinhQuadrature = "2.1"
FiniteDiff = "2.12"
ForwardDiff = "0.10.36, 1"
HAdaptiveIntegration = "0.2, 1.0"
Expand Down
14 changes: 6 additions & 8 deletions ext/IntegralsFastTanhSinhQuadratureExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ function Integrals.__solvebp_call(
@assert f isa IntegralFunction "FastTanhSinhQuadratureJL does not support BatchIntegralFunction"
@assert !isinplace(prob) "FastTanhSinhQuadratureJL does not support in-place integrands"

# Determine the effective tolerance
tol = alg.tol
if reltol !== nothing
tol = reltol
end
# Determine the effective tolerances
_rtol = reltol !== nothing ? reltol : alg.rtol
_atol = abstol !== nothing ? abstol : alg.atol
max_levels = alg.max_levels

# Determine dimensionality
Expand All @@ -32,19 +30,19 @@ function Integrals.__solvebp_call(
_lb = lb isa Number ? lb : only(lb)
_ub = ub isa Number ? ub : only(ub)
_f = x -> f.f(x, p)
val = quad(_f, _lb, _ub; tol = tol, max_levels = max_levels)
val = quad(_f, _lb, _ub; rtol = _rtol, atol = _atol, max_levels = max_levels)
elseif dim == 2
# 2D integration - use Vectors which quad() converts to SVector internally
_lb = collect(lb)
_ub = collect(ub)
_f = (x, y) -> f.f([x, y], p)
val = quad(_f, _lb, _ub; tol = tol, max_levels = max_levels)
val = quad(_f, _lb, _ub; rtol = _rtol, atol = _atol, max_levels = max_levels)
elseif dim == 3
# 3D integration - use Vectors which quad() converts to SVector internally
_lb = collect(lb)
_ub = collect(ub)
_f = (x, y, z) -> f.f([x, y, z], p)
val = quad(_f, _lb, _ub; tol = tol, max_levels = max_levels)
val = quad(_f, _lb, _ub; rtol = _rtol, atol = _atol, max_levels = max_levels)
else
error("FastTanhSinhQuadratureJL only supports 1D, 2D, and 3D integration. Got dimension = $dim")
end
Expand Down
14 changes: 8 additions & 6 deletions src/algorithms_extension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,16 @@ function HAdaptiveIntegrationJL(; kws...)
end

"""
FastTanhSinhQuadratureJL(; tol = 1e-12, max_levels = 10)
FastTanhSinhQuadratureJL(; rtol = 1e-12, atol = 0.0, max_levels = 10)

One-dimensional adaptive Tanh-Sinh (double exponential) quadrature from FastTanhSinhQuadrature.jl.
This method uses a double exponential transformation that provides excellent convergence properties,
especially for integrands with endpoint singularities or infinite derivatives at endpoints.

## Keyword Arguments

- `tol`: Relative tolerance for convergence (default: `1e-12`)
- `rtol`: Relative tolerance for convergence (default: `1e-12`)
- `atol`: Absolute tolerance for convergence (default: `0.0`)
- `max_levels`: Maximum number of refinement levels in adaptive integration (default: `10`)

## Limitations
Expand All @@ -360,12 +361,13 @@ publisher={Research Institute for Mathematical Sciences}
}
```
"""
struct FastTanhSinhQuadratureJL{T} <: AbstractIntegralExtensionAlgorithm
tol::T
struct FastTanhSinhQuadratureJL{T, S} <: AbstractIntegralExtensionAlgorithm
rtol::T
atol::S
max_levels::Int
end
function FastTanhSinhQuadratureJL(; tol = 1.0e-12, max_levels = 10)
function FastTanhSinhQuadratureJL(; rtol = 1.0e-12, atol = 0.0, max_levels = 10)
isnothing(Base.get_extension(@__MODULE__, :IntegralsFastTanhSinhQuadratureExt)) &&
error("FastTanhSinhQuadratureJL requires `using FastTanhSinhQuadrature`")
return FastTanhSinhQuadratureJL(tol, max_levels)
return FastTanhSinhQuadratureJL(rtol, atol, max_levels)
end
Loading