Skip to content

Commit 90ccdde

Browse files
authored
Merge branch 'main' into source
2 parents 358c30d + d656a7a commit 90ccdde

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

src/HarmonicEquation.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ function _remove_brackets(eom::HarmonicEquation)
144144
return substitute_all(equations_lhs, variable_rules)
145145
end
146146

147+
function _remove_brackets(eqs::Vector{Num}, vars::Vector{Num})
148+
vars_ = _remove_brackets.(vars)
149+
variable_rules = Dict(zip(vars, vars_))
150+
return substitute_all(eqs, variable_rules), vars_
151+
end
152+
147153
"""
148154
$(TYPEDSIGNATURES)
149155
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)