Skip to content

Commit d656a7a

Browse files
authored
feat: empty HarmonicVariable(symbol::Num) (#37)
1 parent cda13b1 commit d656a7a

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "QuestBase"
22
uuid = "7e80f742-43d6-403d-a9ea-981410111d43"
33
authors = ["Orjan Ameye <orjan.ameye@hotmail.com>", "Jan Kosata <kosataj@phys.ethz.ch>", "Javier del Pino <jdelpino@phys.ethz.ch>"]
4-
version = "0.3.3"
4+
version = "0.3.4"
55

66
[deps]
77
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"

src/HarmonicEquation.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ function _remove_brackets(eom::HarmonicEquation)
137137
return substitute_all(equations_lhs, variable_rules)
138138
end
139139

140+
function _remove_brackets(eqs::Vector{Num}, vars::Vector{Num})
141+
vars_ = _remove_brackets.(vars)
142+
variable_rules = Dict(zip(vars, vars_))
143+
return substitute_all(eqs, variable_rules), vars_
144+
end
145+
140146
"""
141147
$(TYPEDSIGNATURES)
142148
Rearrange `eom` to the standard form, such that the derivatives of the variables are on one side.

src/HarmonicVariable.jl

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,30 @@ mutable struct HarmonicVariable
1919
natural_variable::Num
2020
end
2121

22+
function HarmonicVariable(symbol::Num)
23+
return HarmonicVariable(symbol, "", "", Num(1), Num(0))
24+
end
25+
2226
function Base.show(io::IO, hv::HarmonicVariable)
23-
return println(
24-
io,
25-
"Harmonic variable ",
26-
string.(hv.symbol) * " for harmonic ",
27-
string(hv.ω),
28-
" of ",
29-
string(hv.natural_variable),
30-
)
27+
if isempty(hv.type)
28+
s = "Harmonic variable " * string.(hv.symbol)
29+
else
30+
s =
31+
"Harmonic variable " *
32+
string.(hv.symbol) *
33+
" for harmonic " *
34+
string(hv.ω) *
35+
" of " *
36+
string(hv.natural_variable)
37+
end
38+
return println(io, s)
3139
end
3240

3341
"""Gives the relation between `var` and the underlying natural variable."""
3442
function _show_ansatz(var::HarmonicVariable)
43+
if isempty(var.type)
44+
return string(var.symbol)
45+
end
3546
t = var.natural_variable.val.arguments
3647
t = length(t) == 1 ? string(t[1]) : error("more than 1 independent variable")
3748
ω = string(var.ω)

test/HarmonicVariable.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ end
3737

3838
# Test _show_ansatz
3939
@test contains(_show_ansatz(hv), "cos(ωt)")
40+
41+
@variables x
42+
hv = HarmonicVariable(x)
43+
@test repr(hv) == "Harmonic variable x\n"
44+
45+
@test _show_ansatz(hv) == "x"
4046
end
4147

4248
@testset "Coordinate Transforms" begin

0 commit comments

Comments
 (0)