Skip to content

Commit

Permalink
add error and test for #255 (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
oameye authored Oct 6, 2024
1 parent c1550d4 commit afa425c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,28 @@ mutable struct DifferentialEquation
return DifferentialEquation(exprs .~ Int(0), vars)
end

function DifferentialEquation(arg1, arg2)
return DifferentialEquation(
arg1 isa Vector ? arg1 : [arg1], arg2 isa Vector ? arg2 : [arg2]
function DifferentialEquation(eq::Equation, var::Num)
typerhs = typeof(eq.rhs)
typelhs = typeof(eq.lhs)
if eq.rhs isa AbstractVector || eq.lhs isa AbstractVector
throw(
ArgumentError(
"The equation is of the form $(typerhs)~$(typelhs) is not supported. Commenly one forgot to broadcast the equation symbol `~`.",
),
)
end
return DifferentialEquation([eq], [var])
end
function DifferentialEquation(eq::Equation, vars::Vector{Num})
typerhs = typeof(eq.rhs)
typelhs = typeof(eq.lhs)
throw(
ArgumentError(
"The variables are of type $(typeof(vars)). Whereas you gave one equation of type $(typerhs)~$(typelhs). Commenly one forgot to broadcast the equation symbol `~`.",
),
)
end
DifferentialEquation(lhs::Num, var::Num) = DifferentialEquation([lhs ~ Int(0)], [var])
end

function Base.show(io::IO, diff_eq::DifferentialEquation)
Expand Down
11 changes: 11 additions & 0 deletions test/API.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using HarmonicBalance

# define equation of motion
@variables ω1, ω2, t, ω, F, γ, α1, α2, k, x(t), y(t);
rhs = [
d(x, t, 2) + ω1^2 * x + γ * d(x, t) + α1 * x^3 - k * y,
d(d(y, t), t) + ω2^2 * y + γ * d(y, t) + α2 * y^3 - k * x,
]
eqs = rhs .~ [F * cos* t), 0]

@test_throws ArgumentError DifferentialEquation(rhs ~ [F * cos* t), 0], [x, y])
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ end
JET.test_package(HarmonicBalance; target_defined_modules=true)
end

@testset "Symbolics customised" begin
include("API.jl")
end

@testset "Symbolics customised" begin
include("powers.jl")
include("harmonics.jl")
Expand Down

2 comments on commit afa425c

@oameye
Copy link
Member Author

@oameye oameye commented on afa425c Oct 6, 2024

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

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.10.8 -m "<description of version>" afa425ceb096439a4ff601e5145532d557edf0e3
git push origin v0.10.8

Please sign in to comment.