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

Ensure consistent extra columns in SolutionArray #931

Merged
merged 3 commits into from
Jan 19, 2021

Conversation

ischoegl
Copy link
Member

@ischoegl ischoegl commented Sep 5, 2020

Changes proposed in this pull request

  • Fix bugs in beta release of 2.5.0b1
  • Ensure that dimensions of extra columns are consistent
  • Enable multi-dimensional extra 'columns' (e.g. 2D arrays similar to what already exists for other SolutionArray attributes)
  • Like the existing code, this PR takes advantage of NumPy for on-the-fly adjustments of data types.

If applicable, fill in the issue number this pull request is fixing

Fixes #895, fixes #930

Illustration

In [2]: gas = ct.Solution("air.yaml")
   ...: states = ct.SolutionArray(gas, 3, extra={"prop": [5, 6, 7]})
   ...: states.append(TPX=(1100, 3e5, "AR:1.0"), prop=[1, 2, 3]) # <--- Fix #895
   ...: 
---------------------------------------------------------------------------
[...]
ValueError: Encountered incompatible value '[1, 2, 3]' for extra column 'prop'.

In [3]: states.prop = ‘spam’ # <--- overwrite individual entries / Fix #930
   ...: states.prop
   ...: 
Out[3]: array([‘spam’, ‘spam’, ‘spam’], dtype=‘<U4’)

In [4]: states.prop = np.ones((3,4)) # <--- enable multi-dimensional extra 'columns'
   ...: states.prop
   ...: 
Out[4]: 
array([[1., 1., 1., 1.],
       [1., 1., 1., 1.],
       [1., 1., 1., 1.]])

In [5]: states.prop = [1, 2, 3, 4] # <--- ensure that dimensions are consistent
---------------------------------------------------------------------------
[...]
ValueError: Incompatible shapes for extra column 'prop': cannot assign value with shape (4,) to SolutionArray with shape (3,)

Checklist

  • There is a clear use-case for this code change
  • The commit message has a short title & references relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • The pull request is ready for review

@ischoegl
Copy link
Member Author

ischoegl commented Sep 6, 2020

@speth / @bryanwweber ... I cannot request a review, but I’d appreciate if those fixes could make it into 2.5.

Copy link
Member Author

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor edits are taken care of]

Copy link
Member

@speth speth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are useful improvements to eliminate some confusing behavior in the SolutionArray class. Just noticed a couple of things to fix up further.

interfaces/cython/cantera/composite.py Outdated Show resolved Hide resolved
interfaces/cython/cantera/composite.py Outdated Show resolved Hide resolved
@ischoegl
Copy link
Member Author

ischoegl commented Dec 6, 2020

@speth ... thanks for the review. I believe it's all addressed.

As for the other PR's, I can rebase once #946 is merged.

@ischoegl ischoegl mentioned this pull request Dec 11, 2020
4 tasks
@ischoegl ischoegl requested a review from speth December 11, 2020 12:32
Copy link
Member

@speth speth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks.

@speth speth merged commit 52630d4 into Cantera:main Jan 19, 2021
@ischoegl ischoegl deleted the consistent-extra-columns branch January 29, 2021 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants