将python2.6 cantera1.8转换为python2.7 cantera2.2

2024-10-02 20:35:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我是化学网络模型的新手。目前,我正在转换以前的学生python代码,以适应实验室中的新版本。你知道吗

首先,定义了来自机理(预定义)的气体混合物

gas_mix = ct.import_phases(mech,['gas'])

然后,我想得到物种的数量,并使用cantera nSpecies

nsp = gas_mix.nSpecies()

我得到的错误信息是

AttributeError: 'list' object has no attribute 'nSpecies'

我也试过:

nsp = gas_mix.n_species

它也显示了

AttributeError: 'list' object has no attribute

你能帮我一下吗? 谢谢并致以最诚挚的问候, 尤比


Tags: no模型网络objectattribute学生listattributeerror
2条回答

它看起来像是import_phases返回一个对象列表,或者是一个“gas mix”列表,或者只是一个“gas”对象。我不是很确定,因为这是非常具体的程序,你正在工作。你知道吗

无论如何,请尝试在gas_mix中的值上循环,看看是否可以调用nSpecies()方法或访问n_species属性:

gas_mix = ct.import_phases(mech,['gas'])
for gm in gas_mix:
    print(gm.nSpecies())
    # or you can try this:
    print(gm.n_species)

也许这会让你更接近你想要的。你知道吗

函数import_phases返回一个列表,对于从同一个文件导入多个阶段定义的情况非常有用,例如

mixtures = ct.import_phases(mech, ['gas1', 'gas2'])

其中mixtures[0]mixtures[2]将是单相定义。如果只想定义一个阶段,则更容易编写:

gas_mix = ct.Solution(mech,'gas')

或者,如果机制文件仅包含一个阶段定义,则

gas_mix = ct.Solution(mech)

从这里,你应该可以访问物种的数量

gas_mix.n_species

文档页面“Migrating from the Old Python Module”中描述了从旧Cantera接口迁移到新Cantera接口的许多细节。你知道吗

相关问题 更多 >