Skip to content

Commit 959c9fd

Browse files
committed
add new extensivity tests for composites
1 parent a451924 commit 959c9fd

File tree

1 file changed

+176
-0
lines changed

1 file changed

+176
-0
lines changed

tests/test_composite.py

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,182 @@ def test_relaxed_composite(self):
558558
)
559559
)
560560

561+
def test_formula_extensivity_composite(self):
562+
min1 = minerals.SLB_2011.mg_perovskite()
563+
min2 = minerals.SLB_2011.periclase()
564+
molar_fractions = [0.5, 0.5]
565+
c1 = burnman.Composite([min1, min2], molar_fractions, fraction_type="molar")
566+
c2 = burnman.Composite([min1, min2], molar_fractions, fraction_type="molar")
567+
c2.number_of_moles = 2.0
568+
569+
self.assertFloatEqual(c1.number_of_moles, c2.number_of_moles / 2.0)
570+
self.assertFloatEqual(c1.formula["Mg"], c2.formula["Mg"] / 2.0)
571+
self.assertFloatEqual(c1.formula["Si"], c2.formula["Si"] / 2.0)
572+
self.assertFloatEqual(c1.formula["O"], c2.formula["O"] / 2.0)
573+
self.assertFloatEqual(c1.molar_mass, c2.molar_mass)
574+
self.assertFloatEqual(c1.mass, c2.mass / 2.0)
575+
576+
def test_property_extensivity_composite(self):
577+
min1 = minerals.SLB_2011.mg_perovskite()
578+
min2 = minerals.SLB_2011.periclase()
579+
molar_fractions = [0.5, 0.5]
580+
c1 = burnman.Composite([min1, min2], molar_fractions, fraction_type="molar")
581+
c2 = burnman.Composite([min1, min2], molar_fractions, fraction_type="molar")
582+
c2.number_of_moles = 2.0
583+
584+
c1.set_state(40.0e9, 2000.0)
585+
c2.set_state(40.0e9, 2000.0)
586+
587+
properties_extensive = [
588+
"internal_energy",
589+
"helmholtz",
590+
"gibbs",
591+
"enthalpy",
592+
"entropy",
593+
"volume",
594+
"heat_capacity_p",
595+
"heat_capacity_v",
596+
"mass",
597+
"V",
598+
"S",
599+
"H",
600+
"C_v",
601+
"C_p",
602+
]
603+
604+
for prop in properties_extensive:
605+
val1 = getattr(c1, prop)
606+
val2 = getattr(c2, prop)
607+
self.assertFloatEqual(val1, val2 / 2.0)
608+
609+
properties_intensive = [
610+
"molar_internal_energy",
611+
"molar_helmholtz",
612+
"molar_gibbs",
613+
"molar_enthalpy",
614+
"molar_entropy",
615+
"molar_volume",
616+
"molar_heat_capacity_p",
617+
"molar_heat_capacity_v",
618+
"isothermal_bulk_modulus_reuss",
619+
"isentropic_bulk_modulus_reuss",
620+
"isothermal_compressibility_reuss",
621+
"isentropic_compressibility_reuss",
622+
"grueneisen_parameter",
623+
"thermal_expansivity",
624+
"molar_mass",
625+
"density",
626+
]
627+
628+
for prop in properties_intensive:
629+
val1 = getattr(c1, prop)
630+
val2 = getattr(c2, prop)
631+
self.assertFloatEqual(val1, val2)
632+
633+
def test_composite_state_not_set(self):
634+
min1 = minerals.SLB_2011.mg_perovskite()
635+
min2 = minerals.SLB_2011.periclase()
636+
molar_fractions = [0.5, 0.5]
637+
c = burnman.Composite([min1, min2], molar_fractions, fraction_type="molar")
638+
639+
with self.assertRaises(AttributeError):
640+
_ = c.density
641+
642+
def test_formula_extensivity_relaxed_composite(self):
643+
fper = minerals.SLB_2024.ferropericlase()
644+
bdg = minerals.SLB_2024.bridgmanite()
645+
c1_unrelaxed = burnman.Composite([fper, bdg], [0.5, 0.5])
646+
c2_unrelaxed = burnman.Composite([fper, bdg], [0.5, 0.5])
647+
c2_unrelaxed.number_of_moles = 2.0
648+
649+
fper.set_composition([0.35, 0.3, 0.2, 0.1, 0.05])
650+
bdg.set_composition([0.7, 0.1, 0.1, 0.05, 0.03, 0.01, 0.01])
651+
652+
formula = c1_unrelaxed.formula.copy()
653+
formula2 = c2_unrelaxed.formula.copy()
654+
655+
self.assertFloatEqual(formula["Mg"] * 2.0, formula2["Mg"])
656+
657+
c1 = RelaxedComposite(c1_unrelaxed, c1_unrelaxed.reaction_basis)
658+
c2 = RelaxedComposite(c2_unrelaxed, c2_unrelaxed.reaction_basis)
659+
660+
c1.set_state(40.0e9, 2000.0)
661+
c2.set_state(40.0e9, 2000.0)
662+
663+
self.assertFloatEqual(c1.number_of_moles, c2.number_of_moles / 2.0)
664+
self.assertFloatEqual(c1.formula["Mg"], c2.formula["Mg"] / 2.0)
665+
self.assertFloatEqual(c1.formula["Si"], c2.formula["Si"] / 2.0)
666+
self.assertFloatEqual(c1.formula["O"], c2.formula["O"] / 2.0)
667+
self.assertFloatEqual(c1.molar_mass, c2.molar_mass)
668+
self.assertFloatEqual(c1.mass, c2.mass / 2.0)
669+
670+
def test_property_extensivity_relaxed_composite(self):
671+
fper = minerals.SLB_2024.ferropericlase()
672+
bdg = minerals.SLB_2024.bridgmanite()
673+
c1_unrelaxed = burnman.Composite([fper, bdg], [0.5, 0.5])
674+
c2_unrelaxed = burnman.Composite([fper, bdg], [0.5, 0.5])
675+
c2_unrelaxed.number_of_moles = 2.0
676+
677+
fper.set_composition([0.35, 0.3, 0.2, 0.1, 0.05])
678+
bdg.set_composition([0.7, 0.1, 0.1, 0.05, 0.03, 0.01, 0.01])
679+
680+
formula = c1_unrelaxed.formula.copy()
681+
formula2 = c2_unrelaxed.formula.copy()
682+
683+
self.assertFloatEqual(formula["Mg"] * 2.0, formula2["Mg"])
684+
685+
c1 = RelaxedComposite(c1_unrelaxed, c1_unrelaxed.reaction_basis)
686+
c2 = RelaxedComposite(c2_unrelaxed, c2_unrelaxed.reaction_basis)
687+
688+
c1.set_state(40.0e9, 2000.0)
689+
c2.set_state(40.0e9, 2000.0)
690+
691+
properties_extensive = [
692+
"internal_energy",
693+
"helmholtz",
694+
"gibbs",
695+
"enthalpy",
696+
"entropy",
697+
"volume",
698+
"heat_capacity_p",
699+
"heat_capacity_v",
700+
"mass",
701+
"H",
702+
"S",
703+
"V",
704+
"C_p",
705+
"C_v",
706+
]
707+
708+
for prop in properties_extensive:
709+
val1 = getattr(c1, prop)
710+
val2 = getattr(c2, prop)
711+
self.assertFloatEqual(val1, val2 / 2.0)
712+
713+
properties_intensive = [
714+
"molar_internal_energy",
715+
"molar_helmholtz",
716+
"molar_gibbs",
717+
"molar_enthalpy",
718+
"molar_entropy",
719+
"molar_volume",
720+
"molar_heat_capacity_p",
721+
"molar_heat_capacity_v",
722+
"isothermal_bulk_modulus_reuss",
723+
"isentropic_bulk_modulus_reuss",
724+
"isothermal_compressibility_reuss",
725+
"isentropic_compressibility_reuss",
726+
"grueneisen_parameter",
727+
"thermal_expansivity",
728+
"molar_mass",
729+
"density",
730+
]
731+
732+
for prop in properties_intensive:
733+
val1 = getattr(c1, prop)
734+
val2 = getattr(c2, prop)
735+
self.assertFloatEqual(val1, val2)
736+
561737

562738
if __name__ == "__main__":
563739
unittest.main()

0 commit comments

Comments
 (0)