本文整理汇总了Python中sfepy.discrete.fem.FEDomain类的典型用法代码示例。如果您正苦于以下问题:Python FEDomain类的具体用法?Python FEDomain怎么用?Python FEDomain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FEDomain类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_bqp
def _get_bqp(geometry, order):
from sfepy.discrete import Integral
from sfepy.discrete.fem.geometry_element import GeometryElement
from sfepy.discrete.fem import Mesh, FEDomain, Field
gel = GeometryElement(geometry)
mesh = Mesh.from_data('aux', gel.coors, None,
[gel.conn[None, :]], [[0]], [geometry])
domain = FEDomain('domain', mesh)
omega = domain.create_region('Omega', 'all')
surf = domain.create_region('Surf', 'vertices of surface', 'facet')
field = Field.from_args('f', nm.float64, shape=1,
region=omega, approx_order=1)
field.setup_surface_data(surf)
integral = Integral('aux', order=order)
field.create_bqp('Surf', integral)
sd = field.surface_data['Surf']
qp = field.qp_coors[(integral.order, sd.bkey)]
output('geometry:', geometry, 'order:', order, 'num. points:',
qp.vals.shape[1], 'true_order:',
integral.qps[gel.surface_facet_name].order)
output('min. weight:', qp.weights.min())
output('max. weight:', qp.weights.max())
return (gel, qp.vals.reshape((-1, mesh.dim)),
nm.tile(qp.weights, qp.vals.shape[0]))
开发者ID:rc,项目名称:sfepy,代码行数:30,代码来源:plot_quadrature.py
示例2: from_conf
def from_conf(conf, options):
import sfepy
from sfepy.discrete.fem import Mesh, FEDomain, Field
mesh = Mesh.from_file('meshes/2d/rectangle_tri.mesh',
prefix_dir=sfepy.data_dir)
domain = FEDomain('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
开发者ID:Nasrollah,项目名称:sfepy,代码行数:26,代码来源:test_high_level.py
示例3: refine_mesh
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
开发者ID:Nasrollah,项目名称:sfepy,代码行数:33,代码来源:utils.py
示例4: main
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)
开发者ID:lokik,项目名称:sfepy,代码行数:59,代码来源:show_mesh_info.py
示例5: refine_region
def refine_region(domain0, region0, region1):
"""
Coarse cell sub_cells[ii, 0] in mesh0 is split into sub_cells[ii, 1:] in
mesh1.
The new fine cells are interleaved among the original coarse cells so that
the indices of the coarse cells do not change.
The cell groups are preserved. The vertex groups are preserved only in the
coarse (non-refined) cells.
"""
if region1 is None:
return domain0, None
mesh0 = domain0.mesh
mesh1 = Mesh.from_region(region1, mesh0)
domain1 = FEDomain('d', mesh1)
domain1r = domain1.refine()
mesh1r = domain1r.mesh
n_cell = region1.shape.n_cell
n_sub = 4 if mesh0.cmesh.tdim == 2 else 8
sub_cells = nm.empty((n_cell, n_sub + 1), dtype=nm.uint32)
sub_cells[:, 0] = region1.cells
sub_cells[:, 1] = region1.cells
aux = nm.arange((n_sub - 1) * n_cell, dtype=nm.uint32)
sub_cells[:, 2:] = mesh0.n_el + aux.reshape((n_cell, -1))
coors0, vgs0, conns0, mat_ids0, descs0 = mesh0._get_io_data()
coors, vgs, _conns, _mat_ids, descs = mesh1r._get_io_data()
# Preserve vertex groups of non-refined cells.
vgs[:len(vgs0)] = vgs0
def _interleave_refined(c0, c1):
if c1.ndim == 1:
c0 = c0[:, None]
c1 = c1[:, None]
n_row, n_col = c1.shape
n_new = region0.shape.n_cell + n_row
out = nm.empty((n_new, n_col), dtype=c0.dtype)
out[region0.cells] = c0[region0.cells]
out[region1.cells] = c1[::n_sub]
aux = c1.reshape((-1, n_col * n_sub))
out[mesh0.n_el:] = aux[:, n_col:].reshape((-1, n_col))
return out
conn = _interleave_refined(conns0[0], _conns[0])
mat_id = _interleave_refined(mat_ids0[0], _mat_ids[0]).squeeze()
mesh = Mesh.from_data('a', coors, vgs, [conn], [mat_id], descs)
domain = FEDomain('d', mesh)
return domain, sub_cells
开发者ID:clazaro,项目名称:sfepy,代码行数:58,代码来源:refine_hanging.py
示例6: test_projection_iga_fem
def test_projection_iga_fem(self):
from sfepy.discrete import FieldVariable
from sfepy.discrete.fem import FEDomain, Field
from sfepy.discrete.iga.domain import IGDomain
from sfepy.mesh.mesh_generators import gen_block_mesh
from sfepy.discrete.iga.domain_generators import gen_patch_block_domain
from sfepy.discrete.projections import (make_l2_projection,
make_l2_projection_data)
shape = [10, 12, 12]
dims = [5, 6, 6]
centre = [0, 0, 0]
degrees = [2, 2, 2]
nurbs, bmesh, regions = gen_patch_block_domain(dims, shape, centre,
degrees,
cp_mode='greville',
name='iga')
ig_domain = IGDomain('iga', nurbs, bmesh, regions=regions)
ig_omega = ig_domain.create_region('Omega', 'all')
ig_field = Field.from_args('iga', nm.float64, 1, ig_omega,
approx_order='iga', poly_space_base='iga')
ig_u = FieldVariable('ig_u', 'parameter', ig_field,
primary_var_name='(set-to-None)')
mesh = gen_block_mesh(dims, shape, centre, name='fem')
fe_domain = FEDomain('fem', mesh)
fe_omega = fe_domain.create_region('Omega', 'all')
fe_field = Field.from_args('fem', nm.float64, 1, fe_omega,
approx_order=2)
fe_u = FieldVariable('fe_u', 'parameter', fe_field,
primary_var_name='(set-to-None)')
def _eval_data(ts, coors, mode, **kwargs):
return nm.prod(coors**2, axis=1)[:, None, None]
make_l2_projection_data(ig_u, _eval_data)
make_l2_projection(fe_u, ig_u) # This calls ig_u.evaluate_at().
coors = 0.5 * nm.random.rand(20, 3) * dims
ig_vals = ig_u.evaluate_at(coors)
fe_vals = fe_u.evaluate_at(coors)
ok = nm.allclose(ig_vals, fe_vals, rtol=0.0, atol=1e-12)
if not ok:
self.report('iga-fem projection failed!')
self.report('coors:')
self.report(coors)
self.report('iga fem diff:')
self.report(nm.c_[ig_vals, fe_vals, nm.abs(ig_vals - fe_vals)])
return ok
开发者ID:Nasrollah,项目名称:sfepy,代码行数:56,代码来源:test_projections.py
示例7: from_conf
def from_conf(conf, options):
mesh = Mesh.from_file('meshes/2d/square_unit_tri.mesh',
prefix_dir=sfepy.data_dir)
domain = FEDomain('domain', mesh)
omega = domain.create_region('Omega', 'all')
field = Field.from_args('linear', nm.float64, 'scalar', omega,
approx_order=1)
test = Test(conf=conf, options=options, omega=omega, field=field)
return test
开发者ID:LeiDai,项目名称:sfepy,代码行数:12,代码来源:test_projections.py
示例8: test_interpolation_two_meshes
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
开发者ID:clazaro,项目名称:sfepy,代码行数:53,代码来源:test_mesh_interp.py
示例9: test_normals
def test_normals(self):
"""
Check orientations of surface normals on the reference elements.
"""
import sfepy
from sfepy.discrete import Integral
from sfepy.discrete.fem import Mesh, FEDomain
from sfepy.discrete.fem.poly_spaces import PolySpace
from sfepy.discrete.fem.mappings import SurfaceMapping
from sfepy.linalg import normalize_vectors
ok = True
for geom in ['2_3', '2_4', '3_4', '3_8']:
mesh = Mesh.from_file('meshes/elements/%s_1.mesh' % geom,
prefix_dir=sfepy.data_dir)
domain = FEDomain('domain', mesh)
surface = domain.create_region('Surface', 'vertices of surface',
'facet')
domain.create_surface_group(surface)
sd = domain.surface_groups[surface.name]
coors = domain.get_mesh_coors()
gel = domain.geom_els[geom].surface_facet
ps = PolySpace.any_from_args('aux', gel, 1)
mapping = SurfaceMapping(coors, sd.get_connectivity(), ps)
integral = Integral('i', order=1)
vals, weights = integral.get_qp(gel.name)
# Evaluate just in the first quadrature point...
geo = mapping.get_mapping(vals[:1], weights[:1])
expected = expected_normals[geom].copy()
normalize_vectors(expected)
_ok = nm.allclose(expected, geo.normal[:, 0, :, 0],
rtol=0.0, atol=1e-14)
self.report('%s: %s' % (geom, _ok))
if not _ok:
self.report('expected:')
self.report(expected)
self.report('actual:')
self.report(geo.normal[:, 0, :, 0])
ok = ok and _ok
return ok
开发者ID:Nasrollah,项目名称:sfepy,代码行数:51,代码来源:test_normals.py
示例10: test_evaluate_at
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
开发者ID:lokik,项目名称:sfepy,代码行数:51,代码来源:test_mesh_interp.py
示例11: make_domain
def make_domain(dims, shape, transform=None):
"""
Generate a 2D rectangle domain in 3D space, define regions.
"""
xmin = (-0.5 + 1e-12) * dims[0]
xmax = (0.5 - 1e-12) * dims[0]
mesh = make_mesh(dims, shape, transform=transform)
domain = FEDomain('domain', mesh)
domain.create_region('Omega', 'all')
domain.create_region('Gamma1', 'vertices in (x < %.14f)' % xmin, 'facet')
domain.create_region('Gamma2', 'vertices in (x > %.14f)' % xmax, 'facet')
return domain
开发者ID:lokik,项目名称:sfepy,代码行数:14,代码来源:shell10x_cantilever_interactive.py
示例12: do_interpolation
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
开发者ID:clazaro,项目名称:sfepy,代码行数:47,代码来源:test_mesh_interp.py
示例13: test_invariance_qp
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
开发者ID:midhuniitm,项目名称:sfepy,代码行数:45,代码来源:test_mesh_interp.py
示例14: prepare_variable
def prepare_variable(filename, n_components):
from sfepy.discrete import FieldVariable
from sfepy.discrete.fem import Mesh, FEDomain, Field
mesh = Mesh.from_file(filename)
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])
domain = FEDomain("domain", mesh)
omega = domain.create_region("Omega", "all")
field = Field.from_args("field", nm.float64, n_components, omega, approx_order=2)
u = FieldVariable("u", "parameter", field, primary_var_name="(set-to-None)")
u.set_from_mesh_vertices(data * nm.arange(1, n_components + 1)[None, :])
return u
开发者ID:Gkdnz,项目名称:sfepy,代码行数:18,代码来源:test_mesh_interp.py
示例15: test_projection_tri_quad
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
开发者ID:LeiDai,项目名称:sfepy,代码行数:44,代码来源:test_projections.py
示例16: from_conf
def from_conf(conf, options):
from sfepy.discrete import Integral
from sfepy.discrete.fem import Mesh, FEDomain
domains = []
for filename in filename_meshes:
mesh = Mesh.from_file(filename)
domain = FEDomain('domain_%s' % mesh.name.replace(data_dir, ''),
mesh)
domain.create_region('Omega', 'all')
domain.create_region('Gamma', 'vertices of surface', 'facet')
domains.append(domain)
integral = Integral('i', order=3)
test = Test(domains=domains, integral=integral,
conf=conf, options=options)
return test
开发者ID:iostanin,项目名称:sfepy,代码行数:19,代码来源:test_term_call_modes.py
示例17: mesh_hook
def mesh_hook(mesh, mode):
"""
Load and refine a mesh here.
"""
if mode == 'read':
mesh = Mesh.from_file(base_mesh)
domain = FEDomain(mesh.name, mesh)
for ii in range(3):
output('refine %d...' % ii)
domain = domain.refine()
output('... %d nodes %d elements'
% (domain.shape.n_nod, domain.shape.n_el))
domain.mesh.name = '2_4_2_refined'
return domain.mesh
elif mode == 'write':
pass
开发者ID:Nasrollah,项目名称:sfepy,代码行数:19,代码来源:sinbc.py
示例18: prepare_variable
def prepare_variable(filename, n_components):
from sfepy.discrete import FieldVariable
from sfepy.discrete.fem import Mesh, FEDomain, Field
mesh = Mesh.from_file(filename)
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]))
domain = FEDomain('domain', mesh)
omega = domain.create_region('Omega', 'all')
field = Field.from_args('field', nm.float64, n_components, omega,
approx_order=2)
u = FieldVariable('u', 'parameter', field,
primary_var_name='(set-to-None)')
u.set_from_mesh_vertices(nm.c_[tuple([data] * n_components)])
return u
开发者ID:majnun1337,项目名称:sfepy,代码行数:21,代码来源:test_mesh_interp.py
示例19: test_entity_volumes
def test_entity_volumes(self):
import sfepy
from sfepy.discrete.fem import Mesh, FEDomain
from sfepy.discrete.common import Field
from sfepy.discrete import Integral
mesh = Mesh.from_file('meshes/3d/special/cross3d.mesh',
prefix_dir=sfepy.data_dir)
domain = FEDomain('domain', mesh)
omega = domain.create_region('Omega', 'all')
gamma = domain.create_region('Gamma', 'vertices of surface', 'facet')
top = domain.create_region('Top', 'cell 2')
vfield = Field.from_args('v', nm.float64, 'scalar', omega,
approx_order=1)
sfield = Field.from_args('s', nm.float64, 'scalar', gamma,
approx_order=1)
integral = Integral('i', order=3)
vgeo, _ = vfield.get_mapping(omega, integral, 'volume')
domain.create_surface_group(gamma)
sgeo, _ = sfield.get_mapping(gamma, integral, 'surface')
evols = mesh.cmesh.get_volumes(1)
fvols = mesh.cmesh.get_volumes(2) # Approximate for non-planar faces.
cvols = mesh.cmesh.get_volumes(3)
ok = True
_ok = abs(cvols.sum() - vgeo.volume.sum()) < 1e-15
self.report('total cell volume: %s (ok: %s)' % (cvols.sum(), _ok))
ok = _ok and ok
top_evols = nm.array([ 1. , 1. ,
1. , 1. ,
0.7211102550927979, 0.7211102550927979,
0.7211102550927979, 0.7211102550927979,
1.16619037896906 , 1.16619037896906 ,
1.16619037896906 , 1.16619037896906 ])
_ok = nm.allclose(top_evols, evols[top.edges], rtol=0.0, atol=1e-15)
self.report('total top cell edge length: %s (ok: %s)'
% (evols[top.edges].sum(), _ok))
ok = _ok and ok
i1 = [5, 6, 8, 9]
i2 = nm.setdiff1d(nm.arange(len(gamma.faces)), i1)
aux = fvols[gamma.faces] - sgeo.volume.ravel()
_ok = nm.allclose(aux[i1], 0.10560208437556773, rtol=0.0, atol=1e-15)
ok = _ok and ok
self.report('non-planar faces diff: %s (ok: %s)' % (aux[i1], _ok))
_ok = (nm.abs(aux[i2]) < 1e-15).all()
self.report('max. planar faces diff: %s (ok: %s)'
% (nm.abs(aux[i2]).max(), _ok))
ok = _ok and ok
return ok
开发者ID:clazaro,项目名称:sfepy,代码行数:59,代码来源:test_cmesh.py
示例20: main
def main():
parser = OptionParser(usage=usage)
parser.add_option('-s', '--scale', metavar='scale',
action='store', dest='scale',
default=None, help=help['scale'])
parser.add_option('-c', '--center', metavar='center',
action='store', dest='center',
default=None, help=help['center'])
parser.add_option('-r', '--refine', metavar='level',
action='store', type=int, dest='refine',
default=0, help=help['refine'])
parser.add_option('-f', '--format', metavar='format',
action='store', type='string', dest='format',
default=None, help=help['format'])
parser.add_option('-l', '--list', action='store_true',
dest='list', help=help['list'])
(options, args) = parser.parse_args()
if options.list:
output('Supported readable mesh formats:')
output('--------------------------------')
output_mesh_formats('r')
output('')
output('Supported writable mesh formats:')
output('--------------------------------')
output_mesh_formats('w')
sys.exit(0)
if len(args) != 2:
parser.print_help()
sys.exit(1)
scale = _parse_val_or_vec(options.scale, 'scale', parser)
center = _parse_val_or_vec(options.center, 'center', parser)
filename_in, filename_out = args
mesh = Mesh.from_file(filename_in)
if scale is not None:
if len(scale) == 1:
tr = nm.eye(mesh.dim, dtype=nm.float64) * scale
elif len(scale) == mesh.dim:
tr = nm.diag(scale)
else:
raise ValueError('bad scale! (%s)' % scale)
mesh.transform_coors(tr)
if center is not None:
cc = 0.5 * mesh.get_bounding_box().sum(0)
shift = center - cc
tr = nm.c_[nm.eye(mesh.dim, dtype=nm.float64), shift[:, None]]
mesh.transform_coors(tr)
if options.refine > 0:
domain = FEDomain(mesh.name, mesh)
output('initial mesh: %d nodes %d elements'
% (domain.shape.n_nod, domain.shape.n_el))
for ii in range(options.refine):
output('refine %d...' % ii)
domain = domain.refine()
output('... %d nodes %d elements'
% (domain.shape.n_nod, domain.shape.n_el))
mesh = domain.mesh
io = MeshIO.for_format(filename_out, format=options.format,
writable=True)
cell_types = ', '.join(supported_cell_types[io.format])
output('writing [%s] %s...' % (cell_types, filename_out))
mesh.write(filename_out, io=io)
output('...done')
开发者ID:Nasrollah,项目名称:sfepy,代码行数:74,代码来源:convert_mesh.py
注:本文中的sfepy.discrete.fem.FEDomain类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论