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

Duffing oscillator with PyCont #166

Open
JonEhrmann opened this issue Nov 24, 2021 · 5 comments
Open

Duffing oscillator with PyCont #166

JonEhrmann opened this issue Nov 24, 2021 · 5 comments

Comments

@JonEhrmann
Copy link

Hi Rob,
I'm a Ph.D. student trying to implement the Duffing oscillator in PyCont for path continuation of the periodic solutions. I'm struggeling with the mathematical implementation of the differential equation. I used the following code:

from PyDSTool import *

DSargs = args()
DSargs.name = "duffing"
DSargs.ics = {"q": 0.1, "dq": 0}
DSargs.pars = {"wdach": 0.05, "D": 0.05, "g": -1, "eta": 0.7}
DSargs.tdata = [0, 500]
DSargs.varspecs = {"q": "dq",
                   "dq": "wdach*cos(eta*t)-2*D*dq-q-g*pow(q,3)"}

DS = Generator.Vode_ODEsystem(DSargs)

traj = DS.compute("duffing")
pts = traj.sample()
# plt.plot(pts["t"], pts["q"])
# plt.plot(pts["t"], pts["dq"])

q0 = max(pts["q"][30000:])
dq0 = max(pts["dq"][30000:])

PC = ContClass(DS)
PCargs = args(
    name="duff_cont",
    type="LC-C",
    freepars=["eta"],
    initpoint={"q": q0, "dq": dq0},
    # MaxNumPoints=450,
    # MaxStepSize=1e-4,
    # MinStepSize=1e-5,
    # StepSize=1e-5,
    LocBifPoints=["all"],
    StopAtPoints=["B"],
    SaveEigen=True,
)
PC.newCurve(PCargs)
PC["duff_cont"].forward()
PC["duff_cont"].display(["eta", "q"], stability=True)

Is it possible to implement the differential equation like this? Because the current result of the simulation is like a constant value (q plot over eta).

It would be nice to hear from you!

@robclewley
Copy link
Owner

robclewley commented Nov 24, 2021 via email

@robclewley
Copy link
Owner

robclewley commented Nov 25, 2021 via email

@JonEhrmann
Copy link
Author

Thanks again for your answer!

I'm still not completely sure, if PyDSTool is set up correctly. I implemented the following script

from PyDSTool import *

DSargs = args()
DSargs.name = "duffing"
DSargs.ics = {"q": 0.1, "dq": 0}
DSargs.pars = {"wdach": 0.05, "D": 0.05, "g": -1, "eta": 0.7}
DSargs.tdata = [0, 500]
DSargs.varspecs = {"q": "dq",
                   "dq": "wdach*cos(eta*t)-2*D*dq-q-g*pow(q,3)"}

DS = Generator.Vode_ODEsystem(DSargs)

traj = DS.compute("duffing")
pts = traj.sample()

q0 = max(pts["q"][30000:])
dq0 = max(pts["dq"][30000:])

PC = ContClass(DS)
PCargs = args(
    name="duff_cont",
    type="LC-C",
    freepars=["eta"],
    initpoint={"q": q0, "dq": dq0},
    LocBifPoints=["all"],
    StopAtPoints=["B"],
    SaveEigen=True,
)
PC.newCurve(PCargs)
PC["duff_cont"].forward()
PC["duff_cont"].display(["eta", "q"], stability=True)

And I get the following error

  File "C:\pydstool-master\PyDSTool\core\context_managers.py", line 30, in _stdchannel_redirected
    oldstdchannel = os.dup(stdchannel.fileno())

UnsupportedOperation: fileno


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "L:\duffing_pycont2.py", line 41, in <module>
    PC.newCurve(PCargs)

  File "C:\pydstool-master\PyDSTool\PyCont\ContClass.py", line 211, in newCurve
    self.loadAutoMod()

  File "C:\pydstool-master\PyDSTool\PyCont\ContClass.py", line 423, in loadAutoMod
    self.compileAutoLib()

  File "C:\pydstool-master\PyDSTool\PyCont\ContClass.py", line 704, in compileAutoLib
    setup(name="Auto 2000 continuer",

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\site-packages\numpy\distutils\core.py", line 169, in setup
    return old_setup(**new_attr)

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\distutils\core.py", line 148, in setup
    dist.run_commands()

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\site-packages\numpy\distutils\command\build.py", line 61, in run
    old_build.run(self)

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\distutils\command\build.py", line 135, in run
    self.run_command(cmd_name)

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\site-packages\numpy\distutils\command\build_ext.py", line 135, in run
    self.compiler = new_compiler(compiler=compiler_type,

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\site-packages\numpy\distutils\ccompiler.py", line 761, in new_compiler
    compiler = klass(None, dry_run, force)

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 97, in __init__
    build_import_library()

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 411, in build_import_library
    return _build_import_library_amd64()

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 467, in _build_import_library_amd64
    generate_def(dll_file, def_file)

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 293, in generate_def
    dump = dump_table(dll)

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 285, in dump_table
    st = subprocess.check_output(["objdump.exe", "-p", dll])

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\subprocess.py", line 424, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,

  File "C:\WinPython\WPy64-3950\python-3.9.5.amd64\lib\subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,

CalledProcessError: Command '['objdump.exe', '-p', 'C:\\WinPython\\WPy64-3950\\python-3.9.5.amd64\\python39.dll']' returned non-zero exit status 1.


objdump.exe: C:\WinPython\WPy64-3950\python-3.9.5.amd64\python39.dll: File format not recognized

I hope you could help...!

@robclewley
Copy link
Owner

robclewley commented Nov 26, 2021 via email

@JonEhrmann
Copy link
Author

Ok thank you for your help! I will look, how I get around.

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

No branches or pull requests

2 participants