本文整理匯總了Python中sfepy.discrete.FieldVariable.set_from_function方法的典型用法代碼示例。如果您正苦於以下問題:Python FieldVariable.set_from_function方法的具體用法?Python FieldVariable.set_from_function怎麽用?Python FieldVariable.set_from_function使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sfepy.discrete.FieldVariable
的用法示例。
在下文中一共展示了FieldVariable.set_from_function方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_variables
# 需要導入模塊: from sfepy.discrete import FieldVariable [as 別名]
# 或者: from sfepy.discrete.FieldVariable import set_from_function [as 別名]
def test_variables(self):
from sfepy.discrete import FieldVariable, Integral
ok = True
u = FieldVariable('u', 'parameter', self.field,
primary_var_name='(set-to-None)')
u.set_constant(1.0)
vec = u() # Nodal values.
_ok = nm.allclose(vec, 1.0)
self.report('set constant:', _ok)
ok = _ok and ok
def fun(coors):
val = nm.empty_like(coors)
val[:, 0] = 2 * coors[:, 1] - coors[:, 0]
val[:, 1] = coors[:, 0] + 3 * coors[:, 1]
return val
u.set_from_function(fun)
coors = u.field.get_coor()
eu = u.evaluate_at(coors)
_ok = nm.allclose(eu, fun(coors), rtol=0.0, atol=1e-13)
self.report('set from function:', _ok)
ok = _ok and ok
integral = Integral('i', order=2)
gu_qp = u.evaluate(mode='grad', integral=integral)
# du_i/dx_j, i = column, j = row.
gu = nm.array([[-1., 1.],
[ 2., 3.]])
_ok = nm.allclose(gu_qp, gu[None, None, ...], rtol=0.0, atol=1e-13)
self.report('set from function - gradient:', _ok)
ok = _ok and ok
u_qp = gu_qp[..., :, :1]
u.set_from_qp(u_qp, integral)
vu = u()
_ok = (nm.allclose(vu[::2], -1, rtol=0.0, atol=1e-13) and
nm.allclose(vu[1::2], 2, rtol=0.0, atol=1e-13))
self.report('set from qp:', _ok)
ok = _ok and ok
return ok