Skip to content

Commit 75528ae

Browse files
authored
Parsing of time-dependent data, plot overload (#31)
* transform_solutions for time-dependent results * plot overloaded for Result and ODESolution * examples and docs changes * Jacobian bugfix
1 parent 47174b8 commit 75528ae

File tree

13 files changed

+129
-64
lines changed

13 files changed

+129
-64
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "HarmonicBalance"
22
uuid = "e13b9ff6-59c3-11ec-14b1-f3d2cc6c135e"
33
authors = ["Jan Kosata <[email protected]>", "Javier del Pino <[email protected]>"]
4-
version = "0.5.1"
4+
version = "0.5.2"
55

66
[deps]
77
BijectiveHilbert = "91e7fc40-53cd-4118-bd19-d7fcd1de2a54"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Classes: stable, physical, Hopf, binary_labels
4848
```
4949

5050
```julia
51-
plot_1D_solutions(solutions, x="ω", y="sqrt(u1^2 + v1^2)");
51+
plot(solutions, x="ω", y="sqrt(u1^2 + v1^2)");
5252
```
5353

5454
<img src="/docs/images/DuffingPlot.png" width="500">

docs/src/examples/linear_response.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fixed = (α => 1, ω0 => 1.0, γ => 1E-2, F => 1E-6) # fixed parameters
2929
swept = ω => LinRange(0.9, 1.1, 100) # range of parameter values
3030
solutions = get_steady_states(harmonic_eq, swept, fixed)
3131

32-
plot_1D_solutions(solutions, x="ω", y="sqrt(u1^2 + v1^2)")
32+
plot(solutions, x="ω", y="sqrt(u1^2 + v1^2)")
3333
```
3434

3535
```@raw html
@@ -54,7 +54,7 @@ fixed = (α => 1, ω0 => 1.0, γ => 1E-2, F => 1E-2) # fixed parameters
5454
swept = ω => LinRange(0.9, 1.1, 100) # range of parameter values
5555
solutions = get_steady_states(harmonic_eq, swept, fixed)
5656
57-
plot_1D_solutions(solutions, x="ω", y="sqrt(u1^2 + v1^2)");
57+
plot(solutions, x="ω", y="sqrt(u1^2 + v1^2)");
5858
```
5959
```@raw html
6060
<img style="display: block; margin: 0 auto;" src="../../assets/linear_response/Duffing_nonlin_amp.png" width="450" alignment="left" \>
@@ -81,7 +81,7 @@ fixed = (α => 1., ω0 => 1.0, γ => 1E-2, ω => 1) # fixed parameters
8181
swept = F => 10 .^ LinRange(-6, -1, 200) # range of parameter values
8282
solutions = get_steady_states(harmonic_eq, swept, fixed)
8383
84-
plot_1D_solutions(solutions, x="F", y="sqrt(u1^2 + v1^2)");
84+
plot(solutions, x="F", y="sqrt(u1^2 + v1^2)");
8585
HarmonicBalance.xscale("log") # use log scale on x
8686
8787
LinearResponse.plot_jacobian_spectrum(solutions, x,

docs/src/examples/single_Duffing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ The "Classes" are boolean labels classifying each solution point, which may be u
104104

105105
We now want to visualize the results. Here we plot the solution amplitude, ``\sqrt{U^2 + V^2}`` against the drive frequency ``\omega``:
106106
```julia
107-
plot_1D_solutions(solutions, x="ω", y="sqrt(u1^2 + v1^2)")
107+
plot(solutions, x="ω", y="sqrt(u1^2 + v1^2)")
108108
```
109109
```@raw html
110110
<img style="display: block; margin: 0 auto;" src="../../assets/duffing_single.png" width="450" alignment="center" \>
@@ -170,8 +170,8 @@ Classes: stable, physical, Hopf, binary_labels
170170

171171
Although 9 branches were found in total, only 3 remain physical (real-valued). Let us visualise the amplitudes corresponding to the two harmonics, ``\sqrt{U_1^2 + V_1^2}`` and ``\sqrt{U_2^2 + V_2^2}`` :
172172
```julia
173-
plot_1D_solutions(solutions, x="ω", y="sqrt(u1^2 + v1^2)")
174-
plot_1D_solutions(solutions, x="ω", y="sqrt(u2^2 + v2^2)")
173+
plot(solutions, x="ω", y="sqrt(u1^2 + v1^2)")
174+
plot(solutions, x="ω", y="sqrt(u2^2 + v2^2)")
175175
```
176176
![fig3](./../assets/duff_nonpert_w_3w.png)
177177

docs/src/examples/single_parametron_1D.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ HarmonicBalance.save("parametron_result.jld2", soln);
5555

5656
During the execution of `get_steady_states`, different solution branches are classified by their proximity in complex space, with subsequent filtering of real (physically accceptable solutions). In addition, the stability properties of each steady state is assesed from the eigenvalues of the Jacobian matrix. All this information can be succintly represented in a 1D plot via
5757
```julia
58-
save_dict = HarmonicBalance.plot_1D_solutions(soln, x="ω", y="sqrt(u1^2 + v1^2)", plot_only=["physical"]);
58+
save_dict = HarmonicBalance.plot(soln, x="ω", y="sqrt(u1^2 + v1^2)", plot_only=["physical"]);
5959
```
60-
where `save_dict` is a dictionary that contains the plotted data and can be also exported if desired by setting a filename through the argument `filename` in `plot_1D_solutions`. A call to the above function produces the following figure
60+
where `save_dict` is a dictionary that contains the plotted data and can be also exported if desired by setting a filename through the argument `filename` in `plot`. A call to the above function produces the following figure
6161

6262
![fig1](./../assets/single_parametron_1D.png)
6363

6464
The user can also can also introduce custom clases based on parameter conditions. Here we show some arbitrary example
6565
```julia
66-
plt = HarmonicBalance.plot_1D_solutions(soln, x="ω", y="sqrt(u1^2 + v1^2)", marker_classification="ω^15 * sqrt(u1^2 + v1^2) < 0.1")
66+
plt = HarmonicBalance.plot(soln, x="ω", y="sqrt(u1^2 + v1^2)", marker_classification="ω^15 * sqrt(u1^2 + v1^2) < 0.1")
6767
```
6868
producing
6969

docs/src/examples/single_parametron_time_dep.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fixed_parameters = ParameterList(Ω => 1.0,γ => 1E-2, λ => 5E-2, F => 1E-3,
3030
Finally, we solve the harmonic equations and represent the solutions by
3131

3232
```julia
33-
time_dep = HarmonicBalance.TimeEvolution.ODEProblem(averagedEOM, fixed_parameters, sweep=HarmonicBalance.TimeEvolution.ParameterSweep(), x0 = x0, timespan = times);
33+
time_dep = HarmonicBalance.TimeEvolution.(averagedEOM, fixed_parameters, sweep=HarmonicBalance.TimeEvolution.ParameterSweep(), x0 = x0, timespan = times);
3434
time_soln = HarmonicBalance.TimeEvolution.solve(time_dep, saveat=dt);
3535
HarmonicBalance.plot(getindex.(time_soln.u, 1), getindex.(time_soln.u,2))
3636
HarmonicBalance.xlabel("u",fontsize=20)

docs/src/examples/time_dependent.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ DifferentialEquations.jl takes it from here - we only need to use `solve`.
6767

6868
```julia
6969
time_evo = solve(ode_problem, saveat=1.);
70-
plot(getindex.(time_evo.u, 1), getindex.(time_evo.u,2))
70+
plot(time_evo, ["u1", "v1"], harmonic_eqs)
7171
```
7272

7373
Running the above code with `x0 = [0., 0.]` and `x0 = [0.2, 0.2]` gives the plots
@@ -79,7 +79,7 @@ Let us compare this to the steady state diagram.
7979
```julia
8080
range = ω => LinRange(0.9, 1.1, 100) # range of parameter values
8181
solutions = get_steady_states(harmonic_eqs, range, fixed)
82-
plot_1D_solutions(solutions, x="ω", y="sqrt(u1^2 + v1^2)*sign(u1)");
82+
plot(solutions, x="ω", y="sqrt(u1^2 + v1^2)*sign(u1)");
8383
```
8484
```@raw html
8585
<img style="display: block; margin: 0 auto;" src="../../assets/time_dependent/parametron_response.png" width="600" alignment="center" \>
@@ -101,7 +101,7 @@ Let us now define a new `ODEProblem` which incorporates `sweep` and again use `s
101101
```julia
102102
ode_problem = ODEProblem(harmonic_eqs, fixed, sweep=sweep, x0=[0.1;0.0], timespan=(0, 2E4))
103103
time_evo = solve(prob, saveat=100)
104-
plot(time_evo.t, sqrt.(getindex.(time_evo.u,1).^2 .+ getindex.(time_evo,2).^2))
104+
plot(time_evo, "sqrt(u1^2 + v1^2)", harmonic_eqs)
105105
```
106106
```@raw html
107107
<img style="display: block; margin: 0 auto;" src="../../assets/time_dependent/sweep_omega.png" width="450" alignment="center" \>
@@ -190,7 +190,7 @@ Solution branches: 9
190190

191191
Let us first see the steady states.
192192
```julia
193-
plt = plot_1D_solutions(soln, x="F0", y="u1^2 + v1^2", yscale=:log);
193+
plt = plot(soln, x="F0", y="u1^2 + v1^2", yscale=:log);
194194
```
195195
```@raw html
196196
<img style="display: block; margin: 0 auto; padding-bottom: 20px" src="../../assets/time_dependent/pra_ss.png" width="1000" alignment="center"\>
@@ -212,7 +212,7 @@ TDsoln = solve(TDproblem, saveat=1); # space datapoints by 1
212212
```
213213
Inspecting for example $u_1(T)$ as a function of time,
214214
```julia
215-
plot(TDsoln.t, getindex.(TDsoln.u, 1))
215+
plot(time_evo, "u1", harmonic_eqs)
216216
```
217217
```@raw html
218218
<img style="display: block; margin: 0 auto; padding-bottom: 20px" src="../../assets/time_dependent/lc_sweep.png" width="450" alignment="center" \>

docs/src/manual/plotting.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ HarmonicBalance.transform_solutions
1111
Any function of the steady state solutions may be plotted.
1212
In 1D, the solutions are colour-coded according to the branches obtained by `sort_solutions`.
1313

14+
Note: from v0.5.2, `plot(r::Result, x::String, y::String)` can be used to call `plot_1D_solutions` and `plot_2D_solutions` as needed.
15+
To plot a function `y` of a time-dependent result `r`, the syntax is `plot(r::OrdinaryDiffEq.ODECompositeSolution, y, he::HarmonicEquation)`. For `y::String`, `y` is parsed into a function and plotted as a function of time.
16+
1417
```@docs
1518
HarmonicBalance.plot_1D_solutions
1619
HarmonicBalance.plot_1D_jacobian_eigenvalues
1720
HarmonicBalance.plot_2D_solutions
1821
```
1922

23+
24+
2025
## Plotting phase diagrams (2D)
2126

2227
In many problems, rather than in any property of the solutions themselves, we are interested in the phase diagrams, encoding the number of (stable) solutions in different regions of the parameter space. We provide functions to tackle solutions calculated over 2D parameter grids.

src/HarmonicBalance.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module HarmonicBalance
4444
include("sorting.jl")
4545
include("classification.jl")
4646
include("saving.jl")
47+
include("transform_solutions.jl")
4748
include("plotting_static.jl")
4849
include("plotting_interactive.jl")
4950
include("hysteresis_sweep.jl")

src/modules/HC_wrapper/homotopy_interface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function Problem(eom::HarmonicEquation; Jacobian=true)
4747
elseif Jacobian == "implicit"
4848
# compute the Jacobian implicitly
4949
J = HarmonicBalance.LinearResponse.get_implicit_Jacobian(eom)
50-
elseif Jacobian == "false"
50+
elseif Jacobian == "false" || Jacobian == false
5151
dummy_J(arg) = I(1)
5252
J = dummy_J
5353
else

0 commit comments

Comments
 (0)