本文整理汇总了Python中chemreac.ReactionDiffusion.f方法的典型用法代码示例。如果您正苦于以下问题:Python ReactionDiffusion.f方法的具体用法?Python ReactionDiffusion.f怎么用?Python ReactionDiffusion.f使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chemreac.ReactionDiffusion
的用法示例。
在下文中一共展示了ReactionDiffusion.f方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dc
# 需要导入模块: from chemreac import ReactionDiffusion [as 别名]
# 或者: from chemreac.ReactionDiffusion import f [as 别名]
def test_dc():
n = 7
k = [1]*(n-1)
rd = ReactionDiffusion(n, [[i] for i in range(n-1)],
[[i] for i in range(1, n)], k=k)
fout = rd.alloc_fout()
y0 = [0]*n
y0[0] = 1
y_ = [0] + y0
y0 = np.asarray(y0, dtype=np.float64)
rd.f(0, y0, fout)
pos, neg = [0]+k, k+[0]
_test_f(rd, 0, y0)
fref = [pos[i]*y_[i] - neg[i]*y_[i+1] for i in range(n)]
assert np.allclose(fref, fout)
jout = rd.alloc_jout(order='C')
rd.dense_jac_rmaj(0, y0, jout)
jref = np.zeros_like(jout)
for i in range(n):
if i < n - 1:
jref[i, i] = -k[i]
if i > 0:
jref[i, i-1] = k[i-1]
assert np.allclose(jref, jout)
_test_dense_jac_rmaj(rd, 0, y0)
示例2: test_ReactionDiffusion__f__wrong_fout_dimension
# 需要导入模块: from chemreac import ReactionDiffusion [as 别名]
# 或者: from chemreac.ReactionDiffusion import f [as 别名]
def test_ReactionDiffusion__f__wrong_fout_dimension():
y0 = np.array([2.0, 3.0])
k = 5.0
# A -> B
rd = ReactionDiffusion(2, [[0]], [[1]], [k])
fout = np.ones((1,))*99 # fout too small
with pytest.raises(AssertionError):
rd.f(0.0, y0, fout)
示例3: test_per_bin_diffusion
# 需要导入模块: from chemreac import ReactionDiffusion [as 别名]
# 或者: from chemreac.ReactionDiffusion import f [as 别名]
def test_per_bin_diffusion():
rd = ReactionDiffusion(1, [], [], [], N=5, D=[0, 0, 1, 0, 0])
fout = rd.alloc_fout()
y = [0, 1, 2, 1, 0]
rd.f(0.0, np.asarray(y, dtype=np.float64), fout)
assert np.all(fout[:2] == 0) and np.all(fout[-2:] == 0) and fout[2] < 0