当前位置: 首页>>代码示例>>Python>>正文


Python ReactionDiffusion._as_odesys方法代码示例

本文整理汇总了Python中chemreac.ReactionDiffusion._as_odesys方法的典型用法代码示例。如果您正苦于以下问题:Python ReactionDiffusion._as_odesys方法的具体用法?Python ReactionDiffusion._as_odesys怎么用?Python ReactionDiffusion._as_odesys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chemreac.ReactionDiffusion的用法示例。


在下文中一共展示了ReactionDiffusion._as_odesys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_chained_parameter_variation

# 需要导入模块: from chemreac import ReactionDiffusion [as 别名]
# 或者: from chemreac.ReactionDiffusion import _as_odesys [as 别名]
def test_chained_parameter_variation():
    # A -> B
    names = ['A', 'B']
    rd = ReactionDiffusion(len(names), [], [], k=[],
                           substance_names=names, g_value_parents=[0], g_values=[[0, 1]],
                           param_names=['doserate'])
    durations = [1., 3., 2.]
    y0 = [13., 7.]
    ic = dict(zip(names, y0))
    doserates = [.3, .11, .7]
    npoints = 3
    odesys = rd._as_odesys(variables_from_params=dict(
        density=lambda self, params: 1.0
    ))
    res = odesys.chained_parameter_variation(
        durations, ic, {'doserate': doserates}, npoints=npoints,
        integrate_kwargs=dict(atol={k: 1e-8 for k in odesys.names}))
    assert res.xout.size == npoints*len(durations) + 1
    assert res.xout[0] == 0
    assert np.all(res.yout[0, :] == y0)
    expected = [.3]*npoints + [.11]*npoints + [.7]*(npoints+1)
    assert np.all(res.params[:, odesys.param_names.index('doserate')] == expected)
    cumulative = 0.0
    for dr, dur in zip(doserates, durations):
        mask = (cumulative <= res.xout) & (res.xout <= cumulative + dur)
        cumulative += dur
        t, y = res.xout[mask], res.yout[mask, :]
        a, b = y[:, 0], y[:, 1]
        refa = a[0]
        refb = b[0] + (t - t[0])*dr*a[0]
        assert np.allclose(refa, a)
        assert np.allclose(refb, b)
    res.extend_by_integration(np.sum(durations)+1, dict(doserate=doserates[-1]), integrator='cvode')
    assert abs(res.yout[-1, 1] - (refb[-1] + doserates[-1]*a[0])) < 1e-8
开发者ID:chemreac,项目名称:chemreac,代码行数:36,代码来源:test_odesys.py

示例2: _get_odesys

# 需要导入模块: from chemreac import ReactionDiffusion [as 别名]
# 或者: from chemreac.ReactionDiffusion import _as_odesys [as 别名]
def _get_odesys():
    names = ['A', 'B', 'C']
    pns = ['kA', 'kB']
    rd = ReactionDiffusion(len(names), [[0], [1]], [[1], [2]], k=[0, 0],
                           substance_names=names, param_names=pns)
    return rd._as_odesys(k_from_params=lambda self, p: [p[k] for k in self.param_names])
开发者ID:chemreac,项目名称:chemreac,代码行数:8,代码来源:test_odesys.py


注:本文中的chemreac.ReactionDiffusion._as_odesys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。