Skip to content

Commit c772612

Browse files
committed
test fit composition to solution
1 parent 5e5249b commit c772612

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test_fitting.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from burnman.optimize.eos_fitting import fit_XPTp_data
1010
from burnman.optimize.nonlinear_fitting import nonlinear_least_squares_fit
1111
from burnman.utils.misc import attribute_function, pretty_string_values
12+
from burnman.optimize.composition_fitting import fit_composition_to_solution
1213

1314
path = os.path.dirname(os.path.abspath(__file__))
1415

@@ -282,6 +283,30 @@ def test_bounded_solution_fitting(self):
282283
fitted_eos.popt, fitted_eos.pcov
283284
)
284285

286+
def test_fit_composition_to_solution(self):
287+
gt = burnman.minerals.JH_2015.garnet()
288+
fitted_species = ["Fe", "Ca", "Mg", "Cr", "Al", "Si", "Fe3+"]
289+
species_amounts = np.array([1.1, 2.0, 0.0, 0, 1.9, 3.0, 0.1])
290+
species_covariances = np.eye(7) * 0.01 * 0.01
291+
species_conversions = {"Fe3+": {"Fef_B": 1.0}}
292+
293+
np.random.seed(100)
294+
species_amounts = np.random.multivariate_normal(
295+
species_amounts, species_covariances
296+
)
297+
298+
popt, _, _ = fit_composition_to_solution(
299+
gt,
300+
fitted_species,
301+
species_amounts,
302+
species_covariances,
303+
species_conversions,
304+
)
305+
gt.set_composition(popt)
306+
f = [0.004, 0.328, 0.619, 0.048, 0.000]
307+
f2 = np.round(gt.molar_fractions, 3)
308+
self.assertArraysAlmostEqual(f, f2)
309+
285310

286311
if __name__ == "__main__":
287312
unittest.main()

0 commit comments

Comments
 (0)