本文整理汇总了Python中sfepy.discrete.FieldVariable.set_data方法的典型用法代码示例。如果您正苦于以下问题:Python FieldVariable.set_data方法的具体用法?Python FieldVariable.set_data怎么用?Python FieldVariable.set_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfepy.discrete.FieldVariable
的用法示例。
在下文中一共展示了FieldVariable.set_data方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_surface_evaluate
# 需要导入模块: from sfepy.discrete import FieldVariable [as 别名]
# 或者: from sfepy.discrete.FieldVariable import set_data [as 别名]
def test_surface_evaluate(self):
from sfepy.discrete import FieldVariable
problem = self.problem
us = problem.get_variables()['us']
vec = nm.empty(us.n_dof, dtype=us.dtype)
vec[:] = 1.0
us.set_data(vec)
expr = 'ev_surface_integrate.i.Left( us )'
val = problem.evaluate(expr, us=us)
ok1 = nm.abs(val - 1.0) < 1e-15
self.report('with unknown: %s, value: %s, ok: %s'
% (expr, val, ok1))
ps1 = FieldVariable('ps1', 'parameter', us.get_field(),
primary_var_name='(set-to-None)')
ps1.set_data(vec)
expr = 'ev_surface_integrate.i.Left( ps1 )'
val = problem.evaluate(expr, ps1=ps1)
ok2 = nm.abs(val - 1.0) < 1e-15
self.report('with parameter: %s, value: %s, ok: %s'
% (expr, val, ok2))
ok2 = True
return ok1 and ok2
示例2: test_volume_tl
# 需要导入模块: from sfepy.discrete import FieldVariable [as 别名]
# 或者: from sfepy.discrete.FieldVariable import set_data [as 别名]
def test_volume_tl(self):
from sfepy.discrete import FieldVariable
fu = self.problem.fields['vector']
fq = self.problem.fields['scalar']
var_u = FieldVariable('u', 'parameter', fu,
primary_var_name='(set-to-None)')
var_q = FieldVariable('q', 'test', fq,
primary_var_name='(set-to-None)')
var_u.set_data(nm.linspace(0, 0.004, var_u.n_dof))
vval = self.problem.evaluate('dw_tl_volume.i.Omega( q, u )',
term_mode='volume', q=var_q, u=var_u)
sval = self.problem.evaluate('d_tl_volume_surface.i.Gamma( u )',
u=var_u)
ok = abs(vval - sval) < 1e-14
self.report('TL: by volume: %e == by surface: %e -> %s' %
(vval, sval, ok))
return ok
示例3: create_subequations
# 需要导入模块: from sfepy.discrete import FieldVariable [as 别名]
# 或者: from sfepy.discrete.FieldVariable import set_data [as 别名]
def create_subequations(self, var_names, known_var_names=None):
"""
Create sub-equations containing only terms with the given virtual
variables.
Parameters
----------
var_names : list
The list of names of virtual variables.
known_var_names : list
The list of names of (already) known state variables.
Returns
-------
subequations : Equations instance
The sub-equations.
"""
from sfepy.discrete import FieldVariable
known_var_names = get_default(known_var_names, [])
objs = []
for iv, var_name in enumerate(var_names):
terms = [term.copy(name=term.name)
for eq in self for term in eq.terms
if term.get_virtual_name() == var_name]
# Make parameter variables from known state variables in terms
# arguments.
for known_name in known_var_names:
for term in terms:
if known_name in term.arg_names:
ii = term.arg_names.index(known_name)
state = self.variables[known_name]
par = FieldVariable(known_name, 'parameter',
state.field,
primary_var_name='(set-to-None)')
term.args[ii] = par
term._kwargs[known_name] = par
par.set_data(state())
new_terms = Terms(terms)
objs.append(Equation('eq_%d' % iv, new_terms))
subequations = Equations(objs)
return subequations
示例4: test_projection_tri_quad
# 需要导入模块: from sfepy.discrete import FieldVariable [as 别名]
# 或者: from sfepy.discrete.FieldVariable import set_data [as 别名]
def test_projection_tri_quad(self):
from sfepy.discrete.projections import make_l2_projection
source = FieldVariable('us', 'unknown', self.field)
coors = self.field.get_coor()
vals = nm.sin(2.0 * nm.pi * coors[:,0] * coors[:,1])
source.set_data(vals)
name = op.join(self.options.out_dir,
'test_projection_tri_quad_source.vtk')
source.save_as_mesh(name)
mesh = Mesh.from_file('meshes/2d/square_quad.mesh',
prefix_dir=sfepy.data_dir)
domain = FEDomain('domain', mesh)
omega = domain.create_region('Omega', 'all')
field = Field.from_args('bilinear', nm.float64, 'scalar', omega,
approx_order=1)
target = FieldVariable('ut', 'unknown', field)
make_l2_projection(target, source)
name = op.join(self.options.out_dir,
'test_projection_tri_quad_target.vtk')
target.save_as_mesh(name)
bbox = self.field.domain.get_mesh_bounding_box()
x = nm.linspace(bbox[0, 0] + 0.001, bbox[1, 0] - 0.001, 20)
y = nm.linspace(bbox[0, 1] + 0.001, bbox[1, 1] - 0.001, 20)
xx, yy = nm.meshgrid(x, y)
test_coors = nm.c_[xx.ravel(), yy.ravel()].copy()
vec1 = source.evaluate_at(test_coors)
vec2 = target.evaluate_at(test_coors)
ok = (nm.abs(vec1 - vec2) < 0.01).all()
return ok
示例5: save_basis_on_mesh
# 需要导入模块: from sfepy.discrete import FieldVariable [as 别名]
# 或者: from sfepy.discrete.FieldVariable import set_data [as 别名]
def save_basis_on_mesh(mesh, options, output_dir, lin,
permutations=None, suffix=''):
if permutations is not None:
mesh = mesh.copy()
gel = GeometryElement(mesh.descs[0])
perms = gel.get_conn_permutations()[permutations]
conn = mesh.cmesh.get_cell_conn()
n_el, n_ep = conn.num, gel.n_vertex
offsets = nm.arange(n_el) * n_ep
conn.indices[:] = conn.indices.take((perms + offsets[:, None]).ravel())
domain = FEDomain('domain', mesh)
omega = domain.create_region('Omega', 'all')
field = Field.from_args('f', nm.float64, shape=1, region=omega,
approx_order=options.max_order,
poly_space_base=options.basis)
var = FieldVariable('u', 'unknown', field)
if options.plot_dofs:
import sfepy.postprocess.plot_dofs as pd
import sfepy.postprocess.plot_cmesh as pc
ax = pc.plot_wireframe(None, mesh.cmesh)
ax = pd.plot_global_dofs(ax, field.get_coor(), field.econn)
ax = pd.plot_local_dofs(ax, field.get_coor(), field.econn)
if options.dofs is not None:
ax = pd.plot_nodes(ax, field.get_coor(), field.econn,
field.poly_space.nodes,
get_dofs(options.dofs, var.n_dof))
pd.plt.show()
output('dofs: %d' % var.n_dof)
vec = nm.empty(var.n_dof, dtype=var.dtype)
n_digit, _format = get_print_info(var.n_dof, fill='0')
name_template = os.path.join(output_dir,
'dof_%s%s.vtk' % (_format, suffix))
for ip in get_dofs(options.dofs, var.n_dof):
output('dof %d...' % ip)
vec.fill(0.0)
vec[ip] = 1.0
var.set_data(vec)
if options.derivative == 0:
out = var.create_output(vec, linearization=lin)
else:
out = create_expression_output('ev_grad.ie.Elements(u)',
'u', 'f', {'f' : field}, None,
Variables([var]),
mode='qp', verbose=False,
min_level=lin.min_level,
max_level=lin.max_level,
eps=lin.eps)
name = name_template % ip
ensure_path(name)
out['u'].mesh.write(name, out=out)
output('...done (%s)' % name)