本文整理汇总了Python中sfepy.discrete.fem.Mesh.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Mesh.from_file方法的具体用法?Python Mesh.from_file怎么用?Python Mesh.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfepy.discrete.fem.Mesh
的用法示例。
在下文中一共展示了Mesh.from_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_interpolation
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def test_interpolation(self):
from sfepy import data_dir
from sfepy.discrete.fem import Mesh
from sfepy.linalg import make_axis_rotation_matrix
fname = in_dir(self.options.out_dir)
meshes = {
'tp' : Mesh.from_file(data_dir + '/meshes/3d/block.mesh'),
'si' : Mesh.from_file(data_dir + '/meshes/3d/cylinder.mesh'),
}
datas = gen_datas(meshes)
for field_name in ['scalar_si', 'vector_si', 'scalar_tp', 'vector_tp']:
m1 = meshes[field_name[-2:]]
for ia, angle in enumerate(nm.linspace(0.0, nm.pi, 11)):
self.report('%s: %d. angle: %f' % (field_name, ia, angle))
shift = [0.0, 0.0, 0.0]
mtx = make_axis_rotation_matrix([0, 1, 0], angle)
m2 = m1.copy('rotated mesh')
m2.transform_coors(mtx)
data = datas[field_name]
u1, u2 = do_interpolation(m2, m1, data, field_name)
if ia == 0:
u1.save_as_mesh(fname('test_mesh_interp_%s_u1.vtk'
% field_name))
u2.save_as_mesh(fname('test_mesh_interp_%s_u2.%03d.vtk'
% (field_name, ia)))
return True
示例2: test_write_read_meshes
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def test_write_read_meshes(self):
"""
Try to write and then read all supported formats.
"""
from sfepy.discrete.fem import Mesh
from sfepy.discrete.fem.meshio import (supported_formats,
supported_capabilities)
conf_dir = op.dirname(__file__)
mesh0 = Mesh.from_file(data_dir
+ '/meshes/various_formats/small3d.mesh',
prefix_dir=conf_dir)
oks = []
for suffix, format_ in six.iteritems(supported_formats):
if isinstance(format_, tuple):
continue
if 'w' not in supported_capabilities[format_]: continue
filename = op.join(self.options.out_dir, 'test_mesh_wr' + suffix)
self.report('%s format: %s' % (suffix, filename))
mesh0.write(filename, io='auto')
mesh1 = Mesh.from_file(filename)
oks.extend(self._compare_meshes(mesh0, mesh1))
return sum(oks) == len(oks)
示例3: test_interpolation_two_meshes
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [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
示例4: main
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def main():
parser = OptionParser(usage=usage)
(options, args) = parser.parse_args()
if len(args) != 1:
parser.print_help()
sys.exit(1)
mesh_dir = args[0]
mesh_files = []
for (dirpath, dirnames, filenames) in os.walk(mesh_dir):
for ii in filenames:
_, ext = os.path.splitext(ii)
if ext.lower() in ['.mesh', '.vtk']:
mesh_files.append(dirpath + os.path.sep + ii)
for ii in mesh_files:
base, ext = os.path.splitext(ii)
fname_out = base + '.png'
if ext == '.mesh':
fname_in = 'aux.vtk'
mesh = Mesh.from_file(ii)
mesh.write(fname_in, io='auto')
else:
fname_in = ii
print('writing %s...' % fname_out)
gen_shot(fname_in, fname_out)
示例5: test_refine_3_8
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def test_refine_3_8(self):
mesh = Mesh.from_file(data_dir + '/meshes/elements/3_8_1.mesh')
domain = refine(FEDomain('domain', mesh), self.options.out_dir, 1)
ok = compare_mesh('3_8', domain.mesh.coors, domain.mesh.get_conn('3_8'))
return ok
示例6: test_read_meshes
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def test_read_meshes(self):
"""Try to read all listed meshes."""
from sfepy.discrete.fem import Mesh
conf_dir = op.dirname(__file__)
meshes = {}
for ii, filename in enumerate(filename_meshes):
self.report("%d. mesh: %s" % (ii + 1, filename))
mesh = Mesh.from_file(filename, prefix_dir=conf_dir)
assert_(mesh.dim == (mesh.coors.shape[1]))
assert_(mesh.n_nod == (mesh.coors.shape[0]))
assert_(mesh.n_nod == (mesh.ngroups.shape[0]))
assert_(mesh.n_el == sum(mesh.n_els))
for ig, conn in enumerate(mesh.conns):
assert_(conn.shape[0] == len(mesh.mat_ids[ig]))
assert_(conn.shape[0] == mesh.n_els[ig])
assert_(conn.shape[1] == mesh.n_e_ps[ig])
self.report("read ok")
meshes[filename] = mesh
self.meshes = meshes
return True
示例7: main
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def main():
parser = ArgumentParser(description=__doc__.rstrip(),
formatter_class=RawDescriptionHelpFormatter)
parser.add_argument('filename', help=helps['filename'])
parser.add_argument('-d', '--detailed',
action='store_true', dest='detailed',
default=False, help=helps['detailed'])
options = parser.parse_args()
mesh = Mesh.from_file(options.filename)
output(mesh.cmesh)
output('element types:', mesh.descs)
output('nodal BCs:', sorted(mesh.nodal_bcs.keys()))
bbox = mesh.get_bounding_box()
output('bounding box: %s'
% ', '.join('%s: [%s, %s]' % (name, bbox[0, ii], bbox[1, ii])
for ii, name in enumerate('xyz'[:mesh.dim])))
output('centre:', mesh.coors.mean(0))
if not options.detailed: return
from sfepy.discrete.fem.geometry_element import create_geometry_elements
gels = create_geometry_elements()
mesh.cmesh.set_local_entities(gels)
mesh.cmesh.setup_entities()
for dim in range(1, mesh.cmesh.tdim + 1):
volumes = mesh.cmesh.get_volumes(dim)
output('volumes of %d %dD entities: min: %s mean: %s max: %s'
% (mesh.cmesh.num[dim],
dim, volumes.min(), volumes.mean(), volumes.max()))
示例8: from_conf
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def from_conf(conf, options):
import sfepy
from sfepy.discrete.fem import Mesh, Domain, Field
mesh = Mesh.from_file('meshes/2d/rectangle_tri.mesh',
prefix_dir=sfepy.data_dir)
domain = Domain('domain', mesh)
dim = domain.shape.dim
min_x, max_x = domain.get_mesh_bounding_box()[:,0]
eps = 1e-8 * (max_x - min_x)
omega = domain.create_region('Omega', 'all')
gamma1 = domain.create_region('Gamma1',
'vertices in x < %.10f' % (min_x + eps),
'facet')
gamma2 = domain.create_region('Gamma2',
'vertices in x > %.10f' % (max_x - eps),
'facet')
field = Field.from_args('fu', nm.float64, 'vector', omega,
approx_order=2)
test = Test(conf=conf, options=options, dim=dim,
omega=omega, gamma1=gamma1, gamma2=gamma2,
field=field)
return test
示例9: test_rcm
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def test_rcm(self):
from sfepy import data_dir
from sfepy.linalg import rcm, permute_in_place, save_sparse_txt
from sfepy.discrete.fem import Mesh
filename = data_dir + '/meshes/2d/special/square_triquad.mesh'
self.report('testing reversed Cuthill-McKee permutation')
conf_dir = op.dirname(__file__)
mesh = Mesh.from_file(filename, prefix_dir=conf_dir)
graph = mesh.create_conn_graph()
graph0 = graph.copy()
save_sparse_txt(op.join(self.options.out_dir, 'test_rcm_graph_orig'),
graph, fmt='%d %d %d\n')
perm = rcm(graph)
permute_in_place(graph, perm)
save_sparse_txt(op.join(self.options.out_dir, 'test_rcm_graph_rcm'),
graph, fmt='%d %d %d\n')
assert_((graph0.indptr != graph.indptr).any())
assert_((graph0.indices != graph.indices).any())
permute_in_place(graph, perm, inverse=True)
save_sparse_txt(op.join(self.options.out_dir, 'test_rcm_graph_rcm_inv'),
graph, fmt='%d %d %d\n')
assert_((graph0.indptr == graph.indptr).all())
assert_((graph0.indices == graph.indices).all())
return True
示例10: refine_mesh
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def refine_mesh(filename, level):
"""
Uniformly refine `level`-times a mesh given by `filename`.
The refined mesh is saved to a file with name constructed from base
name of `filename` and `level`-times appended `'_r'` suffix.
Parameters
----------
filename : str
The mesh file name.
level : int
The refinement level.
"""
import os
from sfepy.base.base import output
from sfepy.discrete.fem import Mesh, FEDomain
if level > 0:
mesh = Mesh.from_file(filename)
domain = FEDomain(mesh.name, mesh)
for ii in range(level):
output('refine %d...' % ii)
domain = domain.refine()
output('... %d nodes %d elements'
% (domain.shape.n_nod, domain.shape.n_el))
suffix = os.path.splitext(filename)[1]
filename = domain.name + suffix
domain.mesh.write(filename, io='auto')
return filename
示例11: main
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def main():
parser = ArgumentParser(description=__doc__)
parser.add_argument('--version', action='version', version='%(prog)s')
parser.add_argument('--eps', action='store', dest='eps',
default=1e-12, help=helps['eps'])
parser.add_argument('-o', '--filename-out',
action='store', dest='filename_out',
default=None, help=helps['filename-out'])
parser.add_argument('filename')
options = parser.parse_args()
filename = options.filename
mesh = Mesh.from_file(filename)
mesh_out = extract_edges(mesh, eps=float(options.eps))
mesh_out = merge_lines(mesh_out)
filename_out = options.filename_out
if filename_out is None:
filename_out = edit_filename(filename, prefix='edge_', new_ext='.vtk')
output('Outline mesh - vertices: %d, edges: %d, output filename: %s'
% (mesh_out[0].shape[0], mesh_out[2][0].shape[0], filename_out))
# hack to write '3_2' elements - edges
io = VTKMeshIO(None)
aux_mesh = Struct()
aux_mesh._get_io_data = lambda: mesh_out
aux_mesh.n_el = mesh_out[2][0].shape[0]
io.write(filename_out, aux_mesh)
示例12: test_spbox_2d
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def test_spbox_2d(self):
"""
Check position of a given vertex in the deformed mesh.
"""
mesh = Mesh.from_file(data_dir + '/meshes/2d/square_tri1.mesh')
spb = SplineBox([[-1, 1], [-1, 0.6]], mesh.coors, nsg=[2,1])
spb.move_control_point(1, [0.1, -0.2])
spb.move_control_point(2, [0.2, -0.3])
spb.move_control_point(3, [0.0, -0.1])
pt0 = mesh.coors[175,:].copy()
mesh.cmesh.coors[:] = spb.evaluate()
pt1 = mesh.coors[175,:]
expected_distance = 0.165892726387
actual_distance = nm.linalg.norm(pt0 - pt1)
ok = nm.fabs(actual_distance - expected_distance)\
/ expected_distance < tolerance
if not ok:
self.report('expected distance:')
self.report(expected_distance)
self.report('actual distance:')
self.report(actual_distance)
return ok
示例13: main
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def main():
parser = ArgumentParser(description=__doc__)
parser.add_argument('--version', action='version', version='%(prog)s')
parser.add_argument('filename')
options = parser.parse_args()
filename = options.filename
mesh = Mesh.from_file(filename)
output('Mesh:')
output(' dimension: %d, vertices: %d, elements: %d'
% (mesh.dim, mesh.n_nod, mesh.n_el))
domain = FEDomain('domain', mesh)
output(domain.cmesh)
domain.cmesh.cprint(1)
dim = domain.cmesh.dim
entities_opts = [
{'color' : 'k', 'label_global' : 12, 'label_local' : 8},
{'color' : 'b', 'label_global' : 12, 'label_local' : 8},
{'color' : 'g', 'label_global' : 12, 'label_local' : 8},
{'color' : 'r', 'label_global' : 12},
]
if dim == 2: entities_opts.pop(2)
pc.plot_cmesh(None, domain.cmesh,
wireframe_opts = {'color' : 'k'},
entities_opts=entities_opts)
plt.show()
示例14: main
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def main():
parser = ArgumentParser(description=__doc__,
formatter_class=RawDescriptionHelpFormatter)
parser.add_argument('mesh_dir')
options = parser.parse_args()
mesh_dir = options.mesh_dir
mesh_files = []
for (dirpath, dirnames, filenames) in os.walk(mesh_dir):
for ii in filenames:
_, ext = os.path.splitext(ii)
if ext.lower() in ['.mesh', '.vtk']:
mesh_files.append(dirpath + os.path.sep + ii)
for ii in mesh_files:
base, ext = os.path.splitext(ii)
fname_out = base + '.png'
if ext == '.mesh':
fname_in = 'aux.vtk'
mesh = Mesh.from_file(ii)
mesh.write(fname_in, io='auto')
else:
fname_in = ii
print(('writing %s...' % fname_out))
gen_shot(fname_in, fname_out)
示例15: main
# 需要导入模块: from sfepy.discrete.fem import Mesh [as 别名]
# 或者: from sfepy.discrete.fem.Mesh import from_file [as 别名]
def main():
parser = ArgumentParser(description=__doc__.rstrip(),
formatter_class=RawDescriptionHelpFormatter)
parser.add_argument('filename', help=helps['filename'])
parser.add_argument('-d', '--detailed',
action='store_true', dest='detailed',
default=False, help=helps['detailed'])
options = parser.parse_args()
mesh = Mesh.from_file(options.filename)
output(mesh.cmesh)
output('element types:', mesh.descs)
output('nodal BCs:', sorted(mesh.nodal_bcs.keys()))
bbox = mesh.get_bounding_box()
output('bounding box:\n%s'
% '\n'.join('%s: [%14.7e, %14.7e]' % (name, bbox[0, ii], bbox[1, ii])
for ii, name in enumerate('xyz'[:mesh.dim])))
output('centre: [%s]'
% ', '.join('%14.7e' % ii for ii in 0.5 * (bbox[0] + bbox[1])))
output('coordinates mean: [%s]'
% ', '.join('%14.7e' % ii for ii in mesh.coors.mean(0)))
if not options.detailed: return
domain = FEDomain(mesh.name, mesh)
for dim in range(1, mesh.cmesh.tdim + 1):
volumes = mesh.cmesh.get_volumes(dim)
output('volumes of %d %dD entities:\nmin: %.7e mean: %.7e median:'
' %.7e max: %.7e'
% (mesh.cmesh.num[dim], dim, volumes.min(), volumes.mean(),
nm.median(volumes), volumes.max()))
euler = lambda mesh: nm.dot(mesh.cmesh.num, [1, -1, 1, -1])
ec = euler(mesh)
output('Euler characteristic:', ec)
graph = mesh.create_conn_graph(verbose=False)
n_comp, _ = graph_components(graph.shape[0], graph.indptr, graph.indices)
output('number of connected components:', n_comp)
if mesh.dim > 1:
region = domain.create_region('surf', 'vertices of surface', 'facet')
surf_mesh = Mesh.from_region(region, mesh,
localize=True, is_surface=True)
FEDomain(surf_mesh.name, surf_mesh) # Calls CMesh.setup_entities().
sec = euler(surf_mesh)
output('surface Euler characteristic:', sec)
if mesh.dim == 3:
output('surface genus:', (2.0 - sec) / 2.0)
surf_graph = surf_mesh.create_conn_graph(verbose=False)
n_comp, _ = graph_components(surf_graph.shape[0],
surf_graph.indptr, surf_graph.indices)
output('number of connected surface components:', n_comp)