我cantera
在 python 中使用模块,特别是尝试cantera.Solution
使用继承来扩展类。基类可以这样调用:
gas = cantera.Solution("gri30.ct")
其中“gri30.cti”是要使用的化学模型的文件名。
我正在尝试创建一个新类,SolutionExtended
它继承自cantera.Solution
. 这是类定义:
class SolutionExtended(cantera.Solution):
def __init__(self):
print("Beginning of SolutionExtended.__init__")
super().__init__("gri30.cti")
print("End of SolutionExtended.__init__")
实例化SolutionExtended
对象时,出现此错误:
Traceback (most recent call last):
File "E:\Projects\Coursework\Cantera\Code\test.py", line 15, in <module>
gas = SolutionExtended()
File "interfaces\cython\cantera\base.pyx", line 63, in cantera._cantera._SolutionBase.__cinit__
ValueError: Arguments are insufficient to define a phase
cantera.Solution
这与您尝试在没有任何输入参数 ( gas = cantera.Solution()
)的情况下实例化父类时引发的错误相同。
此外,这两条print
语句都没有实际打印。
这让我想到 that cantera.Solution.__init__
is被调用before SolutionExtended.__init__
,因为没有提供输入参数而失败。但是,我绝不是 python 专家,所以这可能完全不成立。
谁能告诉我这里发生了什么?SolutionExtended
在不需要显式输入化学模型的情况下如何使初始化工作?
我对此感到很困惑,所以我非常感谢任何帮助。谢谢!
这是我的完整代码:
import cantera
gas = cantera.Solution('gri30.cti')
gas()
class SolutionExtended(cantera.Solution):
def __init__(self):
print("Beginning of SolutionExtended.__init__")
super().__init__("gri30.cti")
print("End of SolutionExtended.__init__")
gas = SolutionExtended()
gas()
cantera
包网站链接: https ://cantera.org/