Skip to content

Commit

Permalink
Add more kwargs (opt_alg and verbose) to FSBP operators (#279)
Browse files Browse the repository at this point in the history
* add more kwargs (opt_alg and verbose) to FSBP operators

* bump version

---------

Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com>
  • Loading branch information
JoshuaLampert and ranocha committed Jul 18, 2024
1 parent 8080cf4 commit 87bfd2c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SummationByPartsOperators"
uuid = "9f78cca6-572e-554e-b819-917d2f1cf240"
author = ["Hendrik Ranocha"]
version = "0.5.63"
version = "0.5.64"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
11 changes: 7 additions & 4 deletions ext/SummationByPartsOperatorsOptimForwardDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ using SparseArrays: spzeros
function SummationByPartsOperators.function_space_operator(basis_functions, nodes::Vector{T},
source::SourceOfCoefficients;
derivative_order = 1, accuracy_order = 0,
options = Options(g_tol = 1e-14, iterations = 10000)) where {T, SourceOfCoefficients}
opt_alg = LBFGS(), options = Options(g_tol = 1e-14, iterations = 10000),
verbose = false) where {T, SourceOfCoefficients}

if derivative_order != 1
throw(ArgumentError("Derivative order $derivative_order not implemented."))
end
sort!(nodes)
weights, D = construct_function_space_operator(basis_functions, nodes, source; options = options)
weights, D = construct_function_space_operator(basis_functions, nodes, source; opt_alg = opt_alg, options = options, verbose = verbose)
return MatrixDerivativeOperator(first(nodes), last(nodes), nodes, weights, D, accuracy_order, source)
end

Expand Down Expand Up @@ -98,7 +99,8 @@ end

function construct_function_space_operator(basis_functions, nodes,
::GlaubitzNordströmÖffner2023;
options = Options(g_tol = 1e-14, iterations = 10000))
opt_alg = LBFGS(), options = Options(g_tol = 1e-14, iterations = 10000),
verbose = false)
K = length(basis_functions)
N = length(nodes)
L = div(N * (N - 1), 2)
Expand Down Expand Up @@ -127,7 +129,8 @@ function construct_function_space_operator(basis_functions, nodes,

x0 = zeros(L + N)
fg!(F, G, x) = optimization_function_and_grad!(F, G, x, p)
result = optimize(Optim.only_fg!(fg!), x0, LBFGS(), options)
result = optimize(Optim.only_fg!(fg!), x0, opt_alg, options)
verbose && display(result)

x = minimizer(result)
sigma = x[1:L]
Expand Down
8 changes: 5 additions & 3 deletions src/function_space_operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ end
"""
function_space_operator(basis_functions, nodes, source;
derivative_order = 1, accuracy_order = 0,
options = Optim.Options(g_tol = 1e-14, iterations = 10000))
opt_alg = Optim.LBFGS(), options = Optim.Options(g_tol = 1e-14, iterations = 10000),
verbose = false)
Construct an operator that represents a first-derivative operator in a function space spanned by
the `basis_functions`, which is an iterable of functions. The operator is constructed on the
interval `[x_min, x_max]` with the nodes `nodes`, where `x_min` is taken as the minimal value in
`nodes` and `x_max` the maximal value. Note that the `nodes` will be sorted internally. The
`accuracy_order` is the order of the accuracy of the operator, which can optionally be passed,
but does not have any effect on the operator. The operator is constructed solving an optimization
problem with Optim.jl. You can specify the options for the optimization problem with the `options`
argument, see also the [documentation of Optim.jl](https://julianlsolvers.github.io/Optim.jl/stable/user/config/).
problem with Optim.jl. You can specify the optimization algorithm and options for the optimization problem
with the keyword arguments `opt_alg` and `options` respectively, see also the
[documentation of Optim.jl](https://julianlsolvers.github.io/Optim.jl/stable/user/config/)
The operator that is returned follows the general interface. Currently, it is wrapped in a
[`MatrixDerivativeOperator`](@ref), but this might change in the future.
Expand Down

2 comments on commit 87bfd2c

@ranocha
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/111315

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.64 -m "<description of version>" 87bfd2c5613f45b02c77639a2d54802a67af8415
git push origin v0.5.64

Please sign in to comment.