|
9 | 9 | from burnman.optimize.eos_fitting import fit_XPTp_data |
10 | 10 | from burnman.optimize.nonlinear_fitting import nonlinear_least_squares_fit |
11 | 11 | from burnman.utils.misc import attribute_function, pretty_string_values |
| 12 | +from burnman.optimize.composition_fitting import fit_composition_to_solution |
12 | 13 |
|
13 | 14 | path = os.path.dirname(os.path.abspath(__file__)) |
14 | 15 |
|
@@ -282,6 +283,30 @@ def test_bounded_solution_fitting(self): |
282 | 283 | fitted_eos.popt, fitted_eos.pcov |
283 | 284 | ) |
284 | 285 |
|
| 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 | + |
285 | 310 |
|
286 | 311 | if __name__ == "__main__": |
287 | 312 | unittest.main() |
0 commit comments