FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 7501532a authored by Mark Driver's avatar Mark Driver
Browse files

update to add check to make sure phases have fully assigned molefractions during initialisation.

parent 4560b4ba
No related branches found
No related tags found
No related merge requests found
Pipeline #26093 passed
...@@ -55,6 +55,8 @@ class Phase(object): ...@@ -55,6 +55,8 @@ class Phase(object):
""" """
self.molecule_list = molecule_list self.molecule_list = molecule_list
self.temperature = temperature self.temperature = temperature
if not self.total_molefraction_is_one():
raise ValueError("Total molefractions of phase not equal to one")
def __eq__(self, other): def __eq__(self, other):
"""Overload equality comparison operator. """Overload equality comparison operator.
...@@ -146,6 +148,20 @@ class Phase(object): ...@@ -146,6 +148,20 @@ class Phase(object):
""" """
return Temperature.parse_xml(temperature_xml) return Temperature.parse_xml(temperature_xml)
def total_molefraction_is_one(self):
"""Calculate total molefraction of the molecule and check this is 1.0.
Returns
-------
bool
True if total molefraction of components is one.
"""
molefraction_total = 0.0
for mole_frac in self.get_molefractions_by_molecule().values():
molefraction_total += mole_frac
return (abs(1.0-molefraction_total) < 1e-5)
def write_to_xml(self): def write_to_xml(self):
"""Write information to Etree representation of XML. """Write information to Etree representation of XML.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment