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

set first composition in evaluate #586

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading