Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more kwargs (opt_alg and verbose) to FSBP operators #279

Merged
merged 2 commits into from
Jul 18, 2024
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
@@ -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
Loading