diff --git a/Project.toml b/Project.toml index 3107a47..5332501 100644 --- a/Project.toml +++ b/Project.toml @@ -14,6 +14,7 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" +ProgressLogging = "33c8b6b6-d38a-422a-b730-caa89a2f386c" QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" diff --git a/src/continuations/continuations.jl b/src/continuations/continuations.jl index 06d9d2f..47e70d8 100644 --- a/src/continuations/continuations.jl +++ b/src/continuations/continuations.jl @@ -5,6 +5,7 @@ import DiffEqBase: solve, solve!, init, step! using ..ArrayUtils: _similar, _zeros, isalmostzero, zero_if_nan, _lq!, _det, _normalize!, bottomrow, popbottomright +using ..MiscUtils: @progress_if include("interface.jl") include("euler_newton.jl") diff --git a/src/continuations/solver.jl b/src/continuations/solver.jl index 9d5b0a5..c110cb6 100644 --- a/src/continuations/solver.jl +++ b/src/continuations/solver.jl @@ -40,11 +40,6 @@ solve(prob::AbstractContinuationProblem; kwargs...) = function step!(solver::ContinuationSolver) predictor_corrector_step!(solver.cache, solver.opts) - if solver.opts.verbose - print(stdout, '.') - flush(stdout) - end - # Errors are now thrown in predictor_corrector_step!. I need to # reconsider the error handling... if ! solver.cache.adaptation_success @@ -66,7 +61,7 @@ function step!(wrapper::AbstractContinuationSolver, max_steps) solver = as(wrapper, ContinuationSolver) cache = solver.cache cache.h = solver.opts.h0 - for _ in 1:max_steps + @progress_if solver.opts.verbose for _ in 1:max_steps step!(wrapper) if ! isindomain(cache.u, cache.prob_cache) return true diff --git a/src/utils/misc_utils.jl b/src/utils/misc_utils.jl new file mode 100644 index 0000000..8d4882b --- /dev/null +++ b/src/utils/misc_utils.jl @@ -0,0 +1,24 @@ +module MiscUtils + +import ProgressLogging + +""" + @progress_if cond [options...] expr + +If `cond` evaluates to `true`, run `@progress(options..., expr)`; otherwise +just run `expr`. + +`options` and `expr` are passed to +[`ProgressLogging.@progress`](https://junolab.org/ProgressLogging.jl/dev/#ProgressLogging.@progress-Tuple) +""" +macro progress_if(cond, args...) + quote + if $cond + $ProgressLogging.@progress($(args...)) + else + $(args[end]) + end + end |> esc +end + +end # module diff --git a/src/utils/utils.jl b/src/utils/utils.jl index 256befa..78c56f0 100644 --- a/src/utils/utils.jl +++ b/src/utils/utils.jl @@ -1,3 +1,4 @@ include("array_utils.jl") include("fdiff_utils.jl") include("poly_utils.jl") +include("misc_utils.jl")