ekwan / PyPlate

Apache License 2.0
5 stars 7 forks source link

Feature: (Soft) Require Solid Density for Substance.solid() #34

Closed jlw387 closed 2 months ago

jlw387 commented 2 months ago

Various unrealistic behaviors were noticed for solids that resulted from their densities automatically being set to 1.

A simple example would be adding an arbitrary quantity, say 50 grams, of an arbitrary solid substance, say NaCl, to a container. The container would report a volume of 50 mL, but in reality NaCl has a density of around 2.17 g/mL, so the actual volume taken up by the salt would be ~23 mL.

To address these problems, both the Substance() constructor and Substance.solid() have been given an additional parameter, density, to allow for this value to be specified for both currently supported phases of matter (solids and liquids).

However, there are cases where a user may not know the density of a solid, or it may not be required for setting up their experiments (e.g. when the solid is in a very dilute solution, and the concentration in said solution need not be precise). To allow for these cases, Substance.solid() can still be called without providing a density. Doing so will trigger a warning for the user to inform them of the risks associated with not providing a density, which they can either choose to ignore or choose to address by providing a density.

As one might expect, the unit test code responsible for creating solids was refactored to provide solid densities. This broke some of the strict equalities present on many of the assert statements, so a number of these were adjusted to include a call to pytest.approx(). The two example files were also updated to include solid densities for Substance.solid().

Additional cleanup changes that were made to Substance:

Additional changes that were missed in previous features:

jlw387 commented 2 months ago

Checks have passed, so this branch will now be merged and deleted.