Esempio n. 1
0
 def test_get_compliance_expansion(self):
     ce_exp = self.exp_cu.get_compliance_expansion()
     et_comp = ElasticTensorExpansion(ce_exp)
     strain_orig = Strain.from_voigt([0.01, 0, 0, 0, 0, 0])
     stress = self.exp_cu.calculate_stress(strain_orig)
     strain_revert = et_comp.calculate_stress(stress)
     self.assertArrayAlmostEqual(strain_orig, strain_revert, decimal=4)
Esempio n. 2
0
 def test_get_compliance_expansion(self):
     ce_exp = self.exp_cu.get_compliance_expansion()
     et_comp = ElasticTensorExpansion(ce_exp)
     strain_orig = Strain.from_voigt([0.01, 0, 0, 0, 0, 0])
     stress = self.exp_cu.calculate_stress(strain_orig)
     strain_revert = et_comp.calculate_stress(stress)
     self.assertArrayAlmostEqual(strain_orig, strain_revert, decimal=4)
Esempio n. 3
0
class ElasticTensorExpansionTest(PymatgenTest):
    def setUp(self):
        with open(os.path.join(test_dir, 'test_toec_data.json')) as f:
            self.data_dict = json.load(f)
        self.strains = [Strain(sm) for sm in self.data_dict['strains']]
        self.pk_stresses = [Stress(d) for d in self.data_dict['pk_stresses']]
        self.c2 = self.data_dict["C2_raw"]
        self.c3 = self.data_dict["C3_raw"]
        self.exp = ElasticTensorExpansion.from_voigt([self.c2, self.c3])
        self.cu = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.623),
                                            ["Cu"], [[0] * 3])
        indices = [(0, 0), (0, 1), (3, 3)]
        values = [167.8, 113.5, 74.5]
        cu_c2 = ElasticTensor.from_values_indices(values,
                                                  indices,
                                                  structure=self.cu,
                                                  populate=True)
        indices = [(0, 0, 0), (0, 0, 1), (0, 1, 2), (0, 3, 3), (0, 5, 5),
                   (3, 4, 5)]
        values = [-1507., -965., -71., -7., -901., 45.]
        cu_c3 = Tensor.from_values_indices(values,
                                           indices,
                                           structure=self.cu,
                                           populate=True)
        self.exp_cu = ElasticTensorExpansion([cu_c2, cu_c3])
        cu_c4 = Tensor.from_voigt(self.data_dict["Cu_fourth_order"])
        self.exp_cu_4 = ElasticTensorExpansion([cu_c2, cu_c3, cu_c4])
        warnings.simplefilter("ignore")

    def tearDown(self):
        warnings.simplefilter("default")

    def test_init(self):
        cijkl = Tensor.from_voigt(self.c2)
        cijklmn = Tensor.from_voigt(self.c3)
        exp = ElasticTensorExpansion([cijkl, cijklmn])
        from_voigt = ElasticTensorExpansion.from_voigt([self.c2, self.c3])
        self.assertEqual(exp.order, 3)

    def test_from_diff_fit(self):
        exp = ElasticTensorExpansion.from_diff_fit(self.strains,
                                                   self.pk_stresses)

    def test_calculate_stress(self):
        calc_stress = self.exp.calculate_stress(self.strains[0])
        self.assertArrayAlmostEqual(self.pk_stresses[0],
                                    calc_stress,
                                    decimal=2)

    def test_energy_density(self):
        edensity = self.exp.energy_density(self.strains[0])
        self.assertAlmostEqual(edensity, 1.36363099e-4)

    def test_gruneisen(self):
        # Get GGT
        ggt = self.exp_cu.get_ggt([1, 0, 0], [0, 1, 0])
        self.assertArrayAlmostEqual(
            np.eye(3) * np.array([4.92080537, 4.2852349, -0.7147651]), ggt)
        # Get TGT
        tgt = self.exp_cu.get_tgt()
        self.assertArrayAlmostEqual(tgt, np.eye(3) * 2.59631832)

        # Get heat capacity
        c0 = self.exp_cu.get_heat_capacity(0, self.cu, [1, 0, 0], [0, 1, 0])
        self.assertEqual(c0, 0.0)
        c = self.exp_cu.get_heat_capacity(300, self.cu, [1, 0, 0], [0, 1, 0])
        self.assertAlmostEqual(c, 8.285611958)

        # Get Gruneisen parameter
        gp = self.exp_cu.get_gruneisen_parameter()
        self.assertAlmostEqual(gp, 2.59631832)
        gpt = self.exp_cu.get_gruneisen_parameter(temperature=200,
                                                  structure=self.cu)

    def test_thermal_expansion_coeff(self):
        #TODO get rid of duplicates
        alpha_dp = self.exp_cu.thermal_expansion_coeff(self.cu,
                                                       300,
                                                       mode="dulong-petit")
        alpha_debye = self.exp_cu.thermal_expansion_coeff(self.cu,
                                                          300,
                                                          mode="debye")
        alpha_comp = 5.9435148e-7 * np.ones((3, 3))
        alpha_comp[np.diag_indices(3)] = 21.4533472e-06
        self.assertArrayAlmostEqual(alpha_comp, alpha_debye)

    def test_get_compliance_expansion(self):
        ce_exp = self.exp_cu.get_compliance_expansion()
        et_comp = ElasticTensorExpansion(ce_exp)
        strain_orig = Strain.from_voigt([0.01, 0, 0, 0, 0, 0])
        stress = self.exp_cu.calculate_stress(strain_orig)
        strain_revert = et_comp.calculate_stress(stress)
        self.assertArrayAlmostEqual(strain_orig, strain_revert, decimal=4)

    def test_get_effective_ecs(self):
        # Ensure zero strain is same as SOEC
        test_zero = self.exp_cu.get_effective_ecs(np.zeros((3, 3)))
        self.assertArrayAlmostEqual(test_zero, self.exp_cu[0])
        s = np.zeros((3, 3))
        s[0, 0] = 0.02
        test_2percent = self.exp_cu.get_effective_ecs(s)
        diff = test_2percent - test_zero
        self.assertArrayAlmostEqual(self.exp_cu[1].einsum_sequence([s]), diff)

    def test_get_strain_from_stress(self):
        strain = Strain.from_voigt([0.05, 0, 0, 0, 0, 0])
        stress3 = self.exp_cu.calculate_stress(strain)
        strain_revert3 = self.exp_cu.get_strain_from_stress(stress3)
        self.assertArrayAlmostEqual(strain, strain_revert3, decimal=2)
        # fourth order
        stress4 = self.exp_cu_4.calculate_stress(strain)
        strain_revert4 = self.exp_cu_4.get_strain_from_stress(stress4)
        self.assertArrayAlmostEqual(strain, strain_revert4, decimal=2)

    def test_get_yield_stress(self):
        ys = self.exp_cu_4.get_yield_stress([1, 0, 0])
Esempio n. 4
0
class ElasticTensorExpansionTest(PymatgenTest):
    def setUp(self):
        with open(os.path.join(test_dir, 'test_toec_data.json')) as f:
            self.data_dict = json.load(f)
        self.strains = [Strain(sm) for sm in self.data_dict['strains']]
        self.pk_stresses = [Stress(d) for d in self.data_dict['pk_stresses']]
        self.c2 = self.data_dict["C2_raw"]
        self.c3 = self.data_dict["C3_raw"]
        self.exp = ElasticTensorExpansion.from_voigt([self.c2, self.c3])
        self.cu = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.623),
                                            ["Cu"], [[0]*3])
        indices = [(0, 0), (0, 1), (3, 3)]
        values = [167.8, 113.5, 74.5]
        cu_c2 = ElasticTensor.from_values_indices(values, indices, structure=self.cu,
                                                  populate=True)
        indices = [(0, 0, 0), (0, 0, 1), (0, 1, 2),
                   (0, 3, 3), (0, 5, 5), (3, 4, 5)]
        values = [-1507., -965., -71., -7., -901., 45.]
        cu_c3 = Tensor.from_values_indices(values, indices, structure=self.cu,
                                           populate=True)
        self.exp_cu = ElasticTensorExpansion([cu_c2, cu_c3])
        cu_c4 = Tensor.from_voigt(self.data_dict["Cu_fourth_order"])
        self.exp_cu_4 = ElasticTensorExpansion([cu_c2, cu_c3, cu_c4])
        warnings.simplefilter("ignore")

    def tearDown(self):
        warnings.resetwarnings()

    def test_init(self):
        cijkl = Tensor.from_voigt(self.c2)
        cijklmn = Tensor.from_voigt(self.c3)
        exp = ElasticTensorExpansion([cijkl, cijklmn])
        from_voigt = ElasticTensorExpansion.from_voigt([self.c2, self.c3])
        self.assertEqual(exp.order, 3)

    def test_from_diff_fit(self):
        exp = ElasticTensorExpansion.from_diff_fit(self.strains, self.pk_stresses)

    def test_calculate_stress(self):
        calc_stress = self.exp.calculate_stress(self.strains[0])
        self.assertArrayAlmostEqual(self.pk_stresses[0], calc_stress, decimal=2)

    def test_energy_density(self):
        edensity = self.exp.energy_density(self.strains[0])
        self.assertAlmostEqual(edensity, 1.36363099e-4)

    def test_gruneisen(self):
        # Get GGT
        ggt = self.exp_cu.get_ggt([1, 0, 0], [0, 1, 0])
        self.assertArrayAlmostEqual(
                np.eye(3)*np.array([4.92080537, 4.2852349, -0.7147651]), ggt)
        # Get TGT
        tgt = self.exp_cu.get_tgt()
        self.assertArrayAlmostEqual(tgt, np.eye(3)*2.59631832)

        # Get heat capacity
        c0 = self.exp_cu.get_heat_capacity(0, self.cu, [1, 0, 0], [0, 1, 0])
        self.assertEqual(c0, 0.0)
        c = self.exp_cu.get_heat_capacity(300, self.cu, [1, 0, 0], [0, 1, 0])
        self.assertAlmostEqual(c, 8.285611958)

        # Get Gruneisen parameter
        gp = self.exp_cu.get_gruneisen_parameter()
        self.assertAlmostEqual(gp, 2.59631832)
        gpt = self.exp_cu.get_gruneisen_parameter(temperature=200, structure=self.cu)

    def test_thermal_expansion_coeff(self):
        #TODO get rid of duplicates
        alpha_dp = self.exp_cu.thermal_expansion_coeff(self.cu, 300,
                                                       mode="dulong-petit")
        alpha_debye = self.exp_cu.thermal_expansion_coeff(self.cu, 300,
                                                          mode="debye")
        alpha_comp = 5.9435148e-7 * np.ones((3, 3))
        alpha_comp[np.diag_indices(3)] = 21.4533472e-06
        self.assertArrayAlmostEqual(alpha_comp, alpha_debye)

    def test_get_compliance_expansion(self):
        ce_exp = self.exp_cu.get_compliance_expansion()
        et_comp = ElasticTensorExpansion(ce_exp)
        strain_orig = Strain.from_voigt([0.01, 0, 0, 0, 0, 0])
        stress = self.exp_cu.calculate_stress(strain_orig)
        strain_revert = et_comp.calculate_stress(stress)
        self.assertArrayAlmostEqual(strain_orig, strain_revert, decimal=4)

    def test_get_effective_ecs(self):
        # Ensure zero strain is same as SOEC
        test_zero = self.exp_cu.get_effective_ecs(np.zeros((3, 3)))
        self.assertArrayAlmostEqual(test_zero, self.exp_cu[0])
        s = np.zeros((3, 3))
        s[0, 0] = 0.02
        test_2percent = self.exp_cu.get_effective_ecs(s)
        diff = test_2percent - test_zero
        self.assertArrayAlmostEqual(self.exp_cu[1].einsum_sequence([s]), diff)

    def test_get_strain_from_stress(self):
        strain = Strain.from_voigt([0.05, 0, 0, 0, 0, 0])
        stress3 = self.exp_cu.calculate_stress(strain)
        strain_revert3 = self.exp_cu.get_strain_from_stress(stress3)
        self.assertArrayAlmostEqual(strain, strain_revert3, decimal=2)
        # fourth order
        stress4 = self.exp_cu_4.calculate_stress(strain)
        strain_revert4 = self.exp_cu_4.get_strain_from_stress(stress4)
        self.assertArrayAlmostEqual(strain, strain_revert4, decimal=2)

    def test_get_yield_stress(self):
        ys = self.exp_cu_4.get_yield_stress([1, 0, 0])