diff --git a/Project.toml b/Project.toml index f57b78b..2f1a691 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "QuestBase" uuid = "7e80f742-43d6-403d-a9ea-981410111d43" authors = ["Orjan Ameye ", "Jan Kosata ", "Javier del Pino "] -version = "0.3.3" +version = "0.3.4" [deps] DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" diff --git a/src/HarmonicEquation.jl b/src/HarmonicEquation.jl index cb8348a..4889146 100644 --- a/src/HarmonicEquation.jl +++ b/src/HarmonicEquation.jl @@ -137,6 +137,12 @@ function _remove_brackets(eom::HarmonicEquation) return substitute_all(equations_lhs, variable_rules) end +function _remove_brackets(eqs::Vector{Num}, vars::Vector{Num}) + vars_ = _remove_brackets.(vars) + variable_rules = Dict(zip(vars, vars_)) + return substitute_all(eqs, variable_rules), vars_ +end + """ $(TYPEDSIGNATURES) Rearrange `eom` to the standard form, such that the derivatives of the variables are on one side. diff --git a/src/HarmonicVariable.jl b/src/HarmonicVariable.jl index 70c4732..0023311 100644 --- a/src/HarmonicVariable.jl +++ b/src/HarmonicVariable.jl @@ -19,19 +19,30 @@ mutable struct HarmonicVariable natural_variable::Num end +function HarmonicVariable(symbol::Num) + return HarmonicVariable(symbol, "", "", Num(1), Num(0)) +end + function Base.show(io::IO, hv::HarmonicVariable) - return println( - io, - "Harmonic variable ", - string.(hv.symbol) * " for harmonic ", - string(hv.ω), - " of ", - string(hv.natural_variable), - ) + if isempty(hv.type) + s = "Harmonic variable " * string.(hv.symbol) + else + s = + "Harmonic variable " * + string.(hv.symbol) * + " for harmonic " * + string(hv.ω) * + " of " * + string(hv.natural_variable) + end + return println(io, s) end """Gives the relation between `var` and the underlying natural variable.""" function _show_ansatz(var::HarmonicVariable) + if isempty(var.type) + return string(var.symbol) + end t = var.natural_variable.val.arguments t = length(t) == 1 ? string(t[1]) : error("more than 1 independent variable") ω = string(var.ω) diff --git a/test/HarmonicVariable.jl b/test/HarmonicVariable.jl index 9e5d5ea..066e536 100644 --- a/test/HarmonicVariable.jl +++ b/test/HarmonicVariable.jl @@ -37,6 +37,12 @@ end # Test _show_ansatz @test contains(_show_ansatz(hv), "cos(ωt)") + + @variables x + hv = HarmonicVariable(x) + @test repr(hv) == "Harmonic variable x\n" + + @test _show_ansatz(hv) == "x" end @testset "Coordinate Transforms" begin