本文整理汇总了Python中sfepy.discrete.Problem.update_materials方法的典型用法代码示例。如果您正苦于以下问题:Python Problem.update_materials方法的具体用法?Python Problem.update_materials怎么用?Python Problem.update_materials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfepy.discrete.Problem
的用法示例。
在下文中一共展示了Problem.update_materials方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evalValAndDeriv
# 需要导入模块: from sfepy.discrete import Problem [as 别名]
# 或者: from sfepy.discrete.Problem import update_materials [as 别名]
def evalValAndDeriv(D):
m = Material('m', D = D, rho = 2700.0)
integral = Integral('i', order=2)
t1 = Term.new('dw_lin_elastic(m.D, v, u)', integral, omega, m=m, v=v, u=u)
t2 = Term.new('dw_volume_dot(m.rho, v, u)', integral, omega, m=m, v=v, u=u)
eq1 = Equation('stiffness', t1)
eq2 = Equation('mass', t2)
lhs_eqs = Equations([eq1, eq2])
pb = Problem('modal', equations = lhs_eqs)
pb.time_update()
n_rbm = dim * (dim + 1) / 2
pb.update_materials()
# Assemble stiffness and mass matrices.
mtx_k = eq1.evaluate(mode='weak', dw_mode='matrix', asm_obj=pb.mtx_a)
mtx_m = mtx_k.copy()
mtx_m.data[:] = 0.0
mtx_m = eq2.evaluate(mode='weak', dw_mode='matrix', asm_obj=mtx_m)
eigs0, evecs0 = scipy.sparse.linalg.eigsh(mtx_k, k = 10, M = mtx_m, which = 'SM')
eigs = eigs0[3:]
evecs = evecs0[:, 3:]
dydmu = numpy.array([evecs[:, i].T.dot(dKdmu.dot(evecs[:, i])) for i in range(evecs.shape[1])])
dydlambda = numpy.array([evecs[:, i].T.dot(dKdlambda.dot(evecs[:, i])) for i in range(evecs.shape[1])])
return eigs, dydmu, dydlambda
示例2: assemble
# 需要导入模块: from sfepy.discrete import Problem [as 别名]
# 或者: from sfepy.discrete.Problem import update_materials [as 别名]
def assemble(mtx_d):
m = Material('m', D=mtx_d, rho=density)
integral = Integral('i', order=2 * order)
t1 = Term.new('dw_lin_elastic(m.D, v, u)', integral, omega, m=m, v=v, u=u)
t2 = Term.new('dw_volume_dot(m.rho, v, u)', integral, omega, m=m, v=v, u=u)
eq1 = Equation('stiffness', t1)
eq2 = Equation('mass', t2)
lhs_eqs = Equations([eq1, eq2])
pb = Problem('modal', equations=lhs_eqs)
pb.time_update()
n_rbm = dim * (dim + 1) / 2
pb.update_materials()
tmp = time.time()
# Assemble stiffness and mass matrices.
mtx_k = eq1.evaluate(mode='weak', dw_mode='matrix', asm_obj=pb.mtx_a)
mtx_m = mtx_k.copy()
mtx_m.data[:] = 0.0
mtx_m = eq2.evaluate(mode='weak', dw_mode='matrix', asm_obj=mtx_m)
return mtx_k, mtx_m
示例3: main
# 需要导入模块: from sfepy.discrete import Problem [as 别名]
# 或者: from sfepy.discrete.Problem import update_materials [as 别名]
#.........这里部分代码省略.........
m = Material('m', D=mtx_d, rho=options.density)
integral = Integral('i', order=2*options.order)
t1 = Term.new('dw_lin_elastic(m.D, v, u)', integral, omega, m=m, v=v, u=u)
t2 = Term.new('dw_volume_dot(m.rho, v, u)', integral, omega, m=m, v=v, u=u)
eq1 = Equation('stiffness', t1)
eq2 = Equation('mass', t2)
lhs_eqs = Equations([eq1, eq2])
pb = Problem('modal', equations=lhs_eqs)
if options.bc_kind == 'free':
pb.time_update()
n_rbm = dim * (dim + 1) / 2
elif options.bc_kind == 'cantilever':
fixed = EssentialBC('Fixed', bottom, {'u.all' : 0.0})
pb.time_update(ebcs=Conditions([fixed]))
n_rbm = 0
elif options.bc_kind == 'fixed':
fixed = EssentialBC('Fixed', bottom_top, {'u.all' : 0.0})
pb.time_update(ebcs=Conditions([fixed]))
n_rbm = 0
else:
raise ValueError('unsupported BC kind! (%s)' % options.bc_kind)
if options.ignore is not None:
n_rbm = options.ignore
pb.update_materials()
# Assemble stiffness and mass matrices.
mtx_k = eq1.evaluate(mode='weak', dw_mode='matrix', asm_obj=pb.mtx_a)
mtx_m = mtx_k.copy()
mtx_m.data[:] = 0.0
mtx_m = eq2.evaluate(mode='weak', dw_mode='matrix', asm_obj=mtx_m)
try:
eigs, svecs = eig_solver(mtx_k, mtx_m, options.n_eigs + n_rbm,
eigenvectors=True)
except sla.ArpackNoConvergence as ee:
eigs = ee.eigenvalues
svecs = ee.eigenvectors
output('only %d eigenvalues converged!' % len(eigs))
output('%d eigenvalues converged (%d ignored as rigid body modes)' %
(len(eigs), n_rbm))
eigs = eigs[n_rbm:]
svecs = svecs[:, n_rbm:]
omegas = nm.sqrt(eigs)
freqs = omegas / (2 * nm.pi)
output('number | eigenvalue | angular frequency '
'| frequency')
for ii, eig in enumerate(eigs):
output('%6d | %17.12e | %17.12e | %17.12e'
% (ii + 1, eig, omegas[ii], freqs[ii]))
# Make full eigenvectors (add DOFs fixed by boundary conditions).
示例4: create_local_problem
# 需要导入模块: from sfepy.discrete import Problem [as 别名]
# 或者: from sfepy.discrete.Problem import update_materials [as 别名]
def create_local_problem(omega_gi, orders):
"""
Local problem definition using a domain corresponding to the global region
`omega_gi`.
"""
order_u, order_p = orders
mesh = omega_gi.domain.mesh
# All tasks have the whole mesh.
bbox = mesh.get_bounding_box()
min_x, max_x = bbox[:, 0]
eps_x = 1e-8 * (max_x - min_x)
min_y, max_y = bbox[:, 1]
eps_y = 1e-8 * (max_y - min_y)
mesh_i = Mesh.from_region(omega_gi, mesh, localize=True)
domain_i = FEDomain('domain_i', mesh_i)
omega_i = domain_i.create_region('Omega', 'all')
gamma1_i = domain_i.create_region('Gamma1',
'vertices in (x < %.10f)'
% (min_x + eps_x),
'facet', allow_empty=True)
gamma2_i = domain_i.create_region('Gamma2',
'vertices in (x > %.10f)'
% (max_x - eps_x),
'facet', allow_empty=True)
gamma3_i = domain_i.create_region('Gamma3',
'vertices in (y < %.10f)'
% (min_y + eps_y),
'facet', allow_empty=True)
field1_i = Field.from_args('fu', nm.float64, mesh.dim, omega_i,
approx_order=order_u)
field2_i = Field.from_args('fp', nm.float64, 1, omega_i,
approx_order=order_p)
output('field 1: number of local DOFs:', field1_i.n_nod)
output('field 2: number of local DOFs:', field2_i.n_nod)
u_i = FieldVariable('u_i', 'unknown', field1_i, order=0)
v_i = FieldVariable('v_i', 'test', field1_i, primary_var_name='u_i')
p_i = FieldVariable('p_i', 'unknown', field2_i, order=1)
q_i = FieldVariable('q_i', 'test', field2_i, primary_var_name='p_i')
if mesh.dim == 2:
alpha = 1e2 * nm.array([[0.132], [0.132], [0.092]])
else:
alpha = 1e2 * nm.array([[0.132], [0.132], [0.132],
[0.092], [0.092], [0.092]])
mat = Material('m', D=stiffness_from_lame(mesh.dim, lam=10, mu=5),
k=1, alpha=alpha)
integral = Integral('i', order=2*(max(order_u, order_p)))
t11 = Term.new('dw_lin_elastic(m.D, v_i, u_i)',
integral, omega_i, m=mat, v_i=v_i, u_i=u_i)
t12 = Term.new('dw_biot(m.alpha, v_i, p_i)',
integral, omega_i, m=mat, v_i=v_i, p_i=p_i)
t21 = Term.new('dw_biot(m.alpha, u_i, q_i)',
integral, omega_i, m=mat, u_i=u_i, q_i=q_i)
t22 = Term.new('dw_laplace(m.k, q_i, p_i)',
integral, omega_i, m=mat, q_i=q_i, p_i=p_i)
eq1 = Equation('eq1', t11 - t12)
eq2 = Equation('eq1', t21 + t22)
eqs = Equations([eq1, eq2])
ebc1 = EssentialBC('ebc1', gamma1_i, {'u_i.all' : 0.0})
ebc2 = EssentialBC('ebc2', gamma2_i, {'u_i.0' : 0.05})
def bc_fun(ts, coors, **kwargs):
val = 0.3 * nm.sin(4 * nm.pi * (coors[:, 0] - min_x) / (max_x - min_x))
return val
fun = Function('bc_fun', bc_fun)
ebc3 = EssentialBC('ebc3', gamma3_i, {'p_i.all' : fun})
pb = Problem('problem_i', equations=eqs, active_only=False)
pb.time_update(ebcs=Conditions([ebc1, ebc2, ebc3]))
pb.update_materials()
return pb
示例5: create_local_problem
# 需要导入模块: from sfepy.discrete import Problem [as 别名]
# 或者: from sfepy.discrete.Problem import update_materials [as 别名]
def create_local_problem(omega_gi, order):
"""
Local problem definition using a domain corresponding to the global region
`omega_gi`.
"""
mesh = omega_gi.domain.mesh
# All tasks have the whole mesh.
bbox = mesh.get_bounding_box()
min_x, max_x = bbox[:, 0]
eps_x = 1e-8 * (max_x - min_x)
mesh_i = Mesh.from_region(omega_gi, mesh, localize=True)
domain_i = FEDomain('domain_i', mesh_i)
omega_i = domain_i.create_region('Omega', 'all')
gamma1_i = domain_i.create_region('Gamma1',
'vertices in (x < %.10f)'
% (min_x + eps_x),
'facet', allow_empty=True)
gamma2_i = domain_i.create_region('Gamma2',
'vertices in (x > %.10f)'
% (max_x - eps_x),
'facet', allow_empty=True)
field_i = Field.from_args('fu', nm.float64, 1, omega_i,
approx_order=order)
output('number of local field DOFs:', field_i.n_nod)
u_i = FieldVariable('u_i', 'unknown', field_i)
v_i = FieldVariable('v_i', 'test', field_i, primary_var_name='u_i')
integral = Integral('i', order=2*order)
mat = Material('m', lam=10, mu=5)
t1 = Term.new('dw_laplace(m.lam, v_i, u_i)',
integral, omega_i, m=mat, v_i=v_i, u_i=u_i)
def _get_load(coors):
val = nm.ones_like(coors[:, 0])
for coor in coors.T:
val *= nm.sin(4 * nm.pi * coor)
return val
def get_load(ts, coors, mode=None, **kwargs):
if mode == 'qp':
return {'val' : _get_load(coors).reshape(coors.shape[0], 1, 1)}
load = Material('load', function=Function('get_load', get_load))
t2 = Term.new('dw_volume_lvf(load.val, v_i)',
integral, omega_i, load=load, v_i=v_i)
eq = Equation('balance', t1 - 100 * t2)
eqs = Equations([eq])
ebc1 = EssentialBC('ebc1', gamma1_i, {'u_i.all' : 0.0})
ebc2 = EssentialBC('ebc2', gamma2_i, {'u_i.all' : 0.1})
pb = Problem('problem_i', equations=eqs, active_only=False)
pb.time_update(ebcs=Conditions([ebc1, ebc2]))
pb.update_materials()
return pb
示例6: Material
# 需要导入模块: from sfepy.discrete import Problem [as 别名]
# 或者: from sfepy.discrete.Problem import update_materials [as 别名]
m = Material('m', D = D, rho = 2700.0)
integral = Integral('i', order=2)
t1 = Term.new('dw_lin_elastic(m.D, v, u)', integral, omega, m=m, v=v, u=u)
t2 = Term.new('dw_volume_dot(m.rho, v, u)', integral, omega, m=m, v=v, u=u)
eq1 = Equation('stiffness', t1)
eq2 = Equation('mass', t2)
lhs_eqs = Equations([eq1, eq2])
pb = Problem('modal', equations = lhs_eqs)
pb.time_update()
n_rbm = dim * (dim + 1) / 2
pb.update_materials()
# Assemble stiffness and mass matrices.
mtx_k = eq1.evaluate(mode='weak', dw_mode='matrix', asm_obj=pb.mtx_a)
mtx_m = mtx_k.copy()
mtx_m.data[:] = 0.0
mtx_m = eq2.evaluate(mode='weak', dw_mode='matrix', asm_obj=mtx_m)
Ks.append(mtx_k)
Ms.append(mtx_m)
dKdmu = Ks[0]# (Ks[1] - Ks[0]) / (mu1 - mu0)
dKdlambda = Ks[1]# (Ks[3] - Ks[2]) / (lambda1 - lambda0)
print dKdmu
#print Ks[-1]
#%%
示例7: create_local_problem
# 需要导入模块: from sfepy.discrete import Problem [as 别名]
# 或者: from sfepy.discrete.Problem import update_materials [as 别名]
def create_local_problem(omega_gi, orders):
"""
Local problem definition using a domain corresponding to the global region
`omega_gi`.
"""
order_u, order_p = orders
mesh = omega_gi.domain.mesh
# All tasks have the whole mesh.
bbox = mesh.get_bounding_box()
min_x, max_x = bbox[:, 0]
eps_x = 1e-8 * (max_x - min_x)
min_y, max_y = bbox[:, 1]
eps_y = 1e-8 * (max_y - min_y)
mesh_i = Mesh.from_region(omega_gi, mesh, localize=True)
domain_i = FEDomain("domain_i", mesh_i)
omega_i = domain_i.create_region("Omega", "all")
gamma1_i = domain_i.create_region("Gamma1", "vertices in (x < %.10f)" % (min_x + eps_x), "facet", allow_empty=True)
gamma2_i = domain_i.create_region("Gamma2", "vertices in (x > %.10f)" % (max_x - eps_x), "facet", allow_empty=True)
gamma3_i = domain_i.create_region("Gamma3", "vertices in (y < %.10f)" % (min_y + eps_y), "facet", allow_empty=True)
field1_i = Field.from_args("fu", nm.float64, mesh.dim, omega_i, approx_order=order_u)
field2_i = Field.from_args("fp", nm.float64, 1, omega_i, approx_order=order_p)
output("field 1: number of local DOFs:", field1_i.n_nod)
output("field 2: number of local DOFs:", field2_i.n_nod)
u_i = FieldVariable("u_i", "unknown", field1_i, order=0)
v_i = FieldVariable("v_i", "test", field1_i, primary_var_name="u_i")
p_i = FieldVariable("p_i", "unknown", field2_i, order=1)
q_i = FieldVariable("q_i", "test", field2_i, primary_var_name="p_i")
if mesh.dim == 2:
alpha = 1e2 * nm.array([[0.132], [0.132], [0.092]])
else:
alpha = 1e2 * nm.array([[0.132], [0.132], [0.132], [0.092], [0.092], [0.092]])
mat = Material("m", lam=10, mu=5, k=1, alpha=alpha)
integral = Integral("i", order=2 * (max(order_u, order_p)))
t11 = Term.new("dw_lin_elastic_iso(m.lam, m.mu, v_i, u_i)", integral, omega_i, m=mat, v_i=v_i, u_i=u_i)
t12 = Term.new("dw_biot(m.alpha, v_i, p_i)", integral, omega_i, m=mat, v_i=v_i, p_i=p_i)
t21 = Term.new("dw_biot(m.alpha, u_i, q_i)", integral, omega_i, m=mat, u_i=u_i, q_i=q_i)
t22 = Term.new("dw_laplace(m.k, q_i, p_i)", integral, omega_i, m=mat, q_i=q_i, p_i=p_i)
eq1 = Equation("eq1", t11 - t12)
eq2 = Equation("eq1", t21 + t22)
eqs = Equations([eq1, eq2])
ebc1 = EssentialBC("ebc1", gamma1_i, {"u_i.all": 0.0})
ebc2 = EssentialBC("ebc2", gamma2_i, {"u_i.0": 0.05})
def bc_fun(ts, coors, **kwargs):
val = 0.3 * nm.sin(4 * nm.pi * (coors[:, 0] - min_x) / (max_x - min_x))
return val
fun = Function("bc_fun", bc_fun)
ebc3 = EssentialBC("ebc3", gamma3_i, {"p_i.all": fun})
pb = Problem("problem_i", equations=eqs, active_only=False)
pb.time_update(ebcs=Conditions([ebc1, ebc2, ebc3]))
pb.update_materials()
return pb