Example #1
0
    def test_packing_fraction(self):
        builder = MaterialBuilder().setName(NAME).setFormula(FORMULA)

        # setting nothing should be an error
        try:
            material = builder.build()
            raise AssertionError('Should throw an exception')
        except RuntimeError as e:
            assert 'number density' in str(e)

        builder = MaterialBuilder().setName(NAME).setFormula(FORMULA).setNumberDensity(NUMBER_DENSITY)

        # only with number density
        material = builder.build()
        self.assertEqual(material.name(), NAME)
        self.assertEqual(material.numberDensity, material.numberDensityEffective)
        self.assertEqual(material.packingFraction, 1.0)
        self.assertEqual(material.numberDensity, NUMBER_DENSITY)

        # with number density and packing fraction
        material = builder.setPackingFraction(0.5).build()
        self.assertEqual(material.name(), NAME)
        self.assertEqual(material.numberDensity, NUMBER_DENSITY)
        self.assertEqual(material.numberDensityEffective, NUMBER_DENSITY * 0.5)
        self.assertEqual(material.packingFraction, 0.5)

        # start a brand new material builder
        builder = MaterialBuilder().setName(NAME).setFormula(FORMULA).setMassDensity(MASS_DENSITY)

        # only with mass density
        material = builder.build()
        self.assertEqual(material.name(), NAME)
        self.assertEqual(material.numberDensity, material.numberDensityEffective)
        self.assertEqual(material.packingFraction, 1.0)
        self.assertAlmostEqual(material.numberDensityEffective, NUMBER_DENSITY * PACKING_OBS, delta=1e-4)

        # with mass density and number density
        material = builder.setNumberDensity(NUMBER_DENSITY).build()
        self.assertEqual(material.name(), NAME)
        self.assertEqual(material.numberDensity, NUMBER_DENSITY)
        self.assertAlmostEqual(material.numberDensityEffective, NUMBER_DENSITY * PACKING_OBS, delta=1e-4)
        self.assertAlmostEqual(material.packingFraction, PACKING_OBS, delta=1e-4)

        # setting all 3 should be an error
        try:
            material = builder.setPackingFraction(0.5).setNumberDensity(NUMBER_DENSITY).setMassDensity(MASS_DENSITY).build()
            raise AssertionError('Should throw an exception')
        except RuntimeError as e:
            assert 'number density' in str(e)
 def test_number_density_units(self):
     builder = MaterialBuilder()
     builder.setName('Bizarre oxide').setFormula('Al2 O3').setNumberDensity(
         0.23)
     builder.setNumberDensityUnit(NumberDensityUnit.FormulaUnits)
     material = builder.build()
     self.assertEqual(material.numberDensity, 0.23 * (2. + 3.))
Example #3
0
 def test_number_density_units(self):
     builder = MaterialBuilder()
     builder.setName(NAME).setFormula(FORMULA).setNumberDensity(NUMBER_DENSITY)
     builder.setNumberDensityUnit(NumberDensityUnit.FormulaUnits)
     material = builder.build()
     self.assertEqual(material.numberDensity, NUMBER_DENSITY * (2. + 3.))
     self.assertEqual(material.numberDensityEffective, NUMBER_DENSITY * (2. + 3.))
     self.assertEqual(material.packingFraction, 1.)
 def test_number_density_units(self):
     builder = MaterialBuilder()
     builder.setName('Bizarre oxide').setFormula('Al2 O3').setNumberDensity(0.23)
     builder.setNumberDensityUnit(NumberDensityUnit.FormulaUnits)
     material = builder.build()
     self.assertEqual(material.numberDensity, 0.23 * (2. + 3.))