本文整理汇总了Python中sfepy.discrete.Variables.from_conf方法的典型用法代码示例。如果您正苦于以下问题:Python Variables.from_conf方法的具体用法?Python Variables.from_conf怎么用?Python Variables.from_conf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfepy.discrete.Variables
的用法示例。
在下文中一共展示了Variables.from_conf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_interpolation_two_meshes
# 需要导入模块: from sfepy.discrete import Variables [as 别名]
# 或者: from sfepy.discrete.Variables import from_conf [as 别名]
def test_interpolation_two_meshes(self):
from sfepy import data_dir
from sfepy.discrete import Variables
from sfepy.discrete.fem import Mesh, FEDomain, Field
m1 = Mesh.from_file(data_dir + '/meshes/3d/block.mesh')
m2 = Mesh.from_file(data_dir + '/meshes/3d/cube_medium_tetra.mesh')
m2.coors[:] *= 2.0
bbox = m1.get_bounding_box()
dd = bbox[1,:] - bbox[0,:]
data = nm.sin(4.0 * nm.pi * m1.coors[:,0:1] / dd[0]) \
* nm.cos(4.0 * nm.pi * m1.coors[:,1:2] / dd[1])
variables1 = {
'u' : ('unknown field', 'scalar_tp', 0),
'v' : ('test field', 'scalar_tp', 'u'),
}
variables2 = {
'u' : ('unknown field', 'scalar_si', 0),
'v' : ('test field', 'scalar_si', 'u'),
}
d1 = FEDomain('d1', m1)
omega1 = d1.create_region('Omega', 'all')
field1 = Field.from_args('scalar_tp', nm.float64, (1,1), omega1,
approx_order=1)
ff1 = {field1.name : field1}
d2 = FEDomain('d2', m2)
omega2 = d2.create_region('Omega', 'all')
field2 = Field.from_args('scalar_si', nm.float64, (1,1), omega2,
approx_order=0)
ff2 = {field2.name : field2}
vv1 = Variables.from_conf(transform_variables(variables1), ff1)
u1 = vv1['u']
u1.set_from_mesh_vertices(data)
vv2 = Variables.from_conf(transform_variables(variables2), ff2)
u2 = vv2['u']
# Performs interpolation, if other field differs from self.field
# or, in particular, is defined on a different mesh.
u2.set_from_other(u1, strategy='interpolation', close_limit=0.1)
fname = in_dir(self.options.out_dir)
u1.save_as_mesh(fname('test_mesh_interp_block_scalar.vtk'))
u2.save_as_mesh(fname('test_mesh_interp_cube_scalar.vtk'))
return True
示例2: do_interpolation
# 需要导入模块: from sfepy.discrete import Variables [as 别名]
# 或者: from sfepy.discrete.Variables import from_conf [as 别名]
def do_interpolation(m2, m1, data, field_name, force=False):
"""Interpolate data from m1 to m2. """
from sfepy.discrete import Variables
from sfepy.discrete.fem import FEDomain, Field
fields = {
'scalar_si' : ((1,1), 'Omega', 2),
'vector_si' : ((3,1), 'Omega', 2),
'scalar_tp' : ((1,1), 'Omega', 1),
'vector_tp' : ((3,1), 'Omega', 1),
}
d1 = FEDomain('d1', m1)
omega1 = d1.create_region('Omega', 'all')
f = fields[field_name]
field1 = Field.from_args('f', nm.float64, f[0], d1.regions[f[1]],
approx_order=f[2])
ff = {field1.name : field1}
vv = Variables.from_conf(transform_variables(variables), ff)
u1 = vv['u']
u1.set_from_mesh_vertices(data)
d2 = FEDomain('d2', m2)
omega2 = d2.create_region('Omega', 'all')
field2 = Field.from_args('f', nm.float64, f[0], d2.regions[f[1]],
approx_order=f[2])
ff2 = {field2.name : field2}
vv2 = Variables.from_conf(transform_variables(variables), ff2)
u2 = vv2['u']
if not force:
# Performs interpolation, if other field differs from self.field
# or, in particular, is defined on a different mesh.
u2.set_from_other(u1, strategy='interpolation', close_limit=0.5)
else:
coors = u2.field.get_coor()
vals = u1.evaluate_at(coors, close_limit=0.5)
u2.set_data(vals)
return u1, u2
示例3: test_evaluate_at
# 需要导入模块: from sfepy.discrete import Variables [as 别名]
# 或者: from sfepy.discrete.Variables import from_conf [as 别名]
def test_evaluate_at(self):
from sfepy import data_dir
from sfepy.discrete.fem import Mesh
from sfepy.discrete import Variables
from sfepy.discrete.fem import FEDomain, Field
meshes = {
'tp' : Mesh.from_file(data_dir + '/meshes/3d/block.mesh'),
}
datas = gen_datas(meshes)
fields = {
'scalar_tp' : ((1,1), 'Omega', 1),
'vector_tp' : ((3,1), 'Omega', 1),
}
ok = True
for field_name in ['scalar_tp', 'vector_tp']:
d = FEDomain('d', meshes['tp'])
d.create_region('Omega', 'all')
f = fields[field_name]
field = Field.from_args('f', nm.complex128, f[0],
d.regions[f[1]],
approx_order=f[2])
ff = {field.name : field}
vv = Variables.from_conf(transform_variables(variables), ff)
u = vv['u']
bbox = d.get_mesh_bounding_box()
t = nm.expand_dims(nm.linspace(0, 1, 100), 1)
coors = nm.expand_dims(bbox[1] - bbox[0], 0) * t + bbox[0]
data_r = datas[field_name]
data_i = 2. / (1 + datas[field_name])
u.set_from_mesh_vertices(data_r)
vals_r = u.evaluate_at(coors)
u.set_from_mesh_vertices(data_i)
vals_i = u.evaluate_at(coors)
u.set_from_mesh_vertices(data_r + data_i * 1j)
vals = u.evaluate_at(coors)
_ok = nm.allclose(vals_r + vals_i * 1j, vals, rtol=0.0, atol=1e-12)
_ok = _ok and nm.abs(vals).sum() > 1
self.report('evaluating complex field %s: %s' % (field_name, _ok))
ok = ok and _ok
return ok
示例4: test_pbc
# 需要导入模块: from sfepy.discrete import Variables [as 别名]
# 或者: from sfepy.discrete.Variables import from_conf [as 别名]
def test_pbc( self ):
from sfepy.discrete import Variables, Conditions
problem = self.problem
conf = self.conf
ebcs = Conditions.from_conf(conf.ebcs, problem.domain.regions)
epbcs = Conditions.from_conf(conf.epbcs, problem.domain.regions)
variables = Variables.from_conf(conf.variables, problem.fields)
variables.equation_mapping(ebcs, epbcs, None, problem.functions)
state = variables.create_state_vector()
variables.apply_ebc(state)
return variables.has_ebc(state)
示例5: test_consistency_d_dw
# 需要导入模块: from sfepy.discrete import Variables [as 别名]
# 或者: from sfepy.discrete.Variables import from_conf [as 别名]
def test_consistency_d_dw(self):
from sfepy.discrete import Variables
ok = True
pb = self.problem
for aux in test_terms:
term_template, (prefix, par_name, d_vars, dw_vars) = aux
print term_template, prefix, par_name, d_vars, dw_vars
term1 = term_template % ((prefix,) + d_vars)
variables = Variables.from_conf(self.conf.variables, pb.fields)
for var_name in d_vars:
var = variables[var_name]
n_dof = var.field.n_nod * var.field.shape[0]
aux = nm.arange(n_dof, dtype=nm.float64)
var.set_data(aux)
if prefix == 'd':
val1 = pb.evaluate(term1, var_dict=variables.as_dict())
else:
val1 = pb.evaluate(term1, call_mode='d_eval',
var_dict=variables.as_dict())
self.report('%s: %s' % (term1, val1))
term2 = term_template % (('dw',) + dw_vars[:2])
vec, vv = pb.evaluate(term2, mode='weak',
var_dict=variables.as_dict(),
ret_variables=True)
pvec = vv.get_state_part_view(vec, dw_vars[2])
val2 = nm.dot(variables[par_name](), pvec)
self.report('%s: %s' % (term2, val2))
err = nm.abs(val1 - val2) / nm.abs(val1)
_ok = err < 1e-12
self.report('relative difference: %e -> %s' % (err, _ok))
ok = ok and _ok
return ok
示例6: test_invariance_qp
# 需要导入模块: from sfepy.discrete import Variables [as 别名]
# 或者: from sfepy.discrete.Variables import from_conf [as 别名]
def test_invariance_qp(self):
from sfepy import data_dir
from sfepy.discrete import Variables, Integral
from sfepy.discrete.fem import Mesh, FEDomain, Field
from sfepy.terms import Term
from sfepy.discrete.common.mappings import get_physical_qps
mesh = Mesh.from_file(data_dir + '/meshes/3d/block.mesh')
bbox = mesh.get_bounding_box()
dd = bbox[1,:] - bbox[0,:]
data = nm.sin(4.0 * nm.pi * mesh.coors[:,0:1] / dd[0]) \
* nm.cos(4.0 * nm.pi * mesh.coors[:,1:2] / dd[1])
variables = {
'u' : ('unknown field', 'scalar_tp', 0),
'v' : ('test field', 'scalar_tp', 'u'),
}
domain = FEDomain('domain', mesh)
omega = domain.create_region('Omega', 'all')
field = Field.from_args('scalar_tp', nm.float64, 1, omega,
approx_order=1)
ff = {field.name : field}
vv = Variables.from_conf(transform_variables(variables), ff)
u = vv['u']
u.set_from_mesh_vertices(data)
integral = Integral('i', order=2)
term = Term.new('ev_volume_integrate(u)', integral, omega, u=u)
term.setup()
val1 = term.evaluate(mode='qp')
val1 = val1.ravel()
qps = get_physical_qps(omega, integral)
coors = qps.values
val2 = u.evaluate_at(coors).ravel()
self.report('max. difference:', nm.abs(val1 - val2).max())
ok = nm.allclose(val1, val2, rtol=0.0, atol=1e-12)
self.report('invariance in qp: %s' % ok)
return ok