Exemplo n.º 1
0
 def test_zeroed(self):
     self.assertArrayEqual(
         self.low_val.zeroed(),
         TensorBase([[0, 1 + 1e-5, 0], [1 + 1e-6, 0, 0], [0, 0, 1 + 1e-5]]))
     self.assertArrayEqual(
         self.low_val.zeroed(tol=1e-6),
         TensorBase([[1e-6, 1 + 1e-5, 1e-6], [1 + 1e-6, 1e-6, 1e-6],
                     [0, 0, 1 + 1e-5]]))
     self.assertArrayEqual(
         TensorBase([[1e-6, -30, 1], [1e-7, 1, 0], [1e-8, 0, 1]]).zeroed(),
         TensorBase([[0, -30, 1], [0, 1, 0], [0, 0, 1]]))
Exemplo n.º 2
0
 def test_convert_to_ieee(self):
     for entry in self.ieee_data:
         xtal = entry['xtal']
         orig = TensorBase(entry['original_tensor'])
         ieee = TensorBase(entry['ieee_tensor'])
         struct = Structure.from_dict(entry['structure'])
         diff = np.max(abs(ieee - orig.convert_to_ieee(struct)))
         err_msg = "{} IEEE conversion failed with max diff {}".format(
             xtal, diff) 
         self.assertArrayAlmostEqual(ieee, orig.convert_to_ieee(struct),
                                     err_msg = err_msg, decimal=3)
Exemplo n.º 3
0
    def __new__(cls, input_array, tol=1e-3):
        """
        Create an ElasticTensor object.  The constructor throws an error if
        the shape of the input_matrix argument is not 3x3x3x3, i. e. in true
        tensor notation.  Issues a warning if the input_matrix argument does
        not satisfy standard symmetries.  Note that the constructor uses
        __new__ rather than __init__ according to the standard method of
        subclassing numpy ndarrays.

        Args:
            input_array (3x3x3x3 array-like): the 3x3x3x3 array-like
                representing the elastic tensor

            tol (float): tolerance for initial symmetry test of tensor
        """

        obj = TensorBase(input_array).view(cls)
        if obj.shape != (3, 3, 3, 3):
            raise ValueError("Default elastic tensor constructor requires "
                             "input to be the true 3x3x3x3 representation. "
                             "To construct from an elastic tensor from "
                             "6x6 Voigt array, use ElasticTensor.from_voigt")

        if not ((obj - np.transpose(obj, (1, 0, 2, 3)) < tol).all() and
                (obj - np.transpose(obj, (0, 1, 3, 2)) < tol).all() and
                (obj - np.transpose(obj, (1, 0, 3, 2)) < tol).all() and
                (obj - np.transpose(obj, (3, 2, 0, 1)) < tol).all()):
            warnings.warn("Input elasticity tensor does "
                          "not satisfy standard symmetries")

        return obj
Exemplo n.º 4
0
    def test_transform(self):
        # Rank 3
        tensor = TensorBase(np.arange(0, 27).reshape(3, 3, 3))
        symm_op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, False,
                                                         [0, 0, 1])
        new_tensor = tensor.transform(symm_op)

        self.assertArrayAlmostEqual(
            new_tensor, [[[-0.871, -2.884, -1.928], [-2.152, -6.665, -4.196],
                          [-1.026, -2.830, -1.572]],
                         [[0.044, 1.531, 1.804], [4.263, 21.008, 17.928],
                          [5.170, 23.026, 18.722]],
                         [[1.679, 7.268, 5.821], [9.268, 38.321, 29.919],
                          [8.285, 33.651, 26.000]]], 3)
Exemplo n.º 5
0
    def __new__(cls, input_array, tol=1e-3):
        """
        Create an PiezoTensor object.  The constructor throws an error if
        the shape of the input_matrix argument is not 3x3x3, i. e. in true
        tensor notation. Note that the constructor uses __new__ rather than
        __init__ according to the standard method of subclassing numpy
        ndarrays.

        Args:
            input_matrix (3x3x3 array-like): the 3x6 array-like
                representing the piezo tensor
        """
        obj = TensorBase(input_array).view(cls)
        if obj.shape != (3, 3, 3):
            raise ValueError("Default piezo tensor constructor requires "
                             "input argument to be the true 3x3x3 "
                             "array.  To construct from a 3x6 array, use "
                             "PiezoTensor.from_voigt")
        if not (obj - np.transpose(obj, (0, 2, 1)) < tol).all():
            warnings.warn("Input piezo tensor does "
                          "not satisfy standard symmetries")
        return obj
Exemplo n.º 6
0
    def setUp(self):
        self.vec = TensorBase([1., 0., 0.])
        self.rand_rank2 = TensorBase(np.random.randn(3, 3))
        self.rand_rank3 = TensorBase(np.random.randn(3, 3, 3))
        self.rand_rank4 = TensorBase(np.random.randn(3, 3, 3, 3))
        a = 3.14 * 42.5 / 180
        self.non_symm = SquareTensor([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6],
                                      [0.2, 0.5, 0.5]])
        self.rotation = SquareTensor([[math.cos(a), 0,
                                       math.sin(a)], [0, 1, 0],
                                      [-math.sin(a), 0,
                                       math.cos(a)]])
        self.low_val = TensorBase([[1e-6, 1 + 1e-5, 1e-6],
                                   [1 + 1e-6, 1e-6, 1e-6],
                                   [1e-7, 1e-7, 1 + 1e-5]])
        self.symm_rank2 = TensorBase([[1, 2, 3], [2, 4, 5], [3, 5, 6]])
        self.symm_rank3 = TensorBase([[[1, 2, 3], [2, 4, 5], [3, 5, 6]],
                                      [[2, 4, 5], [4, 7, 8], [5, 8, 9]],
                                      [[3, 5, 6], [5, 8, 9], [6, 9, 10]]])
        self.symm_rank4 = TensorBase([[[[1.2, 0.4, -0.92], [0.4, 0.05, 0.11],
                                        [-0.92, 0.11, -0.02]],
                                       [[0.4, 0.05, 0.11], [0.05, -0.47, 0.09],
                                        [0.11, 0.09, -0.]],
                                       [[-0.92, 0.11, -0.02], [0.11, 0.09, 0.],
                                        [-0.02, 0., -0.3]]],
                                      [[[0.4, 0.05, 0.11], [0.05, -0.47, 0.09],
                                        [0.11, 0.09, 0.]],
                                       [[0.05, -0.47,
                                         0.09], [-0.47, 0.17, 0.62],
                                        [0.09, 0.62, 0.3]],
                                       [[0.11, 0.09, 0.], [0.09, 0.62, 0.3],
                                        [0., 0.3, -0.18]]],
                                      [[[-0.92, 0.11, -0.02], [0.11, 0.09, 0.],
                                        [-0.02, 0, -0.3]],
                                       [[0.11, 0.09, 0.], [0.09, 0.62, 0.3],
                                        [0., 0.3, -0.18]],
                                       [[-0.02, 0., -0.3], [0., 0.3, -0.18],
                                        [-0.3, -0.18, -0.51]]]])

        # Structural symmetries tested using BaNiO3 piezo/elastic tensors
        self.fit_r3 = TensorBase([[[0., 0., 0.03839], [0., 0., 0.],
                                   [0.03839, 0., 0.]],
                                  [[0., 0., 0.], [0., 0., 0.03839],
                                   [0., 0.03839, 0.]],
                                  [[6.89822, 0., 0.], [0., 6.89822, 0.],
                                   [0., 0., 27.4628]]])
        self.fit_r4 = TensorBase([[[[157.9, 0., 0.], [0., 63.1, 0.],
                                    [0., 0., 29.4]],
                                   [[0., 47.4, 0.], [47.4, 0., 0.],
                                    [0., 0., 0.]],
                                   [[0., 0., 4.3], [0., 0., 0.], [4.3, 0.,
                                                                  0.]]],
                                  [[[0., 47.4, 0.], [47.4, 0., 0.],
                                    [0., 0., 0.]],
                                   [[63.1, 0., 0.], [0., 157.9, 0.],
                                    [0., 0., 29.4]],
                                   [[0., 0., 0.], [0., 0., 4.3], [0., 4.3,
                                                                  0.]]],
                                  [[[0., 0., 4.3], [0., 0., 0.], [4.3, 0.,
                                                                  0.]],
                                   [[0., 0., 0.], [0., 0., 4.3], [0., 4.3,
                                                                  0.]],
                                   [[29.4, 0., 0.], [0., 29.4, 0.],
                                    [0., 0., 207.6]]]])

        self.unfit4 = TensorBase([[[[161.26, 0., 0.], [0., 62.76, 0.],
                                    [0., 0., 30.18]],
                                   [[0., 47.08, 0.], [47.08, 0., 0.],
                                    [0., 0., 0.]],
                                   [[0., 0., 4.23], [0., 0., 0.],
                                    [4.23, 0., 0.]]],
                                  [[[0., 47.08, 0.], [47.08, 0., 0.],
                                    [0., 0., 0.]],
                                   [[62.76, 0., 0.], [0., 155.28, -0.06],
                                    [0., -0.06, 28.53]],
                                   [[0., 0., 0.], [0., -0.06, 4.44],
                                    [0., 4.44, 0.]]],
                                  [[[0., 0., 4.23], [0., 0., 0.],
                                    [4.23, 0., 0.]],
                                   [[0., 0., 0.], [0., -0.06, 4.44],
                                    [0., 4.44, 0.]],
                                   [[30.18, 0., 0.], [0., 28.53, 0.],
                                    [0., 0., 207.57]]]])

        self.structure = self.get_structure('BaNiO3')
        ieee_file_path = os.path.join(test_dir, "ieee_conversion_data.json")
        with open(ieee_file_path) as f:
            self.ieee_data = json.load(f)
Exemplo n.º 7
0
 def test_convert_to_ieee(self):
     for xtal in self.ieee_data.keys():
         orig = TensorBase(self.ieee_data[xtal]['original_tensor'])
         ieee = TensorBase(self.ieee_data[xtal]['ieee_tensor'])
         struct = Structure.from_dict(self.ieee_data[xtal]['structure'])
         self.assertArrayAlmostEqual(ieee, orig.convert_to_ieee(struct))