I am using the cantera
module in python, specifically trying to extend the class cantera.Solution
using inheritance. The base class can be called like this:
gas = cantera.Solution("gri30.ct")
Where "gri30.cti" is the file name of the chemistry model to be used.
I am trying to make a new class, SolutionExtended
which inherits from cantera.Solution
. Here is the class definition:
class SolutionExtended(cantera.Solution):
def __init__(self):
print("Beginning of SolutionExtended.__init__")
super().__init__("gri30.cti")
print("End of SolutionExtended.__init__")
When instantiating the SolutionExtended
object, I get this error:
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
This is the same error that is thrown when you try to instantiate the parent class cantera.Solution
without any input arguments (gas = cantera.Solution()
).
Additionally, neither of the print
statements actually print.
This leads me to thinking that cantera.Solution.__init__
is being called before SolutionExtended.__init__
, which fails because no input arguments are supplied. I am by no means a python expert, however, so this may be completely off.
Can anyone tell me what is going on here? How would I make the SolutionExtended
initialization work without requiring the chemistry model to be explicitly input?
I'm pretty stumped by this, so I really appreciate any help. Thanks!
Here is my full code:
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()
Link to the cantera
package website: https://cantera.org/