Skip to content

Commit

Permalink
set first composition in evaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmyhill committed Mar 26, 2024
1 parent 8e95f9c commit 5d86057
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions burnman/classes/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,19 @@ def evaluate(self, vars_list, pressures, temperatures, molar_fractions=None):
"""
old_pressure = self.pressure
old_temperature = self.temperature
try:
old_molar_fractions = self.molar_fractions
except AttributeError:
old_molar_fractions = None

pressures = np.array(pressures)
temperatures = np.array(temperatures)

assert pressures.shape == temperatures.shape

if molar_fractions is not None:
molar_fractions = np.array(molar_fractions)
self.set_composition(molar_fractions[0])
assert temperatures.shape == molar_fractions.shape[:-1]

# First, check the output types of all the requested variables:
Expand All @@ -316,6 +322,11 @@ def evaluate(self, vars_list, pressures, temperatures, molar_fractions=None):
self.reset()
else:
self.set_state(old_pressure, old_temperature)
if old_molar_fractions is not None:
try:
self.set_composition(old_molar_fractions)
except AttributeError:
pass

try:
output = np.array(output)
Expand Down Expand Up @@ -349,13 +360,19 @@ def evaluate_with_volumes(
"""
old_pressure = self.pressure
old_temperature = self.temperature
try:
old_molar_fractions = self.molar_fractions
except AttributeError:
old_molar_fractions = None

volumes = np.array(volumes)
temperatures = np.array(temperatures)

assert volumes.shape == temperatures.shape

if molar_fractions is not None:
molar_fractions = np.array(molar_fractions)
self.set_composition(molar_fractions[0])
assert temperatures.shape == molar_fractions.shape[:-1]

# First, check the output types of all the requested variables:
Expand Down Expand Up @@ -383,6 +400,12 @@ def evaluate_with_volumes(
else:
self.set_state(old_pressure, old_temperature)

if old_molar_fractions is not None:
try:
self.set_composition(old_molar_fractions)
except AttributeError:
pass

try:
output = np.array(output)
except ValueError: # if the lists are different shapes
Expand Down

0 comments on commit 5d86057

Please sign in to comment.