当前位置: 首页>>代码示例>>Python>>正文


Python Problem.get_materials方法代码示例

本文整理汇总了Python中sfepy.discrete.Problem.get_materials方法的典型用法代码示例。如果您正苦于以下问题:Python Problem.get_materials方法的具体用法?Python Problem.get_materials怎么用?Python Problem.get_materials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfepy.discrete.Problem的用法示例。


在下文中一共展示了Problem.get_materials方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from sfepy.discrete import Problem [as 别名]
# 或者: from sfepy.discrete.Problem import get_materials [as 别名]

#.........这里部分代码省略.........
    gamma5 = domain.create_region('Bottom',
                                  'vertices in z < %.10f' % (min_z + eps),
                                  'facet')
    gamma6 = domain.create_region('Top',
                                  'vertices in z > %.10f' % (max_z - eps),
                                  'facet')



    field = Field.from_args('fu', nm.float64, 'vector', omega, approx_order=2)

    u = FieldVariable('u', 'unknown', field)
    v = FieldVariable('v', 'test', field, primary_var_name='u')
    mu=1.1
    lam=1.0
    m = Material('m', lam=lam, mu=mu)
    f = Material('f', val=[[0.0], [0.0],[-1.0]])
    load = Material('Load',val=[[0.0],[0.0],[-Load]])

    D = stiffness_from_lame(3,lam, mu)
    mat = Material('Mat', D=D)

    get_mat = Function('get_mat1',get_mat1)
    get_mat_f = Function('get_mat_f',get_mat1)

    integral = Integral('i', order=3)
    s_integral = Integral('is',order=2)

    t1 = Term.new('dw_lin_elastic(Mat.D, v, u)',
         integral, omega, Mat=mat, v=v, u=u)
    t2 = Term.new('dw_volume_lvf(f.val, v)', integral, omega, f=f, v=v)
    #t3 = Term.new('DotProductSurfaceTerm(Load.val, v)',s_integral,gamma5,Load=load,v=v)
    t3 = Term.new('dw_surface_ltr( Load.val, v )',s_integral,gamma6,Load=load,v=v)
    eq = Equation('balance', t1 + t2 + t3)
    eqs = Equations([eq])

    fix_u = EssentialBC('fix_u', gamma1, {'u.all' : 0.0})
    left_bc  = EssentialBC('Left',  gamma1, {'u.0' : 0.0})
    right_bc = EssentialBC('Right', gamma2, {'u.0' : 0.0})
    back_bc = EssentialBC('Front', gamma3, {'u.1' : 0.0})
    front_bc = EssentialBC('Back', gamma4, {'u.1' : 0.0})
    bottom_bc = EssentialBC('Bottom', gamma5, {'u.all' : 0.0})
    top_bc = EssentialBC('Top', gamma6, {'u.2' : 0.2})

    bc=[left_bc,right_bc,back_bc,front_bc,bottom_bc]
    #bc=[bottom_bc,top_bc]


    ##############################
    #  ##### SOLVER SECTION  #####
    ##############################

    conf = Struct(method='bcgsl', precond='jacobi', sub_precond=None,
                  i_max=10000, eps_a=1e-50, eps_r=1e-10, eps_d=1e4,
                  verbose=True)

    ls = PETScKrylovSolver(conf)

    file.write(str(ls.name)+' '+str(ls.conf.method)+' '+str(ls.conf.precond)+' '+str(ls.conf.eps_r)+' '+str(ls.conf.i_max)+'\n' )

    nls_status = IndexedStruct()
    nls = Newton({'i_max':1,'eps_a':1e-10}, lin_solver=ls, status=nls_status)

    pb = Problem('elasticity', equations=eqs, nls=nls, ls=ls)

    dd=pb.get_materials()['Mat']
    dd.set_function(get_mat1)
    #xload = pb.get_materials()['f']
    #xload.set_function(get_mat_f)

    pb.save_regions_as_groups('regions')

    pb.time_update(ebcs=Conditions(bc))

    vec = pb.solve()
    print nls_status


    file.write('TIME TO SOLVE\n')
    file.write(str(nls.status.time_stats['solve'])+'\n')
    file.write('TIME TO CREATE MATRIX\n')
    file.write(str(nls.status.time_stats['matrix'])+'\n')

    ev = pb.evaluate
    out = vec.create_output_dict()
    strain = ev('ev_cauchy_strain.3.Omega(u)', mode='el_avg')
    stress = ev('ev_cauchy_stress.3.Omega(Mat.D, u)', mode='el_avg',
                copy_materials=False)

    out['cauchy_strain'] = Struct(name='output_data', mode='cell',
                                  data=strain, dofs=None)
    out['cauchy_stress'] = Struct(name='output_data', mode='cell',
                                  data=stress, dofs=None)

    pb.save_state('strain.vtk', out=out)

    print nls_status


    file.close()
开发者ID:adantra,项目名称:Arma_paper,代码行数:104,代码来源:Elasticity_paper.py

示例2: main

# 需要导入模块: from sfepy.discrete import Problem [as 别名]
# 或者: from sfepy.discrete.Problem import get_materials [as 别名]

#.........这里部分代码省略.........
                  i_max=10000, eps_a=1e-50, eps_r=1e-10, eps_d=1e4,
                  verbose=True)
                  #conf = Struct(method = 'cg', precond = 'icc', eps_r = 1e-10, i_max = 5000)
    ls = PETScKrylovSolver(conf)
#if hasattr(ls.name,'ls.scipy_iterative'):
    file.write(str(ls.name)+' '+str(ls.conf.method)+' '+str(ls.conf.precond)+' '+str(ls.conf.eps_r)+' '+str(ls.conf.i_max)+'\n' )
        #    else:
#file.write(str(ls.name)+' '+str(ls.conf.method)+'\n')



   
   
   # conf = Struct(method='bcgsl', precond='jacobi', sub_precond=None,
   #                 i_max=10000, eps_a=1e-50, eps_r=1e-8, eps_d=1e4,
#              verbose=True)
            
                 
                 
#ls = PETScKrylovSolver(conf)



#ls = ScipyIterative({'method':'bicgstab','i_max':100,'eps_r':1e-10})


    nls_status = IndexedStruct()
    nls = Newton({'i_max':1,'eps_a':1e-10}, lin_solver=ls, status=nls_status)

    pb = Problem('elasticity', equations=eqs, nls=nls, ls=ls)
    


    dd=pb.get_materials()['Mat']
    dd.set_function(get_mat1)
    
    
    pb.save_regions_as_groups('regions')

    #pb.time_update(ebcs=Conditions([fix_u, shift_u]))

    pb.time_update(ebcs=Conditions(bc))
    pb.save_regions_as_groups('regions')

#ls = ScipyIterative({'method':'bicgstab','i_max':100,'eps_r':1e-10})


#   A = pb.mtx_a
#   M = spilu(A,fill_factor = 1)
    
    #conf = Struct(solvers ='ScipyIterative',method='bcgsl', sub_precond=None,
# i_max=1000, eps_r=1e-8)
        
#pb.set_conf_solvers(conf)
    vec = pb.solve()
    print nls_status
    file.write('TIME TO SOLVE\n')
    file.write(str(nls.status.time_stats['solve'])+'\n')
    file.write('TIME TO CREATE MATRIX\n')
    file.write(str(nls.status.time_stats['matrix'])+'\n')
    #out = post_process(out, pb, state, extend=False)
    ev = pb.evaluate
    out = vec.create_output_dict()
    strain = ev('ev_cauchy_strain.3.Omega(u)', mode='el_avg')
    stress = ev('ev_cauchy_stress.3.Omega(Mat.D, u)', mode='el_avg',
                copy_materials=False)
开发者ID:adantra,项目名称:Arma_paper,代码行数:70,代码来源:linear_elastic.py


注:本文中的sfepy.discrete.Problem.get_materials方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。