Cantera / cantera

Chemical kinetics, thermodynamics, and transport tool suite
https://cantera.org
Other
581 stars 342 forks source link

Unable to call solution object when using units #1649

Closed mefuller closed 6 months ago

mefuller commented 6 months ago

Problem description

It is possible to create a solution object with 'normal' cantera and call it to print the current state using the Python interface (see e.g. https://cantera.org/tutorials/python-tutorial.html). When using cantera with units, i.e. 'import cantera.with_units', this functionality is lost leading to TypeError: 'Solution' object is not callable

Steps to reproduce

Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cantera as ct
>>> gas0 = ct.Solution('gri30.yaml')
>>> gas0()

  gri30:

       temperature   300 K
          pressure   1.0133e+05 Pa
           density   0.081894 kg/m^3
  mean mol. weight   2.016 kg/kmol
   phase of matter   gas

                          1 kg             1 kmol
                     ---------------   ---------------
          enthalpy             26469             53361  J
   internal energy       -1.2108e+06        -2.441e+06  J
           entropy             64910        1.3086e+05  J/K
    Gibbs function       -1.9447e+07       -3.9204e+07  J
 heat capacity c_p             14311             28851  J/K
 heat capacity c_v             10187             20536  J/K

                      mass frac. Y      mole frac. X     chem. pot. / RT
                     ---------------   ---------------   ---------------
                H2                 1                 1           -15.717
     [  +52 minor]                 0                 0

>>> import cantera.with_units as ctu
>>> gas1 = ctu.Solution('gri30.yaml') 
>>> gas1()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'Solution' object is not callable

Behavior

System information

bryanwweber commented 6 months ago

Thanks Mark! Looks like we forgot to copy over the __call__ method in the builder.

mefuller commented 6 months ago

Thanks - I'll try to write a fix and submit a PR shortly