Ejemplo n.º 1
0
def create_model():
    pars = {'g': 9.8}  #, 'pi': np.pi}

    #ODE
    ode_def = {
        'x': 'vx',
        'y': 'vy',
        'vx': '-(pi**2)*x',
        'vy': '-g',
        'tt': '1.0',
    }
    event_bounce = dst.makeZeroCrossEvent(
        'x-y',
        1, {
            'name': 'bounce',
            'eventtol': 1e-3,
            'term': True,
            'active': True,
            'eventinterval': 1,
            'eventdelay': 1e-2,
            'starttime': 0,
            'precise': True
        },
        varnames=['x', 'y'],
        targetlang='python')  # targetlang is redundant (defaults to python)

    DSargs = dst.args(name='bball_sin')  # struct-like data
    DSargs.events = [event_bounce]
    #DSargs.pars = pars
    #DSargs.tdata = [0, 10]
    #DSargs.algparams = {'max_pts': 3000, 'stiff': False}
    DSargs.algparams = {'stiff': False, 'init_step': 0.01}
    DSargs.varspecs = ode_def
    DSargs.pars = pars
    #DSargs.xdomain = {'y': [0, 100]}

    DS_fall = dst.embed(dst.Generator.Vode_ODEsystem(DSargs))
    DS_fall_MI = dst.intModelInterface(DS_fall)

    # Reset
    ev_map = dst.EvMapping({
        'y': 'x+0.001',
        'vy': '0.9*(vx-vy)'
    },
                           model=DS_fall)
    #ev_map = dst.EvMapping({'y': '10', 'x': '20'}, model=DS_fall)

    DS_BBall = dst.makeModelInfoEntry(DS_fall_MI, ['bball_sin'],
                                      [('bounce', ('bball_sin', ev_map))])

    modelInfoDict = dst.makeModelInfo([DS_BBall])
    bball_sin_model = dst.Model.HybridModel({
        'name': 'Bouncing_Ball_Sinusiodal',
        'modelInfo': modelInfoDict
    })
    return bball_sin_model
Ejemplo n.º 2
0
def create_model():
    pars = {'g': 9.8}#, 'pi': np.pi}

    #ODE
    ode_def = {
           'x': 'vx',
           'y': 'vy',
           'vx': '-(pi**2)*x',
           'vy': '-g',
           'tt': '1.0',
            }
    event_bounce = dst.makeZeroCrossEvent(
            'x-y', 1,
            {'name': 'bounce',
             'eventtol': 1e-3,
             'term': True,
             'active': True,
             'eventinterval': 1,
             'eventdelay': 1e-2,
             'starttime': 0,
             'precise': True
             },
            varnames=['x', 'y'],
            targetlang='python')  # targetlang is redundant (defaults to python)

    DSargs = dst.args(name='bball_sin')  # struct-like data
    DSargs.events = [event_bounce]
    #DSargs.pars = pars
    #DSargs.tdata = [0, 10]
    #DSargs.algparams = {'max_pts': 3000, 'stiff': False}
    DSargs.algparams = {'stiff': False, 'init_step': 0.01}
    DSargs.varspecs = ode_def
    DSargs.pars = pars
    #DSargs.xdomain = {'y': [0, 100]}

    DS_fall = dst.embed(dst.Generator.Vode_ODEsystem(DSargs))
    DS_fall_MI = dst.intModelInterface(DS_fall)

    # Reset
    ev_map = dst.EvMapping({'y': 'x+0.001', 'vy': '0.9*(vx-vy)'}, model=DS_fall)
    #ev_map = dst.EvMapping({'y': '10', 'x': '20'}, model=DS_fall)

    DS_BBall = dst.makeModelInfoEntry(DS_fall_MI, ['bball_sin'],
                                      [('bounce', ('bball_sin', ev_map))])

    modelInfoDict = dst.makeModelInfo([DS_BBall])
    bball_sin_model = dst.Model.HybridModel(
            {'name': 'Bouncing_Ball_Sinusiodal', 'modelInfo': modelInfoDict})
    return bball_sin_model
Ejemplo n.º 3
0
def create_model():
    pars = {'g': 1}
    icdict = {'y': 5, 'vy': 0}

    y_str = 'vy'
    vy_str = '-g'

    event_bounce = dst.makeZeroCrossEvent(
        'y',
        0, {
            'name': 'bounce',
            'eventtol': 1e-3,
            'term': True,
            'active': True
        },
        varnames=['y'],
        parnames=['g'],
        targetlang='python')  # targetlang is redundant (defaults to python)

    DSargs = dst.args(name='bball')  # struct-like data
    DSargs.events = [event_bounce]
    #DSargs.pars = pars
    #DSargs.tdata = [0, 10]
    #DSargs.algparams = {'max_pts': 3000, 'stiff': False}
    DSargs.algparams = {'stiff': False}
    DSargs.varspecs = {'y': y_str, 'vy': vy_str}
    DSargs.pars = pars
    #DSargs.xdomain = {'y': [0, 100], 'vy': [-100, 100]}

    DSargs.ics = icdict

    DS_fall = dst.embed(dst.Generator.Vode_ODEsystem(DSargs))
    DS_fall_MI = dst.intModelInterface(DS_fall)

    ev_map = dst.EvMapping({'y': 0, 'vy': '-0.75*vy'}, model=DS_fall)

    DS_BBall = dst.makeModelInfoEntry(DS_fall_MI, ['bball'],
                                      [('bounce', ('bball', ev_map))])

    modelInfoDict = dst.makeModelInfo([DS_BBall])
    bball_model = dst.Model.HybridModel({
        'name': 'Bouncing_Ball',
        'modelInfo': modelInfoDict
    })
    return bball_model
Ejemplo n.º 4
0
def create_model():
    pars = {'g': 1}
    icdict = {'y': 5, 'vy': 0}

    y_str = 'vy'
    vy_str = '-g'

    event_bounce = dst.makeZeroCrossEvent('y', 0,
                                {'name': 'bounce',
                                 'eventtol': 1e-3,
                                 'term': True,
                                 'active': True},
                        varnames=['y'],
                        parnames=['g'],
                        targetlang='python')  # targetlang is redundant (defaults to python)

    DSargs = dst.args(name='bball')  # struct-like data
    DSargs.events = [event_bounce]
    #DSargs.pars = pars
    #DSargs.tdata = [0, 10]
    #DSargs.algparams = {'max_pts': 3000, 'stiff': False}
    DSargs.algparams = {'stiff': False}
    DSargs.varspecs = {'y': y_str, 'vy': vy_str}
    DSargs.pars = pars
    #DSargs.xdomain = {'y': [0, 100], 'vy': [-100, 100]}

    DSargs.ics = icdict

    DS_fall = dst.embed(dst.Generator.Vode_ODEsystem(DSargs))
    DS_fall_MI = dst.intModelInterface(DS_fall)

    ev_map = dst.EvMapping({'y': 0, 'vy': '-0.75*vy'}, model=DS_fall)

    DS_BBall = dst.makeModelInfoEntry(DS_fall_MI, ['bball'],
                                      [('bounce', ('bball', ev_map))])

    modelInfoDict = dst.makeModelInfo([DS_BBall])
    bball_model = dst.Model.HybridModel({'name': 'Bouncing_Ball', 'modelInfo': modelInfoDict})
    return bball_model