Menu

Auxiliary function returning several values ?

Help
2015-03-11
2015-03-11
  • Benjamin Nguyen-Van-Yen

    I'm trying to define a function

    :::python
     Field = Fun([x_dot(x), x_dot(x), x_dot(x)], [x], 'Field')
    

    (to keep it simple) where x_dot is a Fun
    This works fine with Vode, but breaks at compilation with Dopri or Radau.
    Why is that ? How to proceed ?

    Actually what I need to compute is a Jacobian,
    but I only need it for a subsystem of the whole system,
    which makes it impossible to pass it as a 'Jacobian' for the integrator.
    (what is done in Tutorial_SymbolicJac.py for example)

    My minimal example :

    :::python
     import numpy as np
     from PyDSTool import *
    
     x = Var('x')
    
     x_dot = Fun(- 2 * x, [x], 'x_dot')
    
     Field = Fun([x_dot(x), x_dot(x), x_dot(x)], [x], 'Field')
    
     DSargs = args(name='single_strain')
     DSargs.fnspecs = [Field, x_dot]
     DSargs.tdomain = [0,365 * 5]
    
     DSargs.varspecs = {x:x_dot(x)}
    
     DSargs.algparams = {'init_step':0.001}
     DSargs.checklevel = 2
    
     ssODE = Generator.Dopri_ODEsystem(DSargs)
    
     info(ssODE)
    

    Thanks in advance,
    Benjamin

     
  • Rob Clewley

    Rob Clewley - 2015-03-11

    Alas, aux functions cannot return multiple values unless they are one of the specialized ones for Jacobian or Mass Matrix. Although the code compiles for vode, you are not using the Field function inside of the specs and you would not be syntactically allowed to index the return result, even with Vode.

    You are also not making an auxiliary variable that records the value of Field throughout an integration, so there's little benefit in making a C version of the function anyway. You might be best off just making a python version of the function that you call whenever you need it outside of the Generator. Otherwise, I would create all the entries of the vector symbolically and making individual aux fns for each that will work inside your PyDSTool specs. Sorry there's not inherent vectorized support!

    Does that help, though?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.