Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SolutionArray truncates negative values #1016

Closed
DavidAkinpelu opened this issue Apr 19, 2021 · 2 comments · Fixed by #1037
Closed

SolutionArray truncates negative values #1016

DavidAkinpelu opened this issue Apr 19, 2021 · 2 comments · Fixed by #1037
Labels

Comments

@DavidAkinpelu
Copy link
Contributor

DavidAkinpelu commented Apr 19, 2021

For SolutionArray/FlameBase, importers are not currently creating the same states. Negative values are truncated to zero which makes it impossible to have the same states initially stored in the SolutionArray or FlameBase object.

Quick example:

Operating system: Windows 10
Python Version: 3.9.2
Cantera version: 2.6.0a1

In [1]: import cantera as ct
   ...: gas = ct.Solution('h2o2.yaml')
   ...: gas.set_unnormalized_mole_fractions(gas.X - 1e-16)
   ...: arr = ct.SolutionArray(gas, 5)
   
In [2]: arr.X
Out[2]: 
array([[ 1.e+00, -1.e-16, -1.e-16, -1.e-16, -1.e-16, -1.e-16, -1.e-16,
        -1.e-16, -1.e-16, -1.e-16],
       [ 1.e+00, -1.e-16, -1.e-16, -1.e-16, -1.e-16, -1.e-16, -1.e-16,
        -1.e-16, -1.e-16, -1.e-16],
       [ 1.e+00, -1.e-16, -1.e-16, -1.e-16, -1.e-16, -1.e-16, -1.e-16,
        -1.e-16, -1.e-16, -1.e-16],
       [ 1.e+00, -1.e-16, -1.e-16, -1.e-16, -1.e-16, -1.e-16, -1.e-16,
        -1.e-16, -1.e-16, -1.e-16],
       [ 1.e+00, -1.e-16, -1.e-16, -1.e-16, -1.e-16, -1.e-16, -1.e-16,
        -1.e-16, -1.e-16, -1.e-16]])
In [3]: arr.write_hdf('test.h5') # save to HDF
Out[3]: 'group0'
   
In [4]: gas_new = ct.Solution('h2o2.yaml')
   ...: arr_new = ct.SolutionArray(gas_new)
In [5]: arr_new.read_hdf('test.h5') # load from HDF
   ...: arr_new.X
Out[5]: 
array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [1., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])

Also, SolutionArray does not have set_unnormalized_mole_fractions() or set_unnormalized_mass_fractions() methods like a Solution object which I think should be applicable to SolutionArray too.

In [6]: arr_new.set_unnormalized_mole_fractions(arr.X - 1e-16)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-22b735859e09> in <module>
----> 1 arr_new.set_unnormalized_mole_fractions(arr.X - 1e-16)
~/.pyenv/versions/miniconda3-latest/envs/cantera-2.5.1/lib/python3.8/site-packages/cantera/composite.py in __getattr__(self, name)
    604             super().__getattr__(name)
    605         else:
--> 606             raise AttributeError("'{}' object has no attribute '{}'".format(
    607                 self.__class__.__name__, name))
    608 
AttributeError: 'SolutionArray' object has no attribute 'set_unnormalized_mole_fractions'

A proposed fix for the two issues raised above would be to implement set_unnormalized_mass_fractions and set_unnormalized_mole_fractions for SolutionArray objects.

Another related issue which I think would be fixed together with the above raise issues is

In [7]: states = ct.SolutionArray(gas)
   ...: states.append(T=600., P=ct.one_atm, X=[0.1, 0.3, 0.3, -0.4, 0.25, 0.15, -0.2, 0.1, 0, 0])
   ...: states.X            
Out[7]:
    array([[0.08333333, 0.25      , 0.25      , 0.        , 0.20833333,
            0.125     , 0.        , 0.08333333, 0.        , 0.        ]])
@DavidAkinpelu DavidAkinpelu changed the title Import of SolutionArray/FlameBase from file truncates negative values SolutionArray from file truncates negative values Apr 19, 2021
@DavidAkinpelu DavidAkinpelu changed the title SolutionArray from file truncates negative values SolutionArray truncates negative values Apr 19, 2021
@ischoegl
Copy link
Member

@DavidAkinpelu ... thank you for reporting. I believe you know how to fix the issue, so feel free to submit a PR.

@DavidAkinpelu
Copy link
Contributor Author

Okay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants