# SPDX-FileCopyrightText: 2025-present The Bluemira Developers <https://github.com/Fusion-Power-Plant-Framework/bluemira>
#
# SPDX-License-Identifier: LGPL-2.1-or-later
"""An example to show how to create a mixture in `matproplib`"""
Material Mixtures¶
In matproplib, we can create a mixture of materials using the Mixture class. This
allows us to define a material that is composed of multiple other materials,
each with its own properties.
In this example, we will create a mixture of steel and water.
from matproplib.conditions import OperationalConditions
from matproplib.library.fluids import Water
from matproplib.library.steel import SS316_L
from matproplib.material import mixture
Let us create the base materials first.
steel = SS316_L()
water = Water()
Now we can create a mixture of these two materials. We will define the mass fractions of steel and water in the mixture. For example, we can create a mixture with 70% steel and 30% water.
my_mixture = mixture(
"SteelWaterMixture", [(steel, 0.7), (water, 0.3)], fraction_type="mass"
)
We can now use this mixture material in our simulations. For example, we can evaluate the density of the mixture at a given temperature. Mixture properties are computed as a weighted average of the underlying material properties, assuming a homogenous mixture.
op_cond = OperationalConditions(temperature=300, pressure=8e5)
mixture_density = my_mixture.density(op_cond)
print(f"{mixture_density} kg/m^3")
We can always override the properties of the mixture by defining a new property.
my_mixture.density = lambda _: 5000.0 # Override density to be 5000 kg/m^3
overriden_density = my_mixture.density(op_cond)
We can still access the underlying materials in the mixture.
steel_density = my_mixture.mixture_fraction[0].material.density(op_cond)
water_density = my_mixture.mixture_fraction[1].material.density(op_cond)
recalculated_density = 0.7 * steel_density + 0.3 * water_density
print(f"{steel_density=} kg/m^3")
print(f"{water_density=} kg/m^3")
print(f"{mixture_density=} kg/m^3")
print(f"{recalculated_density=} kg/m^3")
print(f"{overriden_density=} kg/m^3")