Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added keyword to control the display of the progress bar (resolves #60) #65

Merged
merged 7 commits into from
Oct 24, 2022

Conversation

oameye
Copy link
Member

@oameye oameye commented Oct 23, 2022

resolves #60

The keyword is added for

  • get_steady_states
  • sort_solutions
  • plot_linear_response

Also removed trailing spaces because of this stackexchange page.

The code has been tested with the following script:

using HarmonicBalance
using DifferentialEquations, ModelingToolkit

@variables t x(t);
@parameters ω₁ ω γ λ α₁;

equation = [d(d(x, t),t) + ω₁^2*(1-λ*cos(2*ω*t)) * x + γ*d(x,t)  + α₁*x^3]
DE = DifferentialEquation(equation, x)
add_harmonic!(DE, x, ω)
harmonic_eq = get_harmonic_equations(DE);

fixed = Dict(ω₁ => 1.0, γ => 0.01, α₁ => 0.5)
varied ==> range(0.93, 1.09, 100), λ => range(1e-6, 0.06, 100))
result_2D = get_steady_states(harmonic_eq, varied, fixed, show_progress=false)

###
using HarmonicBalance
using DifferentialEquations, ModelingToolkit


@variables t x(t) y(t);
@parameters ω₁ ω₂ ω γ λ α₁ α₂ J;

natural_equation = [d(d(x, t),t) + ω₁^2*(1-λ*cos(2*ω*t)) * x + γ*d(x,t)  + α₁*x^3 - J*y ,
                    d(d(y,t),t)  + ω₂^2*(1-λ*cos(2*ω*t)) * y + γ*d(y,t)  + α₂*y^3 - J*x]


dEOM_coupled = DifferentialEquation(natural_equation, [x, y])

add_harmonic!(dEOM_coupled, x, ω) # x will rotate at ω
add_harmonic!(dEOM_coupled, y, ω) # y will rotate at ω

harmonic_eq = get_harmonic_equations(dEOM_coupled);

fixed2 = Dict(ω₁ => 1.0, ω₂ => 1.0, γ => 0.01, α₁ => 0.5, α₂ => 0.5, J => 0.04)
varied2 ==> range(0.96, 1.1, 100), λ => range(1e-6, 0.06, 100))
result_2D = get_steady_states(harmonic_eq, varied2, fixed2, random_warmup=false, threading=true, show_progress=false);

###
using HarmonicBalance
using DifferentialEquations, ModelingToolkit

@parameters α, ω, ω0, F, γ
@variables t x(t) y(t);

# define ODE
diff = DifferentialEquation(d(x,t,2) + ω0*x + α*x^3 + γ*d(x,t) ~ F*cos*t), x)

# specify the ansatz x = u(T) cos(ω*t) + v(T) sin(ω*t)
add_harmonic!(diff, x, ω) 

# implement ansatz to get harmonic equations
harmonic = get_harmonic_equations(diff)

fixed1 ==> 1, ω0 => 1.0, γ => 1E-2, F => 1E-6)   # fixed parameters
varied1 = ω => LinRange(0.9, 1.1, 100)           # range of parameter values
result = get_steady_states(harmonic, varied1, fixed1)

HarmonicBalance.plot_linear_response(result, x, Ω_range=range(0.9,1.1,300), branch=1, logscale=true, )

@jkosata
Copy link
Member

jkosata commented Oct 24, 2022

Cool stuff! Is there no spurious output because of ProgressBar being called irrespective of show_progress ? I guess it’s only next! that prints the bar

@oameye
Copy link
Member Author

oameye commented Oct 24, 2022

Yes, In my tests only next! prints the ProgressBar. However, it is indeed not needed to allocate the ProgressBar. I will check if I can do that in a nice way this week. Maybe, it could also be nice to write some tests on the progress bar.

@jkosata jkosata merged commit 1085805 into NonlinearOscillations:master Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A keyword to control the loading bar
2 participants