Skip to content

Commit

Permalink
fix evaluate for B-series of numerical integrators (#214)
Browse files Browse the repository at this point in the history
* fix bug from issue 213

* add test
  • Loading branch information
ranocha authored Jun 12, 2024
1 parent 7195ea3 commit 9cae0eb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BSeries"
uuid = "ebb8d67c-85b4-416c-b05f-5f409e808f32"
authors = ["Hendrik Ranocha <[email protected]> and contributors"]
version = "0.1.60"
version = "0.1.61"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down
11 changes: 10 additions & 1 deletion src/BSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,16 @@ function elementary_differentials(f::AbstractVector, u, order)
differentials = OrderedDict{RootedTree{Int, Vector{Int}}, typeof(f)}()

t = rootedtree(Int[])
differentials[t] = one.(f)
if typeof(u) == typeof(f)
differentials[t] = u
else
# `u` may be a tuple of symbolic variables
# Since we determine the type of the values of `differentials` based on
# the type of `f`, we need to create a vector of the same type as `f`.
val = zero(f)
val .= u
differentials[t] = val
end

t = rootedtree([1])
differentials[t] = f
Expand Down
14 changes: 13 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,19 @@ using Aqua: Aqua
end
end # @testset "modified_equation"

@testset "elementary differentials" begin
@testset "elementary differentials and evaluate" begin
@testset "Rooted trees" begin
@testset "Issue #213" begin
y, h = SymPyPythonCall.symbols("y, h")
u = [y]
f = [-y]
series = @inferred bseries(AverageVectorFieldMethod(), 3)
expansion = first(evaluate(f, u, h, series))
reference = y - h * y + h^2 * y / 2 - h^3 * y / 4
@test expansion == reference
end
end

@testset "Bicolored trees" begin
@testset "Lotka-Volterra" begin
# Verified with Mathematica
Expand Down

2 comments on commit 9cae0eb

@ranocha
Copy link
Owner Author

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/108787

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.1.61 -m "<description of version>" 9cae0eb7258371896020fb8978c6068413126e4d
git push origin v0.1.61

Please sign in to comment.