本文整理汇总了Python中sfepy.discrete.FieldVariable.set_constant方法的典型用法代码示例。如果您正苦于以下问题:Python FieldVariable.set_constant方法的具体用法?Python FieldVariable.set_constant怎么用?Python FieldVariable.set_constant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfepy.discrete.FieldVariable
的用法示例。
在下文中一共展示了FieldVariable.set_constant方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_variables
# 需要导入模块: from sfepy.discrete import FieldVariable [as 别名]
# 或者: from sfepy.discrete.FieldVariable import set_constant [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
示例2: test_variables
# 需要导入模块: from sfepy.discrete import FieldVariable [as 别名]
# 或者: from sfepy.discrete.FieldVariable import set_constant [as 别名]
def test_variables(self):
from sfepy.discrete import FieldVariable
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)
## print u()
## print u.get_vector() # Coefficient vector w.r.t. the field space basis.
## print u(gamma1)
## print u.get_vector(gamma2)
return ok
示例3: test_project_tensors
# 需要导入模块: from sfepy.discrete import FieldVariable [as 别名]
# 或者: from sfepy.discrete.FieldVariable import set_constant [as 别名]
def test_project_tensors(self):
from sfepy.discrete import FieldVariable
from sfepy.discrete.projections import project_by_component
ok = True
u = FieldVariable('u', 'parameter', self.field,
primary_var_name='(set-to-None)')
u.set_constant(1.0)
component = FieldVariable('component', 'parameter', self.field,
primary_var_name='(set-to-None)')
nls_options = {'eps_a' : 1e-16, 'i_max' : 1}
u_qp = u.evaluate()
u2 = FieldVariable('u2', 'parameter', self.field,
primary_var_name='(set-to-None)')
project_by_component(u2, u_qp, component, self.field.approx_order,
nls_options=nls_options)
_ok = self.compare_vectors(u(), u2())
ok = ok and _ok
gu_qp = u.evaluate(mode='grad')
gfield = Field.from_args('gu', nm.float64, 2, self.field.region,
approx_order=self.field.approx_order)
gu = FieldVariable('gu', 'parameter', gfield,
primary_var_name='(set-to-None)')
project_by_component(gu, gu_qp, component, gfield.approx_order,
nls_options=nls_options)
_ok = self.compare_vectors(gu(), nm.zeros_like(gu()))
ok = ok and _ok
return ok
示例4: make_term_args
# 需要导入模块: from sfepy.discrete import FieldVariable [as 别名]
# 或者: from sfepy.discrete.FieldVariable import set_constant [as 别名]
def make_term_args(arg_shapes, arg_kinds, arg_types, ats_mode, domain,
material_value=None, poly_space_base=None):
from sfepy.base.base import basestr
from sfepy.discrete import FieldVariable, Material, Variables, Materials
from sfepy.discrete.fem import Field
from sfepy.solvers.ts import TimeStepper
from sfepy.mechanics.tensors import dim2sym
omega = domain.regions['Omega']
dim = domain.shape.dim
sym = dim2sym(dim)
def _parse_scalar_shape(sh):
if isinstance(sh, basestr):
if sh == 'D':
return dim
elif sh == 'D2':
return dim**2
elif sh == 'S':
return sym
elif sh == 'N': # General number ;)
return 1
else:
return int(sh)
else:
return sh
def _parse_tuple_shape(sh):
if isinstance(sh, basestr):
return [_parse_scalar_shape(ii.strip()) for ii in sh.split(',')]
else:
return (int(sh),)
args = {}
str_args = []
materials = []
variables = []
for ii, arg_kind in enumerate(arg_kinds):
if arg_kind != 'ts':
if ats_mode is not None:
extended_ats = arg_types[ii] + ('/%s' % ats_mode)
else:
extended_ats = arg_types[ii]
try:
sh = arg_shapes[arg_types[ii]]
except KeyError:
sh = arg_shapes[extended_ats]
if arg_kind.endswith('variable'):
shape = _parse_scalar_shape(sh[0] if isinstance(sh, tuple) else sh)
field = Field.from_args('f%d' % ii, nm.float64, shape, omega,
approx_order=1,
poly_space_base=poly_space_base)
if arg_kind == 'virtual_variable':
if sh[1] is not None:
istate = arg_types.index(sh[1])
else:
# Only virtual variable in arguments.
istate = -1
# -> Make fake variable.
var = FieldVariable('u-1', 'unknown', field)
var.set_constant(0.0)
variables.append(var)
var = FieldVariable('v', 'test', field,
primary_var_name='u%d' % istate)
elif arg_kind == 'state_variable':
var = FieldVariable('u%d' % ii, 'unknown', field)
var.set_constant(0.0)
elif arg_kind == 'parameter_variable':
var = FieldVariable('p%d' % ii, 'parameter', field,
primary_var_name='(set-to-None)')
var.set_constant(0.0)
variables.append(var)
str_args.append(var.name)
args[var.name] = var
elif arg_kind.endswith('material'):
if sh is None: # Switched-off opt_material.
continue
prefix = ''
if isinstance(sh, basestr):
aux = sh.split(':')
if len(aux) == 2:
prefix, sh = aux
#.........这里部分代码省略.........