def transform_directions(dec_x, dec_y, dec_z, tilt_x, tilt_y, tilt_z, local_directions): """ Sequential local/global and back transformation yields original vector. """ 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_directions = system.returnLocalToGlobalDirections(local_directions) local_directions2 = system.returnGlobalToLocalDirections(global_directions) assert np.allclose(local_directions2 - local_directions, 0)
def directions_scalarproduct(dec_x, dec_y, dec_z, tilt_x, tilt_y, tilt_z, local1, local2): """ Two vectors have same scalar product in two 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) global1 = system.returnLocalToGlobalDirections(local1) global2 = system.returnLocalToGlobalDirections(local2) scalarproduct_local = np.einsum('i...,i...', local1, local2) scalarproduct_global = np.einsum('i...,i...', global1, global2) assert np.allclose(scalarproduct_local - scalarproduct_global, 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)