CalebBell / chemicals

chemicals: Chemical database of Chemical Engineering Design Library (ChEDL)
MIT License
186 stars 36 forks source link

Heat capacity functions by mol #19

Closed yoelcortes closed 4 years ago

yoelcortes commented 4 years ago

Is your feature request related to a problem? Please describe.

Most T and P dependent chemical property functions are on a molar basis (e.g. volume, Hvap, and most heat capacity functions). However, Lastovka_Shaw, Dadgostar_Shaw, and Lastovka_solid heat capacity functions are on a per kg basis. I'd like to allow these functions to return values in J/mol-K if given an optional parameter MW (the molecular weight). This would allow backwards compatibility as well as more consistency in units if measure.

Do you acknowledge the project is developed by volunteers adding features primarily for their own purposes? Yes!

Additional context @CalebBell, thumbs up if you agree and I'll get to adding this feature!

yoelcortes commented 4 years ago

Would this conflict with the support for pint Quantities?

CalebBell commented 4 years ago

Hi Yoel, Yes, it is an issue with pint. It is also an issue I have faced before. The solution I did before was to manually code a wrapper as can be seen for some functions in fluids: https://github.com/CalebBell/fluids/blob/master/fluids/units.py#L471 Nothing has been coded in chemicals yet about this issue. There are existing issues, like speed_of_sound which has two different types of outputs. One option would be to only ever have a function return a fixed type. I don't find that user friendly/convenient. Too much documentation duplication and it's harder to remember function names. After working with numba, it occurs to me that so long as the types of the inputs define what the types of the outputs are, it should be possible to write a general wrapper function, and manually write metadata about how to handle types in these cases (without writing new functions). I'm thinking a dictionary in units.py and some smarts in the units.py of fluids. It is an existing issue, but thank you for reminding me of the fact it hasn't gone away while I wasn't looking at it :) Cheers, Caleb

yoelcortes commented 4 years ago

Thanks for the quick reply! I should be done with this soon, so I'll go ahead and close the issue.