mactavishcl 2020-10-05 10:53 采纳率: 0%
浏览 1804

怎么解决python maximum recursion depth exceeded while calling a Python object?

怎么解决python maximum recursion depth exceeded while calling a Python object

程序运行到for Pc in filter_pc:
update_phase_and_phys(OP_1.results(Pc=Pc))
这一步堆栈溢出,按网上的操作修改内存容量或是import sys
sys.setrecursionlimit都不管用,想问一下大家怎么解决这个问题的。

    data = OP_1.get_intrusion_data()

    filter_pc = [data.Pcap[0]]
    sat = [data.Snwp[0]]
    for i, pc in enumerate(data.Pcap):
    if  data.Snwp[i] - sat[-1] > 0.05:
        filter_pc.append(pc)
        sat.append(data.Snwp[i])
    filter_pc.append(data.Pcap[-1])
    sat.append(data.Snwp[-1]) 
    def update_phase_and_phys(results):
    water['pore.occupancy'] = results['pore.occupancy']
    air['pore.occupancy'] = 1-results['pore.occupancy']
    water['throat.occupancy'] = results['throat.occupancy']
    air['throat.occupancy'] = 1-results['throat.occupancy']
    # Add multiphase conductances
    mode='strict'
    phys_air.add_model(model=mods.physics.multiphase.conduit_conductance,
                       propname='throat.conduit_diffusive_conductance',
                       throat_conductance='throat.diffusive_conductance',
                       mode=mode)
    phys_water.add_model(model=mods.physics.multiphase.conduit_conductance,
                         propname='throat.conduit_diffusive_conductance',
                         throat_conductance='throat.diffusive_conductance',
                         mode=mode)
    phys_air.add_model(model=mods.physics.multiphase.conduit_conductance,
                       propname='throat.conduit_hydraulic_conductance',
                       throat_conductance='throat.hydraulic_conductance',
                       mode=mode)
    phys_water.add_model(model=mods.physics.multiphase.conduit_conductance,
                         propname='throat.conduit_hydraulic_conductance',
                         throat_conductance='throat.hydraulic_conductance',
                         mode=mode)
    phys_air_b.add_model(model=mods.physics.multiphase.conduit_conductance,
                         propname='throat.conduit_diffusive_conductance',
                         throat_conductance='throat.diffusive_conductance',
                         mode=mode)
    phys_water_b.add_model(model=mods.physics.multiphase.conduit_conductance,
                           propname='throat.conduit_diffusive_conductance',
                           throat_conductance='throat.diffusive_conductance',
                           mode=mode)
    phys_air_b.add_model(model=mods.physics.multiphase.conduit_conductance,
                         propname='throat.conduit_hydraulic_conductance',
                         throat_conductance='throat.hydraulic_conductance',
                         mode=mode)
    phys_water_b.add_model(model=mods.physics.multiphase.conduit_conductance,
                           propname='throat.conduit_hydraulic_conductance',
                           throat_conductance='throat.hydraulic_conductance',
                           mode=mode)

    update_phase_and_phys(OP_1.results(Pc=1e3))
    perm_air = {'0': [], '1': [], '2': []}
    diff_air = {'0': [], '1': [], '2': []}
    perm_water = {'0': [], '1': [], '2': []}
    diff_water = {'0': [], '1': [], '2': []}

    max_Pc = max(OP_1['throat.invasion_pressure'])
    print(max_Pc)
    num_seq = 20
    pore_volumes = sgl['pore.volume']
    throat_volumes = sgl['throat.volume']
    totV = np.sum(pore_volumes) + np.sum(throat_volumes)

    K_air_single_phase = [None, None, None]
    D_air_single_phase = [None, None, None]
    K_water_single_phase = [None, None, None]
    D_water_single_phase = [None, None, None]
    bounds = [['front', 'back'], ['left', 'right'], ['top', 'bottom']]

    for bound_increment in range(len(bounds)):
    # Run Single phase algs effective properties
    BC1_pores = sgl.pores(labels=bounds[bound_increment][0]+'_boundary')
    BC2_pores = sgl.pores(labels=bounds[bound_increment][1]+'_boundary')

    # Effective permeability : air
    sf_air = op.algorithms.StokesFlow(network=sgl, phase=air)
    sf_air.setup(conductance='throat.hydraulic_conductance')
    sf_air.set_value_BC(values=0.6, pores=BC1_pores)
    sf_air.set_value_BC(values=0.2, pores=BC2_pores)
    sf_air.run()
    K_air_single_phase[bound_increment] = sf_air.calc_effective_permeability()
    proj.purge_object(obj=sf_air)

    # Effective diffusivity : air
    fd_air = op.algorithms.FickianDiffusion(network=sgl,phase=air)
    fd_air.setup(conductance='throat.diffusive_conductance')
    fd_air.set_value_BC(values=0.6, pores=BC1_pores)
    fd_air.set_value_BC(values=0.2, pores=BC2_pores)
    fd_air.run()
    D_air_single_phase[bound_increment] = fd_air.calc_effective_diffusivity()
    proj.purge_object(obj=fd_air)

    # Effective permeability : water
    sf_water = op.algorithms.StokesFlow(network=sgl, phase=water)
    sf_water.setup(conductance='throat.hydraulic_conductance')
    sf_water.set_value_BC(values=0.6, pores=BC1_pores)
    sf_water.set_value_BC(values=0.2, pores=BC2_pores)
    sf_water.run()
    K_water_single_phase[bound_increment] = sf_water.calc_effective_permeability()
    proj.purge_object(obj=sf_water)

    # Effective diffusivity : water
    fd_water = op.algorithms.FickianDiffusion(network=sgl,phase=water)
    fd_water.setup(conductance='throat.diffusive_conductance')
    fd_water.set_value_BC(values=0.6, pores=BC1_pores)
    fd_water.set_value_BC(values=0.2, pores=BC2_pores)
    fd_water.run()
    D_water_single_phase[bound_increment] = fd_water.calc_effective_diffusivity()
    proj.purge_object(obj=fd_water)

    for Pc in filter_pc:
    update_phase_and_phys(OP_1.results(Pc=Pc))
    print('-' * 80)
    print('Pc', Pc)

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-10-05 22:11
    关注

    maximum recursion depth exceeded 错误无非2个原因
    递归调用的层次太深——将递归改写成循环/堆栈
    存在无限递归,也就是自己调用自己,没有正确的结束跳出函数的逻辑——修改代码

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮