Skip to content

Commit 9a61001

Browse files
authored
feat: Method structs (#298)
1 parent 9d1efd8 commit 9a61001

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+854
-516
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
99
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
1010
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
1111
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
12+
EndpointRanges = "340492b5-2a47-5f55-813d-aca7ddf97656"
1213
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
1314
HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327"
1415
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
@@ -42,6 +43,7 @@ DelimitedFiles = "1.9"
4243
Distances = "0.10.11"
4344
DocStringExtensions = "0.9.3"
4445
Documenter = "1.4"
46+
EndpointRanges = "0.2.2"
4547
ExplicitImports = "1.6"
4648
FFTW = "1.8"
4749
HomotopyContinuation = "2.9"
@@ -51,8 +53,8 @@ Latexify = "0.16"
5153
ModelingToolkit = "9.34"
5254
NonlinearSolve = "3.14"
5355
OrderedCollections = "1.6"
54-
OrdinaryDiffEqTsit5 = "1.1"
5556
OrdinaryDiffEqRosenbrock = "1.1"
57+
OrdinaryDiffEqTsit5 = "1.1"
5658
Peaks = "0.5"
5759
Plots = "1.39"
5860
PrecompileTools = "1.2"
@@ -69,8 +71,8 @@ ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
6971
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
7072
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
7173
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
72-
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
7374
OrdinaryDiffEqRosenbrock = "43230ef6-c299-4910-a778-202eb28ce4ce"
75+
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
7476
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
7577
SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f"
7678
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

benchmark/parametron.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using HarmonicBalance
2+
using BenchmarkTools
23

34
using Random
45
const SEED = 0xd8e5d8df
@@ -18,8 +19,13 @@ dEOM = DifferentialEquation(natural_equation + forces, x)
1819
add_harmonic!(dEOM, x, ω)
1920

2021
@time harmonic_eq = get_harmonic_equations(dEOM; slow_time=T, fast_time=t);
21-
@time prob = HarmonicBalance.Problem(harmonic_eq)
2222

2323
fixed ==> 1.0, γ => 1e-2, λ => 5e-2, F => 0, α => 1.0, η => 0.3, θ => 0, ψ => 0)
24-
varied = ω => range(0.9, 1.1, 20)
25-
@time res = get_steady_states(prob, varied, fixed; show_progress=false)
24+
varied = ω => range(0.9, 1.1, 100)
25+
26+
@btime res = get_steady_states(harmonic_eq, WarmUp(), varied, fixed; show_progress=false)
27+
@btime res = get_steady_states(harmonic_eq, WarmUp(;compile=true), varied, fixed; show_progress=false)
28+
@btime res = get_steady_states(harmonic_eq, Polyhedral(;only_non_zero=true), varied, fixed; show_progress=false)
29+
@btime res = get_steady_states(harmonic_eq, Polyhedral(;only_non_zero=false), varied, fixed; show_progress=false)
30+
@btime res = get_steady_states(harmonic_eq, TotalDegree(;compile=true), varied, fixed; show_progress=false)
31+
@btime res = get_steady_states(harmonic_eq, TotalDegree(), varied, fixed; show_progress=false)

docs/src/.vitepress/config.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default defineConfig({
6464
text: 'Manual', items: [
6565
{ text: 'Entering equations of motion', link: '/manual/entering_eom.md' },
6666
{ text: 'Computing effective system', link: '/manual/extracting_harmonics' },
67+
{ text: 'Computing steady states', link: '/manual/methods' },
6768
{ text: 'Krylov-Bogoliubov', link: '/manual/Krylov-Bogoliubov_method' },
6869
{ text: 'Time evolution', link: '/manual/time_dependent' },
6970
{ text: 'Linear response', link: '/manual/linear_response' },
@@ -100,6 +101,7 @@ export default defineConfig({
100101
"/manual/": [
101102
{ text: 'Entering equations of motion', link: '/manual/entering_eom.md' },
102103
{ text: 'Computing effective system', link: '/manual/extracting_harmonics' },
104+
{ text: 'Computing steady states', link: '/manual/methods' },
103105
{ text: 'Krylov-Bogoliubov', link: '/manual/Krylov-Bogoliubov_method' },
104106
{ text: 'Time evolution', link: '/manual/time_dependent' },
105107
{ text: 'Linear response', link: '/manual/linear_response' },

docs/src/examples/parametric_via_three_wave_mixing.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
```@meta
2-
EditURL = "parametric_via_three_wave_mixing.jl"
2+
EditURL = "../../../examples/parametric_via_three_wave_mixing.jl"
33
```
44

55
# Parametric Pumping via Three-Wave Mixing
@@ -33,7 +33,7 @@ If we both have quadratic and cubic nonlineariy, we observe the normal duffing o
3333
varied = (ω => range(0.99, 1.1, 200)) # range of parameter values
3434
fixed = (α => 1.0, β => 1.0, ω0 => 1.0, γ => 0.005, F => 0.0025) # fixed parameters
3535
36-
result = get_steady_states(harmonic_eq, varied, fixed; threading=true)
36+
result = get_steady_states(harmonic_eq, varied, fixed)
3737
plot(result; y="u1^2+v1^2")
3838
````
3939

@@ -43,7 +43,7 @@ If we set the cubic nonlinearity to zero, we recover the driven damped harmonic
4343
varied = (ω => range(0.99, 1.1, 100))
4444
fixed = (α => 0.0, β => 1.0, ω0 => 1.0, γ => 0.005, F => 0.0025)
4545
46-
result = get_steady_states(harmonic_eq, varied, fixed; threading=true)
46+
result = get_steady_states(harmonic_eq, varied, fixed)
4747
plot(result; y="u1^2+v1^2")
4848
````
4949

@@ -65,17 +65,16 @@ harmonic_eq2 = get_krylov_equations(diff_eq; order=2)
6565
varied = (ω => range(0.4, 1.1, 500))
6666
fixed = (α => 1.0, β => 2.0, ω0 => 1.0, γ => 0.001, F => 0.005)
6767
68-
result = get_steady_states(harmonic_eq2, varied, fixed; threading=true)
68+
result = get_steady_states(harmonic_eq2, varied, fixed)
6969
plot(result; y="v1")
7070
````
7171

7272
````@example parametric_via_three_wave_mixing
7373
varied = (ω => range(0.4, 0.6, 100), F => range(1e-6, 0.01, 50))
7474
fixed = (α => 1.0, β => 2.0, ω0 => 1.0, γ => 0.01)
7575
76-
result = get_steady_states(
77-
harmonic_eq2, varied, fixed; threading=true, method=:total_degree
78-
)
76+
method = TotalDegree()
77+
result = get_steady_states(harmonic_eq2, method, varied, fixed)
7978
plot_phase_diagram(result; class="stable")
8079
````
8180

docs/src/examples/parametron.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
```@meta
2-
EditURL = "parametron.jl"
2+
EditURL = "../../../examples/parametron.jl"
33
```
44

55
# [Parametrically driven resonator](@id parametron)
@@ -64,7 +64,7 @@ varied = ω => range(0.9, 1.1, 100)
6464
result = get_steady_states(harmonic_eq, varied, fixed)
6565
````
6666

67-
In `get_steady_states`, the default value for the keyword `method=:random_warmup` initiates the homotopy in a generalised version of the harmonic equations, where parameters become random complex numbers. A parameter homotopy then follows to each of the frequency values $\omega$ in sweep. This offers speed-up, but requires to be tested in each scenario againts the method `:total_degree`, which initializes the homotopy in a total degree system (maximum number of roots), but needs to track significantly more homotopy paths and there is slower. The `threading` keyword enables parallel tracking of homotopy paths, and it's set to `false` simply because we are using a single core computer for now.
67+
In `get_steady_states`, the default method `WarmUp()` initiates the homotopy in a generalised version of the harmonic equations, where parameters become random complex numbers. A parameter homotopy then follows to each of the frequency values $\omega$ in sweep. This offers speed-up, but requires to be tested in each scenario againts the method `TotalDegree`, which initializes the homotopy in a total degree system (maximum number of roots), but needs to track significantly more homotopy paths and there is slower.
6868

6969
After solving the system, we can save the full output of the simulation and the model (e.g. symbolic expressions for the harmonic equations) into a file
7070

@@ -100,6 +100,7 @@ The parametrically driven oscillator boasts a stability diagram called "Arnold's
100100
To perform a 2D sweep over driving frequency $\omega$ and parametric drive strength $\lambda$, we keep `fixed` from before but include 2 variables in `varied`
101101

102102
````@example parametron
103+
fixed = (ω₀ => 1.0, γ => 1e-2, F => 1e-3, α => 1.0, η => 0.3)
103104
varied = (ω => range(0.8, 1.2, 50), λ => range(0.001, 0.6, 50))
104105
result_2D = get_steady_states(harmonic_eq, varied, fixed);
105106
nothing #hide

docs/src/examples/wave_mixing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
```@meta
2-
EditURL = "wave_mixing.jl"
2+
EditURL = "../../../examples/wave_mixing.jl"
33
```
44

55
# Three Wave Mixing vs four wave mixing
@@ -39,7 +39,7 @@ response with no response at $2\omega$.
3939
````@example wave_mixing
4040
varied = (ω => range(0.9, 1.2, 200)) # range of parameter values
4141
fixed = (α => 1.0, β => 0.0, ω0 => 1.0, γ => 0.005, F => 0.0025) # fixed parameters
42-
result = get_steady_states(harmonic_eq, varied, fixed; threading=true)# compute steady states
42+
result = get_steady_states(harmonic_eq, varied, fixed)# compute steady states
4343
4444
p1 = plot(result; y="√(u1^2+v1^2)", legend=:best)
4545
p2 = plot(result; y="√(u2^2+v2^2)", legend=:best, ylims=(-0.1, 0.1))
@@ -57,7 +57,7 @@ We would like to investigate the three-wave mixing of the driven Duffing oscilla
5757
````@example wave_mixing
5858
varied = (ω => range(0.9, 1.2, 200))
5959
fixed = (α => 0.0, β => 1.0, ω0 => 1.0, γ => 0.005, F => 0.0025)
60-
result = get_steady_states(harmonic_eq, varied, fixed; threading=true)
60+
result = get_steady_states(harmonic_eq, varied, fixed)
6161
6262
p1 = plot(result; y="√(u1^2+v1^2)", legend=:best)
6363
p2 = plot(result; y="√(u2^2+v2^2)", legend=:best, ylims=(-0.1, 0.1))
@@ -75,7 +75,7 @@ We would like to investigate the three-wave mixing of the driven Duffing oscilla
7575
````@example wave_mixing
7676
varied = (ω => range(0.9, 1.2, 200))
7777
fixed = (α => 1.0, β => 1.0, ω0 => 1.0, γ => 0.005, F => 0.0025)
78-
result = get_steady_states(harmonic_eq, varied, fixed; threading=true)
78+
result = get_steady_states(harmonic_eq, varied, fixed)
7979
8080
p1 = plot(result; y="√(u1^2+v1^2)", legend=:best)
8181
p2 = plot(result; y="√(u2^2+v2^2)", legend=:best, ylims=(-0.1, 0.1))

docs/src/manual/methods.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Methods
2+
3+
We offer several methods for solving the nonlinear algebraic equations that arise from the harmonic balance procedure. Each method has different tradeoffs between speed, robustness, and completeness.
4+
5+
## Total Degree Method
6+
```@docs
7+
TotalDegree
8+
```
9+
10+
## Polyhedral Method
11+
```@docs
12+
Polyhedral
13+
```
14+
15+
## Warm Up Method
16+
```@docs
17+
WarmUp
18+
```

docs/src/manual/plotting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The function `plot` is multiple-dispatched to plot 1D and 2D datasets.
1212
In 1D, the solutions are colour-coded according to the branches obtained by `sort_solutions`.
1313

1414
```@docs
15-
HarmonicBalance.plot(::Result, varags...)
15+
HarmonicBalance.plot(::HarmonicBalance.Result, varags...)
1616
```
1717

1818

docs/src/manual/solving_harmonics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ having called `get_harmonic_equations`, we need to set all time-derivatives to z
88
Once defined, a `Problem` can be solved for a set of input parameters using `get_steady_states` to obtain `Result`.
99

1010
```@docs
11-
Problem
11+
HarmonicBalance.Problem
1212
get_steady_states
13-
Result
13+
HarmonicBalance.Result
1414
```
1515

1616

docs/src/tutorials/classification.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ We performe a 2d sweep in the driving frequency $\omega$ and driving strength $\
2020
fixed = (ω₀ => 1.0, γ => 0.002, α => 1.0)
2121
varied = (ω => range(0.99, 1.01, 100), λ => range(1e-6, 0.03, 100))
2222
23-
result_2D = get_steady_states(harmonic_eq, varied, fixed, threading=true)
23+
result_2D = get_steady_states(harmonic_eq, varied, fixed)
2424
```
2525
By default the steady states of the system are classified by four different catogaries:
2626
* `physical`: Solutions that are physical, i.e., all variables are purely real.

0 commit comments

Comments
 (0)