def tensors_scalarproduct(dec_x, dec_y, dec_z, tilt_x, tilt_y, tilt_z, directions1, directions2, tensor1, tensor2): """ Vectors/tensors have same contractions in different coordinate systems. """ system = LocalCoordinates(name="1", decx=100.*(2.*dec_x-1.), decy=100.*(2.*dec_y-1.), decz=100.*(2.*dec_z-1.), tiltx=2.*math.pi*tilt_x, tilty=2.*math.pi*tilt_y, tiltz=2.*math.pi*tilt_z) global_directions1 = system.returnLocalToGlobalDirections(directions1) global_directions2 = system.returnLocalToGlobalDirections(directions2) global_tensor1 = system.returnLocalToGlobalTensors(tensor1) global_tensor2 = system.returnLocalToGlobalTensors(tensor2) # check whether a transformation between coordinate # systems changes indeed the components # assert np.any(t1glob - t1loc != 0) FIXME: currently breaks # assert np.any(t2glob - t2loc != 0) FIXME: currently breaks # assert np.any(v1glob - v1loc != 0) FIXME: currently breaks # assert np.any(v2glob - v2loc != 0) FIXME: currently breaks # test trace of tensor assert np.allclose((np.trace(global_tensor1, axis1=0, axis2=1)- np.trace(tensor1, axis1=0, axis2=1)), 0) # test t1 t2 tensor contraction assert np.allclose((np.einsum('ij...,ij...', global_tensor1, global_tensor2)- np.einsum('ij...,ij...', tensor1, tensor2)), 0) # test v1 t1 v2 assert np.allclose((np.einsum('i...,ij...,j...', global_directions1, global_tensor1, global_directions2)- np.einsum('i...,ij...,j...', directions1, tensor1, directions2)), 0) # test v1 t1 t2 v2 assert np.allclose((np.einsum('i...,ij...,jk...,k...', global_directions1, global_tensor1, global_tensor2, global_directions2)- np.einsum('i...,ij...,jk...,k...', directions1, tensor1, tensor2, directions2)), 0)
def transform_tensors(dec_x, dec_y, dec_z, tilt_x, tilt_y, tilt_z, local_tensor): """ Sequential local/global and back transformation yields original tensor. """ system = LocalCoordinates(name="1", decx=100. * (2. * dec_x - 1.), decy=100. * (2. * dec_y - 1.), decz=100. * (2. * dec_z - 1.), tiltx=2. * math.pi * tilt_x, tilty=2. * math.pi * tilt_y, tiltz=2. * math.pi * tilt_z) global_tensor = system.returnLocalToGlobalTensors(local_tensor) local_tensor2 = system.returnGlobalToLocalTensors(global_tensor) assert np.allclose(local_tensor2 - local_tensor, 0)
def transform_tensors(dec_x, dec_y, dec_z, tilt_x, tilt_y, tilt_z, local_tensor): """ Sequential local/global and back transformation yields original tensor. """ system = LocalCoordinates(name="1", decx=100.*(2.*dec_x-1.), decy=100.*(2.*dec_y-1.), decz=100.*(2.*dec_z-1.), tiltx=2.*math.pi*tilt_x, tilty=2.*math.pi*tilt_y, tiltz=2.*math.pi*tilt_z) global_tensor = system.returnLocalToGlobalTensors(local_tensor) local_tensor2 = system.returnGlobalToLocalTensors(global_tensor) assert np.allclose(local_tensor2-local_tensor, 0)
def tensors_scalarproduct(dec_x, dec_y, dec_z, tilt_x, tilt_y, tilt_z, directions1, directions2, tensor1, tensor2): """ Vectors/tensors have same contractions in different coordinate systems. """ system = LocalCoordinates(name="1", decx=100. * (2. * dec_x - 1.), decy=100. * (2. * dec_y - 1.), decz=100. * (2. * dec_z - 1.), tiltx=2. * math.pi * tilt_x, tilty=2. * math.pi * tilt_y, tiltz=2. * math.pi * tilt_z) global_directions1 = system.returnLocalToGlobalDirections(directions1) global_directions2 = system.returnLocalToGlobalDirections(directions2) global_tensor1 = system.returnLocalToGlobalTensors(tensor1) global_tensor2 = system.returnLocalToGlobalTensors(tensor2) # check whether a transformation between coordinate # systems changes indeed the components # assert np.any(t1glob - t1loc != 0) FIXME: currently breaks # assert np.any(t2glob - t2loc != 0) FIXME: currently breaks # assert np.any(v1glob - v1loc != 0) FIXME: currently breaks # assert np.any(v2glob - v2loc != 0) FIXME: currently breaks # test trace of tensor assert np.allclose((np.trace(global_tensor1, axis1=0, axis2=1) - np.trace(tensor1, axis1=0, axis2=1)), 0) # test t1 t2 tensor contraction assert np.allclose( (np.einsum('ij...,ij...', global_tensor1, global_tensor2) - np.einsum('ij...,ij...', tensor1, tensor2)), 0) # test v1 t1 v2 assert np.allclose( (np.einsum('i...,ij...,j...', global_directions1, global_tensor1, global_directions2) - np.einsum('i...,ij...,j...', directions1, tensor1, directions2)), 0) # test v1 t1 t2 v2 assert np.allclose( (np.einsum('i...,ij...,jk...,k...', global_directions1, global_tensor1, global_tensor2, global_directions2) - np.einsum('i...,ij...,jk...,k...', directions1, tensor1, tensor2, directions2)), 0)