|
| 1 | +using HarmonicBalance, HarmonicSteadyState |
| 2 | +using HarmonicSteadyState: HomotopyContinuationProblem, OrderedDict |
| 3 | +using HarmonicSteadyState: sort_solutions, _classify_default! |
| 4 | + |
| 5 | +function benchmark_kpo!(SUITE) |
| 6 | + @variables ω₀ γ λ F η α ω t x(t) |
| 7 | + |
| 8 | + natural_equation = |
| 9 | + d(d(x, t), t) + |
| 10 | + γ * d(x, t) + |
| 11 | + (ω₀^2 - λ * cos(2 * ω * t)) * x + |
| 12 | + α * x^3 + |
| 13 | + η * d(x, t) * x^2 |
| 14 | + forces = F * cos(ω * t) |
| 15 | + diff_eq = DifferentialEquation(natural_equation + forces, x) |
| 16 | + add_harmonic!(diff_eq, x, ω) |
| 17 | + |
| 18 | + harmonic_eq = get_harmonic_equations(diff_eq) |
| 19 | + |
| 20 | + SUITE["Construction"]["Harmonic Equation"]["One Frequency"] = @benchmarkable begin |
| 21 | + get_harmonic_equations($diff_eq) |
| 22 | + end seconds = 10 |
| 23 | + |
| 24 | + krylov_eq = get_krylov_equations(diff_eq; order=1) |
| 25 | + krylov_eq2 = get_krylov_equations(diff_eq; order=2) |
| 26 | + |
| 27 | + SUITE["Construction"]["Krylov Equation"]["Order 1"] = @benchmarkable begin |
| 28 | + get_krylov_equations($diff_eq; order=1) |
| 29 | + end seconds = 10 |
| 30 | + SUITE["Construction"]["Krylov Equation"]["Order 2"] = @benchmarkable begin |
| 31 | + get_krylov_equations($diff_eq; order=2) |
| 32 | + end seconds = 10 |
| 33 | + |
| 34 | + fixed = OrderedDict(ω₀ => 1.0, γ => 1e-2, λ => 5e-2, F => 1e-3, α => 1.0, η => 0.3) |
| 35 | + varied = OrderedDict(ω => range(0.9, 1.1, 100)) |
| 36 | + |
| 37 | + problem = HomotopyContinuationProblem(harmonic_eq, varied, fixed) |
| 38 | + SUITE["Construction"]["Problem"]["HomotopyContinuationProblem"] = @benchmarkable begin |
| 39 | + HomotopyContinuationProblem($harmonic_eq, $varied, $fixed) |
| 40 | + end seconds = 10 |
| 41 | + |
| 42 | + show_progress = false |
| 43 | + sorting = "no_sorting" |
| 44 | + classify_default = false |
| 45 | + |
| 46 | + method = WarmUp(; thread=false) |
| 47 | + result = get_steady_states(problem, method; show_progress, sorting, classify_default) |
| 48 | + |
| 49 | + SUITE["Steady states"]["Homotopy Problem"]["Warm up method"] = @benchmarkable begin |
| 50 | + get_steady_states( |
| 51 | + $problem, |
| 52 | + $method; |
| 53 | + show_progress=false, |
| 54 | + sorting="no_sorting", |
| 55 | + classify_default=false, |
| 56 | + ) |
| 57 | + end seconds = 10 |
| 58 | + |
| 59 | + method = TotalDegree(; thread=false) |
| 60 | + result = get_steady_states(problem, method; show_progress, sorting, classify_default) |
| 61 | + |
| 62 | + SUITE["Steady states"]["Homotopy Problem"]["Total degree homotopy"] = @benchmarkable begin |
| 63 | + get_steady_states( |
| 64 | + $problem, |
| 65 | + $method; |
| 66 | + show_progress=false, |
| 67 | + sorting="no_sorting", |
| 68 | + classify_default=false, |
| 69 | + ) |
| 70 | + end seconds = 10 |
| 71 | + |
| 72 | + method = Polyhedral(; thread=false) |
| 73 | + result = get_steady_states(problem, method; show_progress, sorting, classify_default) |
| 74 | + |
| 75 | + SUITE["Steady states"]["Homotopy Problem"]["Polyhedral homotopy"] = @benchmarkable begin |
| 76 | + get_steady_states( |
| 77 | + $problem, |
| 78 | + $method; |
| 79 | + show_progress=false, |
| 80 | + sorting="no_sorting", |
| 81 | + classify_default=false, |
| 82 | + ) |
| 83 | + end seconds = 10 |
| 84 | + |
| 85 | + solutions_not_sorted = result.solutions |
| 86 | + sort_solutions(solutions_not_sorted; sorting="nearest", show_progress=false) |
| 87 | + sort_solutions(solutions_not_sorted; sorting="hilbert", show_progress=false) |
| 88 | + |
| 89 | + SUITE["Sorting"]["One dimensional"]["Nearest-neighbor sorting"] = @benchmarkable begin |
| 90 | + sort_solutions($solutions_not_sorted; show_progress=false, sorting="nearest") |
| 91 | + end seconds = 10 |
| 92 | + |
| 93 | + SUITE["Sorting"]["One dimensional"]["Hilbert sorting"] = @benchmarkable begin |
| 94 | + sort_solutions($solutions_not_sorted; show_progress=false, sorting="hilbert") |
| 95 | + end seconds = 10 |
| 96 | + |
| 97 | + _classify_default!(deepcopy(result)) |
| 98 | + SUITE["Classification"]["One Dimensional"]["Default classifications"] = @benchmarkable begin |
| 99 | + _classify_default!(x) |
| 100 | + end setup = (x = deepcopy($result)) evals = 1 seconds = 10 |
| 101 | + |
| 102 | + method = WarmUp(; thread=false) |
| 103 | + result = get_steady_states(problem, method; show_progress) |
| 104 | + |
| 105 | + Ω_range = range(0.95, 1.05, 100) |
| 106 | + get_jacobian_response(result, x, Ω_range, 3; show_progress=false) |
| 107 | + get_rotframe_jacobian_response(result, Ω_range, 3; show_progress=false, damping_mod=1.0) |
| 108 | + |
| 109 | + SUITE["Linear response"]["Lab frame"]["Jacobian Response"] = @benchmarkable begin |
| 110 | + get_jacobian_response($result, $x, $(Ω_range), 3; show_progress=false) |
| 111 | + end seconds = 10 |
| 112 | + |
| 113 | + SUITE["Linear response"]["Rotating frame"]["Jacobian Response"] = @benchmarkable begin |
| 114 | + get_rotframe_jacobian_response( |
| 115 | + $result, $(Ω_range), 3; show_progress=false, damping_mod=1.0 |
| 116 | + ) |
| 117 | + end seconds = 10 |
| 118 | + |
| 119 | + return nothing |
| 120 | +end |
0 commit comments